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