Skip to content

Instantly share code, notes, and snippets.

@dougsyer
Forked from cluther/addMultiGraphReport.py
Created October 31, 2012 11:03
Show Gist options
  • Save dougsyer/3986465 to your computer and use it in GitHub Desktop.
Save dougsyer/3986465 to your computer and use it in GitHub Desktop.
Programatically Build a Multi-Graph Report
#!/usr/bin/env python
import sys
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
# Check command line options.
if len(sys.argv) < 2:
print >> sys.stderr, "Usage: %s <device>" % sys.argv[0]
sys.exit(1)
dmd = ZenScriptBase(connect=True).dmd
device = dmd.Devices.findDevice(sys.argv[1])
if not device:
print >> sys.stderr, "%s is not a valid device name." % sys.argv[1]
sys.exit(1)
# Create the multi-graph report.
mgrs = dmd.Reports.getOrganizer('/Multi-Graph Reports')
mgr = mgrs.manage_addMultiGraphReport('Interfaces - %s' % device.id)
# Create the collection of interfaces.
c = mgr.manage_addCollection('interfaces')
for iface in device.os.interfaces():
if iface.adminStatus > 1 or iface.monitor == False: continue
c.createCollectionItem(
devId=device.id, compPath='/'.join(iface.getPrimaryPath()[-3:]),
checkExists=True)
# Create the graph definition.
gd1 = mgr.manage_addGraphDefinition('Inbound Throughput')
gd1.units = 'bits/sec'
gd1.miny = 0
gps1 = gd1.manage_addDataPointGraphPoints(['ifInOctets_ifInOctets'])
gps1[0].rpn = '8,*'
gps1[0].lineType = 'AREA'
gps1[0].stacked = True
gps1[0].legend = '${here/name | here/id}'
gd2 = mgr.manage_addGraphDefinition('Outbound Throughput')
gd2.units = 'bits/sec'
gd2.miny = 0
gps2 = gd2.manage_addDataPointGraphPoints(['ifOutOctets_ifOutOctets'])
gps2[0].rpn = '8,*'
gps2[0].lineType = 'AREA'
gps2[0].stacked = True
gps2[0].legend = '${here/name | here/id}'
# Create the graph group.
gg1 = mgr.manage_addGraphGroup(
'Inbound Graph', 'interfaces', 'Inbound Throughput')
gg1.combineDevices = True
gg2 = mgr.manage_addGraphGroup(
'Outbound Graph', 'interfaces', 'Outbound Throughput')
gg2.combineDevices = True
# Commit changes to the database.
from transaction import commit
commit()
print "Added Multi-Graph Report: Interfaces - %s" % device.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment