Exemple #1
0
    def processResults(self, cmd, result):

        # best effort.  Try Nagios first, if that doesn't return data values
        # try Cacti. If cacti doesn't return value use results from nagios
        # since it is more likely to have been an error parsing nagios data
        # and the nagios parser puts more data in the event.  Both parsers
        # have the same logic for event severity based on exit code

        cactiResult= None
        nagiosResult = ParsedResults()

        nagiosParser = Nagios()
        nagiosParser.processResults(cmd, nagiosResult)

        if not nagiosResult.values:
            cactiParser = Cacti()
            cactiResult= ParsedResults()
            cactiParser.processResults(cmd, cactiResult)

        if cactiResult and cactiResult.values:
           #use cacti results
            parserResult = cactiResult
        else:
            parserResult = nagiosResult

        result.events.extend(parserResult.events)
        result.values.extend(parserResult.values)
class TestCacti(BaseTestCase):

    def setUp(self):
        self.parser = Cacti()


    def testCacti(self):
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        p1 = Object()
        p1.id = 'cacti_single_result'
        p1.data = dict(processName='someJob a b c',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = "77"
        cmd.result.exitCode = 2
        cmd.severity = 2
        cmd.command = "testCactiPlugin"
        cmd.name = "testCactiPlugin"
        cmd.eventKey = "cactiKey"
        cmd.eventClass = "/Cmd"
        cmd.component = "zencommand"
        results = ParsedResults()
        self.parser.processResults(cmd, results)
        self.assertEquals( len(results.values), 1)
        self.assertEquals(77,  int(results.values[0][1]))

        # Now test multiple data points
        p2 = Object()
        p2.id = 'cacti_multi_result'
        p2.data = dict(processName='someJob a b c',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points.append( p2 )
        cmd.result.output = "cacti_single_result:77 cacti_multi_result: 4.03E02"
        results = ParsedResults()
        self.parser.processResults(cmd, results)
        self.assertEquals( len(results.values), 2)
        values = map(lambda x: x[1], results.values)
        self.assertTrue(77.0 in values)
        self.assertTrue(403.0 in values)
Exemple #3
0
class TestCacti(BaseTestCase):
    def setUp(self):
        self.parser = Cacti()

    def testCacti(self):
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        p1 = Object()
        p1.id = 'cacti_single_result'
        p1.data = dict(processName='someJob a b c',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = "77"
        cmd.result.exitCode = 2
        cmd.severity = 2
        cmd.command = "testCactiPlugin"
        cmd.name = "testCactiPlugin"
        cmd.eventKey = "cactiKey"
        cmd.eventClass = "/Cmd"
        cmd.component = "zencommand"
        results = ParsedResults()
        self.parser.processResults(cmd, results)
        self.assertEquals(len(results.values), 1)
        self.assertEquals(77, int(results.values[0][1]))

        # Now test multiple data points
        p2 = Object()
        p2.id = 'cacti_multi_result'
        p2.data = dict(processName='someJob a b c',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points.append(p2)
        cmd.result.output = "cacti_single_result:77 cacti_multi_result: 4.03E02"
        results = ParsedResults()
        self.parser.processResults(cmd, results)
        self.assertEquals(len(results.values), 2)
        values = map(lambda x: x[1], results.values)
        self.assertTrue(77.0 in values)
        self.assertTrue(403.0 in values)