예제 #1
0
    def test_automonitor_functions(self):
        MonitoringRule.monitor_objects = {'service': {}, 'host': {}}
        drone = FakeDrone(
            {'data': {
                'ocf': {
                    'assimilation/neo4j',
                },
                'lsb': {
                    'bacula',
                },
            }})
        ocf_string = '''{
        "class":        "ocf", "type":         "neo4j", "provider":     "assimilation",
        "classconfig": [
            ["classpath",   "@flagvalue(-cp)"],
            ["ipaddr",      "@serviceip($JSON_procinfo.listenaddrs)"],
            ["port",        "@serviceport()",   "[0-9]+$"]
        ]
        }'''
        ssh_json = '''{
          "exe": "/usr/sbin/sshd",
          "argv": [ "/usr/sbin/sshd", "-D" ],
          "uid": "root",
          "gid": "root",
          "cwd": "/",
          "listenaddrs": {
            "0.0.0.0:22": {
              "proto": "tcp",
              "addr": "0.0.0.0",
              "port": 22
            },
            ":::22": {
              "proto": "tcp6",
              "addr": "::",
              "port": 22
            }
          }
        }'''
        neo4j_json = '''{
          "exe": "/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java",
          "argv": [ "/usr/bin/java", "-cp", "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar: ...", "-server", "-XX:+DisableExplicitGC", "-Dorg.neo4j.server.properties=conf/neo4
    j-server.properties", "-Djava.util.logging.config.file=conf/logging.properties", "-Dlog4j.configuration=file:conf/log4j.properties", "-XX:
    +UseConcMarkSweepGC", "-XX:+CMSClassUnloadingEnabled", "-Dneo4j.home=/var/lib/neo4j", "-Dneo4j.instance=/var/lib/neo4j", "-Dfile.encoding=
    UTF-8", "org.neo4j.server.Bootstrapper" ],
          "uid": "neo4j",
          "gid": "neo4j",
          "cwd": "/var/lib/neo4j",
          "listenaddrs": {
            ":::1337": {
              "proto": "tcp6",
              "addr": "::",
              "port": 1337
            },
            ":::39185": {
              "proto": "tcp6",
              "addr": "::",
              "port": 39185
            }
          }
        }'''
        bacula_json = '''{
      "exe": "/usr/sbin/bacula-dir",
      "argv": [ "/usr/sbin/bacula-dir", "-c", "/etc/bacula/bacula-dir.conf", "-u", "bacula", "-g", "bacula" ],
      "uid": "bacula",
      "gid": "bacula",
      "cwd": "/",
      "listenaddrs": {
        "10.10.10.5:9101": {
          "proto": "tcp",
          "addr": "10.10.10.5",
          "port": 9101
        }
      }
    }'''
        MonitoringRule.ConstructFromString(ocf_string)
        neoargs = pyConfigContext(neo4j_json)['argv']
        testnode = ProcessNode('global',
                               'foofred',
                               'fred',
                               '/usr/bin/java',
                               neoargs,
                               'root',
                               'root',
                               '/',
                               roles=(CMAconsts.ROLE_server, ))

        testnode.JSON_procinfo = neo4j_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['ipaddr'], '::1')
        self.assertEqual(match['arglist']['port'], '1337')

        testnode.JSON_procinfo = ssh_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['port'], '22')
        self.assertEqual(match['arglist']['ipaddr'], '127.0.0.1')

        testnode.JSON_procinfo = bacula_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['port'], '9101')
        self.assertEqual(match['arglist']['ipaddr'], '10.10.10.5')
