Code
stringlengths
103
85.9k
Summary
listlengths
0
94
Please provide a description of the function:def get_overall_state(self, services): overall_state = 0 if not self.monitored: overall_state = 5 elif self.acknowledged: overall_state = 1 elif self.downtimed: overall_state = 2 elif self....
[ "Get the host overall state including the host self status\n and the status of its services\n\n Compute the host overall state identifier, including:\n - the acknowledged state\n - the downtime state\n\n The host overall state is (prioritized):\n - an host not monitored (5)...
Please provide a description of the function:def linkify(self, timeperiods=None, commands=None, contacts=None, # pylint: disable=R0913 realms=None, resultmodulations=None, businessimpactmodulations=None, escalations=None, hostgroups=None, checkmodulations=None, macromodu...
[ "Create link between objects::\n\n * hosts -> timeperiods\n * hosts -> hosts (parents, etc)\n * hosts -> commands (check_command)\n * hosts -> contacts\n\n :param timeperiods: timeperiods to link\n :type timeperiods: alignak.objects.timeperiod.Timeperiods\n :para...
Please provide a description of the function:def linkify_h_by_h(self): for host in self: # The new member list new_parents = [] for parent in getattr(host, 'parents', []): parent = parent.strip() o_parent = self.find_by_name(parent) ...
[ "Link hosts with their parents\n\n :return: None\n " ]
Please provide a description of the function:def linkify_h_by_realms(self, realms): default_realm = realms.get_default() for host in self: if not getattr(host, 'realm', None): # Applying default realm to an host host.realm = default_realm.uuid if defa...
[ "Link hosts with realms\n\n :param realms: realms object to link with\n :type realms: alignak.objects.realm.Realms\n :return: None\n " ]
Please provide a description of the function:def linkify_h_by_hg(self, hostgroups): # Register host in the hostgroups for host in self: new_hostgroups = [] if hasattr(host, 'hostgroups') and host.hostgroups != []: hgs = [n.strip() for n in host.hostgroups...
[ "Link hosts with hostgroups\n\n :param hostgroups: hostgroups object to link with\n :type hostgroups: alignak.objects.hostgroup.Hostgroups\n :return: None\n " ]
Please provide a description of the function:def explode(self, hostgroups, contactgroups): for template in list(self.templates.values()): # items::explode_contact_groups_into_contacts # take all contacts from our contact_groups into our contact property self.explode_...
[ "Explode hosts with hostgroups, contactgroups::\n\n * Add contact from contactgroups to host contacts\n * Add host into their hostgroups as hostgroup members\n\n :param hostgroups: Hostgroups to explode\n :type hostgroups: alignak.objects.hostgroup.Hostgroups\n :param contactgroup...
Please provide a description of the function:def apply_dependencies(self): for host in self: for parent_id in getattr(host, 'parents', []): if parent_id is None: continue parent = self[parent_id] if parent.active_checks_ena...
[ "Loop on hosts and register dependency between parent and son\n\n call Host.fill_parents_dependency()\n\n :return: None\n " ]
Please provide a description of the function:def find_hosts_that_use_template(self, tpl_name): return [h.host_name for h in self if tpl_name in h.tags if hasattr(h, "host_name")]
[ "Find hosts that use the template defined in argument tpl_name\n\n :param tpl_name: the template name we filter or\n :type tpl_name: str\n :return: list of the host_name of the hosts that got the template tpl_name in tags\n :rtype: list[str]\n " ]
Please provide a description of the function:def is_correct(self): state = True # Internal checks before executing inherited function... loop = self.no_loop_in_parents("self", "parents") if loop: self.add_error("Loop detected while checking hosts") state...
[ "Check if the hosts list configuration is correct ::\n\n * check if any loop exists in each host dependencies\n * Call our parent class is_correct checker\n\n :return: True if the configuration is correct, otherwise False\n :rtype: bool\n " ]
Please provide a description of the function:def is_me(self): # pragma: no cover, seems not to be used anywhere logger.info("And arbiter is launched with the hostname:%s " "from an arbiter point of view of addr:%s", self.host_name, socket.getfqdn()) return self.host_name ==...
[ "Check if parameter name if same than name of this object\n\n TODO: is it useful?\n\n :return: true if parameter name if same than this name\n :rtype: bool\n " ]
Please provide a description of the function:def do_not_run(self): logger.debug("[%s] do_not_run", self.name) try: self.con.get('_do_not_run') return True except HTTPClientConnectionException as exp: # pragma: no cover, simple protection self.add_fa...
[ "Check if satellite running or not\n If not, try to run\n\n :return: true if satellite not running\n :rtype: bool\n " ]
Please provide a description of the function:def get_broks(self, broker_name): logger.debug("Broker %s requests my broks list", broker_name) res = [] if not broker_name: return res for broker_link in list(self.brokers.values()): if broker_name == broker_...
[ "Send broks to a specific broker\n\n :param broker_name: broker name to send broks\n :type broker_name: str\n :greturn: dict of brok for this broker\n :rtype: dict[alignak.brok.Brok]\n " ]
Please provide a description of the function:def compensate_system_time_change(self, difference): # pragma: no cover, # pylint: disable=too-many-branches # not with unit tests super(Alignak, self).compensate_system_time_change(difference) # We only need to change some value ...
[ "Compensate a system time change of difference for all hosts/services/checks/notifs\n\n :param difference: difference in seconds\n :type difference: int\n :return: None\n " ]
Please provide a description of the function:def do_loop_turn(self): if not self.first_scheduling: # Ok, now all is initialized, we can make the initial broks logger.info("First scheduling launched") _t0 = time.time() # Program start brok self...
[ "Scheduler loop turn\n\n Simply run the Alignak scheduler loop\n\n This is called when a configuration got received by the scheduler daemon. As of it,\n check if the first scheduling has been done... and manage this.\n\n :return: None\n " ]
Please provide a description of the function:def get_managed_configurations(self): # for scheduler_link in list(self.schedulers.values()): # res[scheduler_link.instance_id] = { # 'hash': scheduler_link.hash, # 'push_flavor': scheduler_link.push_flavor, ...
[ "Get the configurations managed by this scheduler\n\n The configuration managed by a scheduler is the self configuration got\n by the scheduler during the dispatching.\n\n :return: a dict of scheduler links with instance_id as key and\n hash, push_flavor and configuration identifier as v...
Please provide a description of the function:def setup_new_conf(self): # pylint: disable=too-many-statements, too-many-branches, too-many-locals # Execute the base class treatment... super(Alignak, self).setup_new_conf() # ...then our own specific treatment! with self.c...
[ "Setup new conf received for scheduler\n\n :return: None\n " ]
Please provide a description of the function:def clean_previous_run(self): # Execute the base class treatment... super(Alignak, self).clean_previous_run() # Clean all lists self.pollers.clear() self.reactionners.clear() self.brokers.clear()
[ "Clean variables from previous configuration\n\n :return: None\n " ]
Please provide a description of the function:def get_daemon_stats(self, details=False): # Call the base Daemon one res = super(Alignak, self).get_daemon_stats(details=details) res.update({'name': self.name, 'type': self.type, 'monitored_objects': {}}) counters = res['counters'...
[ "Increase the stats provided by the Daemon base class\n\n :return: stats dictionary\n :rtype: dict\n " ]
Please provide a description of the function:def get_monitoring_problems(self): res = {} if not self.sched: return res # Get statistics from the scheduler scheduler_stats = self.sched.get_scheduler_stats(details=True) if 'livesynthesis' in scheduler_stats: ...
[ "Get the current scheduler livesynthesis\n\n :return: live synthesis and problems dictionary\n :rtype: dict\n " ]
Please provide a description of the function:def merge(self, services): for extinfo in self: if hasattr(extinfo, 'register') and not getattr(extinfo, 'register'): # We don't have to merge template continue hosts_names = extinfo.get_name().split(",...
[ "Merge extended host information into services\n\n :param services: services list, to look for a specific one\n :type services: alignak.objects.service.Services\n :return: None\n " ]
Please provide a description of the function:def merge_extinfo(service, extinfo): properties = ['notes', 'notes_url', 'icon_image', 'icon_image_alt'] # service properties have precedence over serviceextinfo properties for prop in properties: if getattr(service, prop) == '' a...
[ "Merge extended host information into a service\n\n :param service: the service to edit\n :type service: alignak.objects.service.Service\n :param extinfo: the external info we get data from\n :type extinfo: alignak.objects.serviceextinfo.ServiceExtInfo\n :return: None\n " ]
Please provide a description of the function:def get_command_and_args(self): r # First protect p_call = self.call.replace(r'\!', '___PROTECT_EXCLAMATION___') tab = p_call.split('!') return tab[0].strip(), [s.replace('___PROTECT_EXCLAMATION___', '!') for s in tab[1:]]
[ "We want to get the command and the args with ! splitting.\n but don't forget to protect against the \\! to avoid splitting on them\n\n Remember: A Nagios-like command is command_name!arg1!arg2!...\n\n :return: None\n " ]
Please provide a description of the function:def get_a_satellite_link(sat_type, sat_dict): cls = get_alignak_class('alignak.objects.%slink.%sLink' % (sat_type, sat_type.capitalize())) return cls(params=sat_dict, parsing=False)
[ "Get a SatelliteLink object for a given satellite type and a dictionary\n\n :param sat_type: type of satellite\n :param sat_dict: satellite configuration data\n :return:\n " ]
Please provide a description of the function:def get_livestate(self): livestate = 0 if self.active: if not self.reachable: livestate = 1 elif not self.alive: livestate = 2 else: livestate = 3 livestate_output =...
[ "Get the SatelliteLink live state.\n\n The live state is a tuple information containing a state identifier and a message, where:\n state is:\n - 0 for an up and running satellite\n - 1 if the satellite is not reachale\n - 2 if the satellite is dead\n - 3...
Please provide a description of the function:def set_arbiter_satellite_map(self, satellite_map=None): self.satellite_map = { 'address': self.address, 'port': self.port, 'use_ssl': self.use_ssl, 'hard_ssl_name_check': self.hard_ssl_name_check } if satellite_map: ...
[ "\n satellite_map is the satellites map in current context:\n - A SatelliteLink is owned by an Arbiter\n - satellite_map attribute of a SatelliteLink is the map defined\n IN THE satellite configuration but for creating connections,\n we need to ...
Please provide a description of the function:def get_and_clear_context(self): res = (self.broks, self.actions, self.wait_homerun, self.pushed_commands) self.broks = [] self.actions = {} self.wait_homerun = {} self.pushed_commands = [] return res
[ "Get and clean all of our broks, actions, external commands and homerun\n\n :return: list of all broks of the satellite link\n :rtype: list\n " ]
Please provide a description of the function:def prepare_for_conf(self): logger.debug("- preparing: %s", self) self.cfg = { 'self_conf': self.give_satellite_cfg(), 'schedulers': {}, 'arbiters': {} } logger.debug("- prepared: %s", self.cfg)
[ "Initialize the pushed configuration dictionary\n with the inner properties that are to be propagated to the satellite link.\n\n :return: None\n " ]
Please provide a description of the function:def give_satellite_cfg(self): # All the satellite link class properties that are 'to_send' are stored in a # dictionary to be pushed to the satellite when the configuration is dispatched res = {} properties = self.__class__.properties...
[ "Get the default information for a satellite.\n\n Overridden by the specific satellites links\n\n :return: dictionary of information common to all the links\n :rtype: dict\n " ]
Please provide a description of the function:def give_satellite_json(self): daemon_properties = ['type', 'name', 'uri', 'spare', 'configuration_sent', 'realm_name', 'manage_sub_realms', 'active', 'reachable', 'alive', 'passive', ...
[ "Get the json information for a satellite.\n\n This to provide information that will be exposed by a daemon on its HTTP interface.\n\n :return: dictionary of information common to all the links\n :rtype: dict\n " ]
Please provide a description of the function:def manages(self, cfg_part): logger.debug("Do I (%s/%s) manage: %s, my managed configuration(s): %s", self.type, self.name, cfg_part, self.cfg_managed) # If we do not yet manage a configuration if not self.cfg_managed: ...
[ "Tell if the satellite is managing this configuration part\n\n The managed configuration is formed as a dictionary indexed on the link instance_id:\n {\n u'SchedulerLink_1': {\n u'hash': u'4d08630a3483e1eac7898e7a721bd5d7768c8320',\n u'push_flavor': u'4d08630a...
Please provide a description of the function:def create_connection(self): # Create the HTTP client for the connection try: self.con = HTTPClient(address=self.satellite_map['address'], port=self.satellite_map['port'], ...
[ "Initialize HTTP connection with a satellite (con attribute) and\n set its uri attribute\n\n This is called on the satellite link initialization\n\n :return: None\n " ]
Please provide a description of the function:def set_alive(self): was_alive = self.alive self.alive = True self.reachable = True self.attempt = 0 # We came from dead to alive! We must propagate the good news if not was_alive: logger.info("Setting %s ...
[ "Set alive, reachable, and reset attempts.\n If we change state, raise a status brok update\n\n alive, means the daemon is prenset in the system\n reachable, means that the HTTP connection is valid\n\n With this function we confirm that the daemon is reachable and, thus, we assume it is ...
Please provide a description of the function:def set_dead(self): was_alive = self.alive self.alive = False self.reachable = False self.attempt = 0 # We will have to create a new connection... self.con = None # We are dead now! We must propagate the sad n...
[ "Set the satellite into dead state:\n If we change state, raise a status brok update\n\n :return:None\n " ]
Please provide a description of the function:def add_failed_check_attempt(self, reason=''): self.reachable = False self.attempt = self.attempt + 1 logger.debug("Failed attempt for %s (%d/%d), reason: %s", self.name, self.attempt, self.max_check_attempts, reason) ...
[ "Set the daemon as unreachable and add a failed attempt\n if we reach the maximum attempts, set the daemon as dead\n\n :param reason: the reason of adding an attempts (stack trace sometimes)\n :type reason: str\n :return: None\n " ]
Please provide a description of the function:def valid_connection(*outer_args, **outer_kwargs): # pylint: disable=unused-argument, no-method-argument def decorator(func): # pylint: disable=missing-docstring def decorated(*args, **kwargs): # pylint: disable=missing-docstring ...
[ "Check if the daemon connection is established and valid" ]
Please provide a description of the function:def communicate(*outer_args, **outer_kwargs): # pylint: disable=unused-argument, no-method-argument def decorator(func): # pylint: disable=missing-docstring def decorated(*args, **kwargs): # pylint: disable=missing-docstring ...
[ "Check if the daemon connection is authorized and valid" ]
Please provide a description of the function:def get_running_id(self): former_running_id = self.running_id logger.info(" get the running identifier for %s %s.", self.type, self.name) # An exception is raised in this function if the daemon is not reachable self.running_id = sel...
[ "Send a HTTP request to the satellite (GET /identity)\n Used to get the daemon running identifier that allows to know if the daemon got restarted\n\n This is called on connection initialization or re-connection\n\n If the daemon is notreachable, this function will raise an exception and the cal...
Please provide a description of the function:def stop_request(self, stop_now=False): logger.debug("Sending stop request to %s, stop now: %s", self.name, stop_now) res = self.con.get('stop_request', {'stop_now': '1' if stop_now else '0'}) return res
[ "Send a stop request to the daemon\n\n :param stop_now: stop now or go to stop wait mode\n :type stop_now: bool\n :return: the daemon response (True)\n " ]
Please provide a description of the function:def update_infos(self, forced=False, test=False): logger.debug("Update informations, forced: %s", forced) # First look if it's not too early to ping now = time.time() if not forced and self.last_check and self.last_check + self.polli...
[ "Update satellite info each self.polling_interval seconds\n so we smooth arbiter actions for just useful actions.\n\n Raise a satellite update status Brok\n\n If forced is True, then ignore the ping period. This is used when the configuration\n has not yet been dispatched to the Arbiter ...
Please provide a description of the function:def get_daemon_stats(self, details=False): logger.debug("Get daemon statistics for %s, %s %s", self.name, self.alive, self.reachable) return self.con.get('stats%s' % ('?details=1' if details else ''))
[ "Send a HTTP request to the satellite (GET /get_daemon_stats)\n\n :return: Daemon statistics\n :rtype: dict\n " ]
Please provide a description of the function:def get_initial_broks(self, broker_name): logger.debug("Getting initial broks for %s, %s %s", self.name, self.alive, self.reachable) return self.con.get('_initial_broks', {'broker_name': broker_name}, wait=True)
[ "Send a HTTP request to the satellite (GET /_initial_broks)\n\n Used to build the initial broks for a broker connecting to a scheduler\n\n :param broker_name: the concerned broker name\n :type broker_name: str\n :return: Boolean indicating if the running id changed\n :type: bool\n...
Please provide a description of the function:def wait_new_conf(self): logger.debug("Wait new configuration for %s, %s %s", self.name, self.alive, self.reachable) return self.con.get('_wait_new_conf')
[ "Send a HTTP request to the satellite (GET /wait_new_conf)\n\n :return: True if wait new conf, otherwise False\n :rtype: bool\n " ]
Please provide a description of the function:def put_conf(self, configuration, test=False): logger.debug("Sending configuration to %s, %s %s", self.name, self.alive, self.reachable) # ---------- if test: setattr(self, 'unit_test_pushed_configuration', configuration) ...
[ "Send the configuration to the satellite\n HTTP request to the satellite (POST /push_configuration)\n\n If test is True, store the configuration internally\n\n :param configuration: The conf to send (data depend on the satellite)\n :type configuration:\n :return: None\n " ]
Please provide a description of the function:def has_a_conf(self, magic_hash=None): # pragma: no cover logger.debug("Have a configuration for %s, %s %s", self.name, self.alive, self.reachable) self.have_conf = self.con.get('_have_conf', {'magic_hash': magic_hash}) return self.have_conf
[ "Send a HTTP request to the satellite (GET /have_conf)\n Used to know if the satellite has a conf\n\n :param magic_hash: Config hash. Only used for HA arbiter communication\n :type magic_hash: int\n :return: Boolean indicating if the satellite has a (specific) configuration\n :typ...
Please provide a description of the function:def get_conf(self, test=False): logger.debug("Get managed configuration for %s, %s %s", self.name, self.alive, self.reachable) # ---------- if test: self.cfg_managed = {} self.have_conf = True ...
[ "Send a HTTP request to the satellite (GET /managed_configurations)\n and update the cfg_managed attribute with the new information\n Set to {} on failure\n\n the managed configurations are a dictionary which keys are the scheduler link instance id\n and the values are the push_flavor\n\...
Please provide a description of the function:def push_broks(self, broks): logger.debug("[%s] Pushing %d broks", self.name, len(broks)) return self.con.post('_push_broks', {'broks': broks}, wait=True)
[ "Send a HTTP request to the satellite (POST /push_broks)\n Send broks to the satellite\n\n :param broks: Brok list to send\n :type broks: list\n :return: True on success, False on failure\n :rtype: bool\n " ]
Please provide a description of the function:def push_actions(self, actions, scheduler_instance_id): logger.debug("Pushing %d actions from %s", len(actions), scheduler_instance_id) return self.con.post('_push_actions', {'actions': actions, 'schedul...
[ "Post the actions to execute to the satellite.\n Indeed, a scheduler post its checks to a poller and its actions to a reactionner.\n\n :param actions: Action list to send\n :type actions: list\n :param scheduler_instance_id: Scheduler instance identifier\n :type scheduler_instance...
Please provide a description of the function:def push_results(self, results, scheduler_name): logger.debug("Pushing %d results", len(results)) result = self.con.post('put_results', {'results': results, 'from': scheduler_name}, wait=True) return result
[ "Send a HTTP request to the satellite (POST /put_results)\n Send actions results to the satellite\n\n :param results: Results list to send\n :type results: list\n :param scheduler_name: Scheduler name\n :type scheduler_name: uuid\n :return: True on success, False on failure...
Please provide a description of the function:def push_external_commands(self, commands): logger.debug("Pushing %d external commands", len(commands)) return self.con.post('_run_external_commands', {'cmds': commands}, wait=True)
[ "Send a HTTP request to the satellite (POST /r_un_external_commands)\n to send the external commands to the satellite\n\n :param results: Results list to send\n :type results: list\n :return: True on success, False on failure\n :rtype: bool\n " ]
Please provide a description of the function:def get_external_commands(self): res = self.con.get('_external_commands', wait=False) logger.debug("Got %d external commands from %s: %s", len(res), self.name, res) return unserialize(res, True)
[ "Send a HTTP request to the satellite (GET /_external_commands) to\n get the external commands from the satellite.\n\n :return: External Command list on success, [] on failure\n :rtype: list\n " ]
Please provide a description of the function:def get_broks(self, broker_name): res = self.con.get('_broks', {'broker_name': broker_name}, wait=False) logger.debug("Got broks from %s: %s", self.name, res) return unserialize(res, True)
[ "Send a HTTP request to the satellite (GET /_broks)\n Get broks from the satellite.\n Un-serialize data received.\n\n :param broker_name: the concerned broker link\n :type broker_name: BrokerLink\n :return: Broks list on success, [] on failure\n :rtype: list\n " ]
Please provide a description of the function:def get_events(self): res = self.con.get('_events', wait=False) logger.debug("Got events from %s: %s", self.name, res) return unserialize(res, True)
[ "Send a HTTP request to the satellite (GET /_events)\n Get monitoring events from the satellite.\n\n :return: Broks list on success, [] on failure\n :rtype: list\n " ]
Please provide a description of the function:def get_results(self, scheduler_instance_id): res = self.con.get('_results', {'scheduler_instance_id': scheduler_instance_id}, wait=True) logger.debug("Got %d results from %s: %s", len(res), self.name, res) return res
[ "Send a HTTP request to the satellite (GET /_results)\n Get actions results from satellite (only passive satellites expose this method.\n\n :param scheduler_instance_id: scheduler instance identifier\n :type scheduler_instance_id: str\n :return: Results list on success, [] on failure\n ...
Please provide a description of the function:def get_actions(self, params): res = self.con.get('_checks', params, wait=True) logger.debug("Got checks to execute from %s: %s", self.name, res) return unserialize(res, True)
[ "Send a HTTP request to the satellite (GET /_checks)\n Get actions from the scheduler.\n Un-serialize data received.\n\n :param params: the request parameters\n :type params: str\n :return: Actions list on success, [] on failure\n :rtype: list\n " ]
Please provide a description of the function:def linkify(self, modules): logger.debug("Linkify %s with %s", self, modules) self.linkify_s_by_module(modules)
[ "Link modules and Satellite links\n\n :param modules: Module object list\n :type modules: alignak.objects.module.Modules\n :return: None\n " ]
Please provide a description of the function:def get_return_from(self, notif): self.exit_status = notif.exit_status self.execution_time = notif.execution_time
[ "Setter of exit_status and execution_time attributes\n\n :param notif: notification to get data from\n :type notif: alignak.notification.Notification\n :return: None\n " ]
Please provide a description of the function:def get_initial_status_brok(self): data = {'uuid': self.uuid} self.fill_data_brok_from(data, 'full_status') return Brok({'type': 'notification_raise', 'data': data})
[ "Get a initial status brok\n\n :return: brok with wanted data\n :rtype: alignak.brok.Brok\n " ]
Please provide a description of the function:def serialize(self): res = super(Notification, self).serialize() if res['command_call'] is not None: if not isinstance(res['command_call'], string_types) and \ not isinstance(res['command_call'], dict): ...
[ "This function serialize into a simple dict object.\n It is used when transferring data to other daemons over the network (http)\n\n Here we directly return all attributes\n\n :return: json representation of a Timeperiod\n :rtype: dict\n " ]
Please provide a description of the function:def add(self, elt): if isinstance(elt, Brok): # For brok, we tag the brok with our instance_id elt.instance_id = self.instance_id if elt.type == 'monitoring_log': # The brok is a monitoring event ...
[ "Generic function to add objects to the daemon internal lists.\n Manage Broks, External commands and Messages (from modules queues)\n\n :param elt: object to add\n :type elt: alignak.AlignakObject\n :return: None\n " ]
Please provide a description of the function:def manage_brok(self, brok): # Unserialize the brok before consuming it brok.prepare() for module in self.modules_manager.get_internal_instances(): try: _t0 = time.time() module.manage_brok(brok) ...
[ "Get a brok.\n We put brok data to the modules\n\n :param brok: object with data\n :type brok: object\n :return: None\n " ]
Please provide a description of the function:def get_internal_broks(self): statsmgr.gauge('get-new-broks-count.broker', len(self.internal_broks)) # Add the broks to our global list self.external_broks.extend(self.internal_broks) self.internal_broks = []
[ "Get all broks from self.broks_internal_raised and append them to our broks\n to manage\n\n :return: None\n " ]
Please provide a description of the function:def get_arbiter_broks(self): with self.arbiter_broks_lock: statsmgr.gauge('get-new-broks-count.arbiter', len(self.arbiter_broks)) # Add the broks to our global list self.external_broks.extend(self.arbiter_broks) ...
[ "Get the broks from the arbiters,\n but as the arbiter_broks list can be push by arbiter without Global lock,\n we must protect this with a lock\n\n TODO: really? check this arbiter behavior!\n\n :return: None\n " ]
Please provide a description of the function:def get_new_broks(self): for satellites in [self.schedulers, self.pollers, self.reactionners, self.receivers]: for satellite_link in list(satellites.values()): logger.debug("Getting broks from %s", satellite_link) ...
[ "Get new broks from our satellites\n\n :return: None\n " ]
Please provide a description of the function:def setup_new_conf(self): # pylint: disable=too-many-branches, too-many-locals # Execute the base class treatment... super(Broker, self).setup_new_conf() # ...then our own specific treatment! with self.conf_lock: ...
[ "Broker custom setup_new_conf method\n\n This function calls the base satellite treatment and manages the configuration needed\n for a broker daemon:\n - get and configure its pollers, reactionners and receivers relation\n - configure the modules\n\n :return: None\n " ]
Please provide a description of the function:def clean_previous_run(self): # Execute the base class treatment... super(Broker, self).clean_previous_run() # Clean all satellites relations self.pollers.clear() self.reactionners.clear() self.receivers.clear() ...
[ "Clean all (when we received new conf)\n\n :return: None\n " ]
Please provide a description of the function:def do_loop_turn(self): # pylint: disable=too-many-branches if not self.got_initial_broks: # Asking initial broks from my schedulers my_satellites = self.get_links_of_type(s_type='scheduler') for satellite in list(...
[ "Loop used to:\n * get initial status broks\n * check if modules are alive, if not restart them\n * get broks from ourself, the arbiters and our satellites\n * add broks to the queue of each external module\n * manage broks with each internal module\n\n If the interna...
Please provide a description of the function:def get_daemon_stats(self, details=False): # Call the base Daemon one res = super(Broker, self).get_daemon_stats(details=details) res.update({'name': self.name, 'type': self.type}) counters = res['counters'] counters['broks-...
[ "Increase the stats provided by the Daemon base class\n\n :return: stats dictionary\n :rtype: dict\n " ]
Please provide a description of the function:def add_group_members(self, members): if not isinstance(members, list): members = [members] if not getattr(self, 'group_members', None): self.group_members = members else: self.group_members.extend(members...
[ "Add a new group member to the groups list\n\n :param members: member name\n :type members: str\n :return: None\n " ]
Please provide a description of the function:def prepare_satellites(self, satellites): for sat_type in ["scheduler", "reactionner", "poller", "broker", "receiver"]: # We get potential TYPE at realm level first for sat_link_uuid in getattr(self, "%ss" % sat_type): ...
[ "Update the following attributes of a realm::\n\n * nb_*satellite type*s\n * self.potential_*satellite type*s\n\n (satellite types are scheduler, reactionner, poller, broker and receiver)\n\n :param satellites: dict of SatelliteLink objects\n :type satellites: dict\n :retur...
Please provide a description of the function:def get_realms_by_explosion(self, realms): # If rec_tag is already set, then we detected a loop in the realms hierarchy! if getattr(self, 'rec_tag', False): self.add_error("Error: there is a loop in the realm definition %s" % self.get_nam...
[ "Get all members of this realm including members of sub-realms on multi-levels\n\n :param realms: realms list, used to look for a specific one\n :type realms: alignak.objects.realm.Realms\n :return: list of members and add realm to realm_members attribute\n :rtype: list\n " ]
Please provide a description of the function:def set_level(self, level, realms): self.level = level if not self.level: logger.info("- %s", self.get_name()) else: logger.info(" %s %s", '+' * self.level, self.get_name()) self.all_sub_members = [] se...
[ "Set the realm level in the realms hierarchy\n\n :return: None\n " ]
Please provide a description of the function:def get_all_subs_satellites_by_type(self, sat_type, realms): res = copy.copy(getattr(self, sat_type)) for member in self.all_sub_members: res.extend(realms[member].get_all_subs_satellites_by_type(sat_type, realms)) return res
[ "Get all satellites of the wanted type in this realm recursively\n\n :param sat_type: satellite type wanted (scheduler, poller ..)\n :type sat_type:\n :param realms: all realms\n :type realms: list of realm object\n :return: list of satellite in this realm\n :rtype: list\n ...
Please provide a description of the function:def get_satellites_by_type(self, s_type): if hasattr(self, s_type + 's'): return getattr(self, s_type + 's') logger.debug("[realm %s] do not have this kind of satellites: %s", self.name, s_type) return []
[ "Generic function to access one of the satellite attribute\n ie : self.pollers, self.reactionners ...\n\n :param s_type: satellite type wanted\n :type s_type: str\n :return: self.*type*s\n :rtype: list\n " ]
Please provide a description of the function:def get_potential_satellites_by_type(self, satellites, s_type): if not hasattr(self, 'potential_' + s_type + 's'): logger.debug("[realm %s] do not have this kind of satellites: %s", self.name, s_type) return [] matching_satel...
[ "Generic function to access one of the potential satellite attribute\n ie : self.potential_pollers, self.potential_reactionners ...\n\n :param satellites: list of SatelliteLink objects\n :type satellites: SatelliteLink list\n :param s_type: satellite type wanted\n :type s_type: st...
Please provide a description of the function:def get_nb_of_must_have_satellites(self, s_type): if hasattr(self, 'nb_' + s_type + 's'): return getattr(self, 'nb_' + s_type + 's') logger.debug("[realm %s] do not have this kind of satellites: %s", self.name, s_type) return 0
[ "Generic function to access one of the number satellite attribute\n ie : self.nb_pollers, self.nb_reactionners ...\n\n :param s_type: satellite type wanted\n :type s_type: str\n :return: self.nb_*type*s\n :rtype: int\n " ]
Please provide a description of the function:def get_links_for_a_broker(self, pollers, reactionners, receivers, realms, manage_sub_realms=False): # Create void satellite links cfg = { 'pollers': {}, 'reactionners': {}, 'receive...
[ "Get a configuration dictionary with pollers, reactionners and receivers links\n for a broker\n\n :param pollers: pollers\n :type pollers:\n :param reactionners: reactionners\n :type reactionners:\n :param receivers: receivers\n :type receivers:\n :param realm...
Please provide a description of the function:def get_links_for_a_scheduler(self, pollers, reactionners, brokers): # Create void satellite links cfg = { 'pollers': {}, 'reactionners': {}, 'brokers': {}, } # Our self.daemons are only identifie...
[ "Get a configuration dictionary with pollers, reactionners and brokers links\n for a scheduler\n\n :return: dict containing pollers, reactionners and brokers links (key is satellite id)\n :rtype: dict\n " ]
Please provide a description of the function:def linkify(self): logger.info("Known realms:") for realm in self: for tmp_realm in self: # Ignore if it is me... if tmp_realm == realm: continue # Ignore if I am a sub r...
[ "The realms linkify is done during the default realms/satellites initialization in the\n Config class.\n\n This functione only finishes the process by setting the realm level property according\n to the realm position in the hierarchy.\n\n All ` level` 0 realms are main realms that have ...
Please provide a description of the function:def explode(self): # Manage higher realms where defined for realm in [tmp_realm for tmp_realm in self if tmp_realm.higher_realms]: for parent in realm.higher_realms: higher_realm = self.find_by_name(parent) ...
[ "Explode realms with each realm_members and higher_realms to get all the\n realms sub realms.\n\n :return: None\n " ]
Please provide a description of the function:def get_default(self, check=False): found = [] for realm in sorted(self, key=lambda r: r.level): if getattr(realm, 'default', False): found.append(realm) if not found: # Retain as default realm the fir...
[ "Get the default realm\n\n :param check: check correctness if True\n :type check: bool\n :return: Default realm of Alignak configuration\n :rtype: alignak.objects.realm.Realm | None\n " ]
Please provide a description of the function:def reload_configuration(self): # If I'm not the master arbiter, ignore the command and raise a log if not self.app.is_master: message = u"I received a request to reload the monitored configuration. " \ u"I am not th...
[ "Ask to the arbiter to reload the monitored configuration\n\n **Note** tha the arbiter will not reload its main configuration file (eg. alignak.ini)\n but it will reload the monitored objects from the Nagios legacy files or from the\n Alignak backend!\n\n In case of any error, this funct...
Please provide a description of the function:def backend_notification(self, event=None, parameters=None): # request_parameters = cherrypy.request.json # event = request_parameters.get('event', event) # parameters = request_parameters.get('parameters', parameters) if event is Non...
[ "The Alignak backend raises an event to the Alignak arbiter\n -----\n Possible events are:\n - creation, for a realm or an host creation\n - deletion, for a realm or an host deletion\n\n Calls the reload configuration function if event is creation or deletion\n\n Else, noth...
Please provide a description of the function:def command(self, command=None, timestamp=None, element=None, host=None, service=None, user=None, parameters=None): # pylint: disable=too-many-branches if cherrypy.request.method in ["POST"]: if not cherrypy.request.json: ...
[ " Request to execute an external command\n\n Allowed parameters are:\n `command`: mandatory parameter containing the whole command line or only the command name\n\n `timestamp`: optional parameter containing the timestamp. If not present, the\n current timestamp is added in the command l...
Please provide a description of the function:def monitoring_problems(self): res = self.identity() res['problems'] = {} for scheduler_link in self.app.conf.schedulers: sched_res = scheduler_link.con.get('monitoring_problems', wait=True) res['problems'][scheduler_l...
[ "Get Alignak detailed monitoring status\n\n This will return an object containing the properties of the `identity`, plus a `problems`\n object which contains 2 properties for each known scheduler:\n - _freshness, which is the timestamp when the provided data were fetched\n - problems, wh...
Please provide a description of the function:def livesynthesis(self): res = self.identity() res.update(self.app.get_livesynthesis()) return res
[ "Get Alignak live synthesis\n\n This will return an object containing the properties of the `identity`, plus a\n `livesynthesis`\n object which contains 2 properties for each known scheduler:\n - _freshness, which is the timestamp when the provided data were fetched\n - livesynthe...
Please provide a description of the function:def object(self, o_type, o_name=None): for scheduler_link in self.app.conf.schedulers: sched_res = scheduler_link.con.get('object', {'o_type': o_type, 'o_name': o_name}, wait=True) if isi...
[ "Get a monitored object from the arbiter.\n\n Indeed, the arbiter requires the object from its schedulers. It will iterate in\n its schedulers list until a matching object is found. Else it will return a Json\n structure containing _status and _message properties.\n\n When found, the res...
Please provide a description of the function:def dump(self, o_name=None, details=False, raw=False): if details is not False: details = bool(details) if raw is not False: raw = bool(raw) res = {} for scheduler_link in self.app.conf.schedulers: ...
[ "Dump an host (all hosts) from the arbiter.\n\n The arbiter will get the host (all hosts) information from all its schedulers.\n\n This gets the main host information from the scheduler. If details is set, then some\n more information are provided. This will not get all the host known attribute...
Please provide a description of the function:def status(self, details=False): if details is not False: details = bool(details) return self.app.get_alignak_status(details=details)
[ "Get the overall alignak status\n\n Returns a list of the satellites as in:\n {\n services: [\n {\n livestate: {\n perf_data: \"\",\n timestamp: 1532106561,\n state: \"ok\",\n ...
Please provide a description of the function:def events_log(self, details=False, count=0, timestamp=0): if not count: count = 1 + int(os.environ.get('ALIGNAK_EVENTS_LOG_COUNT', self.app.conf.events_log_count)) count = int(count) tim...
[ "Get the most recent Alignak events\n\n If count is specifies it is the maximum number of events to return.\n\n If timestamp is specified, events older than this timestamp will not be returned\n\n The arbiter maintains a list of the most recent Alignak events. This endpoint\n provides th...
Please provide a description of the function:def satellites_list(self, daemon_type=''): with self.app.conf_lock: res = {} for s_type in ['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']: if daemon_type and daemon_type != s_type: ...
[ "Get the arbiter satellite names sorted by type\n\n Returns a list of the satellites as in:\n {\n reactionner: [\n \"reactionner-master\"\n ],\n broker: [\n \"broker-master\"\n ],\n arbiter: [\n \"arbit...
Please provide a description of the function:def realms(self, details=False): def get_realm_info(realm, realms, satellites, details=False): res = { "name": realm.get_name(), "level": realm.level, "hosts": realm.members, ...
[ "Return the realms / satellites configuration\n\n Returns an object containing the hierarchical realms configuration with the main\n information about each realm:\n {\n All: {\n satellites: {\n pollers: [\n \"poller-master\"\n ...
Please provide a description of the function:def satellites_configuration(self): res = {} for s_type in ['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']: lst = [] res[s_type] = lst for daemon in getattr(self.app.c...
[ "Return all the configuration data of satellites\n\n :return: dict containing satellites data\n Output looks like this ::\n\n {'arbiter' : [{'property1':'value1' ..}, {'property2', 'value11' ..}, ..],\n 'scheduler': [..],\n 'poller': [..],\n 'reactionner': [..],\n 'r...
Please provide a description of the function:def external_commands(self): res = [] with self.app.external_commands_lock: for cmd in self.app.get_external_commands(): res.append(cmd.serialize()) return res
[ "Get the external commands from the daemon\n\n Use a lock for this function to protect\n\n :return: serialized external command list\n :rtype: str\n " ]
Please provide a description of the function:def search(self): # pylint: disable=no-self-use logger.debug("Grafana search... %s", cherrypy.request.method) if cherrypy.request.method == 'OPTIONS': cherrypy.response.headers['Access-Control-Allow-Methods'] = 'GET,POST,PATCH,PUT,DELETE...
[ "\n Request available queries\n\n Posted data: {u'target': u''}\n\n Return the list of available target queries\n\n :return: See upper comment\n :rtype: list\n " ]
Please provide a description of the function:def query(self): logger.debug("Grafana query... %s", cherrypy.request.method) if cherrypy.request.method == 'OPTIONS': cherrypy.response.headers['Access-Control-Allow-Methods'] = 'GET,POST,PATCH,PUT,DELETE' cherrypy.response.h...
[ "\n Request object passed to datasource.query function:\n\n {\n 'timezone': 'browser',\n 'panelId': 38,\n 'range': {\n 'from': '2018-08-29T02:38:09.633Z',\n 'to': '2018-08-29T03:38:09.633Z',\n 'raw': {'from': 'now-1h', 'to':...
Please provide a description of the function:def _build_host_livestate(self, host_name, livestate): # pylint: disable=no-self-use, too-many-locals state = livestate.get('state', 'UP').upper() output = livestate.get('output', '') long_output = livestate.get('long_output', '') ...
[ "Build and notify the external command for an host livestate\n\n PROCESS_HOST_CHECK_RESULT;<host_name>;<status_code>;<plugin_output>\n\n :param host_name: the concerned host name\n :param livestate: livestate dictionary\n :return: external command line\n " ]
Please provide a description of the function:def _build_service_livestate(self, host_name, service_name, livestate): # pylint: disable=no-self-use, too-many-locals state = livestate.get('state', 'OK').upper() output = livestate.get('output', '') long_output = livestate.get('long...
[ "Build and notify the external command for a service livestate\n\n PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<return_code>;<plugin_output>\n\n Create and post a logcheckresult to the backend for the livestate\n\n :param host_name: the concerned host name\n :param ser...
Please provide a description of the function:def host(self): # pylint: disable=too-many-branches logger.debug("Host status...") if cherrypy.request.method not in ["PATCH", "POST"]: cherrypy.response.status = 405 return {'_status': 'ERR', '_err...
[ "Get a passive checks for an host and its services\n\n This function builds the external commands corresponding to the host and services\n provided information\n\n :param host_name: host name\n :param data: dictionary of the host properties to be modified\n :return: command line\n...
Please provide a description of the function:def _wait_new_conf(self): with self.app.conf_lock: logger.warning("My master Arbiter wants me to wait for a new configuration.") self.app.cur_conf = {}
[ "Ask the daemon to drop its configuration and wait for a new one\n\n This overrides the default method from GenericInterface\n\n :return: None\n " ]
Please provide a description of the function:def _push_configuration(self, pushed_configuration=None): pushed_configuration = cherrypy.request.json self.app.must_run = False return super(ArbiterInterface, self)._push_configuration( pushed_configuration=pushed_configuration['...
[ "Send a new configuration to the daemon\n\n This overrides the default method from GenericInterface\n\n Used by the master arbiter to send its configuration to a spare arbiter\n\n This function is not intended for external use. It is quite complex to\n build a configuration for a daemon ...