Пример #1
0
    def testUnableToWrite(self):
        """
        Can't write to disk
        """
        # Verify that we're not root first... 
        if os.geteuid() == 0:
            print "Can't run testUnableToWrite check if running as root"
            return

        # First override sendEvent
        rimpl = RRDImpl(self.dmd)
        evts = []
        def append(evt):
            if evt['severity'] != 0:
                evts.append(evt)
        rimpl.zem.sendEvent = append

        # Store a value.  As RRDImpl caches references to
        # previously stored writes, this allows us to go
        # behind the scenes to diddle with the underlying
        # RRDUtil object (stored in rimpl.rrd)
        self.assertEquals( rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 66), 66 )
        self.assertEquals(len(evts), 0)

        # This will try to create a /.rrd file, which should fail
        for key in rimpl.rrd.keys():
            rimpl.rrd[key].performancePath= lambda(x): "/"

        self.assertEquals( rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 66), None )

        # Now check for our event...
        self.assertNotEquals(len(evts), 0)
Пример #2
0
    def testUnableToWrite(self):
        """
        Can't write to disk
        """
        # Verify that we're not root first...
        if os.geteuid() == 0:
            print "Can't run testUnableToWrite check if running as root"
            return

        # First override sendEvent
        rimpl = RRDImpl(self.dmd)
        evts = []

        def append(evt):
            if evt['severity'] != 0:
                evts.append(evt)

        rimpl.zem.sendEvent = append

        # Store a value.  As RRDImpl caches references to
        # previously stored writes, this allows us to go
        # behind the scenes to diddle with the underlying
        # RRDUtil object (stored in rimpl.rrd)
        self.assertEquals(rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 66), 66)
        self.assertEquals(len(evts), 0)

        # This will try to create a /.rrd file, which should fail
        for key in rimpl.rrd.keys():
            rimpl.rrd[key].performancePath = lambda (x): "/"

        self.assertEquals(rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 66),
                          None)

        # Now check for our event...
        self.assertNotEquals(len(evts), 0)
Пример #3
0
    def testThreshold(self):
        """
        Exceed a threshhold
        """
        rimpl = RRDImpl(self.dmd)
        evts = []
        def append(evt):
            if evt['severity'] != 0:
                evts.append(evt)
        oldSendEvent = rimpl.zem.sendEvent
        rimpl.zem.sendEvent = append

        try:
            rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 99)
            self.assert_(len(evts) == 0)

            rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 101)
            self.assert_(len(evts) != 0)
        finally:
            rimpl.zem.sendEvent = oldSendEvent
Пример #4
0
    def testThreshold(self):
        """
        Exceed a threshhold
        """
        rimpl = RRDImpl(self.dmd)
        evts = []

        def append(evt):
            if evt['severity'] != 0:
                evts.append(evt)

        oldSendEvent = rimpl.zem.sendEvent
        rimpl.zem.sendEvent = append

        try:
            rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 99)
            self.assert_(len(evts) == 0)

            rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 101)
            self.assert_(len(evts) != 0)
        finally:
            rimpl.zem.sendEvent = oldSendEvent
Пример #5
0
 def __init__(self, dmd):
     xmlrpc.XMLRPC.__init__(self)
     self.dmd = dmd
     self.zem = dmd.ZenEventManager
     self.impl = RRDImpl(dmd)