예제 #2
0
    def test_automonitor_LSB_basic(self):
        drone = FakeDrone({'data': {
            'lsb': {
                'ssh',
                'neo4j-service',
            }
        }})
        neoargs = (
            ('$argv[0]', r'.*/[^/]*java[^/]*$'),  # Might be overkill
            ('$argv[3]', r'-server$'),  # Probably overkill
            ('$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$'),
        )
        neorule = LSBMonitoringRule('neo4j-service', neoargs)

        sshnode = ProcessNode(
            'global',
            'foofred',
            'fred',
            '/usr/bin/sshd',
            ['/usr/bin/sshd', '-D']
            #ProcessNode:
            #   (domain, host, nodename, pathname, argv, uid, gid, cwd, roles=None):
            ,
            'root',
            'root',
            '/',
            roles=(CMAconsts.ROLE_server, ))

        sshargs = (
            # This means one of our nodes should have a value called
            # pathname, and it should end in '/sshd'
            ('@basename()', 'sshd$'), )
        sshrule = LSBMonitoringRule('ssh', sshargs)

        udevnode = ProcessNode('global',
                               'foofred',
                               'fred',
                               '/usr/bin/udevd', ['/usr/bin/udevd'],
                               'root',
                               'root',
                               '/',
                               roles=(CMAconsts.ROLE_server, ))

        neoprocargs = (
            "/usr/bin/java", "-cp",
            "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:"
            "AND SO ON:"
            "/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:"
            "/var/lib/neo4j/conf/", "-server", "-XX:"
            "+DisableExplicitGC",
            "-Dorg.neo4j.server.properties=conf/neo4j-server.properties",
            "-Djava.util.logging.config.file=conf/logging.properties",
            "-Dlog4j.configuration=file:conf/log4j.properties",
            "-XX:+UseConcMarkSweepGC", "-XX:+CMSClassUnloadingEnabled",
            "-Dneo4j.home=/var/lib/neo4j", "-Dneo4j.instance=/var/lib/neo4j",
            "-Dfile.encoding=UTF-8", "org.neo4j.server.Bootstrapper")

        neonode = ProcessNode('global',
                              'foofred',
                              'fred',
                              '/usr/bin/java',
                              neoprocargs,
                              'root',
                              'root',
                              '/',
                              roles=(CMAconsts.ROLE_server, ))

        for tup in (sshrule.specmatch(ExpressionContext((udevnode, drone))),
                    sshrule.specmatch(ExpressionContext((neonode, drone))),
                    neorule.specmatch(ExpressionContext((sshnode, drone)))):
            (prio, table) = tup
            self.assertEqual(prio, MonitoringRule.NOMATCH)
            self.assertTrue(table is None)

        (prio, table) = sshrule.specmatch(ExpressionContext((sshnode, drone)))
        self.assertEqual(prio, MonitoringRule.LOWPRIOMATCH)
        self.assertEqual(table['monitorclass'], 'lsb')
        self.assertEqual(table['monitortype'], 'ssh')

        (prio, table) = neorule.specmatch(ExpressionContext((neonode, drone)))
        self.assertEqual(prio, MonitoringRule.LOWPRIOMATCH)
        self.assertEqual(table['monitorclass'], 'lsb')
        self.assertEqual(table['monitortype'], 'neo4j-service')
