Exemplo n.º 1
0
def main():
    args = parse_args(required_root_path=True)

    logger, settings = generic_setup(args['root_path'])

    create_backups(logger, settings, dry_run=args['dry_run'])
    create_symlinks(logger, settings, dry_run=args['dry_run'])
Exemplo n.º 2
0
    def launch_new_checks(self):
        """ Launch checks that are in status
            REF: doc/shinken-action-queues.png (4)
        """
        for chk in self.checks:
            now = time.time()
            if chk.status == 'queue':
                # Ok we launch it
                chk.status = 'launched'
                chk.check_time = now

                # Want the args of the commands so we parse it like a shell
                # shlex want str only
                clean_command = shlex.split(
                    chk.command.encode('utf8', 'ignore'))
                # If the command seems good
                if len(clean_command) > 1:
                    # we do not want the first member, check_snmp thing
                    args = parse_args(clean_command[1:])
                    (host, community, version, triggergroup, dstemplate,
                     instance, instance_name) = args

                # If we do not have the good args, we bail out for this check
                if host is None:
                    chk.status = 'done'
                    chk.exit_status = 2
                    chk.get_outputs(
                        'Error : the parameters host or command '
                        'are not correct.', 8012)
                    chk.execution_time = 0.0
                    continue

                # Ok we are good, we go on
                n = SNMPAsyncClient(host, community, version, self.datasource,
                                    triggergroup, dstemplate, instance,
                                    instance_name, self.memcached_address,
                                    self.max_repetitions, self.show_from_cache)
                chk.con = n
    def launch_new_checks(self):
        """ Launch checks that are in status
            REF: doc/shinken-action-queues.png (4)
        """
        for chk in self.checks:
            now = time.time()
            if chk.status == 'queue':
                # Ok we launch it
                chk.status = 'launched'
                chk.check_time = now

                # Want the args of the commands so we parse it like a shell
                # shlex want str only
                clean_command = shlex.split(chk.command.encode('utf8',
                                                               'ignore'))
                # If the command seems good
                if len(clean_command) > 1:
                    # we do not want the first member, check_snmp thing
                    args = parse_args(clean_command[1:])
                    (host, community, version,
                     triggergroup, dstemplate, instance, instance_name) = args

                # If we do not have the good args, we bail out for this check
                if host is None:
                    chk.status = 'done'
                    chk.exit_status = 2
                    chk.get_outputs('Error : the parameters host or command '
                                    'are not correct.', 8012)
                    chk.execution_time = 0.0
                    continue

                # Ok we are good, we go on
                n = SNMPAsyncClient(host, community, version, self.datasource,
                                    triggergroup, dstemplate, instance,
                                    instance_name, self.memcached_address,
                                    self.max_repetitions, self.show_from_cache)
                chk.con = n
    def hook_late_configuration(self, arb):
        """ Read config and fill memcached """
        for serv in arb.conf.services:
            if serv.check_command.command.module_type == 'snmp_booster':
                chk = serv.check_command.command
                mac_resol = MacroResolver()
                mac_resol.init(arb.conf)
                data = serv.get_data_for_checks()
                command_line = mac_resol.resolve_command(
                    serv.check_command, data)

                # Clean command
                clean_command = shlex.split(
                    command_line.encode('utf8', 'ignore'))
                # If the command doesn't seem good
                if len(clean_command) <= 1:
                    logger.error("[SnmpBooster] Bad command "
                                 "detected: %s" % chk.command)
                    continue

                # we do not want the first member, check_snmp thing
                args = parse_args(clean_command[1:])
                (host, community, version, triggergroup, dstemplate, instance,
                 instance_name) = args

                # Get key from memcached
                obj_key = str(host)
                # looking for old datas
                obj = self.memcached.get(obj_key)

                # Don't force check on first launch
                try:
                    if not obj is None:
                        # Host found
                        new_obj = SNMPHost(host, community, version)
                        if not obj == new_obj:
                            # Update host
                            obj.community = new_obj.community
                            obj.version = new_obj.version
                        new_serv = SNMPService(serv, obj, triggergroup,
                                               dstemplate, instance,
                                               instance_name,
                                               serv.service_description)
                        new_serv.set_oids(self.datasource)
                        new_serv.set_triggers(self.datasource)
                        obj.update_service(new_serv)
                        obj.frequences[serv.check_interval].forced = False
                        self.memcached.set(obj_key, obj, time=604800)
                    else:
                        # No old datas for this host
                        new_obj = SNMPHost(host, community, version)
                        new_serv = SNMPService(serv, new_obj, triggergroup,
                                               dstemplate, instance,
                                               instance_name,
                                               serv.service_description)
                        new_serv.set_oids(self.datasource)
                        new_serv.set_triggers(self.datasource)
                        new_obj.update_service(new_serv)
                        # Save new host in memcache
                        self.memcached.set(obj_key, new_obj, time=604800)
                except Exception, e:
                    message = ("[SnmpBooster] Error adding : "
                               "Host %s - Service %s - Error related "
                               "to: %s" %
                               (obj_key, serv.service_description, str(e)))
                    logger.error(message)