Пример #6
0
class XmlRpcService(xmlrpc.XMLRPC):
    # serializable types
    PRIMITIVES = [
        types.IntType, types.StringType, types.BooleanType, types.DictType,
        types.FloatType, types.LongType, types.NoneType
    ]

    def __init__(self, dmd):
        xmlrpc.XMLRPC.__init__(self)
        self.dmd = dmd
        self.zem = dmd.ZenEventManager
        self.impl = RRDImpl(dmd)

    def xmlrpc_sendEvent(self, data):
        'XMLRPC requests are processed asynchronously in a thread'
        result = self.zem.sendEvent(data)
        if result is None:
            result = "none"
        return result

    def xmlrpc_sendEvents(self, data):
        return self.zem.sendEvents(data)

    def xmlrpc_getDevicePingIssues(self, *unused):
        zep = getFacade('zep')
        return zep.getDevicePingIssues()

    def xmlrpc_getDeviceWinInfo(self, *args):
        return self.dmd.Devices.Server.Windows.getDeviceWinInfo(*args)

    def xmlrpc_getWinServices(self, *args):
        return self.dmd.Devices.Server.Windows.getWinServices(*args)

    def xmlrpc_applyDataMap(self,
                            devName,
                            datamap,
                            relname="",
                            compname="",
                            modname=""):
        """Apply a datamap passed as a list of dicts through XML-RPC.
        """
        dev = self.dmd.findDevice(devName)
        adm = ApplyDataMap()
        adm.applyDataMap(dev,
                         datamap,
                         relname=relname,
                         compname=compname,
                         modname=modname)

    def xmlrpc_getConfigs(self, monitor, dstype):
        '''Return the performance configurations for the monitor name and data
        source provided. '''
        def toDict(device, ds, dps=[]):
            '''marshall the fields from the datasource into a dictionary and
            ignore everything that is not a primitive'''

            vals = {}
            vals['dps'] = []
            vals['dptypes'] = []
            for key, val in ds.__dict__.items():
                if isinstance(val, XmlRpcService.PRIMITIVES):
                    if isinstance(val, basestring) and '$' in val:
                        val = talesEval('string:%s' % (val, ), device)
                    vals[key] = val

            for dp in dps:
                vals['dps'].append(dp.id)
                vals['dptypes'].append(dp.rrdtype)

            # add zproperties
            for propertyId in device.propertyIds():
                value = device.getProperty(propertyId)

                # _millis can't be serialized because it is long, so
                # we skip it to avoid an XML-RPC serialization error
                if isinstance(value, DateTime.DateTime):
                    continue

                vals[propertyId] = value

            vals['device'] = device.id
            vals['manageIp'] = device.manageIp

            return vals

        result = []

        # get the performance conf (if it exists)
        conf = getattr(self.dmd.Monitors.Performance, monitor, None)
        if conf is None:
            return result

        # loop over devices that use the performance monitor
        for device in conf.devices():
            device = device.primaryAq()
            for template in device.getRRDTemplates():
                for ds in template.getRRDDataSources():
                    if ds.sourcetype == dstype:
                        result.append(toDict(device, ds, ds.datapoints()))

        return result

    def xmlrpc_writeRRD(self, devId, compType, compId, dpName, value):
        self.impl.writeRRD(devId, compType, compId, dpName, value)

        # return something for compliance with the XML-RPC specification
        return ""

    def xmlrpc_getPerformanceConfig(self, monitor):
        ''' returns the performance configuration for the monitor provided, or
        {} if no collector with the name provided is located.'''

        result = {}
        fields = [
            'configCycleInterval', 'statusCycleInterval',
            'eventlogCycleInterval', 'renderurl', 'renderpass', 'renderuser',
            'winCycleInterval'
        ]

        # get the performance conf (if it exists)
        conf = getattr(self.dmd.Monitors.Performance, monitor, None)
        if conf is None:
            return result

        for field in fields:
            result[field] = getattr(conf, field, None)

        return result
Пример #7
0
 def testGoodRRDSave(self):
     """
     Sanity check to make sure that RRD stores work
     """
     rimpl = RRDImpl(self.dmd)
     rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 66)
 def __init__(self, dmd):
     xmlrpc.XMLRPC.__init__(self)
     self.dmd = dmd
     self.zem = dmd.ZenEventManager
     self.impl = RRDImpl(dmd)
