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 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   
 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.jsonutils 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 __init__(self, id, description = '', address=''):
107 super(Location, self).__init__(id, description) 108 self.address = address
109 110
111 - def setAddress(self, address):
112 """Sets the mailing address for this location""" 113 self.address = address
114 118
119 - def numMappableChildren(self):
120 children = self.children() 121 return len( 122 filter(lambda x:getattr(x, 'address', None), children) 123 )
124
125 - def getGeomapData(self):
126 """ 127 Gather data for Google Maps. This is not a JSON method; it must be put 128 into a data structure appropriate for JS consumption by another method 129 (specifically, getChildGeomapData, below). 130 """ 131 worstSeverity = self.getWorstEventSeverity() 132 colors = 'red orange yellow green green'.split() 133 colors.reverse() 134 color = 'green' 135 if worstSeverity: 136 try: 137 color = colors[worstSeverity - 1] 138 except IndexError: 139 # show green rather than error 140 pass 141 link = self.absolute_url_path() 142 linkToMap = self.numMappableChildren() 143 if linkToMap: 144 link+='/locationGeoMap' 145 summarytext = self.mapTooltip() # mapTooltip is a page template 146 return [self.address, color, link, summarytext]
147 148 @json
149 - def getChildGeomapData(self):
150 """ 151 Return info ready for Google Maps. 152 """ 153 allnodes = [] 154 data = [] 155 children = self.children() 156 allnodes.extend(children) 157 data = [x.getGeomapData() for x in allnodes if x.address] 158 if not data: data = [self.getGeomapData()] 159 return data
160
161 - def getSecondaryNodes(self):
162 """ Returns geomap info on cousin nodes that should be 163 included in the view due to outside linking. 164 """ 165 data = [] 166 # Short-circuit the method for now 167 return data
168 169 InitializeClass(Location) 170