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

Source Code for Module Products.ZenModel.DeviceResultInt

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