bundles/vmhost: add QEMU VM STATUS check
Some checks failed
bundlewrap/pipeline/head There was a failure building this commit
Some checks failed
bundlewrap/pipeline/head There was a failure building this commit
This commit is contained in:
parent
325f483a26
commit
5639da4954
3 changed files with 61 additions and 0 deletions
47
bundles/vmhost/files/check_vm_status
Normal file
47
bundles/vmhost/files/check_vm_status
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from subprocess import check_output
|
||||||
|
from sys import exit
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = check_output(['virsh', '--readonly', 'list', '--all']).decode('utf-8').split('\n')
|
||||||
|
except Exception as e:
|
||||||
|
# If something fails, this means libvirt is not responding. This is
|
||||||
|
# an error.
|
||||||
|
print(repr(e))
|
||||||
|
exit(2)
|
||||||
|
|
||||||
|
|
||||||
|
running = set()
|
||||||
|
stopped = set()
|
||||||
|
crashed = set()
|
||||||
|
|
||||||
|
for vm in result[2:]:
|
||||||
|
if vm.strip() == '':
|
||||||
|
continue
|
||||||
|
|
||||||
|
info = vm.split()
|
||||||
|
|
||||||
|
if info[2] in {'crashed', 'dying'}:
|
||||||
|
crashed.add('{}: {}'.format(info[1], info[2]))
|
||||||
|
elif info[2] in {'running'}:
|
||||||
|
running.add('{}: {}'.format(info[1], info[2]))
|
||||||
|
else:
|
||||||
|
stopped.add('{}: {}'.format(info[1], info[2]))
|
||||||
|
|
||||||
|
|
||||||
|
for vm in sorted(crashed):
|
||||||
|
print(vm)
|
||||||
|
|
||||||
|
for vm in sorted(stopped):
|
||||||
|
print(vm)
|
||||||
|
|
||||||
|
for vm in sorted(running):
|
||||||
|
print(vm)
|
||||||
|
|
||||||
|
if len(crashed) > 0:
|
||||||
|
exit(2)
|
||||||
|
elif len(stopped) > 0:
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
exit(0)
|
5
bundles/vmhost/items.py
Normal file
5
bundles/vmhost/items.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
files = {
|
||||||
|
'/usr/local/share/icinga/plugins/check_vm_status': {
|
||||||
|
'mode': '0755',
|
||||||
|
},
|
||||||
|
}
|
|
@ -7,4 +7,13 @@ defaults = {
|
||||||
'qemu-system-x86': {},
|
'qemu-system-x86': {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'icinga2_api': {
|
||||||
|
'vmhost': {
|
||||||
|
'services': {
|
||||||
|
'QEMU VM STATUS': {
|
||||||
|
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_vm_status',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue