def parse_args(self, *args, **kwargs): """Parse SNMP plugin arguments Initialize plugin arguments, requiring valid SNMP session settings As a side effect, self.client() is set to SNMP session. """ args = NagiosPlugin.parse_args(self, *args, **kwargs) if not args.v1 and not args.v2c and not args.v3: self.error('SNMP version not specified') if args.v1 or args.v2c: if args.username or args.auth_pass or args.priv_pass: self.error('Incompatible SNMP arguments') elif args.v3 and args.community: self.error('Incompatible SNMP arguments') if args.v1: if args.community is None: self.error('SNMP v1 requires community') auth = SNMPv1Auth(args.community) elif args.v2c: if args.community is None: self.error('SNMP v2c requires community') auth = SNMPv2cAuth(args.community) elif args.v3: if not args.username and not args.auth_pass: self.error( 'SNMP v3 requires username and authentication password') auth = SNMPv3Auth(args.username, args.auth_pass, args.priv_pass, args.auth_protocol, args.priv_protocol) self.client = SNMPClient(address=args.host, auth=auth) return args
def parse_args(self, *args, **kwargs): """Parse SNMP plugin arguments Initialize plugin arguments, requiring valid SNMP session settings As a side effect, self.client() is set to SNMP session. """ args = NagiosPlugin.parse_args(self, *args, **kwargs) if not args.v1 and not args.v2c and not args.v3: self.error('SNMP version not specified') if args.v1 or args.v2c: if args.username or args.auth_pass or args.priv_pass: self.error('Incompatible SNMP arguments') elif args.v3 and args.community: self.error('Incompatible SNMP arguments') if args.v1: if args.community is None: self.error('SNMP v1 requires community') auth = SNMPv1Auth(args.community) elif args.v2c: if args.community is None: self.error('SNMP v2c requires community') auth = SNMPv2cAuth(args.community) elif args.v3: if not args.username and not args.auth_pass: self.error('SNMP v3 requires username and authentication password') auth = SNMPv3Auth(args.username, args.auth_pass, args.priv_pass, args.auth_protocol, args.priv_protocol ) self.client = SNMPClient(address=args.host, auth=auth) return args
def __init__(self, *args, **kwargs): SNMPClient.__init__(self, oid_map=NETWORK_OIDS_MAP, *args, **kwargs)
def __init__(self, oid_map=PROCESS_OIDS_MAP, *args, **kwargs): SNMPClient.__init__(self, oid_map=PROCESS_OIDS_MAP, *args, **kwargs)
def __init__(self,*args,**kwargs): SNMPClient.__init__(self,oid_map=NETWORK_OIDS_MAP,*args,**kwargs)
def __init__(self,oid_map=PROCESS_OIDS_MAP,*args,**kwargs): SNMPClient.__init__(self,oid_map=PROCESS_OIDS_MAP,*args,**kwargs)
class NagiosSNMPPlugin(NagiosPlugin): """Nagios SNMP check plugin wrapper Class to implement plugins which use SNMP to check check_plugin_status Instance of seine.snmp.client.SNMPClient is available to check_plugin_status with provided credentials. """ def __init__(self, description=None): NagiosPlugin.__init__(self, description=description) self.client = None self.add_argument('-H', '--host', required=True, help='SNMP host to contact') self.add_argument('-1', '--v1', action='store_true', help='Use SNMP V1') self.add_argument('-2', '--v2c', action='store_true', help='Use SNMP V2') self.add_argument('-3', '--v3', action='store_true', help='Use SNMP V3') self.add_argument('-C', '--community', help='SNMP community for SNMP v1 / v2') self.add_argument('--username', help='SNMP username for SNMP v3') self.add_argument('--auth-pass', help='SNMP authentication password for SNMP v3') self.add_argument('--priv-pass', help='SNMP privacy password for SNMP v3') self.add_argument('--auth-protocol', help='SNMP v3 authentication protocol') self.add_argument('--priv-protocol', help='SNMP v3 privacy protocol') def parse_args(self, *args, **kwargs): """Parse SNMP plugin arguments Initialize plugin arguments, requiring valid SNMP session settings As a side effect, self.client() is set to SNMP session. """ args = NagiosPlugin.parse_args(self, *args, **kwargs) if not args.v1 and not args.v2c and not args.v3: self.error('SNMP version not specified') if args.v1 or args.v2c: if args.username or args.auth_pass or args.priv_pass: self.error('Incompatible SNMP arguments') elif args.v3 and args.community: self.error('Incompatible SNMP arguments') if args.v1: if args.community is None: self.error('SNMP v1 requires community') auth = SNMPv1Auth(args.community) elif args.v2c: if args.community is None: self.error('SNMP v2c requires community') auth = SNMPv2cAuth(args.community) elif args.v3: if not args.username and not args.auth_pass: self.error('SNMP v3 requires username and authentication password') auth = SNMPv3Auth(args.username, args.auth_pass, args.priv_pass, args.auth_protocol, args.priv_protocol ) self.client = SNMPClient(address=args.host, auth=auth) return args def check_plugin_status_example(self): """Example SNMP GET plugin test Example SNMP GET test: receives sysDescr (1.3.6.1.2.1.1.1.0) from host, splits result and returns second field """ oid = '.1.3.6.1.2.1.1.1.0' try: res = self.client.get(oid) except SNMPError, emsg: raise NagiosPluginError('ERROR reading OID {0}: {1}'.format(oid, emsg)) try: value = '{0}'.format(res[1]) self.message += value.split()[2] self.state = 'OK' except IndexError: raise NagiosPluginError('Error splitting SNMP GET result {0}'.format(res[1]))
int(float(details[i]['level']) / float(details[i]['max']) * 100), }) for i in details.keys()) def reset(self, resettype=DEFAULT_RESET_TYPE): try: resettype = rfc1902.Integer(RESET_TYPE_MAP[resettype]) except KeyError: raise ValueError('Invalid reset type: %s' % resettype) oid = PRINTER_MIB_OID + '.5.1.1.3.1' return self.client.set(oid, resettype) def testpage(self, pagetype=DEFAULT_TESTPAGE): try: pagetype = rfc1902.Integer(TESTPAGE_MAP[pagetype]) except KeyError: raise ValueError('Invalid testpage type: %s' % pagetype) oid = HP_LASERJET_MIB_OID + '.4.2.1.1.5.2.0' return self.client.set(oid, pagetype) if __name__ == '__main__': import sys ljclient = LaserjetSNMPControl( SNMPClient(sys.argv[1], SNMPv1Auth(community=sys.argv[2]))) #ljclient.client.logger.set_level('DEBUG') #for k in sorted(HP_PRINTER_OID_MAP.keys()): print k, getattr(ljclient,k) for color, details in ljclient.supply_level_details().items(): print '%12s %s %%' % (color, details['percent'])
class NagiosSNMPPlugin(NagiosPlugin): """Nagios SNMP check plugin wrapper Class to implement plugins which use SNMP to check check_plugin_status Instance of seine.snmp.client.SNMPClient is available to check_plugin_status with provided credentials. """ def __init__(self, description=None): NagiosPlugin.__init__(self, description=description) self.client = None self.add_argument('-H', '--host', required=True, help='SNMP host to contact') self.add_argument('-1', '--v1', action='store_true', help='Use SNMP V1') self.add_argument('-2', '--v2c', action='store_true', help='Use SNMP V2') self.add_argument('-3', '--v3', action='store_true', help='Use SNMP V3') self.add_argument('-C', '--community', help='SNMP community for SNMP v1 / v2') self.add_argument('--username', help='SNMP username for SNMP v3') self.add_argument('--auth-pass', help='SNMP authentication password for SNMP v3') self.add_argument('--priv-pass', help='SNMP privacy password for SNMP v3') self.add_argument('--auth-protocol', help='SNMP v3 authentication protocol') self.add_argument('--priv-protocol', help='SNMP v3 privacy protocol') def parse_args(self, *args, **kwargs): """Parse SNMP plugin arguments Initialize plugin arguments, requiring valid SNMP session settings As a side effect, self.client() is set to SNMP session. """ args = NagiosPlugin.parse_args(self, *args, **kwargs) if not args.v1 and not args.v2c and not args.v3: self.error('SNMP version not specified') if args.v1 or args.v2c: if args.username or args.auth_pass or args.priv_pass: self.error('Incompatible SNMP arguments') elif args.v3 and args.community: self.error('Incompatible SNMP arguments') if args.v1: if args.community is None: self.error('SNMP v1 requires community') auth = SNMPv1Auth(args.community) elif args.v2c: if args.community is None: self.error('SNMP v2c requires community') auth = SNMPv2cAuth(args.community) elif args.v3: if not args.username and not args.auth_pass: self.error( 'SNMP v3 requires username and authentication password') auth = SNMPv3Auth(args.username, args.auth_pass, args.priv_pass, args.auth_protocol, args.priv_protocol) self.client = SNMPClient(address=args.host, auth=auth) return args def check_plugin_status_example(self): """Example SNMP GET plugin test Example SNMP GET test: receives sysDescr (1.3.6.1.2.1.1.1.0) from host, splits result and returns second field """ oid = '.1.3.6.1.2.1.1.1.0' try: res = self.client.get(oid) except SNMPError, emsg: raise NagiosPluginError('ERROR reading OID {0}: {1}'.format( oid, emsg)) try: value = '{0}'.format(res[1]) self.message += value.split()[2] self.state = 'OK' except IndexError: raise NagiosPluginError( 'Error splitting SNMP GET result {0}'.format(res[1]))