예제 #3
0
    def test_automonitor_search_basic(self):
        AssimEvent.disable_all_observers()
        drone = FakeDrone({
                'data': {
                        'ocf': {
                            'assimilation/neo4j',
                        },
                        'lsb': {
                            'neo4j-service',
                        }
                    }
                })
        MonitoringRule.monitor_objects = {'service': {}, 'host':{}}
        ocf_string = '''{
        "class":        "ocf", "type":         "neo4j", "provider":     "assimilation",
        "classconfig": [
            [null,      "@basename()",          "java$"],
            [null,      "$argv[-1]",             "org\\.neo4j\\.server\\.Bootstrapper$"],
            ["PORT",    "$serviceport"],
            ["NEOHOME", "@argequals(-Dneo4j.home)", "/.*"]
        ]
        }'''
        MonitoringRule.ConstructFromString(ocf_string)
        lsb_string = '''{
        "class":        "lsb", "type":         "neo4j-service",
        "classconfig": [
            ["@basename()",    "java$"],
            ["$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"],
        ]
        }'''
        MonitoringRule.ConstructFromString(lsb_string)
        neoprocargs = ("/usr/bin/java", "-cp"
        , "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:"
        "AND SO ON:"
        "/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:"
        "/var/lib/neo4j/conf/", "-server", "-XX:"
        "+DisableExplicitGC"
        ,   "-Dneo4j.home=/var/lib/neo4j"
        ,   "-Dneo4j.instance=/var/lib/neo4j"
        ,   "-Dfile.encoding=UTF-8"
        ,   "org.neo4j.server.Bootstrapper")

        neonode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoprocargs
        ,   'root', 'root', '/', roles=(CMAconsts.ROLE_server,))
        #neonode.serviceport=7474
        context = ExpressionContext((neonode, drone))
        first = MonitoringRule.findbestmatch(context)
        second = MonitoringRule.findbestmatch(context, False)
        list1 = MonitoringRule.findallmatches(context)
        neonode.serviceport=7474
        third = MonitoringRule.findbestmatch(context)
        list2 = MonitoringRule.findallmatches(context)

        # first should be the LSB instance
        self.assertEqual(first[1]['monitorclass'], 'lsb')
        self.assertEqual(first[0], MonitoringRule.LOWPRIOMATCH)
        # second should be the incomplete OCF instance
        self.assertEqual(second[1]['monitorclass'], 'ocf')
        self.assertEqual(second[0], MonitoringRule.PARTMATCH)
        # third should be the high priority OCF instance
        self.assertEqual(third[1]['monitorclass'], 'ocf')
        self.assertEqual(third[0], MonitoringRule.HIGHPRIOMATCH)
        # list1 should be the incomplete OCF and the complete LSB - in that order
        self.assertEqual(len(list1), 2)
        # They should come out sorted by monitorclass
        self.assertEqual(list1[0][0], MonitoringRule.LOWPRIOMATCH)
        self.assertEqual(list1[0][1]['monitorclass'], 'lsb')
        self.assertEqual(list1[1][0], MonitoringRule.PARTMATCH)
        self.assertEqual(list1[1][1]['monitorclass'], 'ocf')
        # third should be a complete OCF match
        # list2 should be the complete OCF and the complete OCF - in that order
        self.assertEqual(len(list2), 2)
        self.assertEqual(list2[0][0], MonitoringRule.LOWPRIOMATCH)
        self.assertEqual(list2[0][1]['monitorclass'], 'lsb')
        self.assertEqual(list2[1][0], MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(list2[1][1]['monitorclass'], 'ocf')
예제 #4
0
    def test_automonitor_OCF_basic(self):
        AssimEvent.disable_all_observers()
        drone = FakeDrone({
                'data': {
                        'ocf': {
                            'assimilation/neo4j',
                        }
                    }
                })
        kitchensink = OCFMonitoringRule('assimilation', 'neo4j',
        (   ('cantguess',)                  #   length 1 - name
        ,   ('port', '$port')               #   length 2 - name, expression
        ,   (None, '$port')                 #   length 2 - name, expression
        ,   ('-', '$pathname')              #   length 2 - name, expression
        ,   ('port', '$port', '[0-9]+$')    #   length 3 - name, expression, regex
        ,   (None, '$pathname', '.*/java$') #   length 3 - name, expression, regex
        ,   (None, '@basename()', 'java$')  #   length 3 - name, expression, regex
        ,   ('-', '$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$')
                                            #   length 3 - name, expression, regex
        ,   ('port', '@serviceport()', '[0-9]+$', re.I)  #   length 4 - name, expression, regex, flags
        ))
        keys = kitchensink.nvpairs.keys()
        keys.sort()
        self.assertEqual(str(keys), "['cantguess', 'port']")
        values = []
        for key in keys:
            values.append(kitchensink.nvpairs[key])
        self.assertEqual(str(values), "[None, '@serviceport()']")
        regex = re.compile('xxx')
        regextype = type(regex)
        exprlist = []
        for tup in kitchensink._tuplespec:
            self.assertEqual(type(tup[1]), regextype)
            exprlist.append(tup[0])
        self.assertEqual(str(exprlist)
        ,   "['$port', '$pathname', '@basename()', '$argv[-1]', '@serviceport()']")
        #
        # That was a pain...
        #
        # Now, let's test the basics in a little more depth by creating what should be a working
        # set of arguments to a (hypothetical) OCF resource agent
        #
        neo4j = OCFMonitoringRule('assimilation', 'neo4j',
            (   ('port', '$port')
            ,   (None, '$pathname', '.*/java$')
            ,   ('-', '$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$')
            ,   ('home', '@argequals(-Dneo4j.home)', '/.*')
            ,   ('neo4j', '@basename(@argequals(-Dneo4j.home))', '.')
            )
        )
        neoprocargs = ("/usr/bin/java", "-cp"
        , "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:"
        "AND SO ON:"
        "/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:"
        "/var/lib/neo4j/conf/", "-server", "-XX:"
        "+DisableExplicitGC"
        ,   "-Dorg.neo4j.server.properties=conf/neo4j-server.properties"
        ,   "-Djava.util.logging.config.file=conf/logging.properties"
        ,   "-Dlog4j.configuration=file:conf/log4j.properties"
        ,   "-XX:+UseConcMarkSweepGC"
        ,   "-XX:+CMSClassUnloadingEnabled"
        ,   "-Dneo4j.home=/var/lib/neo4j"
        ,   "-Dneo4j.instance=/var/lib/neo4j"
        ,   "-Dfile.encoding=UTF-8"
        ,   "org.neo4j.server.Bootstrapper")

        neonode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoprocargs
        ,   'root', 'root', '/', roles=(CMAconsts.ROLE_server,))
        # We'll be missing the value of 'port'
        neocontext = ExpressionContext((neonode, drone))
        match = neo4j.specmatch(neocontext)
        (prio, table, missing) = neo4j.specmatch(neocontext)
        self.assertEqual(prio, MonitoringRule.PARTMATCH)
        self.assertEqual(missing, ['port'])
        # Now fill in the port value
        neonode.port=7474
        (prio, table) = neo4j.specmatch(neocontext)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(table['monitortype'], 'neo4j')
        self.assertEqual(table['monitorclass'], 'ocf')
        self.assertEqual(table['provider'], 'assimilation')
        keys = table.keys()
        keys.sort()
        self.assertEqual(str(keys), "['arglist', 'monitorclass', 'monitortype', 'provider']")
        arglist = table['arglist']
        keys = arglist.keys()
        keys.sort()
        self.assertEqual(keys, ['home', 'neo4j', 'port'])
        self.assertEqual(arglist['port'], '7474')
        self.assertEqual(arglist['home'], '/var/lib/neo4j')
        self.assertEqual(arglist['neo4j'], 'neo4j')
