Difference between revisions of "Using nxshell to automate bulk operations"
Jump to navigation
Jump to search
Using nxshell to automate bulk operations (view source)
Revision as of 15:47, 8 July 2013
, 15:47, 8 July 2013no edit summary
m (→Introduction) |
|||
Line 170: | Line 170: | ||
for alarm in session.getAlarms().values(): | for alarm in session.getAlarms().values(): | ||
print '%s (%d): %s' % (session.getObjectName(alarm.getSourceObjectId()), alarm.getCurrentSeverity(), alarm.getMessage()) | print '%s (%d): %s' % (session.getObjectName(alarm.getSourceObjectId()), alarm.getCurrentSeverity(), alarm.getMessage()) | ||
</syntaxhighlight> | |||
== Show all nodes with matching SNMP OID === | |||
OID mask is either passed as command line parameter, or hardcoded value used. | |||
<syntaxhighlight lang="python"> | |||
import sys | |||
from fnmatch import fnmatch | |||
if len(sys.argv) > 1: | |||
mask = sys.argv[1] | |||
else | |||
mask = ".1.3.*.0" | |||
nodes = filter(lambda x: isinstance(x, objects.Node), s.getAllObjects()) | |||
matched = filter(lambda x: fnmatch(x.getSnmpOID(), mask), nodes) | |||
for node in matched: | |||
print "% %s" (node.getObjectName(), node.getPrimaryIP().getHostAddress(), ) | |||
</syntaxhighlight> | </syntaxhighlight> |