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

Source Code for Module Products.ZenModel.DeviceResultInt

  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__="""DeviceResult 
 15   
 16  A mixin for objects that get listed like devices 
 17  The primary object must implement device. 
 18   
 19  """ 
 20   
 21   
 22  from AccessControl import ClassSecurityInfo 
 23  from Globals import InitializeClass 
 24   
 25   
26 -class DeviceResultInt:
27 28 security = ClassSecurityInfo() 29 30 security.declareProtected('View', 'getDeviceName')
31 - def getDeviceName(self):
32 '''Get the id of this device or associated device''' 33 d = self.device() 34 if d: 35 return d.getId() 36 return "No Device"
37 38 39 security.declareProtected('View', 'getDeviceUrl')
40 - def getDeviceUrl(self):
41 '''Get the primary url path of the device in which this 42 interface is located''' 43 d = self.device() 44 if d: 45 return d.getPrimaryUrlPath() 46 return ""
47 48 49 security.declareProtected('View', 'getDeviceLink') 60 61 62 security.declareProtected('View', 'getDeviceClassPath')
63 - def getDeviceClassPath(self):
64 '''Get the device class for this device''' 65 d = self.device() 66 if d: 67 return d.deviceClass().getOrganizerName() 68 return "No Device"
69 security.declareProtected('View', 'getDeviceClassName') 70 getDeviceClassName = getDeviceClassPath 71 72 73 security.declareProtected('View', 'getProdState')
74 - def getProdState(self):
75 '''Get the production state of the device associated with 76 this interface''' 77 d = self.device() 78 if d: 79 return self.convertProdState(d.productionState) 80 return "None"
81 82 83 security.declareProtected('View', 'getPingStatus')
84 - def getPingStatus(self):
85 """get the ping status of the box if there is one""" 86 # this import must be deferred to this point to avoid circular imports 87 from Products.ZenEvents.ZenEventClasses import Status_Ping 88 dev = self.device() 89 if dev: 90 dev = dev.primaryAq() 91 if (dev.monitorDevice() and 92 not getattr(dev, 'zPingMonitorIgnore', False)): 93 return dev.getStatus(Status_Ping) 94 else: 95 return self.getStatus(Status_Ping) 96 return -1
97 security.declareProtected('View', 'getPingStatusNumber') 98 getPingStatusNumber = getPingStatus 99 100 101 security.declareProtected('View', 'getSnmpStatus')
102 - def getSnmpStatus(self):
103 """get the snmp status of the box if there is one""" 104 # this import must be deferred to this point to avoid circular imports 105 __pychecker__='no-shadow' 106 from Products.ZenEvents.ZenEventClasses import Status_Snmp 107 dev = self.device() 108 if dev: 109 dev = dev.primaryAq() 110 if (not getattr(dev, 'zSnmpMonitorIgnore', False) 111 and getattr(dev, 'zSnmpCommunity', "") 112 and dev.monitorDevice()): 113 return dev.getStatus(Status_Snmp) 114 return -1
115 getSnmpStatusNumber = getSnmpStatus 116 security.declareProtected('View', 'getSnmpStatusNumber') 117 118 119 security.declareProtected('View', 'isResultLockedFromUpdates')
121 """Return the locked from updates flag""" 122 d = self.device() 123 if d: 124 return d.isLockedFromUpdates() 125 return False
126 127 security.declareProtected('View', 'isResultLockedFromDeletion')
129 """Return the locked from deletion flag""" 130 d = self.device() 131 if d: 132 return d.isLockedFromDeletion() 133 return False
134 135 security.declareProtected('View', 'sendEventWhenResultBlocked')
137 """Return the send event flag""" 138 d = self.device() 139 if d: 140 return d.sendEventWhenBlocked() 141 return False
142 143 144 security.declareProtected('View', 'getDeviceIp')
145 - def getDeviceIp(self):
146 """Get the management ip (only) of a device""" 147 d = self.device() 148 if d: 149 return d.manageIp 150 return ""
151 152 153 security.declareProtected('View', 'getDeviceIpAddress')
154 - def getDeviceIpAddress(self):
155 """Get the management ip with netmask (1.1.1.1/24) of a device""" 156 d = self.device() 157 if d: 158 int = d.getManageInterface() 159 if int: 160 return int.getIpAddress() 161 return ""
162 163 164 security.declareProtected('View', 'getDeviceMacaddress')
165 - def getDeviceMacaddress(self):
166 """get the mac address if there is one of the primary interface""" 167 d = self.device() 168 if d: 169 int = d.getManageInterface() 170 if int: 171 return int.getInterfaceMacaddress() 172 return ""
173 174 security.declareProtected('View', 'getNonLoopbackIpAddresses')
175 - def getNonLoopbackIpAddresses(self, showNetMask=False):
176 """ 177 List the IP addresses to which we can contact the service. 178 Discards the loopback (127.0.0.1) address. 179 By default do not show the netmasks. 180 181 @parameter showNetMask: return IP addresses with netmasks? 182 @type showNetMask: Boolean 183 @return: list of IP addresses 184 @rtype: array of strings 185 """ 186 ip_list = [] 187 dev = self.device() 188 if dev: 189 ip_list = ( obj.getIpAddress() 190 for obj in dev.os.interfaces.objectValuesAll() ) 191 ip_list = [ ip for ip in ip_list if ip and \ 192 not ip.startswith('127.0.0.1')] 193 else: 194 manage_ip = self.getDeviceIp() 195 if manage_ip: 196 ip_list = [ manage_ip ] 197 198 if not showNetMask: 199 ip_list = [ ip.split('/',1)[0] for ip in ip_list ] 200 201 return ip_list
202 203 204 InitializeClass(DeviceResultInt) 205