Trees | Indices | Help |
|
---|
|
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 import logging 15 log = logging.getLogger("zen.OS") 16 17 from Software import Software 18 19 from AccessControl import ClassSecurityInfo 20 from Globals import InitializeClass 21 22 from Products.ZenUtils.Utils import convToUnits 23 from Products.ZenRelations.RelSchema import * 24 25 from Products.ZenModel.Exceptions import * 26 from Products.ZenModel.Service import Service 27 28 from IpInterface import manage_addIpInterface 29 from WinService import manage_addWinService 30 from IpService import manage_addIpService 31 from OSProcess import manage_addOSProcess, OSProcess 32 from IpRouteEntry import manage_addIpRouteEntry 33 from FileSystem import manage_addFileSystem 34 35 from Products.ZenWidgets import messaging 36 from Products.ZenUtils.Utils import prepId 3739 40 totalSwap = 0L 41 uname = "" 42 43 _properties = Software._properties + ( 44 {'id':'totalSwap', 'type':'long', 'mode':'w'}, 45 {'id':'uname', 'type':'string', 'mode':''}, 46 ) 47 48 _relations = Software._relations + ( 49 ("interfaces", ToManyCont(ToOne, 50 "Products.ZenModel.IpInterface", "os")), 51 ("routes", ToManyCont(ToOne, "Products.ZenModel.IpRouteEntry", "os")), 52 ("ipservices", ToManyCont(ToOne, "Products.ZenModel.IpService", "os")), 53 ("winservices", ToManyCont(ToOne, 54 "Products.ZenModel.WinService", "os")), 55 ("processes", ToManyCont(ToOne, "Products.ZenModel.OSProcess", "os")), 56 ("filesystems", ToManyCont(ToOne, 57 "Products.ZenModel.FileSystem", "os")), 58 ("software", ToManyCont(ToOne, "Products.ZenModel.Software", "os")), 59 ) 60 61 security = ClassSecurityInfo() 62 63 routeTypeMap = ('other', 'invalid', 'direct', 'indirect') 64 routeProtoMap = ('other', 'local', 'netmgmt', 'icmp', 65 'egp', 'ggp', 'hello', 'rip', 'is-is', 'es-is', 66 'ciscoIgrp', 'bbnSpfIgrp', 'ospf', 'bgp') 67 68 factory_type_information = ( 69 { 70 'id' : 'Device', 71 'meta_type' : 'Device', 72 'description' : """Base class for all devices""", 73 'icon' : 'Device_icon.gif', 74 'product' : 'ZenModel', 75 'factory' : 'manage_addDevice', 76 'immediate_view' : '../deviceOsDetail', 77 'actions' : () 78 }, 79 ) 80 81657 658 InitializeClass(OperatingSystem) 65983 id = "os" 84 Software.__init__(self, id) 85 self._delObject("os") # OperatingSystem is a software86 # but doens't have os relationship 87 88 9193 """ 94 Trace the route to the target from this device using our routing 95 table and return an array of IP address strings showing the route. 96 97 If the route is not traversable (ie a gap in the routing table), 98 then return the incomplete path with a final value of None. 99 100 @parameter target: destination IP to find 101 @type target: DMD device object 102 @parameter ippath: used to store intermediate results in calls. Call with [] 103 @type ippath: array-like object used for 104 @return: IP addresses to target device 105 @rtype: array of strings 106 """ 107 log.debug("traceRoute from device %s to target %s", 108 self.getDeviceName(), target) 109 # Try to find a specific route to the target device 110 nextdev = None 111 for route in sorted(self.getRouteObjs(),key=lambda route:route.routemask,reverse=True): 112 ip = route.getNextHopIp() 113 log.debug("Route %s next hop %s", route.getTarget(), ip) 114 # Have a host-route 115 if ip == target.getManageIp(): 116 ippath.append(ip) 117 return ippath 118 119 # Have a net-route 120 if route.matchTarget(target.getManageIp()): 121 if route.routetype == 'direct': 122 nextdev = target 123 break 124 nextdev = route.getNextHopDevice() 125 break 126 else: 127 # No routes matched -- try the default route (if any) 128 log.debug("Device %s default route", self.getDeviceName()) 129 ip = "" 130 default = self.routes._getOb("0.0.0.0_0", None) 131 if default: 132 ip = default.getNextHopIp() 133 nextdev = default.getNextHopDevice() 134 135 if target == nextdev or ip == "0.0.0.0": 136 ippath.append(target.id) 137 return ippath 138 139 if nextdev: 140 ippath.append(ip) 141 return nextdev.traceRoute(target, ippath) 142 143 # Oops! No route! 144 log.debug("Unable to trace to %s, gap at %s", target.id, 145 self.getDeviceName()) 146 ippath.append(None) 147 return ippath148 149151 """Return our real route objects. 152 """ 153 return filter(lambda r: r.target(), self.routes())154 155 160162 """Delete device components""" 163 if not componentNames: return self() 164 if isinstance(componentNames, basestring): 165 componentNames = (componentNames,) 166 for componentName in componentNames: 167 dc = context._getOb(componentName, False) 168 if dc: dc.manage_deleteComponent() 169 if REQUEST: 170 return self.callZenScreen(REQUEST)171173 """Unlock device components""" 174 if not componentNames: return self() 175 if isinstance(componentNames, basestring): 176 componentNames = (componentNames,) 177 for componentName in componentNames: 178 dc = context._getOb(componentName) 179 dc.unlock() 180 if REQUEST: 181 return self.callZenScreen(REQUEST)182183 - def lockDeviceComponentsFromDeletion(self, context, componentNames=[], 184 sendEventWhenBlocked=None, REQUEST=None):185 """Lock device components from deletion""" 186 if not componentNames: return self() 187 if isinstance(componentNames, basestring): 188 componentNames = (componentNames,) 189 for componentName in componentNames: 190 dc = context._getOb(componentName) 191 dc.lockFromDeletion(sendEventWhenBlocked) 192 if REQUEST: 193 return self.callZenScreen(REQUEST)194195 - def lockDeviceComponentsFromUpdates(self, context, componentNames=[], 196 sendEventWhenBlocked=None, REQUEST=None):197 """Lock device components from updates""" 198 if not componentNames: return self() 199 if isinstance(componentNames, basestring): 200 componentNames = (componentNames,) 201 for componentName in componentNames: 202 dc = context._getOb(componentName, False) 203 if dc: dc.lockFromUpdates(sendEventWhenBlocked) 204 if REQUEST: 205 return self.callZenScreen(REQUEST)206 207209 """Add IpInterfaces. 210 """ 211 manage_addIpInterface(self.interfaces, newId, userCreated) 212 if REQUEST: 213 messaging.IMessageSender(self).sendToBrowser( 214 'Interface Created', 215 'IP Interface %s was created.' % newId 216 ) 217 REQUEST['RESPONSE'].redirect( 218 self.interfaces._getOb(newId).absolute_url()) 219 self._p_changed = True 220 return self.callZenScreen(REQUEST)221223 """Delete IpInterfaces""" 224 self.deleteDeviceComponents(self.interfaces, componentNames, REQUEST) 225 if REQUEST: 226 messaging.IMessageSender(self).sendToBrowser( 227 'Interfaces Deleted', 228 'IP Interfaces %s was created.' % (', '.join(componentNames)) 229 ) 230 REQUEST['RESPONSE'].redirect(self.absolute_url()) 231 return self.callZenScreen(REQUEST)232233 - def setComponentMonitored(self, context, componentNames=[], 234 monitored=True, REQUEST=None):235 """ 236 Set monitored status for selected components. 237 """ 238 if isinstance(context, basestring): 239 context = getattr(self, context) 240 if not componentNames: return self() 241 if isinstance(componentNames, basestring): 242 componentNames = (componentNames,) 243 monitored = bool(monitored) 244 for componentName in componentNames: 245 comp = context._getOb(componentName, False) 246 if comp and comp.monitored() != monitored: 247 comp.monitor = monitored 248 if isinstance(comp, (Service, OSProcess)): 249 comp.setAqProperty('zMonitor', monitored, 'boolean') 250 comp.index_object() 251 if REQUEST: 252 verb = monitored and "Enabled" or "Disabled" 253 messaging.IMessageSender(self).sendToBrowser( 254 'Monitoring %s' % verb, 255 'Monitoring was %s on %s.' % (verb.lower(), 256 ', '.join(componentNames)) 257 ) 258 return self.callZenScreen(REQUEST)259261 """Unlock IpInterfaces""" 262 self.unlockDeviceComponents(self.interfaces, componentNames, REQUEST) 263 if REQUEST: 264 messaging.IMessageSender(self).sendToBrowser( 265 'Interfaces Unlocked', 266 'Interfaces %s were unlocked.' % (', '.join(componentNames)) 267 ) 268 REQUEST['RESPONSE'].redirect(self.absolute_url()) 269 return self.callZenScreen(REQUEST)270271 - def lockIpInterfacesFromDeletion(self, componentNames=[], 272 sendEventWhenBlocked=None, REQUEST=None):273 """Lock IpInterfaces from deletion""" 274 self.lockDeviceComponentsFromDeletion(self.interfaces, componentNames, 275 sendEventWhenBlocked, REQUEST) 276 if REQUEST: 277 messaging.IMessageSender(self).sendToBrowser( 278 'Interfaces Locked', 279 'Interfaces %s were locked from deletion.' % ( 280 ', '.join(componentNames)) 281 ) 282 REQUEST['RESPONSE'].redirect(self.absolute_url()) 283 return self.callZenScreen(REQUEST)284285 - def lockIpInterfacesFromUpdates(self, componentNames=[], 286 sendEventWhenBlocked=None, REQUEST=None):287 """Lock IpInterfaces from updates""" 288 self.lockDeviceComponentsFromUpdates(self.interfaces, componentNames, 289 sendEventWhenBlocked, REQUEST) 290 if REQUEST: 291 messaging.IMessageSender(self).sendToBrowser( 292 'Interfaces Locked', 293 'Interfaces %s were locked from updates and deletion.' % ( 294 ', '.join(componentNames)) 295 ) 296 REQUEST['RESPONSE'].redirect(self.absolute_url()) 297 return self.callZenScreen(REQUEST)298300 """Add an WinService. 301 """ 302 org = self.dmd.Services 303 wsc = org.unrestrictedTraverse(newClassName) 304 if wsc is not None: 305 ws = manage_addWinService(self.winservices, 306 wsc.id, 307 wsc.description, 308 userCreated=userCreated) 309 self._p_changed = True 310 elif REQUEST: 311 messaging.IMessageSender(self).sendToBrowser( 312 'No Such WinService', 313 'Could not find a WinService named %s.' % (newClassName), 314 priority=messaging.WARNING 315 ) 316 return self.callZenScreen(REQUEST) 317 318 if REQUEST: 319 messaging.IMessageSender(self).sendToBrowser( 320 'WinService Added', 321 'WinService %s was added.' % (newClassName) 322 ) 323 REQUEST['RESPONSE'].redirect(ws.absolute_url()) 324 return self.callZenScreen(REQUEST)325327 """Delete WinServices""" 328 self.deleteDeviceComponents(self.winservices, componentNames, REQUEST) 329 if REQUEST: 330 messaging.IMessageSender(self).sendToBrowser( 331 'WinServices Deleted', 332 'WinServices %s were deleted.' % (', '.join(componentNames)) 333 ) 334 REQUEST['RESPONSE'].redirect(self.absolute_url()) 335 return self.callZenScreen(REQUEST)336338 """Unlock WinServices""" 339 self.unlockDeviceComponents(self.winservices, componentNames, REQUEST) 340 if REQUEST: 341 messaging.IMessageSender(self).sendToBrowser( 342 'WinServices Unlocked', 343 'WinServices %s were unlocked.' % (', '.join(componentNames)) 344 ) 345 REQUEST['RESPONSE'].redirect(self.absolute_url()) 346 return self.callZenScreen(REQUEST)347348 - def lockWinServicesFromDeletion(self, componentNames=[], 349 sendEventWhenBlocked=None, REQUEST=None):350 """Lock WinServices from deletion""" 351 self.lockDeviceComponentsFromDeletion(self.winservices, componentNames, 352 sendEventWhenBlocked, REQUEST) 353 if REQUEST: 354 messaging.IMessageSender(self).sendToBrowser( 355 'WinServices Locked', 356 'WinServices %s were locked from deletion.' % ( 357 ', '.join(componentNames)) 358 ) 359 REQUEST['RESPONSE'].redirect(self.absolute_url()) 360 return self.callZenScreen(REQUEST)361362 - def lockWinServicesFromUpdates(self, componentNames=[], 363 sendEventWhenBlocked=None, REQUEST=None):364 """Lock WinServices from updates""" 365 self.lockDeviceComponentsFromUpdates(self.winservices, componentNames, 366 sendEventWhenBlocked, REQUEST) 367 if REQUEST: 368 messaging.IMessageSender(self).sendToBrowser( 369 'WinServices Locked', 370 'WinServices %s were locked from updates and deletion.' % ( 371 ', '.join(componentNames)) 372 ) 373 REQUEST['RESPONSE'].redirect(self.absolute_url()) 374 return self.callZenScreen(REQUEST)375 380382 """Add an OSProcess. 383 """ 384 osp = manage_addOSProcess(self.processes, newClassName, userCreated) 385 self._p_changed = True 386 if REQUEST: 387 messaging.IMessageSender(self).sendToBrowser( 388 'Process Created', 389 'OS process %s was created.' % newClassName 390 ) 391 REQUEST['RESPONSE'].redirect(osp.absolute_url())392394 """Delete OSProcesses""" 395 self.deleteDeviceComponents(self.processes, componentNames, REQUEST) 396 if REQUEST: 397 messaging.IMessageSender(self).sendToBrowser( 398 'Processes Deleted', 399 'OS processes %s were deleted.' % (', '.join(componentNames)) 400 ) 401 REQUEST['RESPONSE'].redirect(self.absolute_url()) 402 return self.callZenScreen(REQUEST)403405 """Unlock OSProcesses""" 406 self.unlockDeviceComponents(self.processes, componentNames, REQUEST) 407 if REQUEST: 408 messaging.IMessageSender(self).sendToBrowser( 409 'Processes Unlocked', 410 'OS Processes %s were unlocked.' % (', '.join(componentNames)) 411 ) 412 REQUEST['RESPONSE'].redirect(self.absolute_url()) 413 return self.callZenScreen(REQUEST)414415 - def lockOSProcessesFromDeletion(self, componentNames=[], 416 sendEventWhenBlocked=None, REQUEST=None):417 """Lock OSProcesses from deletion""" 418 self.lockDeviceComponentsFromDeletion(self.processes, componentNames, 419 sendEventWhenBlocked, REQUEST) 420 if REQUEST: 421 messaging.IMessageSender(self).sendToBrowser( 422 'Processes Locked', 423 'OS processes %s were locked from deletion.' % ( 424 ', '.join(componentNames)) 425 ) 426 REQUEST['RESPONSE'].redirect(self.absolute_url()) 427 return self.callZenScreen(REQUEST)428429 - def lockOSProcessesFromUpdates(self, componentNames=[], 430 sendEventWhenBlocked=None, REQUEST=None):431 """Lock OSProcesses from updates""" 432 self.lockDeviceComponentsFromUpdates(self.processes, componentNames, 433 sendEventWhenBlocked, REQUEST) 434 if REQUEST: 435 messaging.IMessageSender(self).sendToBrowser( 436 'Processes Locked', 437 'OS processes %s were locked from updates and deletion.' % ( 438 ', '.join(componentNames)) 439 ) 440 REQUEST['RESPONSE'].redirect(self.absolute_url()) 441 return self.callZenScreen(REQUEST)442444 """Add IpServices. 445 """ 446 org = self.dmd.Services 447 ipsc = org.unrestrictedTraverse(newClassName) 448 if ipsc is not None: 449 ips = manage_addIpService(self.ipservices, 450 ipsc.id, 451 protocol, 452 ipsc.port, 453 userCreated=userCreated) 454 self._p_changed = True 455 elif REQUEST: 456 messaging.IMessageSender(self).sendToBrowser( 457 'No Such WinService', 458 'Could not find an IP Service named %s.' % (newClassName), 459 priority=messaging.WARNING 460 ) 461 return self.callZenScreen(REQUEST) 462 463 if REQUEST: 464 messaging.IMessageSender(self).sendToBrowser( 465 'IP Service Added', 466 'IP Service %s was added.' % (newClassName) 467 ) 468 REQUEST['RESPONSE'].redirect(ips.absolute_url()) 469 return self.callZenScreen(REQUEST)470472 """Delete IpServices""" 473 self.deleteDeviceComponents(self.ipservices, componentNames, REQUEST) 474 if REQUEST: 475 messaging.IMessageSender(self).sendToBrowser( 476 'IP Services Deleted', 477 'IP Services %s were deleted.' % (', '.join(componentNames)) 478 ) 479 REQUEST['RESPONSE'].redirect(self.absolute_url()) 480 return self.callZenScreen(REQUEST)481483 """Unlock IpServices""" 484 self.unlockDeviceComponents(self.ipservices, componentNames, REQUEST) 485 if REQUEST: 486 messaging.IMessageSender(self).sendToBrowser( 487 'IpServices Unlocked', 488 'IP Services %s were unlocked.' % (', '.join(componentNames)) 489 ) 490 REQUEST['RESPONSE'].redirect(self.absolute_url()) 491 return self.callZenScreen(REQUEST)492493 - def lockIpServicesFromDeletion(self, componentNames=[], 494 sendEventWhenBlocked=None, REQUEST=None):495 """Lock IpServices from deletion""" 496 self.lockDeviceComponentsFromDeletion(self.ipservices, componentNames, 497 sendEventWhenBlocked, REQUEST) 498 if REQUEST: 499 messaging.IMessageSender(self).sendToBrowser( 500 'Services Locked', 501 'IP services %s were locked from deletion.' % ( 502 ', '.join(componentNames)) 503 ) 504 REQUEST['RESPONSE'].redirect(self.absolute_url()) 505 return self.callZenScreen(REQUEST)506507 - def lockIpServicesFromUpdates(self, componentNames=[], 508 sendEventWhenBlocked=None, REQUEST=None):509 """Lock IpServices from updates""" 510 self.lockDeviceComponentsFromUpdates(self.ipservices, componentNames, 511 sendEventWhenBlocked, REQUEST) 512 if REQUEST: 513 messaging.IMessageSender(self).sendToBrowser( 514 'Services Locked', 515 'IP services %s were locked from updates and deletion.' % ( 516 ', '.join(componentNames)) 517 ) 518 REQUEST['RESPONSE'].redirect(self.absolute_url()) 519 return self.callZenScreen(REQUEST)520522 """Add a FileSystem. 523 """ 524 fsid = prepId(newId) 525 manage_addFileSystem(self.filesystems, newId, userCreated) 526 self._p_changed = True 527 if REQUEST: 528 messaging.IMessageSender(self).sendToBrowser( 529 'Filesystem Added', 530 'Filesystem %s was added.' % newId 531 ) 532 REQUEST['RESPONSE'].redirect( 533 self.filesystems._getOb(fsid).absolute_url()) 534 return self.callZenScreen(REQUEST)535537 """Delete FileSystems""" 538 self.deleteDeviceComponents(self.filesystems, componentNames, REQUEST) 539 if REQUEST: 540 messaging.IMessageSender(self).sendToBrowser( 541 'Filesystems Deleted', 542 'Filesystems %s were deleted.' % (', '.join(componentNames)) 543 ) 544 REQUEST['RESPONSE'].redirect(self.absolute_url()) 545 return self.callZenScreen(REQUEST)546548 """Unlock FileSystems""" 549 self.unlockDeviceComponents(self.filesystems, componentNames, REQUEST) 550 if REQUEST: 551 messaging.IMessageSender(self).sendToBrowser( 552 'Filesystems Unlocked', 553 'Filesystems %s were unlocked.' % (', '.join(componentNames)) 554 ) 555 REQUEST['RESPONSE'].redirect(self.absolute_url()) 556 return self.callZenScreen(REQUEST)557558 - def lockFileSystemsFromDeletion(self, componentNames=[], 559 sendEventWhenBlocked=None, REQUEST=None):560 """Lock FileSystems from deletion""" 561 self.lockDeviceComponentsFromDeletion(self.filesystems, componentNames, 562 sendEventWhenBlocked, REQUEST) 563 if REQUEST: 564 messaging.IMessageSender(self).sendToBrowser( 565 'Filesystems Locked', 566 'Filesystems %s were locked from deletion.' % ( 567 ', '.join(componentNames)) 568 ) 569 REQUEST['RESPONSE'].redirect(self.absolute_url()) 570 return self.callZenScreen(REQUEST)571572 - def lockFileSystemsFromUpdates(self, componentNames=[], 573 sendEventWhenBlocked=None, REQUEST=None):574 """Lock FileSystems from updates""" 575 self.lockDeviceComponentsFromUpdates(self.filesystems, componentNames, 576 sendEventWhenBlocked, REQUEST) 577 if REQUEST: 578 messaging.IMessageSender(self).sendToBrowser( 579 'Filesystems Locked', 580 'Filesystems %s were locked from updates and deletion.' % ( 581 ', '.join(componentNames)) 582 ) 583 REQUEST['RESPONSE'].redirect(self.absolute_url()) 584 return self.callZenScreen(REQUEST)585586 - def addIpRouteEntry(self, dest, routemask, nexthopid, interface, 587 routeproto, routetype, userCreated, REQUEST=None):588 """Add an IpRouteEntry. 589 """ 590 manage_addIpRouteEntry(self.routes, 591 dest, 592 routemask, 593 nexthopid, 594 interface, 595 routeproto, 596 routetype, 597 userCreated=userCreated) 598 self._p_changed = True 599 if REQUEST: 600 messaging.IMessageSender(self).sendToBrowser( 601 'Route Created', 602 'IP route entry was created.' 603 ) 604 REQUEST['RESPONSE'].redirect(self.absolute_url()) 605 return self.callZenScreen(REQUEST)606608 """Delete IpRouteEntries""" 609 self.deleteDeviceComponents(self.routes, componentNames, REQUEST) 610 if REQUEST: 611 messaging.IMessageSender(self).sendToBrowser( 612 'Routes Deleted', 613 'IP route entries %s were deleted.' % (', '.join(componentNames)) 614 ) 615 REQUEST['RESPONSE'].redirect(self.absolute_url()) 616 return self.callZenScreen(REQUEST)617619 """Unlock IpRouteEntries""" 620 self.unlockDeviceComponents(self.routes, componentNames, REQUEST) 621 if REQUEST: 622 messaging.IMessageSender(self).sendToBrowser( 623 'Routes Unlocked', 624 'IP route entries %s were unlocked.' % ( 625 ', '.join(componentNames)) 626 ) 627 REQUEST['RESPONSE'].redirect(self.absolute_url()) 628 return self.callZenScreen(REQUEST)629630 - def lockIpRouteEntriesFromDeletion(self, componentNames=[], 631 sendEventWhenBlocked=None, REQUEST=None):632 """Lock IpRouteEntries from deletion""" 633 self.lockDeviceComponentsFromDeletion(self.routes, componentNames, 634 sendEventWhenBlocked, REQUEST) 635 if REQUEST: 636 messaging.IMessageSender(self).sendToBrowser( 637 'Routes Locked', 638 'IP route entries %s were locked from deletion.' % ( 639 ', '.join(componentNames)) 640 ) 641 REQUEST['RESPONSE'].redirect(self.absolute_url()) 642 return self.callZenScreen(REQUEST)643644 - def lockIpRouteEntriesFromUpdates(self, componentNames=[], 645 sendEventWhenBlocked=None, REQUEST=None):646 """Lock IpRouteEntries from updates""" 647 self.lockDeviceComponentsFromUpdates(self.routes, componentNames, 648 sendEventWhenBlocked, REQUEST) 649 if REQUEST: 650 messaging.IMessageSender(self).sendToBrowser( 651 'Routes Locked', 652 'IP route entries %s were locked from updates and deletion.' % ( 653 ', '.join(componentNames)) 654 ) 655 REQUEST['RESPONSE'].redirect(self.absolute_url()) 656 return self.callZenScreen(REQUEST)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1.1812 on Tue Oct 11 12:51:44 2011 | http://epydoc.sourceforge.net |