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 as published by 8 # 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 import types 18 19 from Software import Software 20 21 from AccessControl import ClassSecurityInfo 22 from Globals import InitializeClass 23 24 from Products.ZenUtils.Utils import convToUnits 25 from Products.ZenRelations.RelSchema import * 26 27 from Products.ZenModel.Exceptions import * 28 from Products.ZenModel.Service import Service 29 30 from IpInterface import manage_addIpInterface 31 from WinService import manage_addWinService 32 from IpService import manage_addIpService 33 from OSProcess import manage_addOSProcess, OSProcess 34 from IpRouteEntry import manage_addIpRouteEntry 35 from FileSystem import manage_addFileSystem 36 37 from Products.ZenWidgets import messaging 38 from Products.ZenUtils.Utils import prepId 3941 42 totalSwap = 0L 43 uname = "" 44 45 _properties = Software._properties + ( 46 {'id':'totalSwap', 'type':'long', 'mode':'w'}, 47 {'id':'uname', 'type':'string', 'mode':''}, 48 ) 49 50 _relations = Software._relations + ( 51 ("interfaces", ToManyCont(ToOne, 52 "Products.ZenModel.IpInterface", "os")), 53 ("routes", ToManyCont(ToOne, "Products.ZenModel.IpRouteEntry", "os")), 54 ("ipservices", ToManyCont(ToOne, "Products.ZenModel.IpService", "os")), 55 ("winservices", ToManyCont(ToOne, 56 "Products.ZenModel.WinService", "os")), 57 ("processes", ToManyCont(ToOne, "Products.ZenModel.OSProcess", "os")), 58 ("filesystems", ToManyCont(ToOne, 59 "Products.ZenModel.FileSystem", "os")), 60 ("software", ToManyCont(ToOne, "Products.ZenModel.Software", "os")), 61 ) 62 63 security = ClassSecurityInfo() 64 65 routeTypeMap = ('other', 'invalid', 'direct', 'indirect') 66 routeProtoMap = ('other', 'local', 'netmgmt', 'icmp', 67 'egp', 'ggp', 'hello', 'rip', 'is-is', 'es-is', 68 'ciscoIgrp', 'bbnSpfIgrp', 'ospf', 'bgp') 69 70 factory_type_information = ( 71 { 72 'id' : 'Device', 73 'meta_type' : 'Device', 74 'description' : """Base class for all devices""", 75 'icon' : 'Device_icon.gif', 76 'product' : 'ZenModel', 77 'factory' : 'manage_addDevice', 78 'immediate_view' : '../deviceOsDetail', 79 'actions' : () 80 }, 81 ) 82 83635 636 InitializeClass(OperatingSystem) 63785 id = "os" 86 Software.__init__(self, id) 87 self._delObject("os") # OperatingSystem is a software88 # but doens't have os relationship 89 90 9395 """Trace the route to target using our routing table. 96 """ 97 log.debug("device %s target %s", self.getDeviceName(), target) 98 nextdev = None 99 for route in self.getRouteObjs(): 100 ip = route.getNextHopIp() 101 log.debug("target %s next hop %s", route.getTarget(), ip) 102 if ip == target.getManageIp(): 103 ippath.append(ip) 104 return ippath 105 if route.matchTarget(target.getManageIp()): 106 if route.routetype == 'direct': 107 nextdev = target 108 break 109 nextdev = route.getNextHopDevice() 110 break 111 else: 112 log.debug("device %s default route", self.getDeviceName()) 113 ip = "" 114 default = self.routes._getOb("0.0.0.0_0", None) 115 if default: 116 ip = default.getNextHopIp() 117 nextdev = default.getNextHopDevice() 118 if target == nextdev or ip=="0.0.0.0": 119 ippath.append(target.id) 120 return ippath 121 if nextdev: 122 ippath.append(ip) 123 return nextdev.traceRoute(target, ippath) 124 raise TraceRouteGap("unable to trace to %s, gap at %s" % (target.id, 125 self.getDeviceName()))126 127129 """Return our real route objects. 130 """ 131 return filter(lambda r: r.target(), self.routes())132 133 138140 """Delete device components""" 141 if not componentNames: return self() 142 if type(componentNames) in types.StringTypes: 143 componentNames = (componentNames,) 144 for componentName in componentNames: 145 dc = context._getOb(componentName, False) 146 if dc: dc.manage_deleteComponent() 147 if REQUEST: 148 return self.callZenScreen(REQUEST)149151 """Unlock device components""" 152 if not componentNames: return self() 153 if type(componentNames) in types.StringTypes: 154 componentNames = (componentNames,) 155 for componentName in componentNames: 156 dc = context._getOb(componentName) 157 dc.unlock() 158 if REQUEST: 159 return self.callZenScreen(REQUEST)160161 - def lockDeviceComponentsFromDeletion(self, context, componentNames=[], 162 sendEventWhenBlocked=None, REQUEST=None):163 """Lock device components from deletion""" 164 if not componentNames: return self() 165 if type(componentNames) in types.StringTypes: 166 componentNames = (componentNames,) 167 for componentName in componentNames: 168 dc = context._getOb(componentName) 169 dc.lockFromDeletion(sendEventWhenBlocked) 170 if REQUEST: 171 return self.callZenScreen(REQUEST)172173 - def lockDeviceComponentsFromUpdates(self, context, componentNames=[], 174 sendEventWhenBlocked=None, REQUEST=None):175 """Lock device components from updates""" 176 if not componentNames: return self() 177 if type(componentNames) in types.StringTypes: 178 componentNames = (componentNames,) 179 for componentName in componentNames: 180 dc = context._getOb(componentName, False) 181 if dc: dc.lockFromUpdates(sendEventWhenBlocked) 182 if REQUEST: 183 return self.callZenScreen(REQUEST)184 185187 """Add IpInterfaces. 188 """ 189 manage_addIpInterface(self.interfaces, id, userCreated) 190 if REQUEST: 191 messaging.IMessageSender(self).sendToBrowser( 192 'Interface Created', 193 'IP Interface %s was created.' % id 194 ) 195 REQUEST['RESPONSE'].redirect( 196 self.interfaces._getOb(id).absolute_url()) 197 self._p_changed = True 198 return self.callZenScreen(REQUEST)199201 """Delete IpInterfaces""" 202 self.deleteDeviceComponents(self.interfaces, componentNames, REQUEST) 203 if REQUEST: 204 messaging.IMessageSender(self).sendToBrowser( 205 'Interfaces Deleted', 206 'IP Interfaces %s was created.' % (', '.join(componentNames)) 207 ) 208 REQUEST['RESPONSE'].redirect(self.absolute_url()) 209 return self.callZenScreen(REQUEST)210211 - def setComponentMonitored(self, context, componentNames=[], 212 monitored=True, REQUEST=None):213 """ 214 Set monitored status for selected components. 215 """ 216 if isinstance(context, basestring): 217 context = getattr(self, context) 218 if not componentNames: return self() 219 if isinstance(componentNames, basestring): 220 componentNames = (componentNames,) 221 monitored = bool(monitored) 222 for componentName in componentNames: 223 comp = context._getOb(componentName, False) 224 if comp and comp.monitored() != monitored: 225 comp.monitor = monitored 226 if isinstance(comp, (Service, OSProcess)): 227 comp.setAqProperty('zMonitor', monitored, 'boolean') 228 comp.index_object() 229 if REQUEST: 230 verb = monitored and "Enabled" or "Disabled" 231 messaging.IMessageSender(self).sendToBrowser( 232 'Monitoring %s' % verb, 233 'Monitoring was %s on %s.' % (verb.lower(), 234 ', '.join(componentNames)) 235 ) 236 return self.callZenScreen(REQUEST)237239 """Unlock IpInterfaces""" 240 self.unlockDeviceComponents(self.interfaces, componentNames, REQUEST) 241 if REQUEST: 242 messaging.IMessageSender(self).sendToBrowser( 243 'Interfaces Unlocked', 244 'Interfaces %s were unlocked.' % (', '.join(componentNames)) 245 ) 246 REQUEST['RESPONSE'].redirect(self.absolute_url()) 247 return self.callZenScreen(REQUEST)248249 - def lockIpInterfacesFromDeletion(self, componentNames=[], 250 sendEventWhenBlocked=None, REQUEST=None):251 """Lock IpInterfaces from deletion""" 252 self.lockDeviceComponentsFromDeletion(self.interfaces, componentNames, 253 sendEventWhenBlocked, REQUEST) 254 if REQUEST: 255 messaging.IMessageSender(self).sendToBrowser( 256 'Interfaces Locked', 257 'Interfaces %s were locked from deletion.' % ( 258 ', '.join(componentNames)) 259 ) 260 REQUEST['RESPONSE'].redirect(self.absolute_url()) 261 return self.callZenScreen(REQUEST)262263 - def lockIpInterfacesFromUpdates(self, componentNames=[], 264 sendEventWhenBlocked=None, REQUEST=None):265 """Lock IpInterfaces from updates""" 266 self.lockDeviceComponentsFromUpdates(self.interfaces, componentNames, 267 sendEventWhenBlocked, REQUEST) 268 if REQUEST: 269 messaging.IMessageSender(self).sendToBrowser( 270 'Interfaces Locked', 271 'Interfaces %s were locked from updates and deletion.' % ( 272 ', '.join(componentNames)) 273 ) 274 REQUEST['RESPONSE'].redirect(self.absolute_url()) 275 return self.callZenScreen(REQUEST)276278 """Add an WinService. 279 """ 280 org = self.dmd.Services.WinService 281 wsc = org.find(org.parseServiceLiveSearchString(className)) 282 if wsc is not None: 283 ws = manage_addWinService(self.winservices, 284 wsc.id, 285 wsc.description, 286 userCreated=userCreated) 287 self._p_changed = True 288 elif REQUEST: 289 messaging.IMessageSender(self).sendToBrowser( 290 'No Such WinService', 291 'Could not find a WinService named %s.' % (className), 292 priority=messaging.WARNING 293 ) 294 return self.callZenScreen(REQUEST) 295 296 if REQUEST: 297 messaging.IMessageSender(self).sendToBrowser( 298 'WinService Added', 299 'WinService %s was added.' % (className) 300 ) 301 REQUEST['RESPONSE'].redirect(ws.absolute_url()) 302 return self.callZenScreen(REQUEST)303305 """Delete WinServices""" 306 self.deleteDeviceComponents(self.winservices, componentNames, REQUEST) 307 if REQUEST: 308 messaging.IMessageSender(self).sendToBrowser( 309 'WinServices Deleted', 310 'WinServices %s were deleted.' % (', '.join(componentNames)) 311 ) 312 REQUEST['RESPONSE'].redirect(self.absolute_url()) 313 return self.callZenScreen(REQUEST)314316 """Unlock WinServices""" 317 self.unlockDeviceComponents(self.winservices, componentNames, REQUEST) 318 if REQUEST: 319 messaging.IMessageSender(self).sendToBrowser( 320 'WinServices Unlocked', 321 'WinServices %s were unlocked.' % (', '.join(componentNames)) 322 ) 323 REQUEST['RESPONSE'].redirect(self.absolute_url()) 324 return self.callZenScreen(REQUEST)325326 - def lockWinServicesFromDeletion(self, componentNames=[], 327 sendEventWhenBlocked=None, REQUEST=None):328 """Lock WinServices from deletion""" 329 self.lockDeviceComponentsFromDeletion(self.winservices, componentNames, 330 sendEventWhenBlocked, REQUEST) 331 if REQUEST: 332 messaging.IMessageSender(self).sendToBrowser( 333 'WinServices Locked', 334 'WinServices %s were locked from deletion.' % ( 335 ', '.join(componentNames)) 336 ) 337 REQUEST['RESPONSE'].redirect(self.absolute_url()) 338 return self.callZenScreen(REQUEST)339340 - def lockWinServicesFromUpdates(self, componentNames=[], 341 sendEventWhenBlocked=None, REQUEST=None):342 """Lock WinServices from updates""" 343 self.lockDeviceComponentsFromUpdates(self.winservices, componentNames, 344 sendEventWhenBlocked, REQUEST) 345 if REQUEST: 346 messaging.IMessageSender(self).sendToBrowser( 347 'WinServices Locked', 348 'WinServices %s were locked from updates and deletion.' % ( 349 ', '.join(componentNames)) 350 ) 351 REQUEST['RESPONSE'].redirect(self.absolute_url()) 352 return self.callZenScreen(REQUEST)353 358360 """Add an OSProcess. 361 """ 362 osp = manage_addOSProcess(self.processes, className, userCreated) 363 self._p_changed = True 364 if REQUEST: 365 messaging.IMessageSender(self).sendToBrowser( 366 'Process Created', 367 'OS process %s was created.' % className 368 ) 369 REQUEST['RESPONSE'].redirect(osp.absolute_url())370372 """Delete OSProcesses""" 373 self.deleteDeviceComponents(self.processes, componentNames, REQUEST) 374 if REQUEST: 375 messaging.IMessageSender(self).sendToBrowser( 376 'Processes Deleted', 377 'OS processes %s were deleted.' % (', '.join(componentNames)) 378 ) 379 REQUEST['RESPONSE'].redirect(self.absolute_url()) 380 return self.callZenScreen(REQUEST)381383 """Unlock OSProcesses""" 384 self.unlockDeviceComponents(self.processes, componentNames, REQUEST) 385 if REQUEST: 386 messaging.IMessageSender(self).sendToBrowser( 387 'Processes Unlocked', 388 'OS Processes %s were unlocked.' % (', '.join(componentNames)) 389 ) 390 REQUEST['RESPONSE'].redirect(self.absolute_url()) 391 return self.callZenScreen(REQUEST)392393 - def lockOSProcessesFromDeletion(self, componentNames=[], 394 sendEventWhenBlocked=None, REQUEST=None):395 """Lock OSProcesses from deletion""" 396 self.lockDeviceComponentsFromDeletion(self.processes, componentNames, 397 sendEventWhenBlocked, REQUEST) 398 if REQUEST: 399 messaging.IMessageSender(self).sendToBrowser( 400 'Processes Locked', 401 'OS processes %s were locked from deletion.' % ( 402 ', '.join(componentNames)) 403 ) 404 REQUEST['RESPONSE'].redirect(self.absolute_url()) 405 return self.callZenScreen(REQUEST)406407 - def lockOSProcessesFromUpdates(self, componentNames=[], 408 sendEventWhenBlocked=None, REQUEST=None):409 """Lock OSProcesses from updates""" 410 self.lockDeviceComponentsFromUpdates(self.processes, componentNames, 411 sendEventWhenBlocked, REQUEST) 412 if REQUEST: 413 messaging.IMessageSender(self).sendToBrowser( 414 'Processes Locked', 415 'OS processes %s were locked from updates and deletion.' % ( 416 ', '.join(componentNames)) 417 ) 418 REQUEST['RESPONSE'].redirect(self.absolute_url()) 419 return self.callZenScreen(REQUEST)420422 """Add IpServices. 423 """ 424 org = self.dmd.Services.IpService 425 ipsc = org.find(org.parseServiceLiveSearchString(className)) 426 if ipsc is not None: 427 ips = manage_addIpService(self.ipservices, 428 ipsc.id, 429 protocol, 430 ipsc.port, 431 userCreated=userCreated) 432 self._p_changed = True 433 elif REQUEST: 434 messaging.IMessageSender(self).sendToBrowser( 435 'No Such WinService', 436 'Could not find an IP Service named %s.' % (className), 437 priority=messaging.WARNING 438 ) 439 return self.callZenScreen(REQUEST) 440 441 if REQUEST: 442 messaging.IMessageSender(self).sendToBrowser( 443 'IP Service Added', 444 'IP Service %s was added.' % (className) 445 ) 446 REQUEST['RESPONSE'].redirect(ips.absolute_url()) 447 return self.callZenScreen(REQUEST)448450 """Delete IpServices""" 451 self.deleteDeviceComponents(self.ipservices, componentNames, REQUEST) 452 if REQUEST: 453 messaging.IMessageSender(self).sendToBrowser( 454 'IP Services Deleted', 455 'IP Services %s were deleted.' % (', '.join(componentNames)) 456 ) 457 REQUEST['RESPONSE'].redirect(self.absolute_url()) 458 return self.callZenScreen(REQUEST)459461 """Unlock IpServices""" 462 self.unlockDeviceComponents(self.ipservices, componentNames, REQUEST) 463 if REQUEST: 464 messaging.IMessageSender(self).sendToBrowser( 465 'IpServices Unlocked', 466 'IP Services %s were unlocked.' % (', '.join(componentNames)) 467 ) 468 REQUEST['RESPONSE'].redirect(self.absolute_url()) 469 return self.callZenScreen(REQUEST)470471 - def lockIpServicesFromDeletion(self, componentNames=[], 472 sendEventWhenBlocked=None, REQUEST=None):473 """Lock IpServices from deletion""" 474 self.lockDeviceComponentsFromDeletion(self.ipservices, componentNames, 475 sendEventWhenBlocked, REQUEST) 476 if REQUEST: 477 messaging.IMessageSender(self).sendToBrowser( 478 'Services Locked', 479 'IP services %s were locked from deletion.' % ( 480 ', '.join(componentNames)) 481 ) 482 REQUEST['RESPONSE'].redirect(self.absolute_url()) 483 return self.callZenScreen(REQUEST)484485 - def lockIpServicesFromUpdates(self, componentNames=[], 486 sendEventWhenBlocked=None, REQUEST=None):487 """Lock IpServices from updates""" 488 self.lockDeviceComponentsFromUpdates(self.ipservices, componentNames, 489 sendEventWhenBlocked, REQUEST) 490 if REQUEST: 491 messaging.IMessageSender(self).sendToBrowser( 492 'Services Locked', 493 'IP services %s were locked from updates and deletion.' % ( 494 ', '.join(componentNames)) 495 ) 496 REQUEST['RESPONSE'].redirect(self.absolute_url()) 497 return self.callZenScreen(REQUEST)498500 """Add a FileSystem. 501 """ 502 fsid = prepId(id) 503 manage_addFileSystem(self.filesystems, id, userCreated) 504 self._p_changed = True 505 if REQUEST: 506 messaging.IMessageSender(self).sendToBrowser( 507 'Filesystem Added', 508 'Filesystem %s was added.' % id 509 ) 510 REQUEST['RESPONSE'].redirect( 511 self.filesystems._getOb(fsid).absolute_url()) 512 return self.callZenScreen(REQUEST)513515 """Delete FileSystems""" 516 self.deleteDeviceComponents(self.filesystems, componentNames, REQUEST) 517 if REQUEST: 518 messaging.IMessageSender(self).sendToBrowser( 519 'Filesystems Deleted', 520 'Filesystems %s were deleted.' % (', '.join(componentNames)) 521 ) 522 REQUEST['RESPONSE'].redirect(self.absolute_url()) 523 return self.callZenScreen(REQUEST)524526 """Unlock FileSystems""" 527 self.unlockDeviceComponents(self.filesystems, componentNames, REQUEST) 528 if REQUEST: 529 messaging.IMessageSender(self).sendToBrowser( 530 'Filesystems Unlocked', 531 'Filesystems %s were unlocked.' % (', '.join(componentNames)) 532 ) 533 REQUEST['RESPONSE'].redirect(self.absolute_url()) 534 return self.callZenScreen(REQUEST)535536 - def lockFileSystemsFromDeletion(self, componentNames=[], 537 sendEventWhenBlocked=None, REQUEST=None):538 """Lock FileSystems from deletion""" 539 self.lockDeviceComponentsFromDeletion(self.filesystems, componentNames, 540 sendEventWhenBlocked, REQUEST) 541 if REQUEST: 542 messaging.IMessageSender(self).sendToBrowser( 543 'Filesystems Locked', 544 'Filesystems %s were locked from deletion.' % ( 545 ', '.join(componentNames)) 546 ) 547 REQUEST['RESPONSE'].redirect(self.absolute_url()) 548 return self.callZenScreen(REQUEST)549550 - def lockFileSystemsFromUpdates(self, componentNames=[], 551 sendEventWhenBlocked=None, REQUEST=None):552 """Lock FileSystems from updates""" 553 self.lockDeviceComponentsFromUpdates(self.filesystems, componentNames, 554 sendEventWhenBlocked, REQUEST) 555 if REQUEST: 556 messaging.IMessageSender(self).sendToBrowser( 557 'Filesystems Locked', 558 'Filesystems %s were locked from updates and deletion.' % ( 559 ', '.join(componentNames)) 560 ) 561 REQUEST['RESPONSE'].redirect(self.absolute_url()) 562 return self.callZenScreen(REQUEST)563564 - def addIpRouteEntry(self, dest, routemask, nexthopid, interface, 565 routeproto, routetype, userCreated, REQUEST=None):566 """Add an IpRouteEntry. 567 """ 568 manage_addIpRouteEntry(self.routes, 569 dest, 570 routemask, 571 nexthopid, 572 interface, 573 routeproto, 574 routetype, 575 userCreated=userCreated) 576 self._p_changed = True 577 if REQUEST: 578 messaging.IMessageSender(self).sendToBrowser( 579 'Route Created', 580 'IP route entry was created.' 581 ) 582 REQUEST['RESPONSE'].redirect(self.absolute_url()) 583 return self.callZenScreen(REQUEST)584586 """Delete IpRouteEntries""" 587 self.deleteDeviceComponents(self.routes, componentNames, REQUEST) 588 if REQUEST: 589 messaging.IMessageSender(self).sendToBrowser( 590 'Routes Deleted', 591 'IP route entries %s were deleted.' % (', '.join(componentNames)) 592 ) 593 REQUEST['RESPONSE'].redirect(self.absolute_url()) 594 return self.callZenScreen(REQUEST)595597 """Unlock IpRouteEntries""" 598 self.unlockDeviceComponents(self.routes, componentNames, REQUEST) 599 if REQUEST: 600 messaging.IMessageSender(self).sendToBrowser( 601 'Routes Unlocked', 602 'IP route entries %s were unlocked.' % ( 603 ', '.join(componentNames)) 604 ) 605 REQUEST['RESPONSE'].redirect(self.absolute_url()) 606 return self.callZenScreen(REQUEST)607608 - def lockIpRouteEntriesFromDeletion(self, componentNames=[], 609 sendEventWhenBlocked=None, REQUEST=None):610 """Lock IpRouteEntries from deletion""" 611 self.lockDeviceComponentsFromDeletion(self.routes, componentNames, 612 sendEventWhenBlocked, REQUEST) 613 if REQUEST: 614 messaging.IMessageSender(self).sendToBrowser( 615 'Routes Locked', 616 'IP route entries %s were locked from deletion.' % ( 617 ', '.join(componentNames)) 618 ) 619 REQUEST['RESPONSE'].redirect(self.absolute_url()) 620 return self.callZenScreen(REQUEST)621622 - def lockIpRouteEntriesFromUpdates(self, componentNames=[], 623 sendEventWhenBlocked=None, REQUEST=None):624 """Lock IpRouteEntries from updates""" 625 self.lockDeviceComponentsFromUpdates(self.routes, componentNames, 626 sendEventWhenBlocked, REQUEST) 627 if REQUEST: 628 messaging.IMessageSender(self).sendToBrowser( 629 'Routes Locked', 630 'IP route entries %s were locked from updates and deletion.' % ( 631 ', '.join(componentNames)) 632 ) 633 REQUEST['RESPONSE'].redirect(self.absolute_url()) 634 return self.callZenScreen(REQUEST)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu May 7 11:46:25 2009 | http://epydoc.sourceforge.net |