Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
myapps:snmp-voice-stats [2021/01/12 15:39] – [Python script] gerardorourkemyapps:snmp-voice-stats [2025/03/12 11:00] (current) gerardorourke
Line 15: Line 15:
 <file python get-snmp-stats.py> <file python get-snmp-stats.py>
 # Author: Gerry O'Rourke # Author: Gerry O'Rourke
-# Jan 2021 +Version 1.1 - Jan 2021 
-# Version 1.1+# Version 1.2 - Mar 2025 - updated Fetch Function to handle tuple rather than iterator (due to changes in get getCmd)
  
 from pysnmp import hlapi from pysnmp import hlapi
Line 73: Line 73:
     for i in range(count):     for i in range(count):
         try:         try:
-            error_indication, error_status, error_index, var_binds = next(handler)+            # Since handler is a tuple, unpack it correctly 
 +            error_indication, error_status, error_index, var_binds = handler 
             if not error_indication and not error_status:             if not error_indication and not error_status:
                 items = {}                 items = {}
Line 81: Line 83:
             else:             else:
                 raise RuntimeError('Got SNMP error: {0}'.format(error_indication))                 raise RuntimeError('Got SNMP error: {0}'.format(error_indication))
-        except StopIteration+        except ValueError
-            break +            raise RuntimeError(f"Unexpected return structure from getCmd(): {handler}") 
-    return result    +    return result
    
    
Line 104: Line 106:
                       'Database=stats_db;'                       'Database=stats_db;'
                       'Trusted_Connection=yes;')                       'Trusted_Connection=yes;')
- +                       
 +#if using SQL auth instead of windows user (remove Trusted_Connection) 
 +#'UID=mysqluser;'  
 +#'PWD=password123!;')  
 +                       
 cursor = conn.cursor() cursor = conn.cursor()
 rows = cursor.execute('SELECT id, ip_address FROM inventory WHERE (type = 1 OR type = 2) AND disabled = \'N\'') rows = cursor.execute('SELECT id, ip_address FROM inventory WHERE (type = 1 OR type = 2) AND disabled = \'N\'')
  • myapps/snmp-voice-stats.1610465977.txt.gz
  • Last modified: 2021/01/12 15:39
  • by gerardorourke