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

Source Code for Module ZenHub.XmlRpcService

  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  from twisted.web import xmlrpc 
 14   
 15  import types 
 16   
 17  from Products.ZenHub.services.RRDImpl import RRDImpl 
 18  from Products.DataCollector.ApplyDataMap import ApplyDataMap 
 19   
 20  from Products.ZenUtils.ZenTales import talesEval 
 21   
22 -class XmlRpcService(xmlrpc.XMLRPC):
23 # serializable types 24 PRIMITIVES = [types.IntType, types.StringType, types.BooleanType, 25 types.DictType, types.FloatType, types.LongType, 26 types.NoneType] 27
28 - def __init__(self, dmd):
29 xmlrpc.XMLRPC.__init__(self) 30 self.dmd = dmd 31 self.zem = dmd.ZenEventManager 32 self.impl = RRDImpl(dmd)
33 34
35 - def xmlrpc_sendEvent(self, data):
36 'XMLRPC requests are processed asynchronously in a thread' 37 result = self.zem.sendEvent(data) 38 if result is None: 39 result = "none" 40 return result
41
42 - def xmlrpc_sendEvents(self, data):
43 return self.zem.sendEvents(data)
44
45 - def xmlrpc_getDevicePingIssues(self, *unused):
46 return self.zem.getDevicePingIssues()
47
48 - def xmlrpc_getWmiConnIssues(self, *args):
49 return self.zem.getWmiConnIssues(*args)
50
51 - def xmlrpc_getDeviceWinInfo(self, *args):
52 return self.dmd.Devices.Server.Windows.getDeviceWinInfo(*args)
53
54 - def xmlrpc_getWinServices(self, *args):
55 return self.dmd.Devices.Server.Windows.getWinServices(*args)
56
57 - def xmlrpc_applyDataMap(self, devName, datamap, 58 relname="", compname="", modname=""):
59 """Apply a datamap passed as a list of dicts through XML-RPC. 60 """ 61 dev = self.dmd.findDevice(devName) 62 adm = ApplyDataMap() 63 adm.applyDataMap(dev, datamap, relname=relname, 64 compname=compname, modname=modname)
65 66
67 - def xmlrpc_getConfigs(self, monitor, dstype):
68 '''Return the performance configurations for the monitor name and data 69 source provided. ''' 70 71 def toDict(device, ds, dps=[]): 72 '''marshall the fields from the datasource into a dictionary and 73 ignore everything that is not a primitive''' 74 75 vals = {} 76 vals['dps'] = [] 77 vals['dptypes'] = [] 78 for key, val in ds.__dict__.items(): 79 if type(val) in XmlRpcService.PRIMITIVES: 80 if (type(val) == types.StringType) and (val.find('$') >= 0): 81 val = talesEval('string:%s' % (val, ), device) 82 vals[key] = val 83 84 for dp in dps: 85 vals['dps'].append(dp.id) 86 vals['dptypes'].append(dp.rrdtype) 87 88 vals['device'] = device.id 89 return vals
90 91 92 result = [] 93 94 # get the performance conf (if it exists) 95 conf = getattr(self.dmd.Monitors.Performance, monitor, None) 96 if conf is None: 97 return result 98 99 # loop over devices that use the performance monitor 100 for device in conf.devices(): 101 device = device.primaryAq() 102 for template in device.getRRDTemplates(): 103 for ds in template.getRRDDataSources(): 104 if ds.sourcetype == dstype: 105 result.append(toDict(device, ds, ds.datapoints())) 106 107 return result
108 109
110 - def xmlrpc_writeRRD(self, devId, compType, compId, dpName, value):
111 self.impl.writeRRD(devId, compType, compId, dpName, value) 112 113 # return something for compliance with the XML-RPC specification 114 return ""
115 116
117 - def xmlrpc_getPerformanceConfig(self, monitor):
118 ''' returns the performance configuration for the monitor provided, or 119 {} if no collector with the name provided is located.''' 120 121 result = {} 122 fields = ['configCycleInterval', 'statusCycleInterval', 123 'processCycleInterval', 'perfsnmpCycleInterval', 124 'eventlogCycleInterval', 'renderurl', 'renderpass', 125 'renderuser', 'winCycleInterval', 'winmodelerCycleInterval'] 126 127 # get the performance conf (if it exists) 128 conf = getattr(self.dmd.Monitors.Performance, monitor, None) 129 if conf is None: 130 return result 131 132 for field in fields: 133 result[field] = getattr(conf, field, None) 134 135 return result
136