Ejemplo n.º 1
0
 def test_by_host_service_name(self):
     """Récupération d'un LowLevelService par son nom d'hôte/service."""
     ob = LowLevelService.by_host_service_name(
         u'myhost', self.attrs['servicename'])
     assert_equals(ob.weight, 100)
     assert_equals(ob.warning_weight, 101)
Ejemplo n.º 2
0
    def load_conf(self):
        services = conf.hostsConf[self.host.name]['services'].keys()
        collector = None

        # Si le service Collector fait partie des services de l'hôte,
        # alors il doit être traité en premier, pour permettre aux services
        # passifs qui en dépendent d'y faire référence.
        try:
            services.remove('Collector')
        except ValueError:
            pass
        else:
            services.insert(0, 'Collector')

        for service in services:
            reroute = None

            # Si le service dépend du Collector, on récupère
            # l'ID du Collector pour faire le lien entre les deux.
            if (service, 'service') in \
                conf.hostsConf[self.host.name]['SNMPJobs']:
                reroute = collector

            # L'hôte est rerouté, on récupère l'ID du service de reroutage.
            elif conf.hostsConf[self.host.name]['services'] \
                [service]['reRoutedBy']:
                reRoutedBy = conf.hostsConf[self.host.name]['services'] \
                    [service]['reRoutedBy']
                reroute = LowLevelService.get_supitem(
                    reRoutedBy['host'], reRoutedBy['service'])

            service = unicode(service)
            weight = conf.hostsConf[self.host.name]['services'] \
                [service]['weight']
            warning_weight = conf.hostsConf[self.host.name]['services'] \
                [service]['warning_weight']
            if weight is None:
                weight = conf.hostsConf[self.host.name][
                        "default_service_weight"]
            if warning_weight is None:
                warning_weight = conf.hostsConf[self.host.name][
                        "default_service_warning_weight"]
            if warning_weight > weight:
                raise ParsingError(_("warning_weight (%(warning_weight)d) must "
                    "be less than or equal to weight (%(weight)d) "
                    "for test '%(test)s' on host '%(host)s'") % {
                        'test': service,
                        'host': self.host.name,
                        'warning_weight': warning_weight,
                        'weight': weight,
                        })

            lls = dict(host=self.host, servicename=service,
                       weight=weight, warning_weight=warning_weight)
            if isinstance(reroute, int):
                lls['idcollector'] = reroute
            elif reroute != None:
                lls['collector'] = reroute
            lls = self.add(lls)

            # on mémorise l'identifiant du Collector pour les
            # services passifs à venir qui en dépendent.
            if service == 'Collector':
                collector = lls

            # directives Nagios du service
            nagios_directives = conf.hostsConf[self.host.name]['nagiosSrvDirs']
            if nagios_directives.has_key(service):
                nagiosconf_loader = NagiosConfLoader(lls,
                                        nagios_directives[service])
                nagiosconf_loader.load()

            # tags
            if service in conf.hostsConf[self.host.name]['services']:
                tag_loader = TagLoader(lls, conf.hostsConf[self.host.name] \
                    ['services'][service].get('tags', {}))
                tag_loader.load_conf()