-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_snapshots.py
69 lines (61 loc) · 1.97 KB
/
check_snapshots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
"""
"This script warns if snapshots are present and crits if they're almost full. This script is meant to be invoked by nagios/icinga."
REQUIREMENTS
This script requires python-argparse and is meant to be run on *nix-systems.
COPYRIGHT
Copyright 2013 - Kumina B.V./Natasja Kranendonk ([email protected]), this script is licensed under the GNU GPL version 3 or higher.
"""
#Import the classes needed
import argparse
from sys import exit
from os import popen
# Define and initialize global variables
exit_ok = 0
exit_warn = 1
exit_crit = 2
exit_err = 3
warn_msg = ""
crit_msg = ""
parser = argparse.ArgumentParser(description="This script warns if snapshots are present and crits if they're almost full. This script is meant to be invoked by nagios/icinga.")
parser.add_argument("-m", "--max_use", action="store", required=True, help="The maximum allowed use percentage.")
def quit(state):
print msg
exit(state)
def addToMsg(newString, message):
if message != "":
message += " | %s" % newString
else:
message += "%s" % newString
return message
# Script starts here...
args=parser.parse_args()
warn = crit = False
try:
p = popen("lvs --noheadings")
except:
msg = 'UNKNOWN: failed to run "lvs --noheadings"'
quit(exit_err)
while 1:
line = p.readline()
if not line:
break
something = line.split()
if len(something) > 4:
if float(something[5]) >= float(args.max_use):
crit = True
crit_msg = addToMsg('name:%s, origin:%s, in use:%s' % (something[0], something[4], something[5]), crit_msg)
else:
warn = True
warn_msg = addToMsg('name:%s, origin:%s, in use:%s' % (something[0], something[4], something[5]), warn_msg)
if crit:
msg = 'CRITICAL: %s' % crit_msg
if warn:
msg += ' | WARNING: %s' % warn_msg
quit(exit_crit)
elif warn:
msg = 'WARNING: %s' % warn_msg
quit(exit_warn)
else:
msg = 'OK: No snapshots found.'
quit(exit_ok)