class XmlRpcService(xmlrpc.XMLRPC):
    # serializable types
    PRIMITIVES = [types.IntType, types.StringType, types.BooleanType,
                  types.DictType, types.FloatType, types.LongType,
                  types.NoneType]

    def __init__(self, dmd):
        xmlrpc.XMLRPC.__init__(self)
        self.dmd = dmd
        self.zem = dmd.ZenEventManager
        self.impl = RRDImpl(dmd)


    def xmlrpc_sendEvent(self, data):
        'XMLRPC requests are processed asynchronously in a thread'
        result = self.zem.sendEvent(data)
        if result is None:
            result = "none"
        return result

    def xmlrpc_sendEvents(self, data):
        return self.zem.sendEvents(data)

    def xmlrpc_getDevicePingIssues(self, *unused):
        zep = getFacade('zep')
        return zep.getDevicePingIssues()
    
    def xmlrpc_getDeviceWinInfo(self, *args):
        return self.dmd.Devices.Server.Windows.getDeviceWinInfo(*args)

    def xmlrpc_getWinServices(self, *args):
        return self.dmd.Devices.Server.Windows.getWinServices(*args)

    def xmlrpc_applyDataMap(self, devName, datamap, 
                            relname="", compname="", modname=""):
        """Apply a datamap passed as a list of dicts through XML-RPC.
        """
        dev = self.dmd.findDevice(devName)
        adm = ApplyDataMap()
        adm.applyDataMap(dev, datamap, relname=relname,
                         compname=compname, modname=modname)


    def xmlrpc_getConfigs(self, monitor, dstype):
        '''Return the performance configurations for the monitor name and data
        source provided. '''

        def toDict(device, ds, dps=[]):
            '''marshall the fields from the datasource into a dictionary and
            ignore everything that is not a primitive'''

            vals = {}
            vals['dps'] = []
            vals['dptypes'] = []
            for key, val in ds.__dict__.items():
                if isinstance(val, XmlRpcService.PRIMITIVES):
                    if isinstance(val, basestring) and '$' in val:
                        val = talesEval('string:%s' % (val, ), device)
                    vals[key] = val

            for dp in dps:
                vals['dps'].append(dp.id)
                vals['dptypes'].append(dp.rrdtype)

            # add zproperties
            for propertyId in device.propertyIds():
                value = device.getProperty(propertyId)

                # _millis can't be serialized because it is long, so
                # we skip it to avoid an XML-RPC serialization error
                if isinstance(value, DateTime.DateTime):
                    continue

                vals[propertyId] = value

            vals['device'] = device.id
            vals['manageIp'] = device.manageIp

            return vals


        result = []
        
        # get the performance conf (if it exists)
        conf = getattr(self.dmd.Monitors.Performance, monitor, None)
        if conf is None:
            return result

        # loop over devices that use the performance monitor
        for device in conf.devices():
            device = device.primaryAq()
            for template in device.getRRDTemplates():
                for ds in template.getRRDDataSources():
                    if ds.sourcetype == dstype:
                        result.append(toDict(device, ds, ds.datapoints()))

        return result


    def xmlrpc_writeRRD(self, devId, compType, compId, dpName, value):
        self.impl.writeRRD(devId, compType, compId, dpName, value)

        # return something for compliance with the XML-RPC specification
        return ""


    def xmlrpc_getPerformanceConfig(self, monitor):
        ''' returns the performance configuration for the monitor provided, or
        {} if no collector with the name provided is located.'''

        result = {}
        fields = ['configCycleInterval', 'statusCycleInterval', 
                  'eventlogCycleInterval', 'renderurl', 'renderpass',
                  'renderuser', 'winCycleInterval']

        # get the performance conf (if it exists)
        conf = getattr(self.dmd.Monitors.Performance, monitor, None)
        if conf is None:
            return result

        for field in fields:
            result[field] = getattr(conf, field, None)
            
        return result
Пример #10
0
 def testGoodRRDSave(self):
     """
     Sanity check to make sure that RRD stores work
     """
     rimpl = RRDImpl(self.dmd)
     rimpl.writeRRD(self.dev.id, '', '', 'ds_dp', 66)