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

# Source Code for Module Products.ZenReports.Utilization

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  from Products.ZenUtils import Time
    12
    13 -def getSummaryArgs(dmd, args):
    14      zem = dmd.ZenEventManager
    15      startDate = args.get('startDate', zem.defaultAvailabilityStart())
    16      endDate = args.get('endDate', zem.defaultAvailabilityEnd())
    17      startDate, endDate = map(Time.ParseUSDate, (startDate, endDate))
    18      endDate = Time.getEndOfDay(endDate)
    19      startDate = min(startDate, endDate - 24 * 60 * 60 + 1) # endDate - 23:59:59
    20      how = args.get('how', 'AVERAGE')
    21      return dict(start=startDate, end=endDate, function=how)
    22
    23 -def reversedSummary(summary):
    24      swapper = { 'MAXIMUM':'MINIMUM', 'MINIMUM':'MAXIMUM'}
    25      summary = summary.copy()
    26      current = summary['function']
    27      summary['function'] = swapper.get(current, current)
    28      return summary
    29
    30
    31 -def filteredDevices(dmd, args):
    32      import re
    33
    34      deviceFilter = args.get('deviceFilter', '') or ''
    35      deviceMatch = re.compile('.*%s.*' % deviceFilter)
    36
    37      # Fall back for backwards compatibility
    38      if 'deviceClass' in args:
    39          # deviceClass should always start with a '/'
    40          args['organizer'] = '/Devices' + args['deviceClass']
    41
    42      # Get organizer
    43      organizer = args.get('organizer', '/Devices') or '/Devices'
    44
    45      # Determine the root organizer
    46      try:
    47          root = dmd.getObjByPath(organizer.lstrip('/'))
    48      except KeyError:
    49          root = dmd.Devices # Show all if org not found
    50
    51      # Iterate all sub-organizers and devices
    52      for d in root.getSubDevices():
    53          if not d.monitorDevice(): continue
    54          if not deviceMatch.match(d.id): continue
    55          yield d
    56