예제 #1
0
    def test_simplelog(self):
        print self.conf.modules
        # get our modules
        mod = None
        for m in self.conf.modules:
            if m.module_type == 'status_dat':
                mod = m
        self.assert_(mod is not None)
        self.assert_(mod.status_file == '/usr/local/shinken/var/status.data')
        self.assert_(mod.module_name == 'Status-Dat')
        self.assert_(mod.object_cache_file == '/usr/local/shinken/var/objects.cache')

        try:
            os.unlink(mod.status_file)
            os.unlink(mod.module_name)
        except:
            pass

        sl = get_instance(mod)
        print sl
        # Hack here :(
        sl.properties = {}
        sl.properties['to_queue'] = None
        self.sched.conf.skip_initial_broks = False
        self.sched.fill_initial_broks()
        print self.sched.broks
        sl.init()
        for b in self.sched.broks.values():
            b.instance_id = 0
            sl.manage_brok(b)

        # Be fun, and add some utf8 char in hosts ;)
        for h in sl.hosts.values():
            print h.__dict__
            h.host_name = h.host_name + u'\xf6'

        # Now verify the objects.dat file
        sl.objects_cache.create_or_update()
        obj = open(mod.object_cache_file)
        buf = obj.read()
        obj.close()
        # Check for 1 service and only one
        nb_services = self.nb_of_string(buf, "define service {")
        self.assert_(nb_services == 1)
        # 2 hosts: host and a router
        nb_hosts = self.nb_of_string(buf, "define host {")
        self.assert_(nb_hosts == 2)

        # Same for status.dat.
        sl.status.create_or_update()
        status = open(mod.status_file)
        buf = status.read()
        obj.close()

        nb_prog = self.nb_of_string(buf, "programstatus {")
        self.assert_(nb_prog == 1)

        nb_hosts = self.nb_of_string(buf, "hoststatus {")
        self.assert_(nb_hosts == 2)

        nb_services = self.nb_of_string(buf, "servicestatus {")
        self.assert_(nb_services == 1)

        # now check if after a resend we still got the good number
        self.sched.broks.clear()
        self.sched.conf.skip_initial_broks = False
        self.sched.fill_initial_broks()
        # And in the good order!!!
        b_ids = self.sched.broks.keys()
        b_ids.sort()
        for b_id in b_ids:
            b = self.sched.broks[b_id]
            b.instance_id = 0
            # print "Add brok", b.type
            sl.manage_brok(b)
        print "Generate file", mod.object_cache_file
        # Now verify the objects.dat file
        sl.objects_cache.create_or_update()
        obj = open(mod.object_cache_file)
        buf = obj.read()
        obj.close()
        # print buf
        # Check for 1 service and only one
        nb_services = self.nb_of_string(buf, "define service {")
        self.assert_(nb_services == 1)
        # 2 hosts: host and a router
        nb_hosts = self.nb_of_string(buf, "define host {")
        self.assert_(nb_hosts == 2)

        # Same for status.dat.
        sl.status.create_or_update()
        status = open(mod.status_file)
        buf = status.read()
        obj.close()

        nb_prog = self.nb_of_string(buf, "programstatus {")
        self.assert_(nb_prog == 1)

        nb_hosts = self.nb_of_string(buf, "hoststatus {")
        self.assert_(nb_hosts == 2)

        nb_services = self.nb_of_string(buf, "servicestatus {")
        self.assert_(nb_services == 1)

        os.unlink(mod.status_file)
        os.unlink(mod.object_cache_file)
