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

# Source Code for Module Products.ZenModel.DmdBuilder

      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__="""DmdBuilder
     15  DmdBuilder builds out the core containment structure used in the dmd database.
     16
     17  Devices
     18  Groups
     19  Locations
     20  Networks
     21  ServiceAreas
     22  Services
     23  Systems
     24  """
     25
     26  from Products.ZenModel.DeviceClass import DeviceClass
     27  from Products.ZenModel.Location import Location
     28  from Products.ZenModel.DeviceGroup import DeviceGroup
     29  from Products.ZenModel.IpNetwork import manage_addIpNetwork
     30  from Products.ZenModel.ManufacturerRoot import ManufacturerRoot
     31  from Products.ZenModel.MibOrganizer import MibOrganizer
     32  from Products.ZenModel.OSProcessOrganizer import OSProcessOrganizer
     33  from Products.ZenModel.ServiceOrganizer import ServiceOrganizer
     34  from Products.ZenModel.System import System
     35  from Products.ZenModel.MonitorClass import MonitorClass
     36  from Products.ZenModel.ReportClass import ReportClass
     37  from Products.ZenModel.DeviceReportClass import DeviceReportClass
     38  from Products.ZenModel.CustomDeviceReportClass import CustomDeviceReportClass
     39  from Products.ZenModel.GraphReportClass import GraphReportClass
     40  from Products.ZenModel.MultiGraphReportClass import MultiGraphReportClass
     41  from Products.ZenModel.DataRoot import DataRoot
     42  from Products.ZenModel.ZDeviceLoader import manage_addZDeviceLoader
     43  from Products.ZenModel.ZenossInfo import manage_addZenossInfo
     44  from Products.ZenWidgets.ZenTableManager import manage_addZenTableManager
     45  from Products.ZenModel.PerformanceConf import manage_addPerformanceConf
     46  from Products.ZenRRD.RenderServer import manage_addRenderServer
     47  from Products.ZenReports.ReportServer import manage_addReportServer
     48  from Products.ZenEvents.MySqlEventManager import manage_addMySqlEventManager
     49  from Products.ZenEvents.EventClass import manage_addEventClass
     50  from Products.CMFCore.DirectoryView import manage_addDirectoryView
     51  from Products.ZenModel.UserSettings import manage_addUserSettingsManager
     52  from Products.ZenModel.LinkManager import manage_addLinkManager
     53  from Products.ZenWidgets.PortletManager import manage_addPortletManager
     54  from Products.ZenWidgets.ZenossPortlets import ZenossPortlets
     55  from Products.ZenModel.ZenPackManager import manage_addZenPackManager
     56  from Products.Jobber.manager import manage_addJobManager
     57  from Products.ZenModel.ZenPackPersistence import CreateZenPackPersistenceCatalog
     58  from Products.ZenModel.RRDTemplate import CreateRRDTemplatesCatalog
     59  from Products.ZenModel.MaintenanceWindow import createMaintenanceWindowCatalog
     60  from Products.ZenModel.ZenossSecurity import \
     61       MANAGER_ROLE, ZEN_MANAGER_ROLE, ZEN_USER_ROLE, OWNER_ROLE
     62
     63 -class DmdBuilder(object):
     64
     65 -    def __init__(self, portal, evthost, evtuser, evtpass, evtdb, evtport,
     66                      smtphost, smtpport, pagecommand):
     67          self.portal = portal
     68          self.evthost = evthost
     69          self.evtuser = evtuser
     70          self.evtpass = evtpass
     71          self.evtport = evtport
     72          self.evtdb = evtdb
     73          dmd = DataRoot('dmd')
     74          self.portal._setObject(dmd.id, dmd)
     75          self.dmd = self.portal._getOb('dmd')
     76          self.dmd._rq = False
     77          self.dmd.smtpHost = smtphost
     78          self.dmd.smtpPort = smtpport
     79          self.dmd.pageCommand = pagecommand
     80          self.dmd.propertyTransformers = {}
     81          self.dmd.manage_permission('Access contents information',
     82                                     ['Authenticated',
     83                                      MANAGER_ROLE,
     84                                      ZEN_MANAGER_ROLE,
     85                                      ZEN_USER_ROLE,
     86                                      OWNER_ROLE],
     87                                     0)
     88
     89 -    def buildRoots(self):
     90          roots = [('Devices', DeviceClass),
     91                   ('Groups', DeviceGroup),
     92                   ('Locations', Location),
     93                   ('Manufacturers', ManufacturerRoot),
     94                   ('Monitors', MonitorClass),
     95                   ('Mibs', MibOrganizer),
     96                   ('Processes', OSProcessOrganizer),
     97                   ('Reports', ReportClass),
     98                   ('Services', ServiceOrganizer),
     99                   ('Systems', System),
    100                   ]
    101          for objectId, construct in roots:
    102              if objectId not in self.dmd.objectIds():
    103                  object = construct(objectId)
    104                  object.isInTree = True
    105                  self.dmd._setObject(objectId, object)
    106          devices = self.dmd._getOb('Devices')
    107          devices.createCatalog()
    108          devices.buildDeviceTreeProperties()
    109
    110 -    def buildMonitors(self):
    111          perfId = 'Performance'
    112          monitors = self.dmd._getOb('Monitors')
    113          if perfId not in monitors.objectIds():
    114              monitors._setObject(perfId, MonitorClass(perfId))
    115              perf = monitors._getOb(perfId)
    116              perf.isInTree = False
    117              perf.sub_class = 'PerformanceConf'
    118              perfConfId = 'localhost'
    119              manage_addPerformanceConf(perf, perfConfId)
    120              perfConf = monitors.Performance._getOb(perfConfId)
    121              perfConf.renderurl = '/zport/RenderServer'
    122
    123 -    def buildUserCommands(self):
    124          for id, cmd, desc in (
    125                  ('ping', 'ping -c2 ${device/manageIp}',
    126                   "Is the device responding to ping?"),
    127                  ('traceroute', 'traceroute -q 1 -w 2 ${device/manageIp}',
    128                   "Show the route to the device"),
    129                  ('DNS forward', 'host ${device/id}',
    130                   "Name to IP address lookup"),
    131                  ('DNS reverse', 'host ${device/manageIp}',
    132                   "IP address to name lookup"),
    133                  ('snmpwalk', 'snmpwalk -${device/zSnmpVer} '
    134                   '-c${device/zSnmpCommunity} ${here/manageIp} system',
    135                   "Display the OIDs available on a device"),
    136                  ):
    137              self.dmd.manage_addUserCommand(id, cmd=cmd, desc=desc)
    138
    139 -    def buildReportClasses(self):
    140          if not hasattr(self.dmd.Reports, 'Device Reports'):
    141              rc = DeviceReportClass('Device Reports')
    142              self.dmd.Reports._setObject(rc.id, rc)
    143          if not hasattr(self.dmd.Reports, 'Custom Device Reports'):
    144              rc = CustomDeviceReportClass('Custom Device Reports')
    145              self.dmd.Reports._setObject(rc.id, rc)
    146          if not hasattr(self.dmd.Reports, 'Graph Reports'):
    147              rc = GraphReportClass('Graph Reports')
    148              self.dmd.Reports._setObject(rc.id, rc)
    149          if not hasattr(self.dmd.Reports, 'Multi-Graph Reports'):
    150              rc = MultiGraphReportClass('Multi-Graph Reports')
    151              self.dmd.Reports._setObject(rc.id, rc)
    152
    153 -    def buildPortlets(self):
    154          manage_addPortletManager(self.portal)
    155          zpmgr = self.portal.ZenPortletManager
    156          ZenossPortlets.register_default_portlets(zpmgr)
    157
    158 -    def build(self):
    159          self.buildRoots()
    160          self.buildMonitors()
    161          self.buildUserCommands()
    162          self.buildReportClasses()
    163          self.buildPortlets()
    164          manage_addEventClass(self.dmd)
    165          manage_addZDeviceLoader(self.dmd)
    166          manage_addZenTableManager(self.portal)
    167          manage_addZenossInfo(self.portal)
    168          manage_addDirectoryView(self.portal,'ZenUtils/js', 'js')
    169          manage_addRenderServer(self.portal, "RenderServer")
    170          manage_addReportServer(self.portal, "ReportServer")
    171          manage_addMySqlEventManager(self.dmd, evthost=self.evthost,
    172                                      evtuser=self.evtuser, evtpass=self.evtpass,
    173                                      evtdb=self.evtdb, evtport=self.evtport)
    174          manage_addMySqlEventManager(self.dmd, evthost=self.evthost,
    175                                      evtuser=self.evtuser, evtpass=self.evtpass,
    176                                      evtdb=self.evtdb, evtport=self.evtport,
    177                                      history=True)
    178          manage_addUserSettingsManager(self.dmd)
    179          manage_addLinkManager(self.dmd)
    180          manage_addJobManager(self.dmd)
    181          manage_addIpNetwork(self.dmd, "Networks")
    182          manage_addZenPackManager(self.dmd)
    183          CreateZenPackPersistenceCatalog(self.dmd)
    184          CreateRRDTemplatesCatalog(self.dmd)
    185          createMaintenanceWindowCatalog(self.dmd)
    186