Ejemplo n.º 1
0
    def test_DatapointsProcessed(self):
        """Verifies that the processResults method populates the second
        argument ('results') with the expected values.
        """
        self.cmd.result.output = "\n".join((
            "  PID   RSS     TIME COMMAND",
            "345 1 00:00:30 someJob a b c",
        ))
        results = ParsedResults()
        ps().processResults(self.cmd, results)

        self.assertEqual(len(results.events), 1)

        event = results.events[0]
        self.assertEqual(event.get("component"), "Job")
        self.assertEqual(event.get("eventGroup"), "Process")
        self.assertEqual(event.get("eventClass"), "/Status/OSProcess")
        self.assertEqual(event.get("severity"), 0)

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

        cpu, cpuValue = _getDatapoint(results.values, "cpu")
        mem, memValue = _getDatapoint(results.values, "mem")
        count, countValue = _getDatapoint(results.values, "count")

        self.assertIsNotNone(cpu)
        self.assertIsNotNone(mem)
        self.assertIsNotNone(count)

        self.assertEqual(cpuValue, 30)
        self.assertEqual(memValue, 1024)
        self.assertEqual(countValue, 1)
Ejemplo n.º 2
0
    def step_processReturns(self):
        """Verifies that a 'repopulated' process set is handled correctly.
        """
        self.cmd.result.output = '\n'.join((
            "  PID   RSS     TIME COMMAND",
            "124 1 00:00:00 someJob a b c",
            "456 1 00:00:00 someOtherJob 1 2 3",
        ))
        results = ParsedResults()
        ps().processResults(self.cmd, results)
        self.assertEqual(len(results.values), 3)

        cpu, cpuValue = _getDatapoint(results.values, "cpu")
        self.assertIsNotNone(cpu)
        self.assertEqual(cpuValue, 0)

        mem, memValue = _getDatapoint(results.values, "mem")
        self.assertIsNotNone(mem)
        self.assertEqual(memValue, 2048)

        count, countValue = _getDatapoint(results.values, "count")
        self.assertIsNotNone(count)
        self.assertEqual(countValue, 2)

        self.assertEqual(len(results.events), 2)
        self.assertTrue(all(e["severity"] == 0 for e in results.events))
        self.assertTrue(all(e["component"] == "Job" for e in results.events))
        self.assertTrue(all(
            e["eventGroup"] == "Process" for e in results.events
        ))
        self.assertTrue(all(
            e["eventClass"] == "/Status/OSProcess" for e in results.events
        ))
Ejemplo n.º 3
0
 def test_NoResultsOnFailure(self):
     """If the ps command has a non-zero exit code, disregard the output.
     The result is a missed collection.
     """
     self.cmd.result.exitCode = 1
     self.cmd.result.output = "\n".join(())
     results = ParsedResults()
     ps().processResults(self.cmd, results)
     self.assertEqual(len(results.values), 0)
     self.assertEqual(len(results.events), 0)
Ejemplo n.º 4
0
 def test_sumsMemory(self):
     """Verifies that the memory usage of multiple instances of the same
     process are summed together.
     """
     self.cmd.result.output = "\n".join((
         "  PID   RSS     TIME COMMAND",
         "345 1 10:23 notherJob1 a b c",
         "123 1 00:05:01 someJob a b c",
         "657 1 2-03:00:00 someJob a b c",
         "8766 1 00:10:00 unrelatedTask a b c",
     ))
     results = ParsedResults()
     ps().processResults(self.cmd, results)
     mem, memValue = _getDatapoint(results.values, "mem")
     self.assertEqual(memValue, 3072)
Ejemplo n.º 5
0
 def test_countsProcesses(self):
     """Verifies that the count of multiple instances of the same
     process is correct.
     """
     self.cmd.result.output = "\n".join((
         "  PID   RSS     TIME COMMAND",
         "345 1 10:23 notherJob1 a b c",
         "123 1 00:05:01 someJob a b c",
         "657 1 2-03:00:00 someJob a b c",
         "8766 1 00:10:00 unrelatedTask a b c",
     ))
     results = ParsedResults()
     ps().processResults(self.cmd, results)
     count, countValue = _getDatapoint(results.values, "count")
     self.assertEqual(countValue, 3)