예제 #5
0
    def test_automonitor_OCF_basic(self):
        AssimEvent.disable_all_observers()
        drone = FakeDrone({
                'data': {
                        'ocf': {
                            'assimilation/neo4j',
                        }
                    }
                })
        kitchensink = OCFMonitoringRule('assimilation', 'neo4j',
        (   ('cantguess',)                  #   length 1 - name
        ,   ('port', '$port')               #   length 2 - name, expression
        ,   (None, '$port')                 #   length 2 - name, expression
        ,   ('-', '$pathname')              #   length 2 - name, expression
        ,   ('port', '$port', '[0-9]+$')    #   length 3 - name, expression, regex
        ,   (None, '$pathname', '.*/java$') #   length 3 - name, expression, regex
        ,   (None, '@basename()', 'java$')  #   length 3 - name, expression, regex
        ,   ('-', '$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$')
                                            #   length 3 - name, expression, regex
        ,   ('port', '@serviceport()', '[0-9]+$', re.I)  #   length 4 - name, expression, regex, flags
        ))
        keys = kitchensink.nvpairs.keys()
        keys.sort()
        self.assertEqual(str(keys), "['cantguess', 'port']")
        values = []
        for key in keys:
            values.append(kitchensink.nvpairs[key])
        self.assertEqual(str(values), "[None, '@serviceport()']")
        regex = re.compile('xxx')
        regextype = type(regex)
        exprlist = []
        for tup in kitchensink._tuplespec:
            self.assertEqual(type(tup[1]), regextype)
            exprlist.append(tup[0])
        self.assertEqual(str(exprlist)
        ,   "['$port', '$pathname', '@basename()', '$argv[-1]', '@serviceport()']")
        #
        # That was a pain...
        #
        # Now, let's test the basics in a little more depth by creating what should be a working
        # set of arguments to a (hypothetical) OCF resource agent
        #
        neo4j = OCFMonitoringRule('assimilation', 'neo4j',
            (   ('port', '$port')
            ,   (None, '$pathname', '.*/java$')
            ,   ('-', '$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$')
            ,   ('home', '@argequals(-Dneo4j.home)', '/.*')
            ,   ('neo4j', '@basename(@argequals(-Dneo4j.home))', '.')
            )
        )
        neoprocargs = ("/usr/bin/java", "-cp"
        , "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:"
        "AND SO ON:"
        "/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:"
        "/var/lib/neo4j/conf/", "-server", "-XX:"
        "+DisableExplicitGC"
        ,   "-Dorg.neo4j.server.properties=conf/neo4j-server.properties"
        ,   "-Djava.util.logging.config.file=conf/logging.properties"
        ,   "-Dlog4j.configuration=file:conf/log4j.properties"
        ,   "-XX:+UseConcMarkSweepGC"
        ,   "-XX:+CMSClassUnloadingEnabled"
        ,   "-Dneo4j.home=/var/lib/neo4j"
        ,   "-Dneo4j.instance=/var/lib/neo4j"
        ,   "-Dfile.encoding=UTF-8"
        ,   "org.neo4j.server.Bootstrapper")

        neonode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoprocargs
        ,   'root', 'root', '/', roles=(CMAconsts.ROLE_server,))
        # We'll be missing the value of 'port'
        neocontext = ExpressionContext((neonode, drone))
        match = neo4j.specmatch(neocontext)
        (prio, table, missing) = neo4j.specmatch(neocontext)
        self.assertEqual(prio, MonitoringRule.PARTMATCH)
        self.assertEqual(missing, ['port'])
        # Now fill in the port value
        neonode.port=7474
        (prio, table) = neo4j.specmatch(neocontext)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(table['monitortype'], 'neo4j')
        self.assertEqual(table['monitorclass'], 'ocf')
        self.assertEqual(table['provider'], 'assimilation')
        keys = table.keys()
        keys.sort()
        self.assertEqual(str(keys), "['arglist', 'monitorclass', 'monitortype', 'provider']")
        arglist = table['arglist']
        keys = arglist.keys()
        keys.sort()
        self.assertEqual(keys, ['home', 'neo4j', 'port'])
        self.assertEqual(arglist['port'], '7474')
        self.assertEqual(arglist['home'], '/var/lib/neo4j')
        self.assertEqual(arglist['neo4j'], 'neo4j')
