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

# Source Code for Module Products.ZenHub.XmlRpcService

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