hostname = opts.hostname if not hostname: print "Error : hostname parameter (-H) is mandatory" sys.exit(2) ssh_key_file = opts.ssh_key_file or os.path.expanduser('~/.ssh/id_rsa') user = opts.user or 'shinken' passphrase = opts.passphrase or '' # Try to get numeic warning/critical values s_warning = opts.warning or DEFAULT_WARNING s_critical = opts.critical or DEFAULT_CRITICAL warning, critical = schecks.get_warn_crit(s_warning, s_critical) # Ok now connect, and try to get values for memory client = schecks.connect(hostname, ssh_key_file, passphrase, user) diff, stats = get_kernel_stats(client) # Maybe we failed at getting data if not stats: print "Error : cannot fetch cpu stats values from host" sys.exit(2) # We are putting diff into float so we are sure we will have float everywhere diff = float(diff) perfdata = [] for k in ['ctxt', 'processes', 'pgfault', 'pgmajfault']: v = stats[k] if len(v) < 2: # Ok maybe this value just disapears or pop up, not a problem
parser.error("Does not accept any argument.") port = opts.port hostname = opts.hostname or '' ssh_key_file = opts.ssh_key_file or os.path.expanduser('~/.ssh/id_rsa') user = opts.user or 'shinken' passphrase = opts.passphrase or '' # Try to get numeic warning/critical values s_warning = opts.warning or DEFAULT_WARNING s_critical = opts.critical or DEFAULT_CRITICAL warning, critical = schecks.get_warn_crit(s_warning, s_critical) # Ok now connect, and try to get values for memory client = schecks.connect(hostname, port, ssh_key_file, passphrase, user) total, used, free, shared, buffed, cached, swap_total, swap_used, swap_free = get_meminfo( client) # Maybe we failed at getting data if total == 0: print "Error : cannot fetch memory values from host" sys.exit(2) # Ok analyse data pct_used = 100 * float(used - buffed - cached) / total pct_used = int(pct_used) d = { 'used': used, 'buffered': buffed,
if __name__ == '__main__': # first parse arguments opts, args = parser.parse_args() if args: parser.error("Does not accept any argument.") hostname = opts.hostname or "" port = opts.port sshKeyFile = opts.sshKeyFile or os.path.expanduser("~/.ssh/id_rsa") user = opts.user or "shinken" passPhrase = opts.passPhrase or "" kaExpectedState = opts.kaExpectedState or "master" critical = opts.critical or defaultCritical # now, connect to the target and try to get the values client = schecks.connect(hostname, port, sshKeyFile, passPhrase, user) kaCurrentRole = getRoleKa(client) if kaCurrentRole == critical: print("Critical: expected role was {}, but the current is {}.".format( kaExpectedState, kaCurrentRole)) sys.exit(2) elif kaCurrentRole == kaExpectedState: print("OK: the expected role was {}, and the current is {}.".format( kaExpectedState, kaCurrentRole)) sys.exit(0) else: print( "Unknown: SNMP or KA isn't running and I can't get the current role. Or maybe it is in fault state." ) sys.exit(3)