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.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 psthresh = self.dmd.prodStateDashboardThresh 132 summary = self.getEventSummary(prodState=psthresh) 133 colors = 'red orange yellow green green'.split() 134 color = 'green' 135 for i in range(5): 136 if summary[i][1]+summary[i][2]>0: 137 color = colors[i] 138 break 139 link = self.absolute_url_path() 140 linkToMap = self.numMappableChildren() 141 if linkToMap: 142 link+='/locationGeoMap' 143 summarytext = self.mapTooltip() # mapTooltip is a page template 144 return [self.address, color, link, summarytext]
145 146 @json
147 - def getChildGeomapData(self):
148 """ 149 Return info ready for Google Maps. 150 """ 151 allnodes = [] 152 data = [] 153 children = self.children() 154 allnodes.extend(children) 155 data = [x.getGeomapData() for x in allnodes if x.address] 156 if not data: data = [self.getGeomapData()] 157 return data
158
159 - def getSecondaryNodes(self):
160 """ Returns geomap info on cousin nodes that should be 161 included in the view due to outside linking. 162 """ 163 data = [] 164 # Short-circuit the method for now 165 return data
166 167 InitializeClass(Location) 168