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 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__="""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 return dev.getStatus(Status_Ping) 92 else: 93 return self.getStatus(Status_Ping) 94 return -1
95 security.declareProtected('View', 'getPingStatusNumber') 96 getPingStatusNumber = getPingStatus 97 98 99 security.declareProtected('View', 'getSnmpStatus')
100 - def getSnmpStatus(self):
101 """get the snmp status of the box if there is one""" 102 # this import must be deferred to this point to avoid circular imports 103 __pychecker__='no-shadow' 104 from Products.ZenEvents.ZenEventClasses import Status_Snmp 105 dev = self.device() 106 if dev: 107 dev = dev.primaryAq() 108 if (not getattr(dev, 'zSnmpMonitorIgnore', False) 109 and getattr(dev, 'zSnmpCommunity', "") 110 and dev.monitorDevice()): 111 return dev.getStatus(Status_Snmp) 112 return -1
113 getSnmpStatusNumber = getSnmpStatus 114 security.declareProtected('View', 'getSnmpStatusNumber') 115 116 117 security.declareProtected('View', 'isResultLockedFromUpdates')
119 """Return the locked from updates flag""" 120 d = self.device() 121 if d: 122 return d.isLockedFromUpdates() 123 return False
124 125 security.declareProtected('View', 'isResultLockedFromDeletion')
127 """Return the locked from deletion flag""" 128 d = self.device() 129 if d: 130 return d.isLockedFromDeletion() 131 return False
132 133 security.declareProtected('View', 'sendEventWhenResultBlocked')
135 """Return the send event flag""" 136 d = self.device() 137 if d: 138 return d.sendEventWhenBlocked() 139 return False
140 141 142 security.declareProtected('View', 'getDeviceIp')
143 - def getDeviceIp(self):
144 """Get the management ip (only) of a device""" 145 d = self.device() 146 if d: 147 return d.manageIp 148 return ""
149 150 151 security.declareProtected('View', 'getDeviceIpAddress')
152 - def getDeviceIpAddress(self):
153 """Get the management ip with netmask (1.1.1.1/24) of a device""" 154 d = self.device() 155 if d: 156 int = d.getManageInterface() 157 if int: 158 return int.getIpAddress() 159 return ""
160 161 162 security.declareProtected('View', 'getDeviceMacaddress')
163 - def getDeviceMacaddress(self):
164 """get the mac address if there is one of the primary interface""" 165 d = self.device() 166 if d: 167 int = d.getManageInterface() 168 if int: 169 return int.getInterfaceMacaddress() 170 return ""
171 172 security.declareProtected('View', 'getNonLoopbackIpAddresses')
173 - def getNonLoopbackIpAddresses(self, showNetMask=False):
174 """ 175 List the IP addresses to which we can contact the service. 176 Discards the loopback (127.0.0.1) address. 177 By default do not show the netmasks. 178 179 @parameter showNetMask: return IP addresses with netmasks? 180 @type showNetMask: Boolean 181 @return: list of IP addresses 182 @rtype: array of strings 183 """ 184 ip_list = [] 185 dev = self.device() 186 if dev: 187 ip_list = ( obj.getIpAddress() 188 for obj in dev.os.interfaces.objectValuesAll() ) 189 ip_list = [ ip for ip in ip_list if ip and \ 190 not ip.startswith('127.0.0.1') and \ 191 not ip.startswith('::1')] 192 else: 193 manage_ip = self.getDeviceIp() 194 if manage_ip: 195 ip_list = [ manage_ip ] 196 197 if not showNetMask: 198 ip_list = [ ip.split('/',1)[0] for ip in ip_list ] 199 200 return ip_list
201 202 203 InitializeClass(DeviceResultInt) 204