예제 #6
0
    def test_automonitor_functions(self):
        AssimEvent.disable_all_observers()
        MonitoringRule.monitor_objects = {'service': {}, 'host':{}}
        drone = FakeDrone({
                'data': {
                        'ocf': {
                            'assimilation/neo4j',
                        },
                        'lsb': {
                            'bacula',
                        },
                    }
                })
        ocf_string = '''{
        "class":        "ocf", "type":         "neo4j", "provider":     "assimilation",
        "classconfig": [
            ["classpath",   "@flagvalue(-cp)"],
            ["ipaddr",      "@serviceip($procinfo.listenaddrs)"],
            ["port",        "@serviceport()",   "[0-9]+$"]
        ]
        }'''
        ssh_json = '''{
          "exe": "/usr/sbin/sshd",
          "argv": [ "/usr/sbin/sshd", "-D" ],
          "uid": "root",
          "gid": "root",
          "cwd": "/",
          "listenaddrs": {
            "0.0.0.0:22": {
              "proto": "tcp",
              "addr": "0.0.0.0",
              "port": 22
            },
            ":::22": {
              "proto": "tcp6",
              "addr": "::",
              "port": 22
            }
          }
        }'''
        neo4j_json = '''{
          "exe": "/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java",
          "argv": [ "/usr/bin/java", "-cp", "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar: ...", "-server", "-XX:+DisableExplicitGC", "-Dorg.neo4j.server.properties=conf/neo4
    j-server.properties", "-Djava.util.logging.config.file=conf/logging.properties", "-Dlog4j.configuration=file:conf/log4j.properties", "-XX:
    +UseConcMarkSweepGC", "-XX:+CMSClassUnloadingEnabled", "-Dneo4j.home=/var/lib/neo4j", "-Dneo4j.instance=/var/lib/neo4j", "-Dfile.encoding=
    UTF-8", "org.neo4j.server.Bootstrapper" ],
          "uid": "neo4j",
          "gid": "neo4j",
          "cwd": "/var/lib/neo4j",
          "listenaddrs": {
            ":::1337": {
              "proto": "tcp6",
              "addr": "::",
              "port": 1337
            },
            ":::39185": {
              "proto": "tcp6",
              "addr": "::",
              "port": 39185
            }
          }
        }'''
        bacula_json = '''{
      "exe": "/usr/sbin/bacula-dir",
      "argv": [ "/usr/sbin/bacula-dir", "-c", "/etc/bacula/bacula-dir.conf", "-u", "bacula", "-g", "bacula" ],
      "uid": "bacula",
      "gid": "bacula",
      "cwd": "/",
      "listenaddrs": {
        "10.10.10.5:9101": {
          "proto": "tcp",
          "addr": "10.10.10.5",
          "port": 9101
        }
      }
    }'''
        MonitoringRule.ConstructFromString(ocf_string)
        neoargs = pyConfigContext(neo4j_json)['argv']
        testnode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoargs
        ,   'root', 'root', '/', roles=(CMAconsts.ROLE_server,))

        testnode.procinfo = neo4j_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['ipaddr'], '::1')
        self.assertEqual(match['arglist']['port'], '1337')

        testnode.procinfo = ssh_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['port'], '22')
        self.assertEqual(match['arglist']['ipaddr'], '127.0.0.1')

        testnode.procinfo = bacula_json
        context = ExpressionContext((testnode, drone))
        (prio, match) = MonitoringRule.findbestmatch(context)
        self.assertEqual(prio, MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(match['arglist']['port'], '9101')
        self.assertEqual(match['arglist']['ipaddr'], '10.10.10.5')
예제 #7
0
    def test_automonitor_search_basic(self):
        AssimEvent.disable_all_observers()
        drone = FakeDrone({
                'data': {
                        'ocf': {
                            'assimilation/neo4j',
                        },
                        'lsb': {
                            'neo4j-service',
                        }
                    }
                })
        MonitoringRule.monitor_objects = {'service': {}, 'host':{}}
        ocf_string = '''{
        "class":        "ocf", "type":         "neo4j", "provider":     "assimilation",
        "classconfig": [
            [null,      "@basename()",          "java$"],
            [null,      "$argv[-1]",             "org\\.neo4j\\.server\\.Bootstrapper$"],
            ["PORT",    "$serviceport"],
            ["NEOHOME", "@argequals(-Dneo4j.home)", "/.*"]
        ]
        }'''
        MonitoringRule.ConstructFromString(ocf_string)
        lsb_string = '''{
        "class":        "lsb", "type":         "neo4j-service",
        "classconfig": [
            ["@basename()",    "java$"],
            ["$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"],
        ]
        }'''
        MonitoringRule.ConstructFromString(lsb_string)
        neoprocargs = ("/usr/bin/java", "-cp"
        , "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:"
        "AND SO ON:"
        "/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:"
        "/var/lib/neo4j/conf/", "-server", "-XX:"
        "+DisableExplicitGC"
        ,   "-Dneo4j.home=/var/lib/neo4j"
        ,   "-Dneo4j.instance=/var/lib/neo4j"
        ,   "-Dfile.encoding=UTF-8"
        ,   "org.neo4j.server.Bootstrapper")

        neonode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoprocargs
        ,   'root', 'root', '/', roles=(CMAconsts.ROLE_server,))
        #neonode.serviceport=7474
        context = ExpressionContext((neonode, drone))
        first = MonitoringRule.findbestmatch(context)
        second = MonitoringRule.findbestmatch(context, False)
        list1 = MonitoringRule.findallmatches(context)
        neonode.serviceport=7474
        third = MonitoringRule.findbestmatch(context)
        list2 = MonitoringRule.findallmatches(context)

        # first should be the LSB instance
        self.assertEqual(first[1]['monitorclass'], 'lsb')
        self.assertEqual(first[0], MonitoringRule.LOWPRIOMATCH)
        # second should be the incomplete OCF instance
        self.assertEqual(second[1]['monitorclass'], 'ocf')
        self.assertEqual(second[0], MonitoringRule.PARTMATCH)
        # third should be the high priority OCF instance
        self.assertEqual(third[1]['monitorclass'], 'ocf')
        self.assertEqual(third[0], MonitoringRule.HIGHPRIOMATCH)
        # list1 should be the incomplete OCF and the complete LSB - in that order
        self.assertEqual(len(list1), 2)
        # They should come out sorted by monitorclass
        self.assertEqual(list1[0][0], MonitoringRule.LOWPRIOMATCH)
        self.assertEqual(list1[0][1]['monitorclass'], 'lsb')
        self.assertEqual(list1[1][0], MonitoringRule.PARTMATCH)
        self.assertEqual(list1[1][1]['monitorclass'], 'ocf')
        # third should be a complete OCF match
        # list2 should be the complete OCF and the complete OCF - in that order
        self.assertEqual(len(list2), 2)
        self.assertEqual(list2[0][0], MonitoringRule.LOWPRIOMATCH)
        self.assertEqual(list2[0][1]['monitorclass'], 'lsb')
        self.assertEqual(list2[1][0], MonitoringRule.HIGHPRIOMATCH)
        self.assertEqual(list2[1][1]['monitorclass'], 'ocf')
