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

Source Code for Module Products.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 or (at your 
  8  # option) any later version as published by the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  # Hide a SyntaxWarning that is raised in twisted.web.microdom under Python>=2.5 
 15  # TODO in 3.1: Remove when twisted is upgraded 
 16  import warnings 
 17  warnings.filterwarnings('ignore', 'assertion is always true', SyntaxWarning) 
 18   
 19  from twisted.web import xmlrpc 
 20   
 21  import types 
 22   
 23  import DateTime 
 24   
 25  from Products.ZenHub.services.RRDImpl import RRDImpl 
 26  from Products.DataCollector.ApplyDataMap import ApplyDataMap 
 27  from Products.Zuul import getFacade 
 28  from Products.ZenUtils.ZenTales import talesEval 
 29   
30 -class XmlRpcService(xmlrpc.XMLRPC):
31 # serializable types 32 PRIMITIVES = [types.IntType, types.StringType, types.BooleanType, 33 types.DictType, types.FloatType, types.LongType, 34 types.NoneType] 35
36 - def __init__(self, dmd):
37 xmlrpc.XMLRPC.__init__(self) 38 self.dmd = dmd 39 self.zem = dmd.ZenEventManager 40 self.impl = RRDImpl(dmd)
41 42
43 - def xmlrpc_sendEvent(self, data):
44 'XMLRPC requests are processed asynchronously in a thread' 45 result = self.zem.sendEvent(data) 46 if result is None: 47 result = "none" 48 return result
49
50 - def xmlrpc_sendEvents(self, data):
51 return self.zem.sendEvents(data)
52
53 - def xmlrpc_getDevicePingIssues(self, *unused):
54 zep = getFacade('zep') 55 return zep.getDevicePingIssues()
56
57 - def xmlrpc_getDeviceWinInfo(self, *args):
58 return self.dmd.Devices.Server.Windows.getDeviceWinInfo(*args)
59
60 - def xmlrpc_getWinServices(self, *args):
61 return self.dmd.Devices.Server.Windows.getWinServices(*args)
62
63 - def xmlrpc_applyDataMap(self, devName, datamap, 64 relname="", compname="", modname=""):
65 """Apply a datamap passed as a list of dicts through XML-RPC. 66 """ 67 dev = self.dmd.findDevice(devName) 68 adm = ApplyDataMap() 69 adm.applyDataMap(dev, datamap, relname=relname, 70 compname=compname, modname=modname)
71 72
73 - def xmlrpc_getConfigs(self, monitor, dstype):
74 '''Return the performance configurations for the monitor name and data 75 source provided. ''' 76 77 def toDict(device, ds, dps=[]): 78 '''marshall the fields from the datasource into a dictionary and 79 ignore everything that is not a primitive''' 80 81 vals = {} 82 vals['dps'] = [] 83 vals['dptypes'] = [] 84 for key, val in ds.__dict__.items(): 85 if isinstance(val, XmlRpcService.PRIMITIVES): 86 if isinstance(val, basestring) and '$' in val: 87 val = talesEval('string:%s' % (val, ), device) 88 vals[key] = val 89 90 for dp in dps: 91 vals['dps'].append(dp.id) 92 vals['dptypes'].append(dp.rrdtype) 93 94 # add zproperties 95 for propertyId in device.propertyIds(): 96 value = device.getProperty(propertyId) 97 98 # _millis can't be serialized because it is long, so 99 # we skip it to avoid an XML-RPC serialization error 100 if isinstance(value, DateTime.DateTime): 101 continue 102 103 vals[propertyId] = value 104 105 vals['device'] = device.id 106 vals['manageIp'] = device.manageIp 107 108 return vals
109 110 111 result = [] 112 113 # get the performance conf (if it exists) 114 conf = getattr(self.dmd.Monitors.Performance, monitor, None) 115 if conf is None: 116 return result 117 118 # loop over devices that use the performance monitor 119 for device in conf.devices(): 120 device = device.primaryAq() 121 for template in device.getRRDTemplates(): 122 for ds in template.getRRDDataSources(): 123 if ds.sourcetype == dstype: 124 result.append(toDict(device, ds, ds.datapoints())) 125 126 return result
127 128
129 - def xmlrpc_writeRRD(self, devId, compType, compId, dpName, value):
130 self.impl.writeRRD(devId, compType, compId, dpName, value) 131 132 # return something for compliance with the XML-RPC specification 133 return ""
134 135
136 - def xmlrpc_getPerformanceConfig(self, monitor):
137 ''' returns the performance configuration for the monitor provided, or 138 {} if no collector with the name provided is located.''' 139 140 result = {} 141 fields = ['configCycleInterval', 'statusCycleInterval', 142 'processCycleInterval', 'perfsnmpCycleInterval', 143 'eventlogCycleInterval', 'renderurl', 'renderpass', 144 'renderuser', 'winCycleInterval'] 145 146 # get the performance conf (if it exists) 147 conf = getattr(self.dmd.Monitors.Performance, monitor, None) 148 if conf is None: 149 return result 150 151 for field in fields: 152 result[field] = getattr(conf, field, None) 153 154 return result
155