1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""zenbuild
15
16 Build the zentinel portal object and the dmd database
17
18 $Id: DmdBuilder.py,v 1.11 2004/04/06 22:33:07 edahl Exp $"""
19
20 __version__ = "$Revision: 1.11 $"[11:-2]
21
22 import sys
23 import os
24
25 import Globals
26 import transaction
27
28 from Products.ZenUtils.Utils import zenPath
29
30 from Products.ZenUtils import Security
31 from Products.ZenUtils.CmdBase import CmdBase
32 from Products.PluggableAuthService import plugins
33
35
36 sitename = "zport"
37
39 CmdBase.__init__(self)
40 zopeconf = zenPath("etc/zope.conf")
41 import Zope2
42 Zope2.configure(zopeconf)
43 self.app = Zope2.app()
44
45
47 CmdBase.buildOptions(self)
48 self.parser.add_option('-s','--evthost', dest="evthost",
49 default="127.0.0.1", help="events database hostname")
50 self.parser.add_option('-u','--evtuser', dest="evtuser", default="root",
51 help="username used to connect to the events database")
52 self.parser.add_option('-p','--evtpass', dest="evtpass", default="",
53 help="password used to connect to the events database")
54 self.parser.add_option('-d','--evtdb', dest="evtdb", default="events",
55 help="name of events database")
56 self.parser.add_option('--smtphost', dest="smtphost", default="localhost",
57 help="smtp host")
58 self.parser.add_option('--smtpport', dest="smtpport", default=25,
59 help="smtp port")
60 self.parser.add_option('--snpphost', dest="snpphost", default="localhost",
61 help="snpp host")
62 self.parser.add_option('--snppport', dest="snppport", default=444,
63 help="snpp port")
64
65
67 site = getattr(self.app, self.sitename, None)
68 if site is not None:
69 print "zport portal object exits; exiting."
70 return
71
72 from Products.ZenModel.ZentinelPortal import manage_addZentinelPortal
73 manage_addZentinelPortal(self.app, self.sitename)
74 site = self.app._getOb(self.sitename)
75
76
77 if self.app.hasObject('index_html'):
78 self.app._delObject('index_html')
79 from Products.PythonScripts.PythonScript import manage_addPythonScript
80 manage_addPythonScript(self.app, 'index_html')
81 newIndexHtml = self.app._getOb('index_html')
82 text = 'container.REQUEST.RESPONSE.redirect("/zport/dmd/")\n'
83 newIndexHtml.ZPythonScript_edit('', text)
84
85
86 if self.app.hasObject('standard_error_message'):
87 self.app._delObject('standard_error_message')
88 file = open(zenPath('Products/ZenModel/dtml/standard_error_message.dtml'))
89 try:
90 text = file.read()
91 finally:
92 file.close()
93 import OFS.DTMLMethod
94 OFS.DTMLMethod.addDTMLMethod(self.app, id='standard_error_message',
95 file=text)
96
97
98
99 Security.replaceACLWithPAS(self.app, deleteBackup=True)
100
101
102 acl = site.acl_users
103 if not hasattr(acl, 'groupManager'):
104 plugins.ZODBGroupManager.addZODBGroupManager(acl, 'groupManager')
105 acl.groupManager.manage_activateInterfaces(['IGroupsPlugin',])
106
107 trans = transaction.get()
108 trans.note("Initial ZentinelPortal load by zenbuild.py")
109 trans.commit()
110 print "ZentinelPortal loaded at %s" % self.sitename
111
112
113 from Products.ZenModel.DmdBuilder import DmdBuilder
114 dmdBuilder = DmdBuilder(site,
115 self.options.evthost,
116 self.options.evtuser,
117 self.options.evtpass,
118 self.options.evtdb,
119 self.options.smtphost,
120 self.options.smtpport,
121 self.options.snpphost,
122 self.options.snppport)
123 dmdBuilder.build()
124 transaction.commit()
125
126
127
128
129 from Products.ZenReports.ReportLoader import ReportLoader
130 rl = ReportLoader(noopts=True, app=self.app)
131 rl.loadDatabase()
132
133
134 from Products.ZenModel.XmlDataLoader import XmlDataLoader
135 dl = XmlDataLoader(noopts=True, app=self.app)
136 dl.loadDatabase()
137
138
139 if __name__ == "__main__":
140 zb = zenbuild()
141 zb.build()
142