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

Source Code for Module 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   
 16  DmdBuilder builds out the core containment structure used in the dmd database. 
 17   
 18  Devices 
 19  Groups 
 20  Locations 
 21  Networks 
 22  ServiceAreas 
 23  Services 
 24  Systems 
 25   
 26  $Id: DmdBuilder.py,v 1.11 2004/04/06 22:33:07 edahl Exp $""" 
 27   
 28  __version__ = "$Revision: 1.11 $"[11:-2] 
 29   
 30  import sys 
 31  import os 
 32   
 33  import transaction 
 34  import Zope2 
 35   
 36  from OFS.Image import File 
 37  from Acquisition import aq_base 
 38   
 39  from Products.ZenModel.DeviceClass import DeviceClass 
 40  from Products.ZenModel.Location import Location 
 41  from Products.ZenModel.DeviceGroup import DeviceGroup 
 42  from Products.ZenModel.ProductClass import ProductClass 
 43  from Products.ZenModel.IpNetwork import manage_addIpNetwork 
 44  from Products.ZenModel.ManufacturerRoot import ManufacturerRoot 
 45  from Products.ZenModel.MibOrganizer import MibOrganizer 
 46  from Products.ZenModel.OSProcessOrganizer import OSProcessOrganizer 
 47  from Products.ZenModel.ServiceOrganizer import ServiceOrganizer 
 48  from Products.ZenModel.System import System 
 49  from Products.ZenModel.MonitorClass import MonitorClass 
 50  from Products.ZenModel.ReportClass import ReportClass 
 51  from Products.ZenModel.DeviceReportClass import DeviceReportClass 
 52  from Products.ZenModel.CustomDeviceReportClass import CustomDeviceReportClass 
 53  from Products.ZenModel.GraphReportClass import GraphReportClass 
 54  from Products.ZenModel.MultiGraphReportClass import MultiGraphReportClass 
 55  from Products.ZenModel.DataRoot import DataRoot 
 56  from Products.ZenModel.ZDeviceLoader import manage_addZDeviceLoader 
 57  from Products.ZenModel.ZenossInfo import manage_addZenossInfo 
 58  from Products.ZenWidgets.ZenTableManager import manage_addZenTableManager 
 59  from Products.ZenModel.PerformanceConf import manage_addPerformanceConf 
 60  from Products.ZenModel.StatusMonitorConf import manage_addStatusMonitorConf 
 61  from Products.ZenRRD.RenderServer import manage_addRenderServer 
 62  from Products.ZenReports.ReportServer import manage_addReportServer 
 63  from Products.ZenEvents.MySqlEventManager import manage_addMySqlEventManager 
 64  from Products.ZenEvents.EventClass import manage_addEventClass 
 65  from Products.CMFCore.DirectoryView import manage_addDirectoryView 
 66  from Products.ZenModel.UserSettings import manage_addUserSettingsManager 
 67  from Products.ZenModel.LinkManager import manage_addLinkManager 
 68  from Products.ZenWidgets.PortletManager import manage_addPortletManager 
 69  from Products.ZenWidgets.ZenossPortlets import ZenossPortlets 
 70   
 71  classifications = { 
 72      'Devices':          DeviceClass, 
 73      'Groups':           DeviceGroup, 
 74      'Locations':        Location, 
 75      'Systems':          System, 
 76      'Services':         ServiceOrganizer, 
 77      'Manufacturers':    ManufacturerRoot, 
 78      'Mibs':             MibOrganizer, 
 79      'Processes':        OSProcessOrganizer, 
 80      'Monitors':         MonitorClass, 
 81      'Reports':          ReportClass, 
 82  } 
 83   
84 -class DmdBuilder:
85 86 # Top level organizers for dmd 87 dmdroots = ( 88 'Devices', 89 'Groups', 90 'Locations', 91 'Systems', 92 'Services', 93 'Processes', 94 'Manufacturers', 95 'Mibs', 96 'Monitors', 97 'Reports', 98 ) 99 100 # default monitor classes 101 monRoots = ('StatusMonitors','Performance') 102 103
104 - def __init__(self, portal, evthost, evtuser, evtpass, evtdb, 105 smtphost, smtpport, snpphost, snppport):
106 self.portal = portal 107 self.evthost = evthost 108 self.evtuser = evtuser 109 self.evtpass = evtpass 110 self.evtdb = evtdb 111 dmd = DataRoot('dmd') 112 self.portal._setObject(dmd.id, dmd) 113 self.dmd = self.portal._getOb('dmd') 114 self.dmd.smtpHost = smtphost 115 self.dmd.snppHost = snpphost 116 self.dmd.smtpPort = smtpport 117 self.dmd.snppPort = snppport
118 119
120 - def buildRoots(self):
121 self.addroots(self.dmd, self.dmdroots, isInTree=True) 122 self.dmd.Devices.buildDeviceTreeProperties()
123 124
125 - def buildMonitors(self):
126 mons = self.dmd.Monitors 127 self.addroots(mons, self.monRoots, "Monitors") 128 mons.Performance.sub_class = 'PerformanceConf' 129 mons.StatusMonitors.sub_class = 'StatusMonitorConf' 130 manage_addPerformanceConf(mons.Performance, "localhost") 131 crk = mons.Performance._getOb("localhost") 132 crk.renderurl = "/zport/RenderServer" 133 manage_addStatusMonitorConf(mons.StatusMonitors,"localhost")
134 135
136 - def buildUserCommands(self):
137 for id, cmd in ( 138 ('ping', 'ping -c2 ${device/manageIp}'), 139 ('traceroute', 'traceroute -q 1 -w 2 ${device/manageIp}'), 140 ('DNS forward', 'host ${device/manageIp}'), 141 ('DNS reverse', 'host ${device/id}'), 142 ('snmpwalk', 'snmpwalk -v1 -c${device/zSnmpCommunity}' 143 ' ${here/manageIp} system'), 144 ): 145 self.dmd.manage_addUserCommand(id, cmd=cmd)
146 147
148 - def addroots(self, base, rlist, classType=None, isInTree=False):
149 for rname in rlist: 150 ctype = classType or rname 151 if not hasattr(base, rname): 152 dr = classifications[ctype](rname) 153 base._setObject(dr.id, dr) 154 dr = base._getOb(dr.id) 155 dr.isInTree = isInTree 156 if dr.id in ('Devices'): 157 dr.createCatalog()
158 159
160 - def buildReportClasses(self):
161 if not hasattr(self.dmd.Reports, 'Device Reports'): 162 rc = DeviceReportClass('Device Reports') 163 self.dmd.Reports._setObject(rc.id, rc) 164 if not hasattr(self.dmd.Reports, 'Custom Device Reports'): 165 rc = CustomDeviceReportClass('Custom Device Reports') 166 self.dmd.Reports._setObject(rc.id, rc) 167 if not hasattr(self.dmd.Reports, 'Graph Reports'): 168 rc = GraphReportClass('Graph Reports') 169 self.dmd.Reports._setObject(rc.id, rc) 170 if not hasattr(self.dmd.Reports, 'Multi-Graph Reports'): 171 rc = MultiGraphReportClass('Multi-Graph Reports') 172 self.dmd.Reports._setObject(rc.id, rc)
173
174 - def buildPortlets(self):
175 manage_addPortletManager(self.portal) 176 zpmgr = self.portal.ZenPortletManager 177 ZenossPortlets.register_default_portlets(zpmgr)
178 179
180 - def build(self):
181 self.buildRoots() 182 self.buildMonitors() 183 self.buildUserCommands() 184 self.buildReportClasses() 185 self.buildPortlets() 186 manage_addEventClass(self.dmd) 187 manage_addZDeviceLoader(self.dmd) 188 manage_addZenTableManager(self.portal) 189 manage_addZenossInfo(self.portal) 190 manage_addDirectoryView(self.portal,'ZenUtils/js', 'js') 191 manage_addRenderServer(self.portal, "RenderServer") 192 manage_addReportServer(self.portal, "ReportServer") 193 manage_addMySqlEventManager(self.dmd, evthost=self.evthost, 194 evtuser=self.evtuser, evtpass=self.evtpass, 195 evtdb=self.evtdb) 196 manage_addMySqlEventManager(self.dmd, evthost=self.evthost, 197 evtuser=self.evtuser, evtpass=self.evtpass, 198 evtdb=self.evtdb, 199 history=True) 200 manage_addUserSettingsManager(self.dmd) 201 manage_addLinkManager(self.dmd) 202 manage_addIpNetwork(self.dmd, "Networks")
203