Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import Globals
- from Products.ZenUtils.ZenScriptBase import ZenScriptBase
- from transaction import commit
- dmd = ZenScriptBase(connect=True, noopts=True).dmd
- from Products.ZenUtils import Time
- import re
- import sys
- from optparse import OptionParser
- parser = OptionParser()
- parser.add_option("-s", "--start-date", dest="startDate",
- help="Select Start Date [MM/DD/YYYY]", metavar="StartDate")
- parser.add_option("-e", "--end-date", dest="endDate",
- help="Select End Date [MM/DD/YYYY]", metavar="EndDate")
- parser.add_option("-c", "--consolidation", dest="how", default="AVERAGE",
- help="Select consolidation [MINIMUM, AVERAGE, MAXIMUM]", metavar="FUNCTION")
- parser.add_option("-y", "--epoch-start", dest="startDateEpoch",
- help="Select start time in seconds", metavar="SECONDS")
- parser.add_option("-z", "--epoch-end", dest="endDateEpoch",
- help="Select end time in seconds", metavar="SECONDS")
- (options, args) = parser.parse_args()
- if not options.startDate and not options.endDate and not options.startDateEpoch and not options.endDateEpoch:
- parser.print_help()
- sys.exit()
- how = options.how
- if not options.startDateEpoch and not options.endDateEpoch:
- if options.startDate and options.endDate:
- startDate = options.startDate
- endDate = options.endDate
- startDate, endDate = map(Time.ParseUSDate, (startDate, endDate))
- startDate = min(startDate, endDate - 1)
- else:
- print "Start and end options need to be used in conjunction with each other."
- sys.exit()
- else:
- if options.startDateEpoch and options.endDateEpoch:
- startDate = options.startDateEpoch
- endDate = options.endDateEpoch
- else:
- print "Start and end options need to be used in conjunction with each other."
- sys.exit()
- print "Device,Interface,Speed,Input,Output,Total,% Util"
- def percent(partial, total):
- if partial is None or total is None:
- return None
- if not total:
- return None
- return partial * 100 / total
- for d in dmd.Devices.getSubDevices():
- isLocal = re.compile(d.zLocalInterfaceNames)
- for i in d.os.interfaces():
- percentUsed = 0
- if isLocal.match(i.name()): continue
- if not i.monitored(): continue
- if i.snmpIgnore(): continue
- if not i.speed: continue
- total = None
- results = i.getRRDValues(['ifHCInOctets',
- 'ifInOctets',
- 'ifOutOctets',
- 'ifHCOutOctets'],
- start=startDate, end=endDate, function=how)
- input = results.get('ifHCInOctets',
- results.get('ifInOctets', None))
- output = results.get('ifHCOutOctets',
- results.get('ifOutOctets', None))
- if None not in [input, output]:
- total = input + output
- if total and i.speed:
- percentUsed = percent(total, i.speed / 8)
- percentUsed = round(percentUsed, 2)
- print "%s,%s,%s,%s,%s,%s,%s" % (d.id, i.id, i.speed, input, output, total, percentUsed)
Advertisement
Add Comment
Please, Sign In to add comment