Package Products :: Package ZenModel :: Module Location |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.Location

      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 as published by
      8  # the Free Software Foundation.
      9  #
     10  # For complete information please visit: http://www.zenoss.com/oss/
     11  #
     12  ###########################################################################
     13
     14  __doc__="""Location
     15
     16  $Id: Location.py,v 1.12 2004/04/22 19:08:47 edahl Exp $"""
     17
     18  __version__ = "$Revision: 1.12 $"[11:-2]
     19
     20  from Globals import InitializeClass
     21  from Globals import DTMLFile
     22
     23  from AccessControl import ClassSecurityInfo
     24
     25  from AccessControl import Permissions as permissions
     26
     27  from Products.ZenRelations.RelSchema import *
     28
     29  from DeviceOrganizer import DeviceOrganizer
     30  from ZenPackable import ZenPackable
     31
     32  from Products.ZenUtils.json import json
     33
     34 -def manage_addLocation(context, id, description = "",
     35                         address="", REQUEST = None):
     36      """make a Location"""
     37      loc = Location(id, description)
     38      context._setObject(id, loc)
     39      loc.description = description
     40      loc.address = address
     41      if REQUEST is not None:
     42          REQUEST['RESPONSE'].redirect(context.absolute_url() +'/manage_main')
     43
     44
     45  addLocation = DTMLFile('dtml/addLocation',globals())
     46
     47
     48 -class Location(DeviceOrganizer, ZenPackable):
     49      """
     50      Location is a DeviceGroup Organizer that manages physical device Locations.
     51      """
     52
     53      # Organizer configuration
     54      dmdRootName = "Locations"
     55
     56      address = ''
     57
     58      portal_type = meta_type = event_key = 'Location'
     59
     60      _properties = DeviceOrganizer._properties + (
     61          {'id':'address','type':'string','mode':'w'},
     62      )
     63
     64      _relations = DeviceOrganizer._relations + ZenPackable._relations + (
     65          ("devices", ToMany(ToOne,"Products.ZenModel.Device","location")),
     66          ("networks", ToMany(ToOne,"Products.ZenModel.IpNetwork","location")),
     67      )
     68
     69      # Screen action bindings (and tab definitions)
     70      factory_type_information = (
     71          {
     72              'immediate_view' : 'deviceOrganizerStatus',
     73              'actions'        :
     74              (
     75                  { 'id'            : 'status'
     76                  , 'name'          : 'Status'
     77                  , 'action'        : 'deviceOrganizerStatus'
     78                  , 'permissions'   : (permissions.view,)
     79                  },
     80                  { 'id'            : 'events'
     81                  , 'name'          : 'Events'
     82                  , 'action'        : 'viewEvents'
     83                  , 'permissions'   : (permissions.view,)
     84                  },
     85  #                { 'id'            : 'historyEvents'
     86  #                , 'name'          : 'History'
     87  #                , 'action'        : 'viewHistoryEvents'
     88  #                , 'permissions'   : (permissions.view,)
     89  #                },
     90                  { 'id'            : 'manage'
     91                  , 'name'          : 'Administration'
     92                  , 'action'        : 'deviceOrganizerManage'
     93                  , 'permissions'   : ('Manage DMD',)
     94                  },
     95                  { 'id'            : 'geomap'
     96                  , 'name'          : 'Map'
     97                  , 'action'        : 'locationGeoMap'
     98                  , 'permissions'   : (permissions.view,)
     99                  },
    100              )
    101           },
    102          )
    103
    104      security = ClassSecurityInfo()
    105
    106 -    def setAddress(self, address):
    107          """Sets the mailing address for this location"""
    108          self.address = address
    109
    110 -    def getChildLinks(self):
    111          """ Returns child link data ready for GMaps """
    112          return self.dmd.ZenLinkManager.getChildLinks(self)
    113
    114 -    def numMappableChildren(self):
    115          children = self.children()
    116          return len(
    117              filter(lambda x:getattr(x, 'address', None), children)
    118          )
    119
    120 -    def getGeomapData(self):
    121          """
    122          Gather data for Google Maps. This is not a JSON method; it must be put
    123          into a data structure appropriate for JS consumption by another method
    124          (specifically, getChildGeomapData, below).
    125          """
    126          address = self.address
    127          psthresh = self.dmd.prodStateDashboardThresh
    128          summary = self.getEventSummary(prodState=psthresh)
    129          colors = 'red orange yellow green green'.split()
    130          color = 'green'
    131          for i in range(5):
    132              if summary[i][1]+summary[i][2]>0:
    133                  color = colors[i]
    134                  break
    135          link = self.absolute_url_path()
    136          linkToMap = self.numMappableChildren()
    137          if linkToMap:
    138              link+='/locationGeoMap'
    139          summarytext = self.mapTooltip() # mapTooltip is a page template
    140          return [address, color, link, summarytext]
    141
    142      @json
    143 -    def getChildGeomapData(self):
    144          """
    145          Return info ready for Google Maps.
    146          """
    147          allnodes = []
    148          data = []
    149          children = self.children()
    150          allnodes.extend(children)
    151          data = [x.getGeomapData() for x in allnodes]
    152          if not data: data = [self.getGeomapData()]
    153          return data
    154
    155 -    def getSecondaryNodes(self):
    156          """ Returns geomap info on cousin nodes that should be
    157              included in the view due to outside linking.
    158          """
    159          data = []
    160          # Short-circuit the method for now
    161          return data
    162
    163  InitializeClass(Location)
    164