Ejemplo n.º 1
0
    def testPsCase15745(self):
        """
        Case 15745
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(processName='oracleYAMDB1 (LOCAL=NO)',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
483362 146300    22:58:11 /usr/local/test/oracleYAMDB1 (LOCAL=NO)
495844 137916    22:45:57 /usr/bin/sendmail: MTA: accepting connections
520290  1808    00:00:00 /usr/sbin/aixmibd
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        # Oracle process with parenthesis in args should be detected
        for ev in results.events:
            summary = ev['summary']
            if summary.find('oracleYAMDB1') >= 0:
                assert summary.find('Process running') >= 0
            else:
                raise AssertionError("unexpected event")
Ejemplo n.º 2
0
    def testPsZen5278(self):
        """
        Jira 5278 - defunct process matching
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(processName='<defunct>',
        #p1.data = dict(processName='aioserver',
                       ignoreParams=False,
                       alertOnRestart=False,
                       failSeverity=0)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
28835916 00:00:00 <defunct>
28967020 1788 00:00:00 sshd: root@sherwood
29622478 448 00:00:08 aioserver
29688042 00:00:00 <defunct>
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        # Ensure that we can track defunct processes
        for ev in results.events:
            summary = ev['summary']
            if summary.find('defunct') >= 0:
                assert summary.find('Process running') >= 0
            else:
                raise AssertionError("unexpected event")
    def _testDataFile(self, filename, Plugins):
        """
        Test a data file.
        """
        command, output = self.__parseCommandAndOutput(filename) 

        # read the file containing the expected values
        expectedfile = open('%s.py' % (filename,))
        expected = eval("".join(expectedfile.readlines()))
        expectedfile.close()

        plugins = [P() for P in Plugins 
                if P.command == command and P.__name__ in expected]

        if not plugins:
            #if we fail to find a plugin the first time we might be dealing
            #with a multiline command, let's try to re-parse the datafile once more
            command, output = self.__parseCommandAndOutput(filename, singleLine=False)
            plugins = [P() for P in Plugins 
                if P.command == command and P.__name__ in expected]
        if not plugins:
                self.fail("No plugins for %s" % command)

        device = Object()
        device.id = filename.split(os.path.sep)[-2]

        expecteds = [expected[p.__class__.__name__] for p in plugins]
        dataMaps = [p.process(device, output, logging) or [] for p in plugins]
        return self._testDataMaps(zip(expecteds, dataMaps), filename)
    def testNagios2case1(self):
        p1 = Object()
        p1.id = 'np1'
        p1.data = self.dpdata
        self.cmd.points = [p1]

        self.cmd.result.output = "OK plugin"
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 0)
Ejemplo n.º 5
0
    def testNagios2case1(self):
        p1 = Object()
        p1.id = 'np1'
        p1.data = self.dpdata
        self.cmd.points = [p1]

        self.cmd.result.output = "OK plugin"
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 0)
    def testNagiosLabelScheme(self):
        """
        No really, Nagios plugin output labels are stunned. WTF???
        """
        p1 = Object()
        p1.id = 'np 1'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'np 2'
        p2.data = self.dpdata

        p3 = Object()
        p3.id = 'label with spaces in it'
        p3.data = self.dpdata

        self.cmd.points = [p1, p2, p3]

        self.cmd.result.output = """OK plugin
|
'np 1'=77.3;;;
'np 2'=77.3e-7;;;
'label with spaces in it'=12%;50;70;0;100
np2=66;;;
np2=66;;;
"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 3)
        self.assertEquals(77.3,  self.results.values[0][1])
        self.assertEquals(7.7300000000000005e-06,  self.results.values[1][1])
        self.assertEquals(12.0,  self.results.values[2][1])
Ejemplo n.º 7
0
    def testNagios3edgeCase2(self):
        """
        performance data only in subsequent lines (after the first)
        """
        p1 = Object()
        p1.id = 'np1'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'np2'
        p2.data = self.dpdata

        self.cmd.points = [p1, p2]

        self.cmd.result.output = """OK plugin

My friendly junk
More stuff |
np1=77;;;
np2=66;;;

np3=55;;;"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 2)
        self.assertEquals(77.0, self.results.values[0][1])
        self.assertEquals(66.0, self.results.values[1][1])
Ejemplo n.º 8
0
    def _testDataFile(self, filename, Plugins, device=None):
        """
        Test a data file.
        """
        command, output = self.__parseCommandAndOutput(filename)

        # read the file containing the expected values
        expectedfile = open('%s.py' % (filename, ))
        expected = eval("".join(expectedfile.readlines()))
        expectedfile.close()

        plugins = [
            P() for P in Plugins
            if P.command == command and P.__name__ in expected
        ]

        if not plugins:
            #if we fail to find a plugin the first time we might be dealing
            #with a multiline command, let's try to re-parse the datafile once more
            command, output = self.__parseCommandAndOutput(filename,
                                                           singleLine=False)
            plugins = [
                P() for P in Plugins
                if P.command == command and P.__name__ in expected
            ]
        if not plugins:
            self.fail("No plugins for %s" % command)

        device = device or Object()
        device.id = filename.split(os.path.sep)[-2]

        expecteds = [expected[p.__class__.__name__] for p in plugins]
        dataMaps = [p.process(device, output, logging) or [] for p in plugins]
        return self._testDataMaps(zip(expecteds, dataMaps), filename)
    def setUp(self):
        self.cmd = Object()
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        self.cmd.deviceConfig = deviceConfig

        self.cmd.name = "testDataSource"
        self.cmd.parser = "JSON"
        self.cmd.result = Object()
        self.cmd.result.exitCode = 0
        self.cmd.severity = 2
        self.cmd.eventClass = '/Cmd'
        self.cmd.command = "testJSONCommand"
        self.cmd.points = []
        self.parser = JSON()
        self.results = ParsedResults()
Ejemplo n.º 10
0
    def setUp(self):
        self.cmd = Object()
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        self.cmd.deviceConfig = deviceConfig

        self.cmd.name = "testDataSource"
        self.cmd.parser = "JSON"
        self.cmd.result = Object()
        self.cmd.result.exitCode = 0
        self.cmd.severity = 2
        self.cmd.eventKey = 'testEventKey'
        self.cmd.eventClass = '/Cmd'
        self.cmd.command = "testJSONCommand"
        self.cmd.points = []
        self.parser = JSON()
        self.results = ParsedResults()
    def setUp(self):
        self.cmd = Object()
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        self.cmd.deviceConfig = deviceConfig

        self.cmd.parser = "Kannel"
        self.cmd.result = Object()
        self.cmd.result.exitCode = 2
        self.cmd.severity = 2
        self.cmd.command = "testKannelPlugin"
        self.cmd.eventKey = "kannelKey"
        self.cmd.eventClass = "/Cmd"
        self.cmd.component = "zencommand"
        self.parser = Kannel.Kannel()
        self.results = ParsedResults()
        self.dpdata = dict(processName='someJob a b c',
                           ignoreParams=False,
                           alertOnRestart=True,
                           failSeverity=3)
