示例#1
0
class DiscoveratorBaseTest(object):
    testmib = None

    def setUp(self):
        setup_db()
        self.tmpdir = setup_tmpdir()
        testfactory = TestFactory(confdir=settings["vigiconf"].get("confdir"))
        self.disc = Discoverator(testfactory, group="Test")
        self.disc.testfactory.load_hclasses_checks()
        walkfile = os.path.join(TESTDATADIR, "discoverator", self.testmib)
        self.disc.scanfile(walkfile)
        self.disc.detect()
        self.testnames = [ t["name"] for t in self.disc.tests ]

    def tearDown(self):
        shutil.rmtree(self.tmpdir)
        teardown_db()

    def test_hostname(self):
        expected = socket.getfqdn("localhost")
        self.assertEqual(self.disc.hostname, expected,
            "Hostname not detected correctly (got %s)" % self.disc.hostname)

    def test_ipaddr(self):
        self.assertEqual(self.disc.ipaddr, "127.0.0.1",
            "IP not detected correcty (got %s)" % self.disc.ipaddr)
示例#2
0
def discover(args):
    from vigilo.vigiconf.lib.confclasses.test import TestFactory
    from vigilo.vigiconf.discoverator import Discoverator, indent
    from vigilo.vigiconf.discoverator import DiscoveratorError
    from vigilo.vigiconf.discoverator import SnmpwalkNotInstalled
    testfactory = TestFactory(confdir=settings["vigiconf"].get("confdir"))
    discoverator = Discoverator(testfactory, args.group)
    discoverator.testfactory.load_hclasses_checks()
    if len(args.target) > 1:
        args.output.write("<hosts>\n")
    for target in args.target:
        try:
            discoverator.scan(target, args.community, args.version)
        except SnmpwalkNotInstalled:
            raise
        except DiscoveratorError, e:
            # On ne fait que logguer l'erreur pour générer quand même ce
            # qu'on a pu détecter jusqu'ici (cas du timeout)
            LOGGER.error(e.value)
        discoverator.detect(args.test)
        elements = discoverator.declaration()
        indent(elements)
        args.output.write(ET.tostring(elements, encoding="utf8"))
示例#3
0
class DiscoveratorSpecificTest(unittest.TestCase):
    testmib = "linux.walk"

    def setUp(self):
        setup_db()
        self.tmpdir = setup_tmpdir()
        testfactory = TestFactory(confdir=settings["vigiconf"].get("confdir"))
        self.disc = Discoverator(testfactory, group="Test")
        self.disc.testfactory.load_hclasses_checks()
        walkfile = os.path.join(TESTDATADIR, "discoverator", self.testmib)
        self.disc.scanfile(walkfile)

    def tearDown(self):
        shutil.rmtree(self.tmpdir)
        teardown_db()


    def test_multiple_test_detection(self):
        """Test the simple test detection on Linux
        This uses the test's detect_oid() method"""
        self.disc.detect(["Swap", "Partition", "Interface"])
        self.testnames = [ t["name"] for t in self.disc.tests ]

        for test in [ "Swap", "Partition", "Interface" ]:
            self.assertTrue(test in self.testnames,
                            "Test %s is not detected" % test)

    def test_single_test_detection(self):
        """Test the simple test detection on Linux
        This uses the test's detect_oid() method"""
        self.disc.detect([ "Partition" ])
        self.testnames = [ t["name"] for t in self.disc.tests ]

        self.assertTrue("Partition" in self.testnames,
                "Test %s is not detected" % "Partition")
        self.assertFalse("Interface" in self.testnames,
                "Test %s is detected" % "Interface")