예제 #8
0
        ('$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$'),
    )
    neoocfargs = (
        (None, "@basename()", "java$"),
        (None, "$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"),
        #("ipport",      "@serviceipport()",          "..."),
        ("neo4j_home", "@argequals(-Dneo4j.home)", "/"),
        ("neo4j", "@basename(@argequals(-Dneo4j.home))", "."))
    neoocfrule = OCFMonitoringRule('assimilation', 'neo4j', neoocfargs)

    #ProcessNode:
    #   (domain, processname, host, pathname, argv, uid, gid, cwd, roles=None):
    sshnode = ProcessNode('global',
                          'fred',
                          'servidor',
                          '/usr/bin/sshd', ['/usr/bin/sshd', '-D'],
                          'root',
                          'root',
                          '/',
                          roles=(CMAconsts.ROLE_server, ))
    setattr(sshnode, 'procinfo',
            '{"listenaddrs":{"0.0.0.0:22":"tcp", ":::22":"tcp6"}}')

    lsbsshargs = (
        # This means one of our nodes should have a value called
        # pathname, and it should end in '/sshd'
        ('$pathname', '.*/sshd$'), )
    lsbsshrule = LSBMonitoringRule('ssh', lsbsshargs)

    nagiossshargs = (
        (None, '@basename()', '.*sshd$'),
        ('-p', '@serviceport()', '[0-9]+'),
예제 #9
0
                ('$argv[3]', r'-server$'),             # Probably overkill
                ('$argv[-1]', r'org\.neo4j\.server\.Bootstrapper$'),
        )
    neorule = LSBMonitoringRule('neo4j-service', neolsbargs)
    neoocfargs = (
        (None,          "@basename()",               "java$"),
        (None,          "$argv[-1]",                 "org\\.neo4j\\.server\\.Bootstrapper$"),
        #("ipport",      "@serviceipport()",          "..."),
        ("neo4j_home",  "@argequals(-Dneo4j.home)", "/"),
        ("neo4j",       "@basename(@argequals(-Dneo4j.home))",".")
    )
    neoocfrule = OCFMonitoringRule('assimilation', 'neo4j', neoocfargs)

    #ProcessNode:
    #   (domain, processname, host, pathname, argv, uid, gid, cwd, roles=None):
    sshnode = ProcessNode('global', 'fred', 'servidor', '/usr/bin/sshd', ['/usr/bin/sshd', '-D' ]
    ,   'root', 'root', '/', roles=(CMAconsts.ROLE_server,))
    setattr(sshnode, 'procinfo'
    ,   '{"listenaddrs":{"0.0.0.0:22":"tcp", ":::22":"tcp6"}}')

    lsbsshargs = (
                # This means one of our nodes should have a value called
                # pathname, and it should end in '/sshd'
                ('$pathname', '.*/sshd$'),
        )
    lsbsshrule = LSBMonitoringRule('ssh', lsbsshargs)

    nagiossshargs = (
                (None, '@basename()', '.*sshd$'),
                ('-p', '@serviceport()', '[0-9]+'),
                ('__ARGV__', '@serviceip()', '.'),
    )