Exemplo n.º 5
0
def main():
    args = parse_args(required_root_path=True)

    logger, settings = generic_setup(args['root_path'])

    install_apps(logger, settings, dry_run=args['dry_run'])
    def hook_get_new_actions(self, sche):
        """ Detect of forced checks """
        for s in sche.services:
            for a in s.actions:
                if isinstance(a, Check):
                    if a.module_type == 'snmp_booster':
                        # Clean command
                        clean_command = shlex.split(a.command.encode('utf8',
                                                                     'ignore'))
                        # If the command doesn't seem good
                        if len(clean_command) <= 1:
                            logger.error("[SnmpBooster] Bad command "
                                         "detected: %s" % a.command)
                            continue

                        # we do not want the first member, check_snmp thing
                        args = parse_args(clean_command[1:])
                        (host, community, version,
                         triggergroup, dstemplate,
                         instance, instance_name) = args

                        # Get key from memcached
                        obj_key = str(host)
                        # looking for old datas
                        obj = self.memcached.get(obj_key)

                        # Don't force check on first launch
                        forced = False
                        if not obj is None:
                            # Host found
                            # try to find if this oid is already in memcache
                            if not s.check_interval in obj.frequences:
                                logger.error("[SnmpBooster] check_interval not"
                                             " found in frequence list -"
                                             "host: %s - check_interval: "
                                             "%s" % (obj_key,
                                                     s.check_interval))
                                # possible ??
                                continue
                            if not obj.frequences[s.check_interval].check_time is None:
                                # Forced or not forced check ??
                                if s.state_type == 'SOFT':
                                    forced = True
                                else:
                                    # Detect if the checked is forced by
                                    # an UI or external command
                                    forced = (s.next_chk - s.last_chk) < \
                                        s.check_interval * s.interval_length - 15

                                if forced:
                                    # Set forced
                                    logger.info("[SnmpBooster] Forced check "
                                                "for this host/service: "
                                                "%s/%s" % (obj_key,
                                                           s.service_description))
                                    obj.frequences[s.check_interval].forced = forced

                            self.memcached.set(obj_key, obj, time=604800)
                        else:
                            # Host Not found
                            logger.error("[SnmpBooster] Host not "
                                         "found: %s" % obj_key)
    def hook_late_configuration(self, arb):
        """ Read config and fill memcached """
        for serv in arb.conf.services:
            if serv.check_command.command.module_type == 'snmp_booster':
                chk = serv.check_command.command
                mac_resol = MacroResolver()
                mac_resol.init(arb.conf)
                data = serv.get_data_for_checks()
                command_line = mac_resol.resolve_command(serv.check_command,
                                                         data)

                # Clean command
                clean_command = shlex.split(command_line.encode('utf8',
                                                                'ignore'))
                # If the command doesn't seem good
                if len(clean_command) <= 1:
                    logger.error("[SnmpBooster] Bad command "
                                 "detected: %s" % chk.command)
                    continue

                # we do not want the first member, check_snmp thing
                args = parse_args(clean_command[1:])
                (host, community, version,
                 triggergroup, dstemplate, instance, instance_name) = args

                # Get key from memcached
                obj_key = str(host)
                # looking for old datas
                obj = self.memcached.get(obj_key)

                # Don't force check on first launch
                try:
                    if not obj is None:
                        # Host found
                        new_obj = SNMPHost(host, community, version)
                        if not obj == new_obj:
                            # Update host
                            obj.community = new_obj.community
                            obj.version = new_obj.version
                        new_serv = SNMPService(serv, obj, triggergroup,
                                               dstemplate, instance,
                                               instance_name,
                                               serv.service_description)
                        new_serv.set_oids(self.datasource)
                        new_serv.set_triggers(self.datasource)
                        obj.update_service(new_serv)
                        obj.frequences[serv.check_interval].forced = False
                        self.memcached.set(obj_key, obj, time=604800)
                    else:
                        # No old datas for this host
                        new_obj = SNMPHost(host, community, version)
                        new_serv = SNMPService(serv, new_obj, triggergroup,
                                               dstemplate, instance,
                                               instance_name,
                                               serv.service_description)
                        new_serv.set_oids(self.datasource)
                        new_serv.set_triggers(self.datasource)
                        new_obj.update_service(new_serv)
                        # Save new host in memcache
                        self.memcached.set(obj_key, new_obj, time=604800)
                except Exception, e:
                    message = ("[SnmpBooster] Error adding : "
                               "Host %s - Service %s - Error related "
                               "to: %s" % (obj_key,
                                           serv.service_description,
                                           str(e)))
                    logger.error(message)