Package ZenRRD :: Module RRDDaemon
[hide private]
[frames] | no frames]

Source Code for Module ZenRRD.RRDDaemon

  1  #! /usr/bin/env python  
  2  ########################################################################### 
  3  # 
  4  # This program is part of Zenoss Core, an open source monitoring platform. 
  5  # Copyright (C) 2007, Zenoss Inc. 
  6  # 
  7  # This program is free software; you can redistribute it and/or modify it 
  8  # under the terms of the GNU General Public License version 2 as published by 
  9  # the Free Software Foundation. 
 10  # 
 11  # For complete information please visit: http://www.zenoss.com/oss/ 
 12  # 
 13  ########################################################################### 
 14   
 15  __doc__='''RRDDaemon 
 16   
 17  Common performance monitoring daemon code for performance daemons. 
 18   
 19  $Id$ 
 20  ''' 
 21   
 22  __version__ = "$Revision$"[11:-2] 
 23   
 24  import socket 
 25   
 26  import Globals 
 27  from Products.ZenEvents import Event 
 28  from Products.ZenEvents.ZenEventClasses import Perf_Snmp, Heartbeat 
 29  from Products.ZenUtils.Driver import drive 
 30   
 31  from twisted.internet import reactor, defer 
 32  from twisted.python import failure 
 33   
 34  from Products.ZenHub.PBDaemon import FakeRemote, PBDaemon as Base 
 35  from Products.ZenRRD.Thresholds import Thresholds 
 36   
 37   
 38  BAD_SEVERITY=Event.Warning 
 39   
 40  BASE_URL = 'http://localhost:8080/zport/dmd' 
 41  DEFAULT_URL = BASE_URL + '/Monitors/Performance/localhost' 
 42   
 43   
 44  COMMON_EVENT_INFO = { 
 45      'manager': socket.getfqdn(), 
 46      } 
 47       
 48   
49 -class RRDDaemon(Base):
50 'Holds the code common to performance gathering daemons.' 51 52 heartbeatevt = {'eventClass':Heartbeat} 53 54 properties = ('configCycleInterval',) 55 heartBeatTimeout = 60*3 56 configCycleInterval = 20 # minutes 57 rrd = None 58 shutdown = False 59 thresholds = None 60
61 - def __init__(self, name):
62 self.events = [] 63 self.name = name 64 Base.__init__(self) 65 evt = self.heartbeatevt.copy() 66 self.thresholds = Thresholds() 67 self.heartbeatevt.update(dict(component=name, 68 device=socket.getfqdn()))
69
70 - def getDevicePingIssues(self):
71 return self.eventService().callRemote('getDevicePingIssues')
72
73 - def remote_updateThresholdClasses(self, classes):
74 from Products.ZenUtils.Utils import importClass 75 self.log.debug("Loading classes %s", classes) 76 for c in classes: 77 try: 78 importClass(c) 79 except ImportError: 80 self.log.exception("Unable to import class %s", c)
81
82 - def remote_setPropertyItems(self, items):
83 self.log.debug("Async update of collection properties") 84 self.setPropertyItems(items)
85 86
87 - def remote_updateDeviceList(self, devices):
88 self.log.debug("Async update of device list")
89 90
91 - def setPropertyItems(self, items):
92 'extract configuration elements used by this server' 93 table = dict(items) 94 for name in self.properties: 95 value = table.get(name, None) 96 if value is not None: 97 if getattr(self, name) != value: 98 self.log.debug('Updated %s config to %s' % (name, value)) 99 setattr(self, name, value)
100 101
102 - def sendThresholdEvent(self, **kw):
103 "Send the right event class for threshhold events" 104 self.sendEvent({}, **kw)
105 106
107 - def heartbeat(self, *unused):
108 'if cycling, send a heartbeat, else, shutdown' 109 if not self.options.cycle: 110 self.stop() 111 return 112 self.sendEvent(self.heartbeatevt, timeout=self.heartBeatTimeout)
113 114
115 - def buildOptions(self):
116 Base.buildOptions(self) 117 self.parser.add_option('-d', '--device', 118 dest='device', 119 default='', 120 help="Specify a specific device to monitor")
121
122 - def logError(self, msg, error):
123 if isinstance(error, failure.Failure): 124 self.log.exception(error) 125 else: 126 self.log.error('%s %s', msg, error)
127
128 - def error(self, error):
129 'Log an error, including any traceback data for a failure Exception' 130 self.logError('Error', error) 131 if not self.options.cycle: 132 self.stop()
133
134 - def errorStop(self, why):
135 self.error(why) 136 self.stop()
137
138 - def model(self):
139 return self.services.get(self.initialServices[-1], FakeRemote())
140