1
2
3
4
5
6
7
8
9
10
11
12
13
14 import types
15 import logging
16 log = logging.getLogger("zen.Events")
17
18 from Globals import InitializeClass
19 from Globals import DTMLFile
20 from AccessControl import ClassSecurityInfo
21
22 from EventManagerBase import EventManagerBase
23 from MySqlSendEvent import MySqlSendEventMixin
24 from Exceptions import *
25
26 -def manage_addMySqlEventManager(context, id=None, evthost="localhost",
27 evtuser="root", evtpass="", evtdb="events",
28 evtport=3306,
29 history=False, REQUEST=None):
51
52
53 addMySqlEventManager = DTMLFile('dtml/addMySqlEventManager',globals())
54
55
57
58 portal_type = meta_type = 'MySqlEventManager'
59
60 backend = "mysql"
61
62 security = ClassSecurityInfo()
63
65 """
66 Return a list of tuples with the CSS class, acknowledged count, count
67
68 [['zenevents_5', 0, 3], ...]
69
70 select severity, count(*), group_concat(eventState),
71 from status where device="win2k.confmon.loc"
72 and eventState < 2 group by severity desc;
73 """
74 select = "select severity, count(*), group_concat(eventState) "
75 select += "from %s where " % self.statusTable
76 where = self._wand(where, "%s >= %s", self.severityField, severity)
77 where = self._wand(where, "%s <= %s", self.stateField, state)
78 if prodState is not None:
79 where = self._wand(where, "%s >= %s", 'prodState', prodState)
80 where = self.restrictedUserFilter(where)
81 select += where
82 select += " group by severity desc"
83
84 sevsum = self.checkCache(select)
85 if sevsum: return sevsum
86 zem = self.dmd.ZenEventManager
87 conn = zem.connect()
88 try:
89 curs = conn.cursor()
90 curs.execute(select)
91 sumdata = {}
92 for row in curs.fetchall():
93 sev, count, acks = row[:3]
94 if hasattr(acks, 'tostring'):
95 acks = acks.tostring()
96 if type(acks) in types.StringTypes:
97 acks = acks.split(",")
98 ackcount = sum([int(n) for n in acks if n.strip()])
99 sumdata[sev] = (ackcount, count)
100 sevsum = []
101 for name, value in self.getSeverities():
102 if value < severity: continue
103 css = self.getEventCssClass(value)
104 ackcount, count = sumdata.get(value, [0,0])
105 sevsum.append([css, ackcount, int(count)])
106 finally: zem.close(conn)
107
108 self.addToCache(select, sevsum)
109 self.cleanCache()
110 return sevsum
111
113 ''' since is number of seconds since epoch, see documentation
114 for python time.time()
115 '''
116 count = 0
117 zem = self.dmd.ZenEventManager
118 conn = zem.connect()
119 try:
120 curs = conn.cursor()
121 for table in ('status', 'history'):
122 curs.execute('select count(*) from %s where firstTime >= %s' %
123 (table, since))
124 count += curs.fetchall()[0][0]
125 finally: zem.close(conn)
126 return count
127
128 InitializeClass(MySqlEventManager)
129