Host hosts in Cloudstack for some reason the status is not up, and you want Nagios to monitor this state through Cloudmonkey, as follows:
#!/usr/bin/python#desc: this script is to check the status of hosts in cloudstack# can use -h to show Usageimport os,sysimport jsonfrom optparse import optionparsere_ok = 0e_ warning = 1e_critical = 2e_unknown = 3e_code = e_okparser = Optionparser () parser.add_option ("-I", "--ignore", dest= "Ignore", help= "ipaddress that ignore to check ") (Options,args) = parser.parse_args () comm = '/usr/bin/ Cloudmonkey -d json list hosts type=routing filter=ipaddress,state ' performance = ' info = ' Host_info = os.popen (comm). Read () Host_json = json.loads ( Host_info) [' Host ']if options.ignore:for item in host_json:if not item[' IPAddress '] in options.ignore and item[' state '] != ' up ':info += '%s : %s ' % (item[' IPAddress '],item[' state ') e_code = e_criticalelse:for item in host_json: if item[' state '] != ' Up ': info += '%s:%s; ' % (item[' IPAddress '],item[' state ') e_code = e_criticalif e_code = = e_ok :p erformance += ' OK ' elif e_code == e_warning: performance = ' warning-' + infoelif e_code == E_CRITICAL:performance = ' critical-' + infoelse:performance = ' unknown-' + infoprint Performancesys.exit (E_code)
This article from "Month Child" blog, declined reprint!
Nagios monitors the status of Cloudstack hosts