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 PBDaemon.__init__(self, noopts, name=name)
65 self.thresholds = Thresholds()
66
67
69 """
70 Determine which devices we shouldn't expect to hear back from.
71
72 @return: list of devices
73 @rtype: list
74 """
75 return self.eventService().callRemote('getDevicePingIssues')
76
77
79 """
80 Set zProperties provided from zenhub.
81
82 @param items: list of zProperties to obtain
83 @type items: list
84 """
85 self.log.debug("Async update of collection properties")
86 self.setPropertyItems(items)
87
88
90 """
91 Callable from zenhub.
92
93 @param devices: list of devices (unused)
94 @type devices: list
95 """
96 unused(devices)
97 self.log.debug("Async update of device list")
98
99
101 """
102 Set zProperties
103
104 @param items: list of zProperties
105 @type items: list
106 """
107 table = dict(items)
108 for name in self.properties:
109 value = table.get(name, None)
110 if value is not None:
111 if getattr(self, name) != value:
112 self.log.debug('Updated %s config to %s' % (name, value))
113 setattr(self, name, value)
114
115
117 """
118 "Send the right event class for threshhold events"
119
120 @param kw: keyword arguments describing an event
121 @type kw: dictionary of keyword arguments
122 """
123 self.sendEvent({}, **kw)
124
125
127 """
128 Command-line options to add
129 """
130 PBDaemon.buildOptions(self)
131 self.parser.add_option('-d', '--device',
132 dest='device',
133 default='',
134 help="Specify a specific device to monitor")
135
136
154
155
157 """
158 Log an error, including any traceback data for a failure Exception
159 Stop if we got the --cycle command-line option.
160
161 @param error: the error message
162 @type error: string
163 """
164 self.logError('Error', error)
165 if not self.options.cycle:
166 self.stop()
167
168
170 """
171 Twisted callback to receive fatal messages.
172
173 @param why: the error message
174 @type why: string
175 """
176 self.error(why)
177 self.stop()
178
179
188