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

Source Code for Module ZenRRD.zenx

  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  #! /usr/bin/python 
 14   
 15  __doc__='''zenx.py 
 16   
 17  Provide sendevent, get config, save perf data, etc services to remote daemons 
 18  via xmlrpc. 
 19  ''' 
 20   
 21  import time 
 22  from sets import Set 
 23  import socket 
 24   
 25  import Globals 
 26  from Products.ZenEvents.EventServer import EventServer 
 27  #from WebTestConfServer import WebTestConfServer 
 28  from Products.ZenEvents.Event import Event 
 29   
 30  from twisted.internet import reactor, defer 
 31  from twisted.python import failure 
 32  from twisted.web import xmlrpc, server 
 33   
 34  XML_RPC_PORT = 8081 
 35   
36 -class ZenX(EventServer, xmlrpc.XMLRPC):
37 38 totalTime = 0. 39 totalEvents = 0 40 maxTime = 0. 41 name = 'zenx' 42
43 - def __init__(self):
44 EventServer.__init__(self) 45 xmlrpc.XMLRPC.__init__(self, allow_none=True) 46 reactor.listenTCP(self.options.xmlrpcport, server.Site(self))
47 48 # Event Server 49
50 - def execute(self, method, data):
51 try: 52 d = defer.Deferred() 53 self.q.put( (method, data, d, time.time()) ) 54 return d 55 except Exception, ex: 56 self.log.exception(ex)
57
58 - def xmlrpc_sendEvent(self, data):
59 'XMLRPC requests are processed asynchronously in a thread' 60 return self.execute(self.sendEvent, (Event(**data),))
61
62 - def xmlrpc_sendEvents(self, data):
63 return self.execute(self.sendEvents, ([Event(**e) for e in data],))
64
65 - def xmlrpc_getDevicePingIssues(self, *unused):
66 return self.execute(self.zem.getDevicePingIssues, ())
67
68 - def xmlrpc_getWmiConnIssues(self, *args):
69 return self.execute(self.zem.getWmiConnIssues, args)
70
71 - def doHandleRequest(self, *args):
72 ''' EventServer is calling this in a separate thread to handle 73 requests in self.q 74 ''' 75 method, data, result, ts = args 76 try: 77 retval = method(*data) 78 if retval is None: 79 retval = '' 80 reactor.callFromThread(result.callback, retval) 81 except Exception, ex: 82 self.log.exception(ex) 83 reactor.callFromThread(result.errback, 84 xmlrpc.Fault(self.FAILURE, str(ex)))
85 86 # ZenWeb 87
88 - def xmlrpc_getPageChecks(self, monitorName=socket.getfqdn()):
89 return self.execute(self.getPageChecks, (monitorName,))
90
91 - def getPageChecks(self, monitorName=socket.getfqdn()):
92 monitor = getattr(self.dmd.Monitors.Performance, monitorName, '') 93 if monitor: 94 import pprint 95 result = monitor.getPageChecks() 96 #result = [{'a':1, 'b':2}, {'c':3, 'd':4}] 97 #result = ('a', 'b', 'c') 98 self.log.info('--------------') 99 self.log.info(pprint.pformat(result)) 100 self.log.info('--------------') 101 else: 102 raise 'No performance monitor named %s' % monitorName 103 return result
104 105 106 # Misc 107
108 - def buildOptions(self):
109 EventServer.buildOptions(self) 110 self.parser.add_option('-x', '--xport', 111 help='Port for xmlrpc.' 112 ' Default is %s' % XML_RPC_PORT, 113 dest='xmlrpcport', 114 type='int', 115 default=XML_RPC_PORT)
116 117 118 if __name__ == '__main__': 119 z = ZenX() 120 z.main() 121