Package Products :: Package ZenReports :: Module Utilization |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenReports.Utilization

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2007, Zenoss Inc.
     5  #
     6  # This program is free software; you can redistribute it and/or modify it
     7  # under the terms of the GNU General Public License version 2 or (at your
     8  # option) any later version as published by the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13  from Products.ZenUtils import Time
    14
    15 -def getSummaryArgs(dmd, args):
    16      zem = dmd.ZenEventManager
    17      startDate = args.get('startDate', zem.defaultAvailabilityStart())
    18      endDate = args.get('endDate', zem.defaultAvailabilityEnd())
    19      startDate, endDate = map(Time.ParseUSDate, (startDate, endDate))
    20      endDate = Time.getEndOfDay(endDate)
    21      startDate = min(startDate, endDate - 24 * 60 * 60 + 1) # endDate - 23:59:59
    22      how = args.get('how', 'AVERAGE')
    23      return dict(start=startDate, end=endDate, function=how)
    24
    25 -def reversedSummary(summary):
    26      swapper = { 'MAXIMUM':'MINIMUM', 'MINIMUM':'MAXIMUM'}
    27      summary = summary.copy()
    28      current = summary['function']
    29      summary['function'] = swapper.get(current, current)
    30      return summary
    31
    32
    33 -def filteredDevices(dmd, args):
    34      import re
    35
    36      deviceFilter = args.get('deviceFilter', '') or ''
    37      deviceMatch = re.compile('.*%s.*' % deviceFilter)
    38
    39      # Fall back for backwards compatibility
    40      if 'deviceClass' in args:
    41          # deviceClass should always start with a '/'
    42          args['organizer'] = '/Devices' + args['deviceClass']
    43
    44      # Get organizer
    45      organizer = args.get('organizer', '/Devices') or '/Devices'
    46
    47      # Determine the root organizer
    48      try:
    49          root = dmd.getObjByPath(organizer.lstrip('/'))
    50      except KeyError:
    51          root = dmd.Devices # Show all if org not found
    52
    53      # Iterate all sub-organizers and devices
    54      for d in root.getSubDevices():
    55          if not d.monitorDevice(): continue
    56          if not deviceMatch.match(d.id): continue
    57          yield d
    58