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

Source Code for Module ZenHub.pbclient2

 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   
22  evt = Event() 
23  evt.device = 'zenoss03' 
24  evt.summary = 'sdfs pb event class' 
25  evt.severity = 5 
26  evt.eventClass = '/' 
27   
28   
29 -class EventClient(pb.Referenceable):
30
31 - def run(self):
32 factory = pb.PBClientFactory() 33 reactor.connectTCP("localhost", 8789, factory) 34 d = factory.login(credentials.UsernamePassword("test", "test"),client=self) 35 d.addCallback(self.connected) 36 d.addErrback(self.bad) 37 reactor.run()
38
39 - def connected(self, perspective):
40 print "got perspective ref:", perspective 41 d = perspective.getService("EventService", self) 42 d.addCallback(self.sendEvent) 43 d.addErrback(self.bad)
44
45 - def sendEvent(self, svc):
46 self.svc = svc 47 d = self.svc.sendEvent(evt) 48 d.addBoth(self.shutdown)
49 50
51 - def bad(self, reason):
52 print 'error: '+str(reason.value)
53
54 - def remote_getName(self):
55 return "EventClient"
56
57 - def remote_shutdown(self, result):
58 print result 59 reactor.stop()
60 61 if __name__ == '__main__': 62 ec = EventClient() 63 ec.run() 64 65 #event = { 66 # 'device': 'zenoss02', 67 # 'summary': 'test pb event', 68 # 'severity': 5, 69 # 'eventClass': '/' 70 #} 71 # 72 #factory = pb.PBClientFactory() 73 #reactor.connectTCP("localhost", 8789, factory) 74 #d = factory.getRootObject() 75 #d.addCallback(lambda object: object.callRemote("sendEvent", event)) 76 #d.addCallback(lambda object: object.callRemote("sendEvent", pbevt)) 77 #def bad(reason): print 'error: '+str(reason.value) 78 #d.addErrback(bad) 79 #d.addCallback(lambda _: reactor.stop()) 80 #reactor.run() 81