Ejemplo n.º 6
0
 def test_sumsCpuTimes(self):
     """Verifies that the CPU times of multiple instances of the same
     process are summed together.
     """
     self.cmd.result.output = "\n".join((
         "  PID   RSS     TIME COMMAND",
         "345 1 10:23 notherJob1 a b c",
         "123 1 00:05:01 someJob a b c",
         "657 1 2-03:00:00 someJob a b c",
         "8766 1 00:10:00 unrelatedTask a b c",
     ))
     results = ParsedResults()
     ps().processResults(self.cmd, results)
     cpu, cpuValue = _getDatapoint(results.values, "cpu")
     self.assertEqual(cpuValue, 184524)
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
0
 def test_resultEvents(self):
     """Verifies the content and quantity of events in the result.
     """
     self.cmd.result.output = "\n".join((
         "  PID   RSS     TIME COMMAND",
         "345 1 10:23 notherJob1 a b c",
         "123 1 00:05:01 someJob a b c",
         "657 1 2-03:00:00 someJob a b c",
         "8766 1 00:10:00 unrelatedTask a b c",
     ))
     results = ParsedResults()
     ps().processResults(self.cmd, results)
     self.assertEqual(len(results.events), 3)
     for event in results.events:
         self.assertEqual(event.get("component"), "Job")
         self.assertEqual(event.get("eventGroup"), "Process")
         self.assertEqual(event.get("eventClass"), "/Status/OSProcess")
         self.assertEqual(event.get("severity"), 0)
Ejemplo n.º 13
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.º 14
0
    def step_regexCaptureGroups_2(self):
        # Reset 'result' for second collection
        results = ParsedResults()
        self.cmd.result.output = '\n'.join((
            "  PID   RSS     TIME COMMAND",
            "120 1 00:00:01 /opt/television/src/celtic/test1.sh",
            "121 1 00:00:02 /opt/television/src/celtic/test11.sh",
            "122 1 00:00:03 /opt/television/src/celery/test2.sh",
            "123 1 00:00:04 /opt/television/src/celery/test22.sh",
            "124 1 00:00:05 /opt/television/src/cellular_phones/test3.sh",
            "125 1 00:00:06 /opt/television/src/cellular_phones/test33.sh",
            "126 1 00:00:07 /opt/telephone/src/celtic/test1.sh",
            "127 1 00:00:08 /opt/telephone/src/celtic/test11.sh",
            "128 1 00:00:09 /opt/telephone/src/celery/test2.sh",
            "129 1 00:00:10 /opt/telephone/src/celery/test22.sh",
            "130 1 00:00:11 /opt/telephone/src/cellular_phones/test3.sh",
            "131 1 00:00:12 /opt/telephone/src/cellular_phones/test33.sh",
            "132 1 00:00:13 /opt/telekinesis/src/celtic/test1.sh",
            "133 1 00:00:14 /opt/telekinesis/src/celtic/test11.sh",
            "134 1 00:00:15 /opt/telekinesis/src/celery/test2.sh",
            "135 1 00:00:16 /opt/telekinesis/src/celery/test22.sh",
            "136 1 00:00:17 /opt/telekinesis/src/cellular_phones/test3.sh",
            "137 1 00:00:18 /opt/telekinesis/src/cellular_phones/test33.sh",
        ))
        ps().processResults(self.cmd, results)

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

        cpu, cpuValue = _getDatapoint(results.values, "cpu")
        self.assertIsNotNone(cpu)
        self.assertEqual(cpuValue, 31)

        mem, memValue = _getDatapoint(results.values, "mem")
        self.assertIsNotNone(mem)
        self.assertEqual(memValue, 2 * 1024.0)

        count, countValue = _getDatapoint(results.values, "count")
        self.assertIsNotNone(count)
        self.assertEqual(countValue, 2)

        self.assertEqual(len(results.events), 2)
        self.assertTrue(all(
            "Process up" in ev.get("summary", "") for ev in results.events
        ))