Ejemplo n.º 12
0
    def setUp(self):
        self.cmd = Object()
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        self.cmd.deviceConfig = deviceConfig

        self.cmd.name = "testDataSource"
        self.cmd.parser = "Auto"
        self.cmd.result = Object()
        self.cmd.result.exitCode = 2
        self.cmd.severity = 2
        self.cmd.command = "testAutoPlugin"
        self.cmd.eventKey = "AutoKey"
        self.cmd.eventClass = "/Cmd"
        self.cmd.component = "zencommand"
        self.parser = Auto()
        self.results = ParsedResults()
        self.dpdata = dict(processName='someJob a b c',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
    def testNagios3edgeCase2(self):
        """
        performance data only in subsequent lines (after the first)
        """
        p1 = Object()
        p1.id = 'np1'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'np2'
        p2.data = self.dpdata

        self.cmd.points = [p1, p2]

        self.cmd.result.output = """OK plugin

My friendly junk
More stuff |
np1=77;;;
np2=66;;;

np3=55;;;"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 2)
        self.assertEquals(77.0,  self.results.values[0][1])
        self.assertEquals(66.0,  self.results.values[1][1])
Ejemplo n.º 14
0
    def test_device_result(self):
        self.cmd.result.output = json.dumps({
            'values': {
                '': {
                    'value1': 1.0,
                    'value2': 2.0,
                },
            },
            'events': [
                {
                    'summary': 'test summary',
                    'severity': 2,
                },
                {
                    'summary': 'another summary',
                    'severity': 3,
                },
            ],
        })

        p1 = Object()
        p1.id = 'value1'
        p1.component = ''

        p2 = Object()
        p2.id = 'value2'
        p2.component = ''

        self.cmd.points = [p1, p2]

        self.parser.processResults(self.cmd, self.results)

        self.assertEquals(len(self.results.values), 2)

        value1 = self.results.values[0]
        self.assertEquals(value1[0].component, '')
        self.assertEquals(value1[0].id, 'value1')
        self.assertEquals(value1[1], 1.0)

        value2 = self.results.values[1]
        self.assertEquals(value2[0].component, '')
        self.assertEquals(value2[0].id, 'value2')
        self.assertEquals(value2[1], 2.0)

        self.assertEquals(len(self.results.events), 2)
Ejemplo n.º 15
0
    def testNagios3edgeCase4(self):
        """
        Incorrect use of pipes.
        """
        p1 = Object()
        p1.id = 'rta'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'pl'
        p2.data = self.dpdata

        self.cmd.points = [p1, p2]

        self.cmd.result.output = """PING OK|LOSS=0 RTA=0.34 |rta=0.337000ms;180.000000;300.000000;0.000000 pl=0%;100;100;0\n"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 2)
        self.assertEquals(0.337, self.results.values[0][1])
        self.assertEquals(0.0, self.results.values[1][1])
Ejemplo n.º 16
0
    def testNagios3edgeCase3(self):
        """
        No performance data
        """
        p1 = Object()
        p1.id = 'np1'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'np2'
        p2.data = self.dpdata

        self.cmd.points = [p1, p2]

        self.cmd.result.output = """OK plugin

My friendly junk
More stuff
"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 0)
    def test_device_result(self):
        self.cmd.result.output = json.dumps({
            'values': {
                '': {
                    'value1': 1.0,
                    'value2': 2.0,
                    },
                },

            'events': [
                {
                    'summary': 'test summary',
                    'severity': 2,
                    },
                {
                    'summary': 'another summary',
                    'severity': 3,
                    },
                ],
            })

        p1 = Object()
        p1.id = 'value1'
        p1.component = ''

        p2 = Object()
        p2.id = 'value2'
        p2.component = ''

        self.cmd.points = [p1, p2]

        self.parser.processResults(self.cmd, self.results)

        self.assertEquals(len(self.results.values), 2)

        value1 = self.results.values[0]
        self.assertEquals(value1[0].component, '')
        self.assertEquals(value1[0].id, 'value1')
        self.assertEquals(value1[1], 1.0)

        value2 = self.results.values[1]
        self.assertEquals(value2[0].component, '')
        self.assertEquals(value2[0].id, 'value2')
        self.assertEquals(value2[1], 2.0)

        self.assertEquals(len(self.results.events), 2)
Ejemplo n.º 18
0
    def testNagios3edgeCase1(self):
        """
        Multi-line parsing, Nagios v3 style
        """
        p1 = Object()
        p1.id = 'np1'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'np2'
        p2.data = self.dpdata

        self.cmd.points = [p1, p2]

        self.cmd.result.output = """OK plugin | np1=77;;;

My friendly junk
More stuff | np2=66;;;

np3=55;;;"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 2)
        self.assertEquals(77.0, self.results.values[0][1])
        self.assertEquals(66.0, self.results.values[1][1])
    def testNagios3edgeCase4(self):
        """
        Incorrect use of pipes.
        """
        p1 = Object()
        p1.id = 'rta'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'pl'
        p2.data = self.dpdata

        self.cmd.points = [p1, p2]

        self.cmd.result.output = """PING OK|LOSS=0 RTA=0.34 |rta=0.337000ms;180.000000;300.000000;0.000000 pl=0%;100;100;0\n"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 2)
        self.assertEquals(0.337,  self.results.values[0][1])
        self.assertEquals(0.0,  self.results.values[1][1])
    def testNagios3edgeCase3(self):
        """
        No performance data
        """
        p1 = Object()
        p1.id = 'np1'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'np2'
        p2.data = self.dpdata

        self.cmd.points = [p1, p2]

        self.cmd.result.output = """OK plugin

My friendly junk
More stuff
"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 0)
    def testNagios3edgeCase1(self):
        """
        Multi-line parsing, Nagios v3 style
        """
        p1 = Object()
        p1.id = 'np1'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'np2'
        p2.data = self.dpdata

        self.cmd.points = [p1, p2]

        self.cmd.result.output = """OK plugin | np1=77;;;

My friendly junk
More stuff | np2=66;;;

np3=55;;;"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 2)
        self.assertEquals(77.0,  self.results.values[0][1])
        self.assertEquals(66.0,  self.results.values[1][1])
Ejemplo n.º 22
0
    def testPs1(self):
        """
        A one-off test of the ps parser that does not use the data files.
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        
        cmd.includeRegex = ".*Job.*"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*"
        cmd.replacement  = "Job"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "Job"
        cmd.eventKey = "bar"
        cmd.severity = 3
        cmd.generatedId = "url_" + md5("Job").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu'
        p1.data = dict(id='url_Job',
                       alertOnRestart=True,
                       failSeverity=3)
        p2 = Object()
        p2.id = 'mem'
        p2.data = dict(id='url_Job',
                       alertOnRestart=True,
                       failSeverity=3)
        p3 = Object()
        p3.id = 'count'
        p3.data = dict(id='url_Job',
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1, p2, p3]
        cmd.result = Object()

        # the last process (with timestamp 10:23 is = 62300?)
        cmd.result.output = """  PID   RSS     TIME COMMAND
345 1 10:23 notherJob1 a b c
123 1 00:00:00 someJob a b c
234 1 00:00:00 anotherJob a b c
"""
        #create empty data structure for results
        results = ParsedResults()
        
        parser = ps()
        # populate results
        parser.processResults(cmd, ParsedResults())
        parser.processResults(cmd, results)
        self.assertEqual(len(results.values), 3)
        self.assertEqual(len(results.events), 3)
        # Check time of 10:23 equals 623 minutes
        #print "623 number = %s" % results.values[0][1]
        #assert results.values[0][1] == 623
        self.assertEqual(len([value for dp, value in results.values if value == 623]), 1)
        self.assertEqual(len([ev for ev in results.events if ev['severity'] == 0]), 3)
        
        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
124 1 00:00:00 someJob a b c
456 1 00:00:00 someOtherJob 1 2 3
"""
        parser.processResults(cmd, results)
        self.assertEqual(len(results.values), 3)
        # anotherJob went down
        # someJob restarted
        # noSuchProcess started
        self.assertEqual(len(results.events), 1)
        
        message = results.events[0]["message"]
        #print "message:", message
        
        firstOpenBracket = message.find('[')+1
        firstClosedBracket = message.find(']')
        discardedPidsString = message[firstOpenBracket : firstClosedBracket]
        #print "discardedPidsString:", discardedPidsString
        discardedPids = discardedPidsString.split(", ")
        #print "discardedPids:", discardedPids

        secondPart = message[firstClosedBracket+1:]
        #print "secondPart:", secondPart

        newPidsString = secondPart[secondPart.find('[')+1 : secondPart.find(']')]
        #print "newPidsString:", newPidsString
        newPids = newPidsString.split(", ")
        #print "newPids:", newPids

        if len(discardedPids) != 3:
            raise AssertionError("unexpected number of discarded PIDs (%s)", len(discardedPids))
        
        for discardedPid in discardedPids:
            if discardedPid != '345' and discardedPid != '123' and discardedPid != '234':
                raise AssertionError("unexpected discarded pid", discardedPid)

        if len(newPids) != 2:
            raise AssertionError("unexpected number of new PIDs (%s)", len(newPids))

        for newPid in newPids:
            if newPid != '124' and newPid != '456':
                raise AssertionError("unexpected newPid pid", newPid)
Ejemplo n.º 23
0
    def testPsZen5278(self):
        """
        Jira 5278 - defunct process matching
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = ".*defunct.*"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*"
        cmd.replacement  = "defunct"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "defunct process set"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("defunct").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(id='url_defunct',
        #p1.data = dict(processName='aioserver',
                       alertOnRestart=False,
                       failSeverity=0)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
28835916 00:00:00 <defunct>
28967020 1788 00:00:00 sshd: root@sherwood
29622478 448 00:00:08 aioserver
29688042 00:00:00 <defunct>
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        #print "results:", results

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
29688042 00:00:00 <defunct>
28835916 00:00:00 <defunct>
"""
        parser.processResults(cmd, results)
        #print "results:", results

        # Ensure that we can track defunct processes
        for ev in results.events:
            message = ev['summary']
            if message.find('defunct') >= 0:
                self.assert_(message.find('Process up') >= 0, "\'%s\' did not contain \'Process up\'")
            else:
                raise AssertionError("unexpected event")
Ejemplo n.º 24
0
    def testPsNameCaptureGroups(self):
        """
        test the search regex and excule regex
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        
        cmd.includeRegex = "tele.[^\/]*\/.*cel[^\/].*\/"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*(tele.[^\/]*)\/.*(cel[^\/].*)\/.*"
        cmd.replacement = "\\1_\\2"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "NCGs"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("telekinesis_celery").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu'
        p1.data = dict(id=cmd.generatedId,
                       alertOnRestart=True,
                       failSeverity=3)
        p2 = Object()
        p2.id = 'mem'
        p2.data = dict(id=cmd.generatedId,
                       alertOnRestart=True,
                       failSeverity=3)
        p3 = Object()
        p3.id = 'count'
        p3.data = dict(id=cmd.generatedId,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1, p2, p3]
        cmd.result = Object()

        cmd.result.output = """  PID   RSS     TIME COMMAND
120 1 00:00:01 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celtic/test1.sh
121 1 00:00:02 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celtic/test11.sh
122 1 00:00:03 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celery/test2.sh
123 1 00:00:04 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celery/test22.sh
124 1 00:00:05 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/cellular_phones/test3.sh
125 1 00:00:06 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/cellular_phones/test33.sh
126 1 00:00:07 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celtic/test1.sh
127 1 00:00:08 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celtic/test11.sh
128 1 00:00:09 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celery/test2.sh
129 1 00:00:10 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celery/test22.sh
130 1 00:00:11 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/cellular_phones/test3.sh
131 1 00:00:12 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/cellular_phones/test33.sh
132 1 00:00:13 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celtic/test1.sh
133 1 00:00:14 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celtic/test11.sh
134 1 00:00:15 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celery/test2.sh
135 1 00:00:16 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celery/test22.sh
136 1 00:00:17 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/cellular_phones/test3.sh
137 1 00:00:18 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/cellular_phones/test33.sh
"""
        #create empty data structure for results
        results = ParsedResults()
        
        parser = ps()
        # populate results
        parser.processResults(cmd, results)

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
120 1 00:00:01 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celtic/test1.sh
121 1 00:00:02 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celtic/test11.sh
122 1 00:00:03 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celery/test2.sh
123 1 00:00:04 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celery/test22.sh
124 1 00:00:05 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/cellular_phones/test3.sh
125 1 00:00:06 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/cellular_phones/test33.sh
126 1 00:00:07 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celtic/test1.sh
127 1 00:00:08 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celtic/test11.sh
128 1 00:00:09 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celery/test2.sh
129 1 00:00:10 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celery/test22.sh
130 1 00:00:11 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/cellular_phones/test3.sh
131 1 00:00:12 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/cellular_phones/test33.sh
132 1 00:00:13 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celtic/test1.sh
133 1 00:00:14 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celtic/test11.sh
134 1 00:00:15 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celery/test2.sh
135 1 00:00:16 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celery/test22.sh
136 1 00:00:17 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/cellular_phones/test3.sh
137 1 00:00:18 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/cellular_phones/test33.sh
"""
        parser.processResults(cmd, results)
        #print "results:", results

        self.assertEqual(len(results.values), 3)
        self.assertEqual(len(results.events), 2)

        for ev in results.events:
            summary = ev['summary']
            if summary.find('Process up') < 0: # and they were still running with the same PIDs
                raise AssertionError("unexpected event")
Ejemplo n.º 25
0
    def testPs(self):
        """
        A one-off test of the ps parser that does not use the data files.
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(processName='someJob a b c',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        p2 = Object()
        p2.id = 'cpu_cpu'
        p2.data = dict(processName='noSuchProcess',
                       ignoreParams=True,
                       alertOnRestart=False,
                       failSeverity=1)
        p3 = Object()
        p3.id = 'cpu_cpu'
        p3.data = dict(processName='anotherJob',
                       ignoreParams=True,
                       alertOnRestart=False,
                       failSeverity=3)
        p4 = Object()
        p4.id = 'cpu_cpu'
        p4.data = dict(processName='notherJob1',
                       ignoreParams=True,
                       alertOnRestart=False,
                       failSeverity=3)
        cmd.points = [p1, p2, p3, p4]
        cmd.result = Object()
        cmd.result.output = """  PID   RSS     TIME COMMAND
123 1 00:00:00 someJob a b c
234 1 00:00:00 anotherJob a b c
345 1 10:23 notherJob1 a b c
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        assert len(results.values)
        assert len(results.events) == 4
        # Check time of 10:23 equals 623 minutes
        #print "623 number = %s" % results.values[0][1]
        #assert results.values[0][1] == 623
        assert len([value for dp, value in results.values if value == 62300]) == 1
        assert len([ev for ev in results.events if ev['severity'] == 0]) == 3
        assert len([ev for ev in results.events if ev['severity'] == 1]) == 1
        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
124 1 00:00:00 someJob a b c
456 1 00:00:00 noSuchProcess
"""
        parser.processResults(cmd, results)
        assert len(results.values) == 2
        # anotherJob went down
        # someJob restarted
        # noSuchProcess started
        assert len(results.events) == 4
        for ev in results.events:
            summary = ev['summary']
            if summary.find('someJob') >= 0:
                assert summary.find('restarted') >= 0
            elif summary.find('noSuchProcess') >= 0:
                assert ev['severity'] == 0
            elif summary.find('notherJob') >= 0:
                assert summary.find('not running') >= 0
            else:
                raise AssertionError("unexpected event")
Ejemplo n.º 26
0
    def testPsCase10733(self):
        """
        Case 10733
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(
            processName='bogoApplication --conf bogo.conf instance4',
            ignoreParams=False,
            alertOnRestart=True,
            failSeverity=3)
        p2 = Object()
        p2.id = 'mem_mem'
        p2.data = dict(
            processName='bogoApplication --conf bogo.conf instance4',
            ignoreParams=False,
            alertOnRestart=True,
            failSeverity=3)
        p3 = Object()
        p3.id = 'count_count'
        p3.data = dict(
            processName='bogoApplication --conf bogo.conf instance4',
            ignoreParams=False,
            alertOnRestart=True,
            failSeverity=3)
        p4 = Object()
        p4.id = 'count_count'
        p4.data = dict(processName='bogoApplication',
                       ignoreParams=True,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1, p2, p3, p4]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
483362 146300    22:58:11 /usr/local/bin/bogoApplication --conf bogo.conf instance5
495844 137916    22:45:57 /usr/local/bin/bogoApplication --conf bogo.conf instance6
508130 138196    22:23:08 /usr/local/bin/bogoApplication --conf bogo.conf instance3
520290  1808    00:00:00 /usr/sbin/aixmibd
561300 140440    22:13:15 /usr/local/bin/bogoApplication --conf bogo.conf instance4
561301 140440    22:13:15 /usr/local/bin/bogoApplication --conf bogo.conf instance4
561302 140440    22:13:15 /usr/local/bin/wrapper bogoApplication --conf bogo.conf instance4
749772  3652    00:00:00 /bin/nmon_aix53 -f -A -P -V -m /tmp
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        self.assertEquals(len(results.values), 4)
        self.assertEquals(len(results.events), 2)
        self.assertEquals(results.events[0]['severity'], 0)
        for dp, value in results.values:
            if 'count' in dp.id:
                if dp.data['processName'] == 'bogoApplication':
                    self.assertEquals(value, 5)
                else:
                    self.assertEquals(value, 3)
            elif 'cpu' in dp.id:
                self.assertEquals(value, 23998500.0)
            elif 'mem' in dp.id:
                self.assertEquals(value, 421320.0)
            else:
                raise AssertionError("unexpected value")
Ejemplo n.º 27
0
    def testPsCase15745(self):
        """
        Case 15745
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = ".*oracle.*"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*"
        cmd.replacement  = "sendmail"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "oracle process set"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("sendmail").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(id='url_oracle',
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
483362 146300    22:58:11 /usr/local/test/oracleYAMDB1 (LOCAL=NO)
495844 137916    22:45:57 /usr/bin/sendmail: MTA: accepting connections
520290  1808    00:00:00 /usr/sbin/aixmibd
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        #print "results:", results

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
483362 146300    22:58:11 /usr/local/test/oracleYAMDB1 (LOCAL=NO)
"""
        parser.processResults(cmd, results)
        #print "results:", results

        # Oracle process with parenthesis in args should be detected
        for ev in results.events:
            summary = ev['summary']
            self.assert_(summary.find('Process up') >= 0, "\'%s\' is not up")
Ejemplo n.º 28
0
    def testNagiosAutoCaseApache(self):
        self.cmd.points = []

        slotDNSLookup = Object()
        slotDNSLookup.id = 'slotDNSLookup'
        slotDNSLookup.data = self.dpdata
        self.cmd.points.append(slotDNSLookup)

        totalAccesses = Object()
        totalAccesses.id = 'totalAccesses'
        totalAccesses.data = self.dpdata
        self.cmd.points.append(totalAccesses)


        slotReadingRequest = Object()
        slotReadingRequest.id = 'slotReadingRequest'
        slotReadingRequest.data = self.dpdata
        self.cmd.points.append(slotReadingRequest)

        busyServers = Object()
        busyServers.id = 'busyServers'
        busyServers.data = self.dpdata
        self.cmd.points.append(busyServers)


        self.cmd.result.output = 'STATUS OK|slotDNSLookup=0 totalAccesses=38 slotReadingRequest=0 totalKBytes=15 busyServers=1 slotKeepAlive=0 slotGracefullyFinishing=0 bytesPerReq=404.211 cpuLoad=.000142755 bytesPerSec=2.19272 slotLogging=0 slotSendingReply=1 slotStartingUp=0 reqPerSec=.0054247 slotWaiting=7 slotOpen=248 idleServers=7'
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(4, len(self.results.values))
Ejemplo n.º 29
0
    def testPsCase10733(self):
        """
        Case 10733
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(processName='bogoApplication --conf bogo.conf instance4',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        p2 = Object()
        p2.id = 'mem_mem'
        p2.data = dict(processName='bogoApplication --conf bogo.conf instance4',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        p3 = Object()
        p3.id = 'count_count'
        p3.data = dict(processName='bogoApplication --conf bogo.conf instance4',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        p4 = Object()
        p4.id = 'count_count'
        p4.data = dict(processName='bogoApplication',
                       ignoreParams=True,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1, p2, p3, p4]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
483362 146300    22:58:11 /usr/local/bin/bogoApplication --conf bogo.conf instance5
495844 137916    22:45:57 /usr/local/bin/bogoApplication --conf bogo.conf instance6
508130 138196    22:23:08 /usr/local/bin/bogoApplication --conf bogo.conf instance3
520290  1808    00:00:00 /usr/sbin/aixmibd
561300 140440    22:13:15 /usr/local/bin/bogoApplication --conf bogo.conf instance4
561301 140440    22:13:15 /usr/local/bin/bogoApplication --conf bogo.conf instance4
561302 140440    22:13:15 /usr/local/bin/wrapper bogoApplication --conf bogo.conf instance4
749772  3652    00:00:00 /bin/nmon_aix53 -f -A -P -V -m /tmp
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        self.assertEquals(len(results.values), 4)
        self.assertEquals(len(results.events), 2)
        self.assertEquals(results.events[0]['severity'], 0)
        for dp, value in results.values:
            if 'count' in dp.id:
                if dp.data['processName'] == 'bogoApplication':
                    self.assertEquals(value, 5)
                else:
                    self.assertEquals(value, 3)
            elif 'cpu' in dp.id:
                self.assertEquals(value, 23998500.0)
            elif 'mem' in dp.id:
                self.assertEquals(value, 421320.0)
            else:
                raise AssertionError("unexpected value")
    def test_component_result(self):
        self.cmd.result.output = json.dumps({
            'values': {
                'component1': {
                    'value1': 1.0,
                    'value2': 2.0,
                    },
                'component2': {
                    'value1': 1.1,
                    'value2': 2.2,
                    }
                }
            })

        p1_1 = Object()
        p1_1.id = 'value1'
        p1_1.component = 'component1'

        p1_2 = Object()
        p1_2.id = 'value2'
        p1_2.component = 'component1'

        p2_1 = Object()
        p2_1.id = 'value1'
        p2_1.component = 'component2'

        p2_2 = Object()
        p2_2.id = 'value2'
        p2_2.component = 'component2'

        self.cmd.points = [p1_1, p1_2, p2_1, p2_2]

        self.parser.processResults(self.cmd, self.results)

        self.assertEquals(len(self.results.values), 4)

        value1_1 = self.results.values[0]
        self.assertEquals(value1_1[0].component, 'component1')
        self.assertEquals(value1_1[0].id, 'value1')
        self.assertEquals(value1_1[1], 1.0)

        value1_2 = self.results.values[1]
        self.assertEquals(value1_2[0].component, 'component1')
        self.assertEquals(value1_2[0].id, 'value2')
        self.assertEquals(value1_2[1], 2.0)

        value2_1 = self.results.values[2]
        self.assertEquals(value2_1[0].component, 'component2')
        self.assertEquals(value2_1[0].id, 'value1')
        self.assertEquals(value2_1[1], 1.1)

        value2_2 = self.results.values[3]
        self.assertEquals(value2_2[0].component, 'component2')
        self.assertEquals(value2_2[0].id, 'value2')
        self.assertEquals(value2_2[1], 2.2)

        self.assertEquals(len(self.results.events), 0)
    def testNagios3case3(self):
        p1 = Object()
        p1.id = '/'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = '/boot'
        p2.data = self.dpdata

        p3 = Object()
        p3.id = '/home'
        p3.data = self.dpdata

        p4 = Object()
        p4.id = '/var/log'
        p4.data = self.dpdata

        self.cmd.points = [p1, p2, p3, p4]

        self.cmd.result.output = \
"""DISK OK - free space: / 3326 MB (56%); | /=2643MB;5948;5958;0;5968
/boot 68 MB (69%);
/home 69357 MB (27%);
/var/log 819 MB (84%); | /boot=68MB;88;93;0;98
/home=69357MB;253404;253409;0;253414
/var/log=818MB;970;975;0;980"""

        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 4)
        self.assertEquals(2643.0,  self.results.values[0][1])
        self.assertEquals(68.0,  self.results.values[1][1])
        self.assertEquals(69357.0,  self.results.values[2][1])
        self.assertEquals(818.0,  self.results.values[3][1])
Ejemplo n.º 32
0
    def testPs(self):
        """
        A one-off test of the ps parser that does not use the data files.
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(processName='someJob a b c',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        p2 = Object()
        p2.id = 'cpu_cpu'
        p2.data = dict(processName='noSuchProcess',
                       ignoreParams=True,
                       alertOnRestart=False,
                       failSeverity=1)
        p3 = Object()
        p3.id = 'cpu_cpu'
        p3.data = dict(processName='anotherJob',
                       ignoreParams=True,
                       alertOnRestart=False,
                       failSeverity=3)
        p4 = Object()
        p4.id = 'cpu_cpu'
        p4.data = dict(processName='notherJob1',
                       ignoreParams=True,
                       alertOnRestart=False,
                       failSeverity=3)
        cmd.points = [p1, p2, p3, p4]
        cmd.result = Object()
        cmd.result.output = """  PID   RSS     TIME COMMAND
123 1 00:00:00 someJob a b c
234 1 00:00:00 anotherJob a b c
345 1 10:23 notherJob1 a b c
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        assert len(results.values)
        assert len(results.events) == 4
        # Check time of 10:23 equals 623 minutes
        #print "623 number = %s" % results.values[0][1]
        #assert results.values[0][1] == 623
        assert len([value for dp, value in results.values
                    if value == 62300]) == 1
        assert len([ev for ev in results.events if ev['severity'] == 0]) == 3
        assert len([ev for ev in results.events if ev['severity'] == 1]) == 1
        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
124 1 00:00:00 someJob a b c
456 1 00:00:00 noSuchProcess
"""
        parser.processResults(cmd, results)
        assert len(results.values) == 2
        # anotherJob went down
        # someJob restarted
        # noSuchProcess started
        assert len(results.events) == 4
        for ev in results.events:
            summary = ev['summary']
            if summary.find('someJob') >= 0:
                assert summary.find('restarted') >= 0
            elif summary.find('noSuchProcess') >= 0:
                assert ev['severity'] == 0
            elif summary.find('notherJob') >= 0:
                assert summary.find('not running') >= 0
            else:
                raise AssertionError("unexpected event")
Ejemplo n.º 33
0
    def testPsZen5278(self):
        """
        Jira 5278 - defunct process matching
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(
            processName='<defunct>',
            #p1.data = dict(processName='aioserver',
            ignoreParams=False,
            alertOnRestart=False,
            failSeverity=0)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
28835916 00:00:00 <defunct>
28967020 1788 00:00:00 sshd: root@sherwood
29622478 448 00:00:08 aioserver
29688042 00:00:00 <defunct>
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        # Ensure that we can track defunct processes
        for ev in results.events:
            summary = ev['summary']
            if summary.find('defunct') >= 0:
                assert summary.find('Process running') >= 0
            else:
                raise AssertionError("unexpected event")
Ejemplo n.º 34
0
    def testPsCase15745(self):
        """
        Case 15745
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = ".*oracle.*"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*"
        cmd.replacement = "sendmail"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "oracle process set"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("sendmail").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(id='url_oracle', alertOnRestart=True, failSeverity=3)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
483362 146300    22:58:11 /usr/local/test/oracleYAMDB1 (LOCAL=NO)
495844 137916    22:45:57 /usr/bin/sendmail: MTA: accepting connections
520290  1808    00:00:00 /usr/sbin/aixmibd
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        #print "results:", results

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
483362 146300    22:58:11 /usr/local/test/oracleYAMDB1 (LOCAL=NO)
"""
        parser.processResults(cmd, results)
        #print "results:", results

        # Oracle process with parenthesis in args should be detected
        for ev in results.events:
            summary = ev['summary']
            self.assert_(summary.find('Process up') >= 0, "\'%s\' is not up")
Ejemplo n.º 35
0
    def test_component_result(self):
        self.cmd.result.output = json.dumps({
            'values': {
                'component1': {
                    'value1': 1.0,
                    'value2': 2.0,
                },
                'component2': {
                    'value1': 1.1,
                    'value2': 2.2,
                }
            }
        })

        p1_1 = Object()
        p1_1.id = 'value1'
        p1_1.component = 'component1'

        p1_2 = Object()
        p1_2.id = 'value2'
        p1_2.component = 'component1'

        p2_1 = Object()
        p2_1.id = 'value1'
        p2_1.component = 'component2'

        p2_2 = Object()
        p2_2.id = 'value2'
        p2_2.component = 'component2'

        self.cmd.points = [p1_1, p1_2, p2_1, p2_2]

        self.parser.processResults(self.cmd, self.results)

        self.assertEquals(len(self.results.values), 4)

        value1_1 = self.results.values[0]
        self.assertEquals(value1_1[0].component, 'component1')
        self.assertEquals(value1_1[0].id, 'value1')
        self.assertEquals(value1_1[1], 1.0)

        value1_2 = self.results.values[1]
        self.assertEquals(value1_2[0].component, 'component1')
        self.assertEquals(value1_2[0].id, 'value2')
        self.assertEquals(value1_2[1], 2.0)

        value2_1 = self.results.values[2]
        self.assertEquals(value2_1[0].component, 'component2')
        self.assertEquals(value2_1[0].id, 'value1')
        self.assertEquals(value2_1[1], 1.1)

        value2_2 = self.results.values[3]
        self.assertEquals(value2_2[0].component, 'component2')
        self.assertEquals(value2_2[0].id, 'value2')
        self.assertEquals(value2_2[1], 2.2)

        self.assertEquals(len(self.results.events), 0)
Ejemplo n.º 36
0
    def testPs1(self):
        """
        A one-off test of the ps parser that does not use the data files.
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = ".*Job.*"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*"
        cmd.replacement = "Job"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "Job"
        cmd.eventKey = "bar"
        cmd.severity = 3
        cmd.generatedId = "url_" + md5("Job").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu'
        p1.data = dict(id='url_Job', alertOnRestart=True, failSeverity=3)
        p2 = Object()
        p2.id = 'mem'
        p2.data = dict(id='url_Job', alertOnRestart=True, failSeverity=3)
        p3 = Object()
        p3.id = 'count'
        p3.data = dict(id='url_Job', alertOnRestart=True, failSeverity=3)
        cmd.points = [p1, p2, p3]
        cmd.result = Object()

        # the last process (with timestamp 10:23 is = 62300?)
        cmd.result.output = """  PID   RSS     TIME COMMAND
345 1 10:23 notherJob1 a b c
123 1 00:00:00 someJob a b c
234 1 00:00:00 anotherJob a b c
"""
        #create empty data structure for results
        results = ParsedResults()

        parser = ps()
        # populate results
        parser.processResults(cmd, ParsedResults())
        parser.processResults(cmd, results)
        self.assertEqual(len(results.values), 3)
        self.assertEqual(len(results.events), 3)
        # Check time of 10:23 equals 623 minutes
        #print "623 number = %s" % results.values[0][1]
        #assert results.values[0][1] == 623
        self.assertEqual(
            len([value for dp, value in results.values if value == 623]), 1)
        self.assertEqual(
            len([ev for ev in results.events if ev['severity'] == 0]), 3)

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
124 1 00:00:00 someJob a b c
456 1 00:00:00 someOtherJob 1 2 3
"""
        parser.processResults(cmd, results)
        self.assertEqual(len(results.values), 3)
        # anotherJob went down
        # someJob restarted
        # noSuchProcess started
        self.assertEqual(len(results.events), 1)

        message = results.events[0]["message"]
        #print "message:", message

        firstOpenBracket = message.find('[') + 1
        firstClosedBracket = message.find(']')
        discardedPidsString = message[firstOpenBracket:firstClosedBracket]
        #print "discardedPidsString:", discardedPidsString
        discardedPids = discardedPidsString.split(", ")
        #print "discardedPids:", discardedPids

        secondPart = message[firstClosedBracket + 1:]
        #print "secondPart:", secondPart

        newPidsString = secondPart[secondPart.find('[') +
                                   1:secondPart.find(']')]
        #print "newPidsString:", newPidsString
        newPids = newPidsString.split(", ")
        #print "newPids:", newPids

        if len(discardedPids) != 3:
            raise AssertionError("unexpected number of discarded PIDs (%s)",
                                 len(discardedPids))

        for discardedPid in discardedPids:
            if discardedPid != '345' and discardedPid != '123' and discardedPid != '234':
                raise AssertionError("unexpected discarded pid", discardedPid)

        if len(newPids) != 2:
            raise AssertionError("unexpected number of new PIDs (%s)",
                                 len(newPids))

        for newPid in newPids:
            if newPid != '124' and newPid != '456':
                raise AssertionError("unexpected newPid pid", newPid)
    def testGood(self):
        p1 = Object()
        p1.id = 'recvqueue'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'sentqueue'
        p2.data = self.dpdata

        p3 = Object()
        p3.id = 'storesize'
        p3.data = self.dpdata

        p4 = Object()
        p4.id = 'recv'
        p4.data = self.dpdata

        p5 = Object()
        p5.id = 'sent'
        p5.data = self.dpdata

        self.cmd.points = [p1, p2, p3, p4, p5]
        self.cmd.result.output = RESULT_X

        self.parser.processResults(self.cmd, self.results)

        #self.assertEquals( len(self.results.values), 3)
        self.assertEquals('recvqueue',  self.results.values[0][0].id)
        self.assertEquals(10,  self.results.values[0][1])
        self.assertEquals('sentqueue',  self.results.values[1][0].id)
        self.assertEquals(100,  self.results.values[1][1])
        self.assertEquals('storesize',  self.results.values[2][0].id)
        self.assertEquals(123456,  self.results.values[2][1])
        self.assertEquals('recv',  self.results.values[3][0].id)
        self.assertEquals(16,  self.results.values[3][1])
        self.assertEquals('sent',  self.results.values[4][0].id)
        self.assertEquals(6701,  self.results.values[4][1])
Ejemplo n.º 38
0
    def testPsZen5278(self):
        """
        Jira 5278 - defunct process matching
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = ".*defunct.*"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*"
        cmd.replacement = "defunct"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "defunct process set"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("defunct").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(
            id='url_defunct',
            #p1.data = dict(processName='aioserver',
            alertOnRestart=False,
            failSeverity=0)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
28835916 00:00:00 <defunct>
28967020 1788 00:00:00 sshd: root@sherwood
29622478 448 00:00:08 aioserver
29688042 00:00:00 <defunct>
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        #print "results:", results

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
29688042 00:00:00 <defunct>
28835916 00:00:00 <defunct>
"""
        parser.processResults(cmd, results)
        #print "results:", results

        # Ensure that we can track defunct processes
        for ev in results.events:
            message = ev['summary']
            if message.find('defunct') >= 0:
                self.assert_(
                    message.find('Process up') >= 0,
                    "\'%s\' did not contain \'Process up\'")
            else:
                raise AssertionError("unexpected event")
Ejemplo n.º 39
0
    def testPsExcludeRegex(self):
        """
        test the search regex and excule regex
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        deviceConfig.lastmodeltime = "a second ago"
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        
        cmd.includeRegex = ".*myapp.*"
        cmd.excludeRegex = ".*(vim|tail|grep|tar|cat|bash).*"
        cmd.replaceRegex = ".*"
        cmd.replacement  = "myapp"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "myapp set name"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("myapp").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu'
        p1.data = dict(id='url_myapp',
                       alertOnRestart=True,
                       failSeverity=3)
        p2 = Object()
        p2.id = 'mem'
        p2.data = dict(id='url_myapp',
                       alertOnRestart=True,
                       failSeverity=3)
        p3 = Object()
        p3.id = 'count'
        p3.data = dict(id='url_myapp',
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1, p2, p3]
        cmd.result = Object()

        cmd.result.output = """  PID   RSS     TIME COMMAND
120 1 00:00:01 myapp
121 1 00:00:02 vim myapp
122 1 00:00:03 vim /path/to/myapp
123 1 00:00:04 tail -f myapp.log
124 1 00:00:05 tail -f /path/to/myapp.log
125 1 00:00:06 /path/to/myapp
126 1 00:00:07 grep foo myapp
127 1 00:00:08 grep foo /path/to/myapp
128 1 00:00:09 tar cvfz bar.tgz /path/to/myapp
129 1 00:00:10 tar cvfz bar.tgz /path/to/myapp
130 1 00:00:11 cat /path/to/myapp
131 1 00:00:12 bash -c /path/to/myapp
132 1 00:00:13 bash -c myapp
"""
        #create empty data structure for results
        results = ParsedResults()
        
        parser = ps()
        # populate results
        parser.processResults(cmd, results)
        #print "results:", results

        self.assertEqual(len(results.values), 3)
        
        for val in results.values:
            if val[0].id == 'cpu':
                self.assertEqual(val[1], 7.0)
            elif val[0].id == 'count':
                self.assertEqual(val[1], 2)
            elif val[0].id == 'mem':
                self.assertEqual(val[1], 2.0)
            else:
                raise AssertionError("unexpected value:", val[0].id)

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
120 1 00:00:01 myapp
125 1 00:00:06 /path/to/myapp
"""
        parser.processResults(cmd, results)
        #print "results:", results

        if len(results.events) != 2: # only 2 made it through the exclude regex
            raise AssertionError("unexpected number of events: %s", len(results.events))

        for ev in results.events:
            summary = ev['summary']
            if summary.find('Process up') < 0: # and they were still running with the same PIDs
                raise AssertionError("unexpected event")
Ejemplo n.º 40
0
    def testPsExcludeRegex(self):
        """
        test the search regex and excule regex
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        deviceConfig.lastmodeltime = "a second ago"
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = ".*myapp.*"
        cmd.excludeRegex = ".*(vim|tail|grep|tar|cat|bash).*"
        cmd.replaceRegex = ".*"
        cmd.replacement = "myapp"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "myapp set name"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("myapp").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu'
        p1.data = dict(id='url_myapp', alertOnRestart=True, failSeverity=3)
        p2 = Object()
        p2.id = 'mem'
        p2.data = dict(id='url_myapp', alertOnRestart=True, failSeverity=3)
        p3 = Object()
        p3.id = 'count'
        p3.data = dict(id='url_myapp', alertOnRestart=True, failSeverity=3)
        cmd.points = [p1, p2, p3]
        cmd.result = Object()

        cmd.result.output = """  PID   RSS     TIME COMMAND
120 1 00:00:01 myapp
121 1 00:00:02 vim myapp
122 1 00:00:03 vim /path/to/myapp
123 1 00:00:04 tail -f myapp.log
124 1 00:00:05 tail -f /path/to/myapp.log
125 1 00:00:06 /path/to/myapp
126 1 00:00:07 grep foo myapp
127 1 00:00:08 grep foo /path/to/myapp
128 1 00:00:09 tar cvfz bar.tgz /path/to/myapp
129 1 00:00:10 tar cvfz bar.tgz /path/to/myapp
130 1 00:00:11 cat /path/to/myapp
131 1 00:00:12 bash -c /path/to/myapp
132 1 00:00:13 bash -c myapp
"""
        #create empty data structure for results
        results = ParsedResults()

        parser = ps()
        # populate results
        parser.processResults(cmd, results)
        #print "results:", results

        self.assertEqual(len(results.values), 3)

        for val in results.values:
            if val[0].id == 'cpu':
                self.assertEqual(val[1], 7.0)
            elif val[0].id == 'count':
                self.assertEqual(val[1], 2)
            elif val[0].id == 'mem':
                self.assertEqual(val[1], 2.0)
            else:
                raise AssertionError("unexpected value:", val[0].id)

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
120 1 00:00:01 myapp
125 1 00:00:06 /path/to/myapp
"""
        parser.processResults(cmd, results)
        #print "results:", results

        if len(results.events
               ) != 2:  # only 2 made it through the exclude regex
            raise AssertionError("unexpected number of events: %s",
                                 len(results.events))

        for ev in results.events:
            summary = ev['summary']
            if summary.find(
                    'Process up'
            ) < 0:  # and they were still running with the same PIDs
                raise AssertionError("unexpected event")
Ejemplo n.º 41
0
    def testNagiosLabelScheme(self):
        """
        No really, Nagios plugin output labels are stunned. WTF???
        """
        p1 = Object()
        p1.id = 'np 1'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = 'np 2'
        p2.data = self.dpdata

        p3 = Object()
        p3.id = 'label with spaces in it'
        p3.data = self.dpdata

        self.cmd.points = [p1, p2, p3]

        self.cmd.result.output = """OK plugin
|
'np 1'=77.3;;;
'np 2'=77.3e-7;;;
'label with spaces in it'=12%;50;70;0;100
np2=66;;;
np2=66;;;
"""
        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 3)
        self.assertEquals(77.3, self.results.values[0][1])
        self.assertEquals(7.7300000000000005e-06, self.results.values[1][1])
        self.assertEquals(12.0, self.results.values[2][1])
Ejemplo n.º 42
0
    def testPsNameCaptureGroups(self):
        """
        test the search regex and excule regex
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = "tele.[^\/]*\/.*cel[^\/].*\/"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*(tele.[^\/]*)\/.*(cel[^\/].*)\/.*"
        cmd.replacement = "\\1_\\2"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "NCGs"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5(
            "telekinesis_celery").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu'
        p1.data = dict(id=cmd.generatedId, alertOnRestart=True, failSeverity=3)
        p2 = Object()
        p2.id = 'mem'
        p2.data = dict(id=cmd.generatedId, alertOnRestart=True, failSeverity=3)
        p3 = Object()
        p3.id = 'count'
        p3.data = dict(id=cmd.generatedId, alertOnRestart=True, failSeverity=3)
        cmd.points = [p1, p2, p3]
        cmd.result = Object()

        cmd.result.output = """  PID   RSS     TIME COMMAND
120 1 00:00:01 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celtic/test1.sh
121 1 00:00:02 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celtic/test11.sh
122 1 00:00:03 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celery/test2.sh
123 1 00:00:04 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celery/test22.sh
124 1 00:00:05 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/cellular_phones/test3.sh
125 1 00:00:06 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/cellular_phones/test33.sh
126 1 00:00:07 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celtic/test1.sh
127 1 00:00:08 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celtic/test11.sh
128 1 00:00:09 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celery/test2.sh
129 1 00:00:10 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celery/test22.sh
130 1 00:00:11 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/cellular_phones/test3.sh
131 1 00:00:12 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/cellular_phones/test33.sh
132 1 00:00:13 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celtic/test1.sh
133 1 00:00:14 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celtic/test11.sh
134 1 00:00:15 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celery/test2.sh
135 1 00:00:16 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celery/test22.sh
136 1 00:00:17 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/cellular_phones/test3.sh
137 1 00:00:18 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/cellular_phones/test33.sh
"""
        #create empty data structure for results
        results = ParsedResults()

        parser = ps()
        # populate results
        parser.processResults(cmd, results)

        results = ParsedResults()
        cmd.result.output = """  PID   RSS     TIME COMMAND
120 1 00:00:01 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celtic/test1.sh
121 1 00:00:02 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celtic/test11.sh
122 1 00:00:03 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celery/test2.sh
123 1 00:00:04 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/celery/test22.sh
124 1 00:00:05 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/cellular_phones/test3.sh
125 1 00:00:06 /home/zenoss/dummy_processes/test_two_name_capture_groups/television/folder1/cellular_phones/test33.sh
126 1 00:00:07 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celtic/test1.sh
127 1 00:00:08 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celtic/test11.sh
128 1 00:00:09 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celery/test2.sh
129 1 00:00:10 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/celery/test22.sh
130 1 00:00:11 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/cellular_phones/test3.sh
131 1 00:00:12 /home/zenoss/dummy_processes/test_two_name_capture_groups/telephone/folder1/cellular_phones/test33.sh
132 1 00:00:13 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celtic/test1.sh
133 1 00:00:14 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celtic/test11.sh
134 1 00:00:15 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celery/test2.sh
135 1 00:00:16 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/celery/test22.sh
136 1 00:00:17 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/cellular_phones/test3.sh
137 1 00:00:18 /home/zenoss/dummy_processes/test_two_name_capture_groups/telekinesis/folder1/cellular_phones/test33.sh
"""
        parser.processResults(cmd, results)
        #print "results:", results

        self.assertEqual(len(results.values), 3)
        self.assertEqual(len(results.events), 2)

        for ev in results.events:
            summary = ev['summary']
            if summary.find(
                    'Process up'
            ) < 0:  # and they were still running with the same PIDs
                raise AssertionError("unexpected event")
Ejemplo n.º 43
0
    def testNagios3case3(self):
        p1 = Object()
        p1.id = '/'
        p1.data = self.dpdata

        p2 = Object()
        p2.id = '/boot'
        p2.data = self.dpdata

        p3 = Object()
        p3.id = '/home'
        p3.data = self.dpdata

        p4 = Object()
        p4.id = '/var/log'
        p4.data = self.dpdata

        self.cmd.points = [p1, p2, p3, p4]

        self.cmd.result.output = \
"""DISK OK - free space: / 3326 MB (56%); | /=2643MB;5948;5958;0;5968
/boot 68 MB (69%);
/home 69357 MB (27%);
/var/log 819 MB (84%); | /boot=68MB;88;93;0;98
/home=69357MB;253404;253409;0;253414
/var/log=818MB;970;975;0;980"""

        self.parser.processResults(self.cmd, self.results)
        self.assertEquals(len(self.results.values), 4)
        self.assertEquals(2643.0, self.results.values[0][1])
        self.assertEquals(68.0, self.results.values[1][1])
        self.assertEquals(69357.0, self.results.values[2][1])
        self.assertEquals(818.0, self.results.values[3][1])
Ejemplo n.º 44
0
    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)
Ejemplo n.º 45
0
    def testPsCase10733(self):
        """
        Case 10733
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = ".*bogo.*"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*"
        cmd.replacement = "bogo"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "foo"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("bogo").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu'
        p1.data = dict(id='url_bogo', alertOnRestart=True, failSeverity=3)
        p2 = Object()
        p2.id = 'mem'
        p2.data = dict(id='url_bogo', alertOnRestart=True, failSeverity=3)
        p3 = Object()
        p3.id = 'count'
        p3.data = dict(id='url_bogo', alertOnRestart=True, failSeverity=3)

        cmd.points = [p1, p2, p3]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
483362 146300    22:58:11 /usr/local/bin/bogoApplication --conf bogo.conf instance5
495844 137916    22:45:57 /usr/local/bin/bogoApplication --conf bogo.conf instance6
508130 138196    22:23:08 /usr/local/bin/bogoApplication --conf bogo.conf instance3
520290  1808    00:00:00 /usr/sbin/aixmibd
561300 140440    22:13:15 /usr/local/bin/bogoApplication --conf bogo.conf instance4
561301 140440    22:13:15 /usr/local/bin/bogoApplication --conf bogo.conf instance4
561302 140440    22:13:15 /usr/local/bin/wrapper bogoApplication --conf bogo.conf instance4
749772  3652    00:00:00 /bin/nmon_aix53 -f -A -P -V -m /tmp
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        #print "results:", results

        self.assertEquals(len(results.values), 3)
        self.assertEquals(len(results.events), 0)
        for dp, value in results.values:
            if 'count' in dp.id:
                self.assertEquals(value, 6)
            elif 'cpu' in dp.id:
                self.assertEquals(value, 485221.0)
            elif 'mem' in dp.id:
                self.assertEquals(value, 843732.0)
            else:
                raise AssertionError("unexpected value")
Ejemplo n.º 46
0
    def testPsCase15745(self):
        """
        Case 15745
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'
        p1 = Object()
        p1.id = 'cpu_cpu'
        p1.data = dict(processName='oracleYAMDB1 (LOCAL=NO)',
                       ignoreParams=False,
                       alertOnRestart=True,
                       failSeverity=3)
        cmd.points = [p1]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
483362 146300    22:58:11 /usr/local/test/oracleYAMDB1 (LOCAL=NO)
495844 137916    22:45:57 /usr/bin/sendmail: MTA: accepting connections
520290  1808    00:00:00 /usr/sbin/aixmibd
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        # Oracle process with parenthesis in args should be detected
        for ev in results.events:
            summary = ev['summary']
            if summary.find('oracleYAMDB1') >= 0:
                assert summary.find('Process running') >= 0
            else:
                raise AssertionError("unexpected event")
Ejemplo n.º 47
0
    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)
Ejemplo n.º 48
0
    def testPsCase10733(self):
        """
        Case 10733
        """
        deviceConfig = Object()
        deviceConfig.device = 'localhost'
        cmd = Object()
        cmd.deviceConfig = deviceConfig
        cmd.command = 'command'

        cmd.includeRegex = ".*bogo.*"
        cmd.excludeRegex = "nothing"
        cmd.replaceRegex = ".*"
        cmd.replacement  = "bogo"
        cmd.primaryUrlPath = "url"
        cmd.displayName = "foo"
        cmd.eventKey = "bar"
        cmd.severity = 1
        cmd.generatedId = "url_" + md5("bogo").hexdigest().strip()

        p1 = Object()
        p1.id = 'cpu'
        p1.data = dict(id='url_bogo',
                       alertOnRestart=True,
                       failSeverity=3)
        p2 = Object()
        p2.id = 'mem'
        p2.data = dict(id='url_bogo',
                       alertOnRestart=True,
                       failSeverity=3)
        p3 = Object()
        p3.id = 'count'
        p3.data = dict(id='url_bogo',
                       alertOnRestart=True,
                       failSeverity=3)

        cmd.points = [p1, p2, p3]
        cmd.result = Object()
        cmd.result.output = """ PID   RSS        TIME COMMAND
483362 146300    22:58:11 /usr/local/bin/bogoApplication --conf bogo.conf instance5
495844 137916    22:45:57 /usr/local/bin/bogoApplication --conf bogo.conf instance6
508130 138196    22:23:08 /usr/local/bin/bogoApplication --conf bogo.conf instance3
520290  1808    00:00:00 /usr/sbin/aixmibd
561300 140440    22:13:15 /usr/local/bin/bogoApplication --conf bogo.conf instance4
561301 140440    22:13:15 /usr/local/bin/bogoApplication --conf bogo.conf instance4
561302 140440    22:13:15 /usr/local/bin/wrapper bogoApplication --conf bogo.conf instance4
749772  3652    00:00:00 /bin/nmon_aix53 -f -A -P -V -m /tmp
"""
        results = ParsedResults()
        parser = ps()
        parser.processResults(cmd, results)
        #print "results:", results

        self.assertEquals(len(results.values), 3)
        self.assertEquals(len(results.events), 0)
        for dp, value in results.values:
            if 'count' in dp.id:
                self.assertEquals(value, 6)
            elif 'cpu' in dp.id:
                self.assertEquals(value, 485221.0)
            elif 'mem' in dp.id:
                self.assertEquals(value, 843732.0)
            else:
                raise AssertionError("unexpected value")