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.Zuul.catalog.global_catalog import createGlobalCatalog
     61  from Products.ZenModel.ZenossSecurity import \
     62       MANAGER_ROLE, ZEN_MANAGER_ROLE, ZEN_USER_ROLE, OWNER_ROLE
     63
     64 -class DmdBuilder(object):
     65
     66 -    def __init__(self, portal, evthost, evtuser, evtpass, evtdb, evtport,
     67                      smtphost, smtpport, pagecommand):
     68          self.portal = portal
     69          self.evthost = evthost
     70          self.evtuser = evtuser
     71          self.evtpass = evtpass
     72          self.evtport = evtport
     73          self.evtdb = evtdb
     74          dmd = DataRoot('dmd')
     75          self.portal._setObject(dmd.id, dmd)
     76          self.dmd = self.portal._getOb('dmd')
     77          self.dmd._rq = False
     78          self.dmd.smtpHost = smtphost
     79          self.dmd.smtpPort = smtpport
     80          self.dmd.pageCommand = pagecommand
     81          self.dmd.propertyTransformers = {}
     82          self.dmd.manage_permission('Access contents information',
     83                                     ['Authenticated',
     84                                      MANAGER_ROLE,
     85                                      ZEN_MANAGER_ROLE,
     86                                      ZEN_USER_ROLE,
     87                                      OWNER_ROLE],
     88                                     0)
     89
     90 -    def buildRoots(self):
     91          roots = [('Devices', DeviceClass),
     92                   ('Groups', DeviceGroup),
     93                   ('Locations', Location),
     94                   ('Manufacturers', ManufacturerRoot),
     95                   ('Monitors', MonitorClass),
     96                   ('Mibs', MibOrganizer),
     97                   ('Processes', OSProcessOrganizer),
     98                   ('Reports', ReportClass),
     99                   ('Services', ServiceOrganizer),
    100                   ('Systems', System),
    101                   ]
    102          for objectId, construct in roots:
    103              if objectId not in self.dmd.objectIds():
    104                  object = construct(objectId)
    105                  object.isInTree = True
    106                  self.dmd._setObject(objectId, object)
    107          devices = self.dmd._getOb('Devices')
    108          devices.createCatalog()
    109          devices.buildDeviceTreeProperties()
    110
    111 -    def buildMonitors(self):
    112          perfId = 'Performance'
    113          monitors = self.dmd._getOb('Monitors')
    114          if perfId not in monitors.objectIds():
    115              monitors._setObject(perfId, MonitorClass(perfId))
    116              perf = monitors._getOb(perfId)
    117              perf.isInTree = False
    118              perf.sub_class = 'PerformanceConf'
    119              perfConfId = 'localhost'
    120              manage_addPerformanceConf(perf, perfConfId)
    121              perfConf = monitors.Performance._getOb(perfConfId)
    122              perfConf.renderurl = '/zport/RenderServer'
    123
    124 -    def buildUserCommands(self):
    125          for id, cmd, desc in (
    126                  ('ping', 'ping -c2 ${device/manageIp}',
    127                   "Is the device responding to ping?"),
    128                  ('traceroute', 'traceroute -q 1 -w 2 ${device/manageIp}',
    129                   "Show the route to the device"),
    130                  ('DNS forward', 'host ${device/id}',
    131                   "Name to IP address lookup"),
    132                  ('DNS reverse', 'host ${device/manageIp}',
    133                   "IP address to name lookup"),
    134                  ('snmpwalk', 'snmpwalk -${device/zSnmpVer} '
    135                   '-c${device/zSnmpCommunity} ${here/manageIp} system',
    136                   "Display the OIDs available on a device"),
    137                  ):
    138              self.dmd.manage_addUserCommand(id, cmd=cmd, desc=desc)
    139
    140 -    def buildReportClasses(self):
    141          if not hasattr(self.dmd.Reports, 'Device Reports'):
    142              rc = DeviceReportClass('Device Reports')
    143              self.dmd.Reports._setObject(rc.id, rc)
    144          if not hasattr(self.dmd.Reports, 'Custom Device Reports'):
    145              rc = CustomDeviceReportClass('Custom Device Reports')
    146              self.dmd.Reports._setObject(rc.id, rc)
    147          if not hasattr(self.dmd.Reports, 'Graph Reports'):
    148              rc = GraphReportClass('Graph Reports')
    149              self.dmd.Reports._setObject(rc.id, rc)
    150          if not hasattr(self.dmd.Reports, 'Multi-Graph Reports'):
    151              rc = MultiGraphReportClass('Multi-Graph Reports')
    152              self.dmd.Reports._setObject(rc.id, rc)
    153
    154 -    def buildPortlets(self):
    155          manage_addPortletManager(self.portal)
    156          zpmgr = self.portal.ZenPortletManager
    157          ZenossPortlets.register_default_portlets(zpmgr)
    158
    159 -    def build(self):
    160          createGlobalCatalog(self.portal)
    161          self.buildRoots()
    162          self.buildMonitors()
    163          self.buildUserCommands()
    164          self.buildReportClasses()
    165          self.buildPortlets()
    166          manage_addEventClass(self.dmd)
    167          manage_addZDeviceLoader(self.dmd)
    168          manage_addZenTableManager(self.portal)
    169          manage_addZenossInfo(self.portal)
    170          manage_addDirectoryView(self.portal,'ZenUtils/js', 'js')
    171          manage_addRenderServer(self.portal, "RenderServer")
    172          manage_addReportServer(self.portal, "ReportServer")
    173          manage_addMySqlEventManager(self.dmd, evthost=self.evthost,
    174                                      evtuser=self.evtuser, evtpass=self.evtpass,
    175                                      evtdb=self.evtdb, evtport=self.evtport)
    176          manage_addMySqlEventManager(self.dmd, evthost=self.evthost,
    177                                      evtuser=self.evtuser, evtpass=self.evtpass,
    178                                      evtdb=self.evtdb, evtport=self.evtport,
    179                                      history=True)
    180          manage_addUserSettingsManager(self.dmd)
    181          manage_addLinkManager(self.dmd)
    182          manage_addJobManager(self.dmd)
    183          manage_addIpNetwork(self.dmd, "Networks")
    184          manage_addZenPackManager(self.dmd)
    185          CreateZenPackPersistenceCatalog(self.dmd)
    186          CreateRRDTemplatesCatalog(self.dmd)
    187          createMaintenanceWindowCatalog(self.dmd)
    188