Beispiel #1
0
    def manage_initial_service_status_brok(self, b):
        data = b.data
        s_id = data['id']

        inst_id = data['instance_id']
        
        #print "Creating Service:", s_id, data
        s = Service({})
        s.instance_id = inst_id

        self.update_element(s, data)
        self.set_schedulingitem_values(s)
        
        h = self.find_host(data['host_name'])
        if h is not None:
            # Reconstruct the connection between hosts and services
            h.service_ids.append(s_id)
            h.services.append(s)
            # There is already a s.host_name, but a reference to the h object can be useful too
            s.host = h
        
        for dtc in s.downtimes + s.comments:
            dtc.ref = s
        self.services[s_id] = s
        self.servicename_lookup_table[s.host_name + s.service_description] = s_id
        self.number_of_objects += 1
Beispiel #2
0
    def manage_initial_service_status_brok(self, b):
        data = b.data
        s_id = data['id']
        host_name = data['host_name']
        service_description = data['service_description']
        inst_id = data['instance_id']
        
        #print "Creating Service:", s_id, data
        s = Service({})
        s.instance_id = inst_id

        self.update_element(s, data)
        self.set_schedulingitem_values(s)
        
        try:
            h = self.hosts[host_name]
            # Reconstruct the connection between hosts and services
            h.services.append(s)
            # There is already a s.host_name, but a reference to the h object can be useful too
            s.host = h
        except Exception:
            return
        for dtc in s.downtimes + s.comments:
            dtc.ref = s
        self.services[host_name+service_description] = s
        self.number_of_objects += 1
        # We need this for manage_initial_servicegroup_status_brok where it
        # will speed things up dramatically
        self.service_id_cache[s.id] = s
Beispiel #3
0
def init_service(params={}):
    """Create a service with specified parameters

    Parameters
    * params : A dict of parms
        * command_name : The command name (default dummy_cmd)
        * command_line : The command line (default dummy_cmd!1)
        * host_name : The host name (default Dummy host)
        * service_description: The service name (default Dummy service)
        * perf_data : The service perf data (default empty)
    """

    command_name = params.get('command_name', 'dummy_cmd')
    command_line = params.get('command_line', 'dummy_cmd!1')
    host_name = params.get('host_name', 'Dummy host')
    service_description = params.get('service_description', 'Dummy service')
    perf_data = params.get('perf_data', '')

    host = Host({
        'host_name': host_name,
    })

    cmd = Command({
        'command_name': command_name,
        'command_line': command_line,
    })

    srv = Service({
        'service_description': service_description,
        'perf_data': perf_data,
    })
    srv.host = host
    srv.check_command = cmd

    return srv
    def manage_initial_service_status_brok(self, b):
        data = b.data
        s_id = data['id']
        #print "Creating Service:", s_id, data
        s = Service({})
        self.update_element(s, data)

        #add instance_id to the host, so we know in which scheduler he is
        s.instance_id = b.instance_id

        s.check_period = self.get_timeperiod(s.check_period)
        s.notification_period = self.get_timeperiod(s.notification_period)

        s.contacts = self.get_contacts(s.contacts)

        del s.escalations

        #print "S:", s
        self.services[s_id] = s
        self.number_of_objects += 1
Beispiel #5
0
    def manage_initial_service_status_brok(self, b):
        data = b.data
        s_id = data['id']
        #print "Creating Service:", s_id, data
        s = Service({})
        self.update_element(s, data)
        self.set_schedulingitem_values(s)

        h = self.find_host(data['host_name'])
        if h is not None:
            # Reconstruct the connection between hosts and services
            h.service_ids.append(s_id)
            h.services.append(s)
            # There is already a s.host_name, but a reference to the h object can be useful too
            s.host = h

        self.services[s_id] = s
        self.servicename_lookup_table[s.host_name +
                                      s.service_description] = s_id
        self.number_of_objects += 1
