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

# Source Code for Module Products.ZenModel.DmdBuilder

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