forked from Sysnove/shinken-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_ganeti.py
executable file
·54 lines (42 loc) · 1.26 KB
/
check_ganeti.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4 nu
from __future__ import (unicode_literals, absolute_import,
division, print_function)
import subprocess
import sys
import re
# nagios exit code
STATUS_OK = 0
STATUS_WARNING = 1
STATUS_ERROR = 2
STATUS_UNKNOWN = 3
def main():
try:
p = subprocess.Popen(["/usr/sbin/gnt-cluster", "verify"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
except Exception as e:
print(e)
return STATUS_UNKNOWN
if err:
print(err.splitlines()[0])
return STATUS_UNKNOWN
ret_code = STATUS_OK
ret_out = []
for line in out.splitlines():
match = re.search('.* - (WARNING|ERROR): (.*)', line)
if match:
status = match.group(1)
msg = match.group(2)
if status == "WARNING":
ret_code = max(ret_code, STATUS_WARNING)
if status == "ERROR":
ret_code = max(ret_code, STATUS_ERROR)
ret_out.append('%s: %s' % (status, msg))
if ret_code == STATUS_OK:
print("Ganeti cluster is OK")
else:
print('\n'.join(ret_out))
return ret_code
if __name__ == "__main__":
sys.exit(main())