Ejemplo n.º 15
0
    def step_changedProcesses(self):
        """Verifies that a changed process set is handled correctly.
        """
        self.cmd.result.output = '\n'.join((
            "  PID   RSS     TIME COMMAND",
            "124 1 00:00:00 someJob a b c",
            "456 1 00:00:00 someOtherJob 1 2 3",
        ))

        results = ParsedResults()
        ps().processResults(self.cmd, results)

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

        cpu, cpuValue = _getDatapoint(results.values, "cpu")
        self.assertIsNotNone(cpu)
        self.assertEqual(cpuValue, 0)

        mem, memValue = _getDatapoint(results.values, "mem")
        self.assertIsNotNone(mem)
        self.assertEqual(memValue, 2048)

        count, countValue = _getDatapoint(results.values, "count")
        self.assertIsNotNone(count)
        self.assertEqual(countValue, 2)

        self.assertEqual(len(results.events), 1)

        event = results.events[0]

        self.assertEqual(event.get("severity"), 3)

        message = event.get("message", "")

        begin = message.find('[') + 1
        end = message.find(']', begin)
        discardedPids = [p.strip() for p in message[begin:end].split(",")]

        begin = message.find('[', end+1) + 1
        end = message.find(']', begin)
        newPids = [p.strip() for p in message[begin:end].split(",")]

        self.assertSetEqual(set(discardedPids), set(["345", "123", "234"]))
        self.assertSetEqual(set(newPids), set(["124", "456"]))
Ejemplo n.º 16
0
    def test_ignoresParenthesis(self):
        """Verify that parenthesis don't disrupt process detection.
        """
        self.cmd.result.output = '\n'.join((
            " PID   RSS        TIME COMMAND",
            "483362 146300  22:58:11 /opt/test/oracleYAMDB1 (LOCAL=NO)",
            "495844 137916  22:45:57 /bin/sendmail: accepting connections",
            "520290  1808   00:00:00 /sbin/aixmibd"
        ))
        results = ParsedResults()
        ps().processResults(self.cmd, results)

        self.assertEqual(len(results.values), 1)
        cpu, cpuValue = _getDatapoint(results.values, "cpu_cpu")
        self.assertIsNotNone(cpu)
        self.assertEqual(cpuValue, 82691)

        self.assertEqual(len(results.events), 1)
        event = results.events[0]
        self.assertIn("Process up", event.get("summary", ""))
Ejemplo n.º 17
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.º 18
0
    def test_defuncts(self):
        """
        """
        self.cmd.result.output = '\n'.join((
            " PID   RSS        TIME COMMAND",
            "288 00:00:00 <defunct>",
            "289 1788 00:00:00 sshd: root@sherwood",
            "294 448 00:00:08 aioserver",
            "296 00:00:00 <defunct>",
        ))
        results = ParsedResults()
        ps().processResults(self.cmd, results)

        self.assertEqual(len(results.values), 1)
        self.assertEqual(len(results.events), 0)

        # Reset 'result' for second collection
        self.cmd.result = Object(**{"exitCode": 0})
        self.cmd.result.output = '\n'.join((
            "  PID   RSS     TIME COMMAND",
            "288 00:00:00 <defunct>",
            "296 00:00:00 <defunct>",
        ))
        results = ParsedResults()
        ps().processResults(self.cmd, results)

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

        self.assertEqual(len(results.events), 2)
        event1, event2 = results.events

        self.assertIn("Process up", event1.get("summary", ""))
        self.assertIn("Process up", event2.get("summary", ""))

        self.assertIn("defunct", event1.get("summary", ""))
        self.assertIn("defunct", event2.get("summary", ""))

        self.assertEqual(event1.get("severity"), 0)
        self.assertEqual(event2.get("severity"), 0)
Ejemplo n.º 19
0
    def step_processDown(self):
        """Verifies that an 'empty' process set is handled correctly.
        """
        self.cmd.result.output = '\n'.join((
            "  PID   RSS     TIME COMMAND",
            "124 1 00:00:00 unrelatedTask a b c",
            "782 1 00:00:00 anotherUnrelatedTask 1 2 3",
        ))
        results = ParsedResults()
        ps().processResults(self.cmd, results)

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

        count, countValue = _getDatapoint(results.values, "count")
        self.assertEqual(countValue, 0)

        self.assertEqual(len(results.events), 1)

        event = results.events[0]
        self.assertEqual(event.get("component"), "Job")
        self.assertEqual(event.get("eventGroup"), "Process")
        self.assertEqual(event.get("eventClass"), "/Status/OSProcess")
        self.assertEqual(event.get("severity"), 3)
