1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 __doc__= """RRDDaemon
16
17 Common performance monitoring daemon code for performance daemons.
18 """
19
20 import socket
21
22 import Globals
23 from Products.ZenEvents import Event
24
25 from twisted.python import failure
26
27 from Products.ZenHub.PBDaemon import FakeRemote, PBDaemon
28 from Products.ZenRRD.Thresholds import Thresholds
29 from Products.ZenUtils.Utils import unused
30
31
32 BAD_SEVERITY=Event.Warning
33
34 BASE_URL = 'http://localhost:8080/zport/dmd'
35 DEFAULT_URL = BASE_URL + '/Monitors/Performance/localhost'
36
37
38 COMMON_EVENT_INFO = {
39 'manager': socket.getfqdn(),
40 }
41
42
44 """
45 Holds the code common to performance gathering daemons.
46 """
47
48 properties = ('configCycleInterval',)
49 configCycleInterval = 20
50 rrd = None
51 shutdown = False
52 thresholds = None
53
55 """
56 Initializer
57
58 @param name: name of the daemon
59 @type name: string
60 @param noopts: process command-line arguments?
61 @type noopts: boolean
62 """
63 self.events = []
64 self.name = name
65 PBDaemon.__init__(self, noopts)
66 self.thresholds = Thresholds()
67
68
70 """
71 Determine which devices we shouldn't expect to hear back from.
72
73 @return: list of devices
74 @rtype: list
75 """
76 return self.eventService().callRemote('getDevicePingIssues')
77
78
80 """
81 Set zProperties provided from zenhub.
82
83 @param items: list of zProperties to obtain
84 @type items: list
85 """
86 self.log.debug("Async update of collection properties")
87 self.setPropertyItems(items)
88
89
91 """
92 Callable from zenhub.
93
94 @param devices: list of devices (unused)
95 @type devices: list
96 """
97 unused(devices)
98 self.log.debug("Async update of device list")
99
100
102 """
103 Set zProperties
104
105 @param items: list of zProperties
106 @type items: list
107 """
108 table = dict(items)
109 for name in self.properties:
110 value = table.get(name, None)
111 if value is not None:
112 if getattr(self, name) != value:
113 self.log.debug('Updated %s config to %s' % (name, value))
114 setattr(self, name, value)
115
116
118 """
119 "Send the right event class for threshhold events"
120
121 @param kw: keyword arguments describing an event
122 @type kw: dictionary of keyword arguments
123 """
124 self.sendEvent({}, **kw)
125
126
128 """
129 Command-line options to add
130 """
131 PBDaemon.buildOptions(self)
132 self.parser.add_option('-d', '--device',
133 dest='device',
134 default='',
135 help="Specify a specific device to monitor")
136
137
139 """
140 Log messages to the logger
141
142 @param msg: the message
143 @type msg: string
144 @param error: an exception
145 @type error: Exception
146 """
147 if isinstance(error, failure.Failure):
148 from twisted.internet.error import TimeoutError
149 if isinstance(error.value, TimeoutError):
150 self.log.warning("Timeout Error")
151 else:
152 self.log.exception(error)
153 else:
154 self.log.error('%s %s', msg, error)
155
156
158 """
159 Log an error, including any traceback data for a failure Exception
160 Stop if we got the --cycle command-line option.
161
162 @param error: the error message
163 @type error: string
164 """
165 self.logError('Error', error)
166 if not self.options.cycle:
167 self.stop()
168
169
171 """
172 Twisted callback to receive fatal messages.
173
174 @param why: the error message
175 @type why: string
176 """
177 self.error(why)
178 self.stop()
179
180
189