############## ## Main ## ############### if __name__ == '__main__': # The default return value should be always OK helper.status(ok) # shows the list of possible types if the flag is set if flag_list == True: for w, v in zip(names, descriptions): print w + ' = ' + v helper.status(unknown) helper.exit(summary='This is just a list and not a check!') # verify that a hostname is set verify_host(host, helper) # open session after validated host sess = netsnmp.Session(Version=version, DestHost=host, Community=community) # verify, that status(/type) parameter is not empty if (status == None) or (status not in names): helper.status(unknown) helper.exit(summary='Argument -t is missing or false!') # snmp gets for all oids in type-list ind = names.index(status) value = get_data(sess, basicoid + oid[ind], helper) # metric compares helper.add_metric(label='type',
return a_helper if __name__ == "__main__": a_helper = setup_plugin_helper() secname, seclevel, authproto, authpass, privproto, privpass = a_helper.options.secname, \ a_helper.options.seclevel, \ a_helper.options.authproto, \ a_helper.options.authpass, \ a_helper.options.privproto, \ a_helper.options.privpass host, version, community = snmpSessionBaseClass.get_common_options(a_helper) snmpSessionBaseClass.verify_host(host, a_helper) verify_type(a_helper.options.type, a_helper) snmp_session = netsnmp.Session(Version=version, DestHost=host, SecLevel=seclevel, SecName=secname, AuthProto=authproto, AuthPass=authpass, PrivProto=privproto, PrivPass=privpass, Community=community) # The default return value should be always OK a_helper.status(pynag.Plugins.ok) eaton_check = eaton_check_configs[a_helper.options.type]["check"] eaton_oid = eaton_check_configs[a_helper.options.type]["oid"] allow_empty = eaton_check_configs[a_helper.options.type].get("allow_snmp_empty", False) a_snmp_value = snmpSessionBaseClass.walk_data(snmp_session, eaton_oid, a_helper)[0][0] eaton_check(snmp_session, a_helper, a_snmp_value)
if __name__ == "__main__": a_helper = setup_plugin_helper() secname, seclevel, authproto, authpass, privproto, privpass = a_helper.options.secname, \ a_helper.options.seclevel, \ a_helper.options.authproto, \ a_helper.options.authpass, \ a_helper.options.privproto, \ a_helper.options.privpass host, version, community = snmpSessionBaseClass.get_common_options( a_helper) snmpSessionBaseClass.verify_host(host, a_helper) verify_type(a_helper.options.type, a_helper) snmp_session = netsnmp.Session(Version=version, DestHost=host, SecLevel=seclevel, SecName=secname, AuthProto=authproto, AuthPass=authpass, PrivProto=privproto, PrivPass=privpass, Community=community) # The default return value should be always OK a_helper.status(pynag.Plugins.ok)
""" calculate the correct OID for the service name """ s = service_name # convert the service_name to ascci service_ascii = [ord(c) for c in s] # we need the length of the service name length = str(len(s)) # make the oid oid = base_oid + "." + length + "." + ".".join(str(x) for x in service_ascii) return oid if __name__ == "__main__": # verify that a hostname is set verify_host(host, helper) sess = netsnmp.Session(Version=version, DestHost=host, Community=community) # The default return value should be always OK helper.status(ok) # if no partition / disk is set, we will do a scan if service == "" or service is None: scan = True ########## # Here we do a scan ########## if scan:
a_helper.parser.add_option('-t', '--type', dest='type', help = "Check type to execute. Available types are: {}".format( ", ".join(apc_check_configs.keys())), type='str') a_helper.parser.add_option('-c', '--critical', dest='critical', help='Critical thresholds in Icinga range format.', type='str') a_helper.parser.add_option('-w', '--warning', dest='warning', help='Warning thresholds in Icinga range format.', type='str') a_helper.parse_arguments() return a_helper if __name__ == "__main__": a_helper = setup_plugin_helper() snmpSessionBaseClass.verify_host(a_helper.options.hostname, a_helper) verify_type(a_helper.options.type, a_helper) snmp_session = netsnmp.Session( Version=a_helper.options.version, DestHost=a_helper.options.hostname, Community=a_helper.options.community) # The default return value should be always OK a_helper.status(pynag.Plugins.ok) apc_check = apc_check_configs[a_helper.options.type]["check"] apc_oid = apc_check_configs[a_helper.options.type]["oid"] a_snmp_value = snmpSessionBaseClass.get_data(snmp_session, apc_oid, a_helper) apc_check(snmp_session, a_helper, a_snmp_value)