#NEWLINE# def check( self , instance ) : #NEWLINE# #INDENT# '\n        Perform two series of SNMP requests, one for all that have MIB asociated\n        and should be looked up and one for those specified by oids\n        ' #NEWLINE# tags = instance . get ( 'tags' , [ ] ) #NEWLINE# ip_address = e [ 'ip_address' ] #NEWLINE# table_oids = [ ] #NEWLINE# raw_oids = [ ] #NEWLINE# timeout = int ( instance . get ( 'timeout' , self . DEFAULT_TIMEOUT ) ) #NEWLINE# retries = int ( instance . get ( 'retries' , self . DEFAULT_RETRIES ) ) #NEWLINE# for metric in instance . get ( 'metrics' , [ ] ) : #NEWLINE# #INDENT# if ( 'MIB' in metric ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# assert ( ( 'table' in metric ) or ( 'symbol' in metric ) ) #NEWLINE# to_query = metric . get ( 'table' , metric . get ( 'symbol' ) ) #NEWLINE# table_oids . append ( cmdgen . MibVariable ( metric [ 'MIB' ] , to_query ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# self . log . warning ( "Can't generate MIB object for variable : %s\nException: %s" , metric , e ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'OID' in metric ) : #NEWLINE# #INDENT# raw_oids . append ( metric [ 'OID' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( ( 'Unsupported metric in config file: %s' % metric ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# if table_oids : #NEWLINE# #INDENT# self . log . debug ( 'Querying device %s for %s oids' , ip_address , len ( table_oids ) ) #NEWLINE# table_results = self . check_table ( instance , table_oids , True , timeout , retries ) #NEWLINE# self . report_table_metrics ( instance , table_results ) #NEWLINE# #UNINDENT# if raw_oids : #NEWLINE# #INDENT# self . log . debug ( 'Querying device %s for %s oids' , ip_address , len ( raw_oids ) ) #NEWLINE# raw_results = self . check_table ( instance , raw_oids , False , timeout , retries ) #NEWLINE# self . report_raw_metrics ( instance , raw_results ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# if ( 'service_check_error' not in instance ) : #NEWLINE# #INDENT# instance [ 'service_check_error' ] = 'Fail to collect metrics: {0}' . format ( e ) #NEWLINE# #UNINDENT# raise #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# service_check_name = 'snmp.can_check' #NEWLINE# tags = [ ( 'snmp_device:%s' % ip_address ) ] #NEWLINE# if ( 'service_check_error' in instance ) : #NEWLINE# #INDENT# self . service_check ( service_check_name , AgentCheck . CRITICAL , tags = tags , message = instance [ 'service_check_error' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . service_check ( service_check_name , AgentCheck . OK , tags = tags )