Package ZenHub :: Module rrdClient
[hide private]
[frames] | no frames]

Source Code for Module ZenHub.rrdClient

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  import Globals 
15   
16  from twisted.internet import reactor 
17  from twisted.cred import credentials 
18  from twisted.spread import pb 
19   
20  from Products.ZenEvents.Event import Event 
21  from zenhub import PB_PORT 
22   
23  evt = Event() 
24  evt.device = 'zenoss03' 
25  evt.summary = 'sdfs pb event class' 
26  evt.severity = 5 
27  evt.eventClass = '/' 
28   
29   
30 -class RRDClient(pb.Referenceable):
31
32 - def __init__(self, value):
33 self.value = value
34
35 - def run(self):
36 factory = pb.PBClientFactory() 37 reactor.connectTCP("localhost", PB_PORT, factory) 38 d = factory.login(credentials.UsernamePassword("admin", "zenoss"), 39 client=self) 40 d.addCallback(self.connected) 41 d.addErrback(self.bad) 42 reactor.run()
43 44
45 - def connected(self, perspective):
46 print "got perspective ref:", perspective 47 d = perspective.callRemote('getService', "RRDService", 'localhost', self) 48 d.addCallback(self.sendValue) 49 d.addErrback(self.bad)
50 51
52 - def sendValue(self, svc):
53 self.svc = svc 54 print "Sending value" 55 d = self.svc.callRemote('writeRRD', 'localhost', None, None, 'MailTx_totalTime', self.value) 56 d.addBoth(self.shutdown)
57 58
59 - def shutdown(self, unused):
60 print unused 61 reactor.stop()
62 63
64 - def bad(self, reason):
65 print reason 66 print 'error: '+str(reason.value)
67 68
69 - def remote_getName(self):
70 return "RRDClient"
71 72
73 - def remote_shutdown(self, result):
74 print result 75 reactor.stop()
76 77 if __name__ == '__main__': 78 import sys 79 try: 80 value = float(sys.argv[1]) 81 except: 82 print 'Unable to use value', sys.argv 83 value = 20. 84 rc = RRDClient(value) 85 rc.run() 86