예제 #2
0
    def test_simplelog(self):
        print self.conf.modules
        #get our modules
        mod = None
        for m in self.conf.modules:
            if m.module_type == 'status_dat':
                mod = m
        self.assert_(mod is not None)
        self.assert_(mod.status_file == '/usr/local/shinken/var/status.data')
        self.assert_(mod.module_name == 'Status-Dat')
        self.assert_(mod.object_cache_file == '/usr/local/shinken/var/objects.cache')

        try :
            os.unlink(mod.status_file)
            os.unlink(mod.module_name)
        except :
            pass

        sl = get_instance(mod)
        print sl
        #Hack here :(
        sl.properties = {}
        sl.properties['to_queue'] = None
        self.sched.fill_initial_broks()
        print self.sched.broks
        sl.init()
        for b in self.sched.broks.values():
            b.instance_id = 0
            sl.manage_brok(b)

        #Now verify the objects.dat file
        sl.objects_cache.create_or_update()
        obj = open(mod.object_cache_file)
        buf = obj.read()
        obj.close()
        #Check for 1 service and only one
        nb_services = self.nb_of_string(buf, "define service {")
        self.assert_(nb_services == 1)
        #2 hosts : host and a router
        nb_hosts = self.nb_of_string(buf, "define host {")
        self.assert_(nb_hosts == 2)

        #Same for status.dat.
        sl.status.create_or_update()
        status = open(mod.status_file)
        buf = status.read()
        obj.close()

        nb_prog = self.nb_of_string(buf, "programstatus {")
        self.assert_(nb_prog == 1)

        nb_hosts = self.nb_of_string(buf, "hoststatus {")
        self.assert_(nb_hosts == 2)

        nb_services = self.nb_of_string(buf, "servicestatus {")
        self.assert_(nb_services  == 1)


        #now check if after a resend we still got the good number
        self.sched.broks.clear()
        self.sched.fill_initial_broks()
        for b in self.sched.broks.values():
            b.instance_id = 0
            sl.manage_brok(b)

        #Now verify the objects.dat file
        sl.objects_cache.create_or_update()
        obj = open(mod.object_cache_file)
        buf = obj.read()
        obj.close()
        #Check for 1 service and only one
        nb_services = self.nb_of_string(buf, "define service {")
        self.assert_(nb_services == 1)
        #2 hosts : host and a router
        nb_hosts = self.nb_of_string(buf, "define host {")
        self.assert_(nb_hosts == 2)

        #Same for status.dat.
        sl.status.create_or_update()
        status = open(mod.status_file)
        buf = status.read()
        obj.close()

        nb_prog = self.nb_of_string(buf, "programstatus {")
        self.assert_(nb_prog == 1)

        nb_hosts = self.nb_of_string(buf, "hoststatus {")
        self.assert_(nb_hosts == 2)

        nb_services = self.nb_of_string(buf, "servicestatus {")
        self.assert_(nb_services  == 1)


        os.unlink(mod.status_file)
        os.unlink(mod.object_cache_file)
예제 #3
0
    def test_simplelog(self):
        print self.conf.modules
        #get our modules
        mod = None
        for m in self.conf.modules:
            if m.module_type == 'status_dat':
                mod = m
        self.assert_(mod is not None)
        self.assert_(mod.status_file == '/usr/local/shinken/var/status.data')
        self.assert_(mod.module_name == 'Status-Dat')
        self.assert_(
            mod.object_cache_file == '/usr/local/shinken/var/objects.cache')

        try:
            os.unlink(mod.status_file)
            os.unlink(mod.module_name)
        except:
            pass

        sl = get_instance(mod)
        print sl
        #Hack here :(
        sl.properties = {}
        sl.properties['to_queue'] = None
        self.sched.fill_initial_broks()
        print self.sched.broks
        sl.init()
        for b in self.sched.broks.values():
            b.instance_id = 0
            sl.manage_brok(b)

        #Now verify the objects.dat file
        sl.objects_cache.create_or_update()
        obj = open(mod.object_cache_file)
        buf = obj.read()
        obj.close()
        #Check for 1 service and only one
        nb_services = self.nb_of_string(buf, "define service {")
        self.assert_(nb_services == 1)
        #2 hosts : host and a router
        nb_hosts = self.nb_of_string(buf, "define host {")
        self.assert_(nb_hosts == 2)

        #Same for status.dat.
        sl.status.create_or_update()
        status = open(mod.status_file)
        buf = status.read()
        obj.close()

        nb_prog = self.nb_of_string(buf, "programstatus {")
        self.assert_(nb_prog == 1)

        nb_hosts = self.nb_of_string(buf, "hoststatus {")
        self.assert_(nb_hosts == 2)

        nb_services = self.nb_of_string(buf, "servicestatus {")
        self.assert_(nb_services == 1)

        #now check if after a resend we still got the good number
        self.sched.broks.clear()
        self.sched.fill_initial_broks()
        for b in self.sched.broks.values():
            b.instance_id = 0
            sl.manage_brok(b)

        #Now verify the objects.dat file
        sl.objects_cache.create_or_update()
        obj = open(mod.object_cache_file)
        buf = obj.read()
        obj.close()
        #Check for 1 service and only one
        nb_services = self.nb_of_string(buf, "define service {")
        self.assert_(nb_services == 1)
        #2 hosts : host and a router
        nb_hosts = self.nb_of_string(buf, "define host {")
        self.assert_(nb_hosts == 2)

        #Same for status.dat.
        sl.status.create_or_update()
        status = open(mod.status_file)
        buf = status.read()
        obj.close()

        nb_prog = self.nb_of_string(buf, "programstatus {")
        self.assert_(nb_prog == 1)

        nb_hosts = self.nb_of_string(buf, "hoststatus {")
        self.assert_(nb_hosts == 2)

        nb_services = self.nb_of_string(buf, "servicestatus {")
        self.assert_(nb_services == 1)

        os.unlink(mod.status_file)
        os.unlink(mod.object_cache_file)