Ejemplo n.º 20
0
 def test_parsesShortTimestamp(self):
     """Verifies that abbreviated timestamps are parsed correctly.
     """
     self.cmd.result.output = "\n".join((
         "  PID   RSS     TIME COMMAND",
         "345 1 10:23 notherJob1 a b c",
     ))
     results = ParsedResults()
     parser = ps()
     parser.processResults(self.cmd, results)
     cpuTime = next(
         (v for dp, v in results.values if dp["id"] == "cpu"), None
     )
     self.assertEqual(cpuTime, 623)
Ejemplo n.º 21
0
    def test_collectionSteps(self):
        """Verifies that data captured in the first collection is
        used in the second collection correctly.
        """
        # First collection
        self.cmd.result.output = "\n".join((
            "  PID   RSS     TIME COMMAND",
            "345 1 10:23 extraJob a b c",
            "123 1 00:00:00 someJob a b c",
            "234 1 00:00:00 anotherJob a b c",
        ))
        ps().processResults(self.cmd, ParsedResults())

        # Reset 'result' for second collection
        self.cmd.result = Object(**{"exitCode": 0})
        self.step_changedProcesses()

        # Reset 'result' for third collection
        self.cmd.result = Object(**{"exitCode": 0})
        self.step_processDown()

        # Reset 'result' for third collection
        self.cmd.result = Object(**{"exitCode": 0})
        self.step_processReturns()
Ejemplo n.º 22
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.º 23
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.º 24
0
 def test_dataForParser(self):
     """Verifies that the dataForParser method on the ps object
     returns the expected result.
     """
     parser = ps()
     ctx = type(
         "Context", (object,), {
             "getOSProcessConf": lambda x: ("someId", True, 3)
         }
     )()
     data = parser.dataForParser(ctx, "unused")
     expected = {
         "id": "someId",
         "alertOnRestart": True,
         "failSeverity": 3
     }
     self.assertEqual(data, expected)
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 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.º 27
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.º 28
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.º 29
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.º 30
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.º 31
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.º 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 test_excludeRegex(self):
        """
        """
        self.cmd.includeRegex = ".*myapp.*"
        self.cmd.excludeRegex = ".*(vim|tail|grep|tar|cat|bash).*"
        self.cmd.replaceRegex = ".*"

        self.cmd.result.output = '\n'.join((
            "  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",
        ))
        results = ParsedResults()
        ps().processResults(self.cmd, results)

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

        cpu, cpuValue = _getDatapoint(results.values, "cpu")
        self.assertIsNotNone(cpu)
        self.assertEqual(cpuValue, 7.0)

        mem, memValue = _getDatapoint(results.values, "mem")
        self.assertIsNotNone(mem)
        self.assertEqual(memValue, 2048.0)

        count, countValue = _getDatapoint(results.values, "count")
        self.assertIsNotNone(count)
        self.assertEqual(countValue, 2)

        self.assertEqual(len(results.events), 2)
        self.assertTrue(all(
            "Process up" in ev.get("summary", "") for ev in results.events
        ))

        # Reset 'result' for second collection
        self.cmd.result = Object(**{"exitCode": 0})
        results = ParsedResults()
        self.cmd.result.output = '\n'.join((
            "  PID   RSS     TIME COMMAND",
            "120 1 00:00:01 myapp",
            "125 1 00:00:06 /path/to/myapp",
        ))
        ps().processResults(self.cmd, results)

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

        cpu, cpuValue = _getDatapoint(results.values, "cpu")
        self.assertIsNotNone(cpu)
        self.assertEqual(cpuValue, 7.0)

        mem, memValue = _getDatapoint(results.values, "mem")
        self.assertIsNotNone(mem)
        self.assertEqual(memValue, 2048.0)

        count, countValue = _getDatapoint(results.values, "count")
        self.assertIsNotNone(count)
        self.assertEqual(countValue, 2)

        self.assertEqual(len(results.events), 2)
        self.assertTrue(all(
            "Process up" in ev.get("summary", "") for ev in results.events
        ))
Ejemplo n.º 34
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.º 35
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.º 36
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")