Beispiel #6
0
    def manage_initial_service_status_brok(self, b):
        data = b.data
        s_id = data["id"]
        # print "Creating Service:", s_id, data
        s = Service({})
        self.update_element(s, data)

        # add instance_id to the host, so we know in which scheduler he is
        s.instance_id = b.instance_id

        s.check_period = self.get_timeperiod(s.check_period)
        s.notification_period = self.get_timeperiod(s.notification_period)

        s.contacts = self.get_contacts(s.contacts)

        del s.escalations

        # print "S:", s
        # We need to rebuild Downtime and Comment relationship
        for dtc in s.downtimes + s.comments:
            dtc.ref = s
        self.services[s_id] = s
        self.number_of_objects += 1
Beispiel #7
0
    def manage_initial_service_status_brok(self, b):
        data = b.data
        s_id = data['id']
        #print "Creating Service:", s_id, data
        s = Service({})
        self.update_element(s, data)

        #add instance_id to the host, so we know in which scheduler he is
        s.instance_id = b.instance_id

        s.check_period = self.get_timeperiod(s.check_period)
        s.notification_period = self.get_timeperiod(s.notification_period)

        s.contacts = self.get_contacts(s.contacts)

        del s.escalations

        #print "S:", s
        self.services[s_id] = s
        self.number_of_objects += 1
Beispiel #8
0
    def test_regenerator(self):
        #
        # Config is not correct because of a wrong relative path
        # in the main config file
        #
        # for h in self.sched.hosts:
        #    h.realm = h.realm.get_name()
        self.sched.conf.skip_initial_broks = False
        self.sched.brokers['Default-Broker'] = {
            'broks': [],
            'has_full_broks': False
        }
        self.sched.fill_initial_broks('Default-Broker')
        self.rg = Regenerator()

        # Got the initial creation ones
        t0 = time.time()
        for b in self.sched.broks:
            print "Manage b", b.type
            b.prepare()
            self.rg.manage_brok(b)
        t1 = time.time()
        print 'First inc', t1 - t0, len(self.sched.broks)
        del self.sched.broks[:]

        self.look_for_same_values()

        print "Get the hosts and services"
        host = self.sched.hosts.find_by_name("test_host_0")
        host.checks_in_progress = []
        host.act_depend_of = []  # ignore the router
        router = self.sched.hosts.find_by_name("test_router_0")
        router.checks_in_progress = []
        router.act_depend_of = []  # ignore the router
        svc = self.sched.services.find_srv_by_name_and_hostname(
            "test_host_0", "test_ok_0")
        svc.checks_in_progress = []
        svc.act_depend_of = []  # no hostchecks on critical checkresults
        self.scheduler_loop(
            3,
            [[host, 2, 'DOWN | value1=1 value2=2'], [router, 0, 'UP | rtt=10'],
             [svc, 2, 'BAD | value1=0 value2=0']])
        self.assertEqual('DOWN', host.state)
        self.assertEqual('HARD', host.state_type)

        t0 = time.time()
        for b in self.sched.broks:
            print "Manage b", b.type
            b.prepare()
            self.rg.manage_brok(b)
        t1 = time.time()
        print 'Time', t1 - t0
        del self.sched.broks[:]

        self.look_for_same_values()

        print 'Time', t1 - t0

        b = svc.get_initial_status_brok()
        b.prepare()
        print "GO BENCH!"
        t0 = time.time()
        for i in xrange(1, 1000):
            b = svc.get_initial_status_brok()
            b.prepare()
            s = Service({})
            for (prop, value) in b.data.iteritems():
                setattr(s, prop, value)
        t1 = time.time()
        print "Bench end:", t1 - t0

        times = {}
        sizes = {}
        import cPickle
        data = {}
        cls = svc.__class__
        start = time.time()
        for i in xrange(1, 10000):
            for prop, entry in svc.__class__.properties.items():
                # Is this property intended for brokking?
                if 'full_status' in entry.fill_brok:
                    data[prop] = svc.get_property_value_for_brok(
                        prop, cls.properties)
                    if not prop in times:
                        times[prop] = 0
                        sizes[prop] = 0
                    t0 = time.time()
                    tmp = cPickle.dumps(data[prop], 0)
                    sizes[prop] += len(tmp)
                    times[prop] += time.time() - t0

        print "Times"
        for (k, v) in times.iteritems():
            print "\t%s: %s" % (k, v)
        print "\n\n"
        print "Sizes"
        for (k, v) in sizes.iteritems():
            print "\t%s: %s" % (k, v)
        print "\n"
        print "total time", time.time() - start