def check_run_change(): run_change_current_d = {} run_change_update_d = {} file = '/var/tmp/run_change_data.pkl' # Grab current SNMP value from each device for device in routers_l: run_change_current = snmp_get_v3(device, oid_run_change) if run_change_current: # Update current dictionary with current data run_change_current_d[run_change_current[0]] = run_change_current[1] #print 'current value:', run_change_current_d else: print 'No SNMP value available for', device['hostname'] # Grab all recorded data run_change_last_d = read_run_change(file) if not run_change_last_d: run_change_last_d = {} # Look at current values for key, value in run_change_current_d.items(): print 'Working on {} : {}'.format(key, value) # if we have previously recorded values, compare with current # Check if our key is in the file results if key in run_change_last_d: print 'Comparing timestamps...current: {} vs last: {}'.format(value, run_change_last_d[key]) if value > run_change_last_d[key]: print 'The running config has been changed since last check, updating...' run_change_update_d[key] = value else: print 'The running config has not changed since last check, nothing to do.' run_change_update_d[key] = run_change_last_d[key] # We don't have recorded data for this device; add it. else: print 'No record for that one, adding it.' run_change_update_d[key] = value if not run_change_update_d == run_change_last_d: if write_run_change(file, run_change_update_d): print 'File updated.' else: print 'Error updating file.'
def check_run_change(): run_change_current_d = {} run_change_update_d = {} file = '/var/tmp/run_change_data.pkl' # Grab current SNMP value from each device for device in routers_l: run_change_current = snmp_get_v3(device, oid_run_change) if run_change_current: # Update current dictionary with current data run_change_current_d[run_change_current[0]] = run_change_current[1] #print 'current value:', run_change_current_d else: print 'No SNMP value available for', device['hostname'] # Grab all recorded data run_change_last_d = read_run_change(file) if not run_change_last_d: run_change_last_d = {} # Look at current values for key, value in run_change_current_d.items(): print 'Working on {} : {}'.format(key, value) # if we have previously recorded values, compare with current # Check if our key is in the file results if key in run_change_last_d: print 'Comparing timestamps...current: {} vs last: {}'.format( value, run_change_last_d[key]) if value > run_change_last_d[key]: print 'The running config has been changed since last check, updating...' run_change_update_d[key] = value else: print 'The running config has not changed since last check, nothing to do.' run_change_update_d[key] = run_change_last_d[key] # We don't have recorded data for this device; add it. else: print 'No record for that one, adding it.' run_change_update_d[key] = value if not run_change_update_d == run_change_last_d: if write_run_change(file, run_change_update_d): print 'File updated.' else: print 'Error updating file.'
def get_int_stats(router, stat, int_index): int_oids_d = { 'in_octets' : '1.3.6.1.2.1.2.2.1.10', 'out_octets' : '1.3.6.1.2.1.2.2.1.16', 'in_ucast_pkts' : '1.3.6.1.2.1.2.2.1.11', 'out_ucast_pkts' : '1.3.6.1.2.1.2.2.1.17' } if stat not in int_oids_d: print 'Invalid stat' return int_index = int(int_index) # Update stat dic with int_index oid = int_oids_d[stat] oid = '{}.{}'.format(oid, str(int_index)) print oid value = snmp_get_v3(router, oid, valueonly=True) return int(value)