id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
21,100
Alignak-monitoring/alignak
alignak/daemons/receiverdaemon.py
Receiver.get_external_commands_from_arbiters
def get_external_commands_from_arbiters(self): """Get external commands from our arbiters As of now, only the arbiter are requested to provide their external commands that the receiver will push to all the known schedulers to make them being executed. :return: None """ for arbiter_link_uuid in self.arbiters: link = self.arbiters[arbiter_link_uuid] if not link.active: logger.debug("The arbiter '%s' is not active, it is not possible to get " "its external commands!", link.name) continue try: logger.debug("Getting external commands from: %s", link.name) external_commands = link.get_external_commands() if external_commands: logger.debug("Got %d commands from: %s", len(external_commands), link.name) else: # Simple protection against None value external_commands = [] for external_command in external_commands: self.add(external_command) except LinkError: logger.warning("Arbiter connection failed, I could not get external commands!") except Exception as exp: # pylint: disable=broad-except logger.error("Arbiter connection failed, I could not get external commands!") logger.exception("Exception: %s", exp)
python
def get_external_commands_from_arbiters(self): for arbiter_link_uuid in self.arbiters: link = self.arbiters[arbiter_link_uuid] if not link.active: logger.debug("The arbiter '%s' is not active, it is not possible to get " "its external commands!", link.name) continue try: logger.debug("Getting external commands from: %s", link.name) external_commands = link.get_external_commands() if external_commands: logger.debug("Got %d commands from: %s", len(external_commands), link.name) else: # Simple protection against None value external_commands = [] for external_command in external_commands: self.add(external_command) except LinkError: logger.warning("Arbiter connection failed, I could not get external commands!") except Exception as exp: # pylint: disable=broad-except logger.error("Arbiter connection failed, I could not get external commands!") logger.exception("Exception: %s", exp)
[ "def", "get_external_commands_from_arbiters", "(", "self", ")", ":", "for", "arbiter_link_uuid", "in", "self", ".", "arbiters", ":", "link", "=", "self", ".", "arbiters", "[", "arbiter_link_uuid", "]", "if", "not", "link", ".", "active", ":", "logger", ".", ...
Get external commands from our arbiters As of now, only the arbiter are requested to provide their external commands that the receiver will push to all the known schedulers to make them being executed. :return: None
[ "Get", "external", "commands", "from", "our", "arbiters" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/receiverdaemon.py#L212-L242
21,101
Alignak-monitoring/alignak
alignak/daemons/receiverdaemon.py
Receiver.push_external_commands_to_schedulers
def push_external_commands_to_schedulers(self): """Push received external commands to the schedulers :return: None """ if not self.unprocessed_external_commands: return # Those are the global external commands commands_to_process = self.unprocessed_external_commands self.unprocessed_external_commands = [] logger.debug("Commands: %s", commands_to_process) # Now get all external commands and put them into the good schedulers logger.debug("Commands to process: %d commands", len(commands_to_process)) for ext_cmd in commands_to_process: cmd = self.external_commands_manager.resolve_command(ext_cmd) logger.debug("Resolved command: %s, result: %s", ext_cmd.cmd_line, cmd) if cmd and cmd['global']: # Send global command to all our schedulers for scheduler_link_uuid in self.schedulers: self.schedulers[scheduler_link_uuid].pushed_commands.append(ext_cmd) # Now for all active schedulers, send the commands count_pushed_commands = 0 count_failed_commands = 0 for scheduler_link_uuid in self.schedulers: link = self.schedulers[scheduler_link_uuid] if not link.active: logger.debug("The scheduler '%s' is not active, it is not possible to push " "external commands to its connection!", link.name) continue # If there are some commands for this scheduler... commands = [ext_cmd.cmd_line for ext_cmd in link.pushed_commands] if not commands: logger.debug("The scheduler '%s' has no commands.", link.name) continue logger.debug("Sending %d commands to scheduler %s", len(commands), link.name) sent = [] try: sent = link.push_external_commands(commands) except LinkError: logger.warning("Scheduler connection failed, I could not push external commands!") # Whether we sent the commands or not, clean the scheduler list link.pushed_commands = [] # If we didn't sent them, add the commands to the arbiter list if sent: statsmgr.gauge('external-commands.pushed.%s' % link.name, len(commands)) count_pushed_commands = count_pushed_commands + len(commands) else: count_failed_commands = count_failed_commands + len(commands) statsmgr.gauge('external-commands.failed.%s' % link.name, len(commands)) # Kepp the not sent commands... for a next try self.external_commands.extend(commands) statsmgr.gauge('external-commands.pushed.all', count_pushed_commands) statsmgr.gauge('external-commands.failed.all', count_failed_commands)
python
def push_external_commands_to_schedulers(self): if not self.unprocessed_external_commands: return # Those are the global external commands commands_to_process = self.unprocessed_external_commands self.unprocessed_external_commands = [] logger.debug("Commands: %s", commands_to_process) # Now get all external commands and put them into the good schedulers logger.debug("Commands to process: %d commands", len(commands_to_process)) for ext_cmd in commands_to_process: cmd = self.external_commands_manager.resolve_command(ext_cmd) logger.debug("Resolved command: %s, result: %s", ext_cmd.cmd_line, cmd) if cmd and cmd['global']: # Send global command to all our schedulers for scheduler_link_uuid in self.schedulers: self.schedulers[scheduler_link_uuid].pushed_commands.append(ext_cmd) # Now for all active schedulers, send the commands count_pushed_commands = 0 count_failed_commands = 0 for scheduler_link_uuid in self.schedulers: link = self.schedulers[scheduler_link_uuid] if not link.active: logger.debug("The scheduler '%s' is not active, it is not possible to push " "external commands to its connection!", link.name) continue # If there are some commands for this scheduler... commands = [ext_cmd.cmd_line for ext_cmd in link.pushed_commands] if not commands: logger.debug("The scheduler '%s' has no commands.", link.name) continue logger.debug("Sending %d commands to scheduler %s", len(commands), link.name) sent = [] try: sent = link.push_external_commands(commands) except LinkError: logger.warning("Scheduler connection failed, I could not push external commands!") # Whether we sent the commands or not, clean the scheduler list link.pushed_commands = [] # If we didn't sent them, add the commands to the arbiter list if sent: statsmgr.gauge('external-commands.pushed.%s' % link.name, len(commands)) count_pushed_commands = count_pushed_commands + len(commands) else: count_failed_commands = count_failed_commands + len(commands) statsmgr.gauge('external-commands.failed.%s' % link.name, len(commands)) # Kepp the not sent commands... for a next try self.external_commands.extend(commands) statsmgr.gauge('external-commands.pushed.all', count_pushed_commands) statsmgr.gauge('external-commands.failed.all', count_failed_commands)
[ "def", "push_external_commands_to_schedulers", "(", "self", ")", ":", "if", "not", "self", ".", "unprocessed_external_commands", ":", "return", "# Those are the global external commands", "commands_to_process", "=", "self", ".", "unprocessed_external_commands", "self", ".", ...
Push received external commands to the schedulers :return: None
[ "Push", "received", "external", "commands", "to", "the", "schedulers" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/receiverdaemon.py#L244-L305
21,102
Alignak-monitoring/alignak
alignak/daemons/receiverdaemon.py
Receiver.do_loop_turn
def do_loop_turn(self): """Receiver daemon main loop :return: None """ # Begin to clean modules self.check_and_del_zombie_modules() # Maybe the arbiter pushed a new configuration... if self.watch_for_new_conf(timeout=0.05): logger.info("I got a new configuration...") # Manage the new configuration self.setup_new_conf() # Maybe external modules raised 'objects' # we should get them _t0 = time.time() self.get_objects_from_from_queues() statsmgr.timer('core.get-objects-from-queues', time.time() - _t0) # Get external commands from the arbiters... _t0 = time.time() self.get_external_commands_from_arbiters() statsmgr.timer('external-commands.got.time', time.time() - _t0) statsmgr.gauge('external-commands.got.count', len(self.unprocessed_external_commands)) _t0 = time.time() self.push_external_commands_to_schedulers() statsmgr.timer('external-commands.pushed.time', time.time() - _t0) # Say to modules it's a new tick :) _t0 = time.time() self.hook_point('tick') statsmgr.timer('hook.tick', time.time() - _t0)
python
def do_loop_turn(self): # Begin to clean modules self.check_and_del_zombie_modules() # Maybe the arbiter pushed a new configuration... if self.watch_for_new_conf(timeout=0.05): logger.info("I got a new configuration...") # Manage the new configuration self.setup_new_conf() # Maybe external modules raised 'objects' # we should get them _t0 = time.time() self.get_objects_from_from_queues() statsmgr.timer('core.get-objects-from-queues', time.time() - _t0) # Get external commands from the arbiters... _t0 = time.time() self.get_external_commands_from_arbiters() statsmgr.timer('external-commands.got.time', time.time() - _t0) statsmgr.gauge('external-commands.got.count', len(self.unprocessed_external_commands)) _t0 = time.time() self.push_external_commands_to_schedulers() statsmgr.timer('external-commands.pushed.time', time.time() - _t0) # Say to modules it's a new tick :) _t0 = time.time() self.hook_point('tick') statsmgr.timer('hook.tick', time.time() - _t0)
[ "def", "do_loop_turn", "(", "self", ")", ":", "# Begin to clean modules", "self", ".", "check_and_del_zombie_modules", "(", ")", "# Maybe the arbiter pushed a new configuration...", "if", "self", ".", "watch_for_new_conf", "(", "timeout", "=", "0.05", ")", ":", "logger"...
Receiver daemon main loop :return: None
[ "Receiver", "daemon", "main", "loop" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/receiverdaemon.py#L307-L341
21,103
Alignak-monitoring/alignak
alignak/check.py
Check.serialize
def serialize(self): """This function serializes into a simple dict object. The only usage is to send to poller, and it does not need to have the depend_on and depend_on_me properties. :return: json representation of a Check :rtype: dict """ res = super(Check, self).serialize() if 'depend_on' in res: del res['depend_on'] if 'depend_on_me' in res: del res['depend_on_me'] return res
python
def serialize(self): res = super(Check, self).serialize() if 'depend_on' in res: del res['depend_on'] if 'depend_on_me' in res: del res['depend_on_me'] return res
[ "def", "serialize", "(", "self", ")", ":", "res", "=", "super", "(", "Check", ",", "self", ")", ".", "serialize", "(", ")", "if", "'depend_on'", "in", "res", ":", "del", "res", "[", "'depend_on'", "]", "if", "'depend_on_me'", "in", "res", ":", "del",...
This function serializes into a simple dict object. The only usage is to send to poller, and it does not need to have the depend_on and depend_on_me properties. :return: json representation of a Check :rtype: dict
[ "This", "function", "serializes", "into", "a", "simple", "dict", "object", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/check.py#L136-L150
21,104
Alignak-monitoring/alignak
alignak/alignakobject.py
AlignakObject.serialize
def serialize(self): """This function serializes into a simple dictionary object. It is used when transferring data to other daemons over the network (http) Here is the generic function that simply export attributes declared in the properties dictionary of the object. Note that a SetProp property will be serialized as a list. :return: Dictionary containing key and value from properties :rtype: dict """ # uuid is not in *_properties res = { 'uuid': self.uuid } for prop in self.__class__.properties: if not hasattr(self, prop): continue res[prop] = getattr(self, prop) if isinstance(self.__class__.properties[prop], SetProp): res[prop] = list(getattr(self, prop)) return res
python
def serialize(self): # uuid is not in *_properties res = { 'uuid': self.uuid } for prop in self.__class__.properties: if not hasattr(self, prop): continue res[prop] = getattr(self, prop) if isinstance(self.__class__.properties[prop], SetProp): res[prop] = list(getattr(self, prop)) return res
[ "def", "serialize", "(", "self", ")", ":", "# uuid is not in *_properties", "res", "=", "{", "'uuid'", ":", "self", ".", "uuid", "}", "for", "prop", "in", "self", ".", "__class__", ".", "properties", ":", "if", "not", "hasattr", "(", "self", ",", "prop",...
This function serializes into a simple dictionary object. It is used when transferring data to other daemons over the network (http) Here is the generic function that simply export attributes declared in the properties dictionary of the object. Note that a SetProp property will be serialized as a list. :return: Dictionary containing key and value from properties :rtype: dict
[ "This", "function", "serializes", "into", "a", "simple", "dictionary", "object", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/alignakobject.py#L92-L117
21,105
Alignak-monitoring/alignak
alignak/alignakobject.py
AlignakObject.fill_default
def fill_default(self): """ Define the object properties with a default value when the property is not yet defined :return: None """ for prop, entry in self.__class__.properties.items(): if hasattr(self, prop): continue if not hasattr(entry, 'default') or entry.default is NONE_OBJECT: continue if hasattr(entry.default, '__iter__'): setattr(self, prop, copy(entry.default)) else: setattr(self, prop, entry.default)
python
def fill_default(self): for prop, entry in self.__class__.properties.items(): if hasattr(self, prop): continue if not hasattr(entry, 'default') or entry.default is NONE_OBJECT: continue if hasattr(entry.default, '__iter__'): setattr(self, prop, copy(entry.default)) else: setattr(self, prop, entry.default)
[ "def", "fill_default", "(", "self", ")", ":", "for", "prop", ",", "entry", "in", "self", ".", "__class__", ".", "properties", ".", "items", "(", ")", ":", "if", "hasattr", "(", "self", ",", "prop", ")", ":", "continue", "if", "not", "hasattr", "(", ...
Define the object properties with a default value when the property is not yet defined :return: None
[ "Define", "the", "object", "properties", "with", "a", "default", "value", "when", "the", "property", "is", "not", "yet", "defined" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/alignakobject.py#L119-L134
21,106
Alignak-monitoring/alignak
alignak/objects/host.py
Host.fill_predictive_missing_parameters
def fill_predictive_missing_parameters(self): """Fill address with host_name if not already set and define state with initial_state :return: None """ if hasattr(self, 'host_name') and not hasattr(self, 'address'): self.address = self.host_name if hasattr(self, 'host_name') and not hasattr(self, 'alias'): self.alias = self.host_name if self.initial_state == 'd': self.state = 'DOWN' elif self.initial_state == 'x': self.state = 'UNREACHABLE'
python
def fill_predictive_missing_parameters(self): if hasattr(self, 'host_name') and not hasattr(self, 'address'): self.address = self.host_name if hasattr(self, 'host_name') and not hasattr(self, 'alias'): self.alias = self.host_name if self.initial_state == 'd': self.state = 'DOWN' elif self.initial_state == 'x': self.state = 'UNREACHABLE'
[ "def", "fill_predictive_missing_parameters", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "'host_name'", ")", "and", "not", "hasattr", "(", "self", ",", "'address'", ")", ":", "self", ".", "address", "=", "self", ".", "host_name", "if", "hasat...
Fill address with host_name if not already set and define state with initial_state :return: None
[ "Fill", "address", "with", "host_name", "if", "not", "already", "set", "and", "define", "state", "with", "initial_state" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L304-L317
21,107
Alignak-monitoring/alignak
alignak/objects/host.py
Host.get_groupnames
def get_groupnames(self, hostgroups): """Get names of the host's hostgroups :return: comma separated names of hostgroups alphabetically sorted :rtype: str """ group_names = [] for hostgroup_id in self.hostgroups: hostgroup = hostgroups[hostgroup_id] group_names.append(hostgroup.get_name()) return ','.join(sorted(group_names))
python
def get_groupnames(self, hostgroups): group_names = [] for hostgroup_id in self.hostgroups: hostgroup = hostgroups[hostgroup_id] group_names.append(hostgroup.get_name()) return ','.join(sorted(group_names))
[ "def", "get_groupnames", "(", "self", ",", "hostgroups", ")", ":", "group_names", "=", "[", "]", "for", "hostgroup_id", "in", "self", ".", "hostgroups", ":", "hostgroup", "=", "hostgroups", "[", "hostgroup_id", "]", "group_names", ".", "append", "(", "hostgr...
Get names of the host's hostgroups :return: comma separated names of hostgroups alphabetically sorted :rtype: str
[ "Get", "names", "of", "the", "host", "s", "hostgroups" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L408-L418
21,108
Alignak-monitoring/alignak
alignak/objects/host.py
Host.get_groupaliases
def get_groupaliases(self, hostgroups): """Get aliases of the host's hostgroups :return: comma separated aliases of hostgroups alphabetically sorted :rtype: str """ group_aliases = [] for hostgroup_id in self.hostgroups: hostgroup = hostgroups[hostgroup_id] group_aliases.append(hostgroup.alias) return ','.join(sorted(group_aliases))
python
def get_groupaliases(self, hostgroups): group_aliases = [] for hostgroup_id in self.hostgroups: hostgroup = hostgroups[hostgroup_id] group_aliases.append(hostgroup.alias) return ','.join(sorted(group_aliases))
[ "def", "get_groupaliases", "(", "self", ",", "hostgroups", ")", ":", "group_aliases", "=", "[", "]", "for", "hostgroup_id", "in", "self", ".", "hostgroups", ":", "hostgroup", "=", "hostgroups", "[", "hostgroup_id", "]", "group_aliases", ".", "append", "(", "...
Get aliases of the host's hostgroups :return: comma separated aliases of hostgroups alphabetically sorted :rtype: str
[ "Get", "aliases", "of", "the", "host", "s", "hostgroups" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L420-L430
21,109
Alignak-monitoring/alignak
alignak/objects/host.py
Host.set_state_from_exit_status
def set_state_from_exit_status(self, status, notif_period, hosts, services): """Set the state in UP, DOWN, or UNREACHABLE according to the status of a check result. :param status: integer between 0 and 3 (but not 1) :type status: int :return: None """ now = time.time() # we should put in last_state the good last state: # if not just change the state by an problem/impact # we can take current state. But if it's the case, the # real old state is self.state_before_impact (it's the TRUE # state in fact) # And only if we enable the impact state change cls = self.__class__ if (cls.enable_problem_impacts_states_change and self.is_impact and not self.state_changed_since_impact): self.last_state = self.state_before_impact else: self.last_state = self.state # There is no 1 case because it should have been managed by the caller for a host # like the schedulingitem::consume method. if status == 0: self.state = u'UP' self.state_id = 0 self.last_time_up = int(self.last_state_update) # self.last_time_up = self.last_state_update state_code = 'u' elif status in (2, 3): self.state = u'DOWN' self.state_id = 1 self.last_time_down = int(self.last_state_update) # self.last_time_down = self.last_state_update state_code = 'd' elif status == 4: self.state = u'UNREACHABLE' self.state_id = 4 self.last_time_unreachable = int(self.last_state_update) # self.last_time_unreachable = self.last_state_update state_code = 'x' else: self.state = u'DOWN' # exit code UNDETERMINED self.state_id = 1 # self.last_time_down = int(self.last_state_update) self.last_time_down = self.last_state_update state_code = 'd' if state_code in self.flap_detection_options: self.add_flapping_change(self.state != self.last_state) # Now we add a value, we update the is_flapping prop self.update_flapping(notif_period, hosts, services) if self.state != self.last_state and \ not (self.state == "DOWN" and self.last_state == "UNREACHABLE"): self.last_state_change = self.last_state_update self.duration_sec = now - self.last_state_change
python
def set_state_from_exit_status(self, status, notif_period, hosts, services): now = time.time() # we should put in last_state the good last state: # if not just change the state by an problem/impact # we can take current state. But if it's the case, the # real old state is self.state_before_impact (it's the TRUE # state in fact) # And only if we enable the impact state change cls = self.__class__ if (cls.enable_problem_impacts_states_change and self.is_impact and not self.state_changed_since_impact): self.last_state = self.state_before_impact else: self.last_state = self.state # There is no 1 case because it should have been managed by the caller for a host # like the schedulingitem::consume method. if status == 0: self.state = u'UP' self.state_id = 0 self.last_time_up = int(self.last_state_update) # self.last_time_up = self.last_state_update state_code = 'u' elif status in (2, 3): self.state = u'DOWN' self.state_id = 1 self.last_time_down = int(self.last_state_update) # self.last_time_down = self.last_state_update state_code = 'd' elif status == 4: self.state = u'UNREACHABLE' self.state_id = 4 self.last_time_unreachable = int(self.last_state_update) # self.last_time_unreachable = self.last_state_update state_code = 'x' else: self.state = u'DOWN' # exit code UNDETERMINED self.state_id = 1 # self.last_time_down = int(self.last_state_update) self.last_time_down = self.last_state_update state_code = 'd' if state_code in self.flap_detection_options: self.add_flapping_change(self.state != self.last_state) # Now we add a value, we update the is_flapping prop self.update_flapping(notif_period, hosts, services) if self.state != self.last_state and \ not (self.state == "DOWN" and self.last_state == "UNREACHABLE"): self.last_state_change = self.last_state_update self.duration_sec = now - self.last_state_change
[ "def", "set_state_from_exit_status", "(", "self", ",", "status", ",", "notif_period", ",", "hosts", ",", "services", ")", ":", "now", "=", "time", ".", "time", "(", ")", "# we should put in last_state the good last state:", "# if not just change the state by an problem/im...
Set the state in UP, DOWN, or UNREACHABLE according to the status of a check result. :param status: integer between 0 and 3 (but not 1) :type status: int :return: None
[ "Set", "the", "state", "in", "UP", "DOWN", "or", "UNREACHABLE", "according", "to", "the", "status", "of", "a", "check", "result", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L492-L548
21,110
Alignak-monitoring/alignak
alignak/objects/host.py
Host.is_state
def is_state(self, status): """Return if status match the current host status :param status: status to compare ( "o", "d", "x"). Usually comes from config files :type status: str :return: True if status <=> self.status, otherwise False :rtype: bool """ if status == self.state: return True # Now low status if status == 'o' and self.state == u'UP': return True if status == 'd' and self.state == u'DOWN': return True if status in ['u', 'x'] and self.state == u'UNREACHABLE': return True return False
python
def is_state(self, status): if status == self.state: return True # Now low status if status == 'o' and self.state == u'UP': return True if status == 'd' and self.state == u'DOWN': return True if status in ['u', 'x'] and self.state == u'UNREACHABLE': return True return False
[ "def", "is_state", "(", "self", ",", "status", ")", ":", "if", "status", "==", "self", ".", "state", ":", "return", "True", "# Now low status", "if", "status", "==", "'o'", "and", "self", ".", "state", "==", "u'UP'", ":", "return", "True", "if", "statu...
Return if status match the current host status :param status: status to compare ( "o", "d", "x"). Usually comes from config files :type status: str :return: True if status <=> self.status, otherwise False :rtype: bool
[ "Return", "if", "status", "match", "the", "current", "host", "status" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L550-L567
21,111
Alignak-monitoring/alignak
alignak/objects/host.py
Host.last_time_non_ok_or_up
def last_time_non_ok_or_up(self): """Get the last time the host was in a non-OK state :return: self.last_time_down if self.last_time_down > self.last_time_up, 0 otherwise :rtype: int """ non_ok_times = [x for x in [self.last_time_down] if x > self.last_time_up] if not non_ok_times: last_time_non_ok = 0 # todo: program_start would be better? else: last_time_non_ok = min(non_ok_times) return last_time_non_ok
python
def last_time_non_ok_or_up(self): non_ok_times = [x for x in [self.last_time_down] if x > self.last_time_up] if not non_ok_times: last_time_non_ok = 0 # todo: program_start would be better? else: last_time_non_ok = min(non_ok_times) return last_time_non_ok
[ "def", "last_time_non_ok_or_up", "(", "self", ")", ":", "non_ok_times", "=", "[", "x", "for", "x", "in", "[", "self", ".", "last_time_down", "]", "if", "x", ">", "self", ".", "last_time_up", "]", "if", "not", "non_ok_times", ":", "last_time_non_ok", "=", ...
Get the last time the host was in a non-OK state :return: self.last_time_down if self.last_time_down > self.last_time_up, 0 otherwise :rtype: int
[ "Get", "the", "last", "time", "the", "host", "was", "in", "a", "non", "-", "OK", "state" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L569-L581
21,112
Alignak-monitoring/alignak
alignak/objects/host.py
Host.notification_is_blocked_by_contact
def notification_is_blocked_by_contact(self, notifways, timeperiods, notif, contact): """Check if the notification is blocked by this contact. :param notif: notification created earlier :type notif: alignak.notification.Notification :param contact: contact we want to notify :type notif: alignak.objects.contact.Contact :return: True if the notification is blocked, False otherwise :rtype: bool """ return not contact.want_host_notification(notifways, timeperiods, self.last_chk, self.state, notif.type, self.business_impact, notif.command_call)
python
def notification_is_blocked_by_contact(self, notifways, timeperiods, notif, contact): return not contact.want_host_notification(notifways, timeperiods, self.last_chk, self.state, notif.type, self.business_impact, notif.command_call)
[ "def", "notification_is_blocked_by_contact", "(", "self", ",", "notifways", ",", "timeperiods", ",", "notif", ",", "contact", ")", ":", "return", "not", "contact", ".", "want_host_notification", "(", "notifways", ",", "timeperiods", ",", "self", ".", "last_chk", ...
Check if the notification is blocked by this contact. :param notif: notification created earlier :type notif: alignak.notification.Notification :param contact: contact we want to notify :type notif: alignak.objects.contact.Contact :return: True if the notification is blocked, False otherwise :rtype: bool
[ "Check", "if", "the", "notification", "is", "blocked", "by", "this", "contact", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L914-L926
21,113
Alignak-monitoring/alignak
alignak/objects/host.py
Host._tot_services_by_state
def _tot_services_by_state(self, services, state): """Get the number of service in the specified state :param state: state to filter service :type state: :return: number of service with s.state_id == state :rtype: int """ return str(sum(1 for s in self.services if services[s].state_id == state))
python
def _tot_services_by_state(self, services, state): return str(sum(1 for s in self.services if services[s].state_id == state))
[ "def", "_tot_services_by_state", "(", "self", ",", "services", ",", "state", ")", ":", "return", "str", "(", "sum", "(", "1", "for", "s", "in", "self", ".", "services", "if", "services", "[", "s", "]", ".", "state_id", "==", "state", ")", ")" ]
Get the number of service in the specified state :param state: state to filter service :type state: :return: number of service with s.state_id == state :rtype: int
[ "Get", "the", "number", "of", "service", "in", "the", "specified", "state" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L1095-L1104
21,114
Alignak-monitoring/alignak
alignak/objects/host.py
Host.get_overall_state
def get_overall_state(self, services): """Get the host overall state including the host self status and the status of its services Compute the host overall state identifier, including: - the acknowledged state - the downtime state The host overall state is (prioritized): - an host not monitored (5) - an host down (4) - an host unreachable (3) - an host downtimed (2) - an host acknowledged (1) - an host up (0) If the host overall state is <= 2, then the host overall state is the maximum value of the host overall state and all the host services overall states. The overall state of an host is: - 0 if the host is UP and all its services are OK - 1 if the host is DOWN or UNREACHABLE and acknowledged or at least one of its services is acknowledged and no other services are WARNING or CRITICAL - 2 if the host is DOWN or UNREACHABLE and in a scheduled downtime or at least one of its services is in a scheduled downtime and no other services are WARNING or CRITICAL - 3 if the host is UNREACHABLE or at least one of its services is WARNING - 4 if the host is DOWN or at least one of its services is CRITICAL - 5 if the host is not monitored :param services: a list of known services :type services: alignak.objects.service.Services :return: the host overall state :rtype: int """ overall_state = 0 if not self.monitored: overall_state = 5 elif self.acknowledged: overall_state = 1 elif self.downtimed: overall_state = 2 elif self.state_type == 'HARD': if self.state == 'UNREACHABLE': overall_state = 3 elif self.state == 'DOWN': overall_state = 4 # Only consider the hosts services state if all is ok (or almost...) if overall_state <= 2: for service in self.services: if service in services: service = services[service] # Only for monitored services if service.overall_state_id < 5: overall_state = max(overall_state, service.overall_state_id) return overall_state
python
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.state_type == 'HARD': if self.state == 'UNREACHABLE': overall_state = 3 elif self.state == 'DOWN': overall_state = 4 # Only consider the hosts services state if all is ok (or almost...) if overall_state <= 2: for service in self.services: if service in services: service = services[service] # Only for monitored services if service.overall_state_id < 5: overall_state = max(overall_state, service.overall_state_id) return overall_state
[ "def", "get_overall_state", "(", "self", ",", "services", ")", ":", "overall_state", "=", "0", "if", "not", "self", ".", "monitored", ":", "overall_state", "=", "5", "elif", "self", ".", "acknowledged", ":", "overall_state", "=", "1", "elif", "self", ".", ...
Get the host overall state including the host self status and the status of its services Compute the host overall state identifier, including: - the acknowledged state - the downtime state The host overall state is (prioritized): - an host not monitored (5) - an host down (4) - an host unreachable (3) - an host downtimed (2) - an host acknowledged (1) - an host up (0) If the host overall state is <= 2, then the host overall state is the maximum value of the host overall state and all the host services overall states. The overall state of an host is: - 0 if the host is UP and all its services are OK - 1 if the host is DOWN or UNREACHABLE and acknowledged or at least one of its services is acknowledged and no other services are WARNING or CRITICAL - 2 if the host is DOWN or UNREACHABLE and in a scheduled downtime or at least one of its services is in a scheduled downtime and no other services are WARNING or CRITICAL - 3 if the host is UNREACHABLE or at least one of its services is WARNING - 4 if the host is DOWN or at least one of its services is CRITICAL - 5 if the host is not monitored :param services: a list of known services :type services: alignak.objects.service.Services :return: the host overall state :rtype: int
[ "Get", "the", "host", "overall", "state", "including", "the", "host", "self", "status", "and", "the", "status", "of", "its", "services" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L1236-L1298
21,115
Alignak-monitoring/alignak
alignak/objects/host.py
Hosts.linkify_h_by_h
def linkify_h_by_h(self): """Link hosts with their parents :return: None """ 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) if o_parent is not None: new_parents.append(o_parent.uuid) else: err = "the parent '%s' for the host '%s' is unknown!" % (parent, host.get_name()) self.add_error(err) # We find the id, we replace the names host.parents = new_parents
python
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) if o_parent is not None: new_parents.append(o_parent.uuid) else: err = "the parent '%s' for the host '%s' is unknown!" % (parent, host.get_name()) self.add_error(err) # We find the id, we replace the names host.parents = new_parents
[ "def", "linkify_h_by_h", "(", "self", ")", ":", "for", "host", "in", "self", ":", "# The new member list", "new_parents", "=", "[", "]", "for", "parent", "in", "getattr", "(", "host", ",", "'parents'", ",", "[", "]", ")", ":", "parent", "=", "parent", ...
Link hosts with their parents :return: None
[ "Link", "hosts", "with", "their", "parents" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L1372-L1390
21,116
Alignak-monitoring/alignak
alignak/objects/host.py
Hosts.linkify_h_by_hg
def linkify_h_by_hg(self, hostgroups): """Link hosts with hostgroups :param hostgroups: hostgroups object to link with :type hostgroups: alignak.objects.hostgroup.Hostgroups :return: None """ # 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 if n.strip()] for hg_name in hgs: # TODO: should an unknown hostgroup raise an error ? hostgroup = hostgroups.find_by_name(hg_name) if hostgroup is not None: new_hostgroups.append(hostgroup.uuid) else: err = ("the hostgroup '%s' of the host '%s' is " "unknown" % (hg_name, host.host_name)) host.add_error(err) host.hostgroups = new_hostgroups
python
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 if n.strip()] for hg_name in hgs: # TODO: should an unknown hostgroup raise an error ? hostgroup = hostgroups.find_by_name(hg_name) if hostgroup is not None: new_hostgroups.append(hostgroup.uuid) else: err = ("the hostgroup '%s' of the host '%s' is " "unknown" % (hg_name, host.host_name)) host.add_error(err) host.hostgroups = new_hostgroups
[ "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"...
Link hosts with hostgroups :param hostgroups: hostgroups object to link with :type hostgroups: alignak.objects.hostgroup.Hostgroups :return: None
[ "Link", "hosts", "with", "hostgroups" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L1415-L1436
21,117
Alignak-monitoring/alignak
alignak/objects/host.py
Hosts.apply_dependencies
def apply_dependencies(self): """Loop on hosts and register dependency between parent and son call Host.fill_parents_dependency() :return: None """ 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_enabled: # Add parent in the list host.act_depend_of.append((parent_id, ['d', 'x', 's', 'f'], '', True)) # Add child in the parent parent.act_depend_of_me.append((host.uuid, ['d', 'x', 's', 'f'], '', True)) # And add the parent/child dep filling too, for broking parent.child_dependencies.add(host.uuid) host.parent_dependencies.add(parent_id)
python
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_enabled: # Add parent in the list host.act_depend_of.append((parent_id, ['d', 'x', 's', 'f'], '', True)) # Add child in the parent parent.act_depend_of_me.append((host.uuid, ['d', 'x', 's', 'f'], '', True)) # And add the parent/child dep filling too, for broking parent.child_dependencies.add(host.uuid) host.parent_dependencies.add(parent_id)
[ "def", "apply_dependencies", "(", "self", ")", ":", "for", "host", "in", "self", ":", "for", "parent_id", "in", "getattr", "(", "host", ",", "'parents'", ",", "[", "]", ")", ":", "if", "parent_id", "is", "None", ":", "continue", "parent", "=", "self", ...
Loop on hosts and register dependency between parent and son call Host.fill_parents_dependency() :return: None
[ "Loop", "on", "hosts", "and", "register", "dependency", "between", "parent", "and", "son" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L1466-L1487
21,118
Alignak-monitoring/alignak
alignak/objects/host.py
Hosts.find_hosts_that_use_template
def find_hosts_that_use_template(self, tpl_name): """Find hosts that use the template defined in argument tpl_name :param tpl_name: the template name we filter or :type tpl_name: str :return: list of the host_name of the hosts that got the template tpl_name in tags :rtype: list[str] """ return [h.host_name for h in self if tpl_name in h.tags if hasattr(h, "host_name")]
python
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")]
[ "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 :param tpl_name: the template name we filter or :type tpl_name: str :return: list of the host_name of the hosts that got the template tpl_name in tags :rtype: list[str]
[ "Find", "hosts", "that", "use", "the", "template", "defined", "in", "argument", "tpl_name" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/host.py#L1489-L1497
21,119
Alignak-monitoring/alignak
alignak/objects/arbiterlink.py
ArbiterLink.is_me
def is_me(self): # pragma: no cover, seems not to be used anywhere """Check if parameter name if same than name of this object TODO: is it useful? :return: true if parameter name if same than this name :rtype: bool """ 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 == socket.getfqdn() or self.host_name == socket.gethostname()
python
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 == socket.getfqdn() or self.host_name == socket.gethostname()
[ "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", ".", "get...
Check if parameter name if same than name of this object TODO: is it useful? :return: true if parameter name if same than this name :rtype: bool
[ "Check", "if", "parameter", "name", "if", "same", "than", "name", "of", "this", "object" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/arbiterlink.py#L79-L89
21,120
Alignak-monitoring/alignak
alignak/objects/arbiterlink.py
ArbiterLink.do_not_run
def do_not_run(self): """Check if satellite running or not If not, try to run :return: true if satellite not running :rtype: bool """ 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_failed_check_attempt("Connection error when " "sending do not run: %s" % str(exp)) self.set_dead() except HTTPClientTimeoutException as exp: # pragma: no cover, simple protection self.add_failed_check_attempt("Connection timeout when " "sending do not run: %s" % str(exp)) except HTTPClientException as exp: self.add_failed_check_attempt("Error when " "sending do not run: %s" % str(exp)) return False
python
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_failed_check_attempt("Connection error when " "sending do not run: %s" % str(exp)) self.set_dead() except HTTPClientTimeoutException as exp: # pragma: no cover, simple protection self.add_failed_check_attempt("Connection timeout when " "sending do not run: %s" % str(exp)) except HTTPClientException as exp: self.add_failed_check_attempt("Error when " "sending do not run: %s" % str(exp)) return False
[ "def", "do_not_run", "(", "self", ")", ":", "logger", ".", "debug", "(", "\"[%s] do_not_run\"", ",", "self", ".", "name", ")", "try", ":", "self", ".", "con", ".", "get", "(", "'_do_not_run'", ")", "return", "True", "except", "HTTPClientConnectionException",...
Check if satellite running or not If not, try to run :return: true if satellite not running :rtype: bool
[ "Check", "if", "satellite", "running", "or", "not", "If", "not", "try", "to", "run" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/arbiterlink.py#L91-L114
21,121
Alignak-monitoring/alignak
alignak/daemons/schedulerdaemon.py
Alignak.get_broks
def get_broks(self, broker_name): """Send broks to a specific broker :param broker_name: broker name to send broks :type broker_name: str :greturn: dict of brok for this broker :rtype: dict[alignak.brok.Brok] """ 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_link.name: for brok in sorted(broker_link.broks, key=lambda x: x.creation_time): # Only provide broks that did not yet sent to our external modules if getattr(brok, 'sent_to_externals', False): res.append(brok) brok.got = True broker_link.broks = [b for b in broker_link.broks if not getattr(b, 'got', False)] logger.debug("Providing %d broks to %s", len(res), broker_name) break else: logger.warning("Got a brok request from an unknown broker: %s", broker_name) return res
python
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_link.name: for brok in sorted(broker_link.broks, key=lambda x: x.creation_time): # Only provide broks that did not yet sent to our external modules if getattr(brok, 'sent_to_externals', False): res.append(brok) brok.got = True broker_link.broks = [b for b in broker_link.broks if not getattr(b, 'got', False)] logger.debug("Providing %d broks to %s", len(res), broker_name) break else: logger.warning("Got a brok request from an unknown broker: %s", broker_name) return res
[ "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", "...
Send broks to a specific broker :param broker_name: broker name to send broks :type broker_name: str :greturn: dict of brok for this broker :rtype: dict[alignak.brok.Brok]
[ "Send", "broks", "to", "a", "specific", "broker" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/schedulerdaemon.py#L127-L153
21,122
Alignak-monitoring/alignak
alignak/daemons/schedulerdaemon.py
Alignak.do_loop_turn
def do_loop_turn(self): """Scheduler loop turn Simply run the Alignak scheduler loop This is called when a configuration got received by the scheduler daemon. As of it, check if the first scheduling has been done... and manage this. :return: None """ 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.sched.initial_program_status() # First scheduling self.sched.schedule() statsmgr.timer('first_scheduling', time.time() - _t0) logger.info("First scheduling done") # Connect to our passive satellites if needed for satellite in [s for s in list(self.pollers.values()) if s.passive]: if not self.daemon_connection_init(satellite): logger.error("Passive satellite connection failed: %s", satellite) for satellite in [s for s in list(self.reactionners.values()) if s.passive]: if not self.daemon_connection_init(satellite): logger.error("Passive satellite connection failed: %s", satellite) # Ticks are for recurrent function call like consume, del zombies etc self.sched.ticks = 0 self.first_scheduling = True # Each loop turn, execute the daemon specific treatment... # only if the daemon has a configuration to manage if self.sched.pushed_conf: # If scheduling is not yet enabled, enable scheduling if not self.sched.must_schedule: self.sched.start_scheduling() self.sched.before_run() self.sched.run() else: logger.warning("#%d - No monitoring configuration to scheduler...", self.loop_count)
python
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.sched.initial_program_status() # First scheduling self.sched.schedule() statsmgr.timer('first_scheduling', time.time() - _t0) logger.info("First scheduling done") # Connect to our passive satellites if needed for satellite in [s for s in list(self.pollers.values()) if s.passive]: if not self.daemon_connection_init(satellite): logger.error("Passive satellite connection failed: %s", satellite) for satellite in [s for s in list(self.reactionners.values()) if s.passive]: if not self.daemon_connection_init(satellite): logger.error("Passive satellite connection failed: %s", satellite) # Ticks are for recurrent function call like consume, del zombies etc self.sched.ticks = 0 self.first_scheduling = True # Each loop turn, execute the daemon specific treatment... # only if the daemon has a configuration to manage if self.sched.pushed_conf: # If scheduling is not yet enabled, enable scheduling if not self.sched.must_schedule: self.sched.start_scheduling() self.sched.before_run() self.sched.run() else: logger.warning("#%d - No monitoring configuration to scheduler...", self.loop_count)
[ "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", "(", ")...
Scheduler loop turn Simply run the Alignak scheduler loop This is called when a configuration got received by the scheduler daemon. As of it, check if the first scheduling has been done... and manage this. :return: None
[ "Scheduler", "loop", "turn" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/schedulerdaemon.py#L238-L282
21,123
Alignak-monitoring/alignak
alignak/daemons/schedulerdaemon.py
Alignak.get_managed_configurations
def get_managed_configurations(self): """Get the configurations managed by this scheduler The configuration managed by a scheduler is the self configuration got by the scheduler during the dispatching. :return: a dict of scheduler links with instance_id as key and hash, push_flavor and configuration identifier as values :rtype: dict """ # for scheduler_link in list(self.schedulers.values()): # res[scheduler_link.instance_id] = { # 'hash': scheduler_link.hash, # 'push_flavor': scheduler_link.push_flavor, # 'managed_conf_id': scheduler_link.managed_conf_id # } res = {} if self.sched.pushed_conf and self.cur_conf and 'instance_id' in self.cur_conf: res[self.cur_conf['instance_id']] = { 'hash': self.cur_conf['hash'], 'push_flavor': self.cur_conf['push_flavor'], 'managed_conf_id': self.cur_conf['managed_conf_id'] } logger.debug("Get managed configuration: %s", res) return res
python
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, # 'managed_conf_id': scheduler_link.managed_conf_id # } res = {} if self.sched.pushed_conf and self.cur_conf and 'instance_id' in self.cur_conf: res[self.cur_conf['instance_id']] = { 'hash': self.cur_conf['hash'], 'push_flavor': self.cur_conf['push_flavor'], 'managed_conf_id': self.cur_conf['managed_conf_id'] } logger.debug("Get managed configuration: %s", res) return res
[ "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,", "# 'managed_conf_id': sche...
Get the configurations managed by this scheduler The configuration managed by a scheduler is the self configuration got by the scheduler during the dispatching. :return: a dict of scheduler links with instance_id as key and hash, push_flavor and configuration identifier as values :rtype: dict
[ "Get", "the", "configurations", "managed", "by", "this", "scheduler" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/schedulerdaemon.py#L284-L309
21,124
Alignak-monitoring/alignak
alignak/daemons/schedulerdaemon.py
Alignak.clean_previous_run
def clean_previous_run(self): """Clean variables from previous configuration :return: None """ # Execute the base class treatment... super(Alignak, self).clean_previous_run() # Clean all lists self.pollers.clear() self.reactionners.clear() self.brokers.clear()
python
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()
[ "def", "clean_previous_run", "(", "self", ")", ":", "# Execute the base class treatment...", "super", "(", "Alignak", ",", "self", ")", ".", "clean_previous_run", "(", ")", "# Clean all lists", "self", ".", "pollers", ".", "clear", "(", ")", "self", ".", "reacti...
Clean variables from previous configuration :return: None
[ "Clean", "variables", "from", "previous", "configuration" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/schedulerdaemon.py#L503-L514
21,125
Alignak-monitoring/alignak
alignak/daemons/schedulerdaemon.py
Alignak.get_monitoring_problems
def get_monitoring_problems(self): """Get the current scheduler livesynthesis :return: live synthesis and problems dictionary :rtype: dict """ 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: res['livesynthesis'] = scheduler_stats['livesynthesis'] if 'problems' in scheduler_stats: res['problems'] = scheduler_stats['problems'] return res
python
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: res['livesynthesis'] = scheduler_stats['livesynthesis'] if 'problems' in scheduler_stats: res['problems'] = scheduler_stats['problems'] return res
[ "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...
Get the current scheduler livesynthesis :return: live synthesis and problems dictionary :rtype: dict
[ "Get", "the", "current", "scheduler", "livesynthesis" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/schedulerdaemon.py#L553-L570
21,126
Alignak-monitoring/alignak
alignak/objects/serviceextinfo.py
ServicesExtInfo.merge_extinfo
def merge_extinfo(service, extinfo): """Merge extended host information into a service :param service: the service to edit :type service: alignak.objects.service.Service :param extinfo: the external info we get data from :type extinfo: alignak.objects.serviceextinfo.ServiceExtInfo :return: None """ properties = ['notes', 'notes_url', 'icon_image', 'icon_image_alt'] # service properties have precedence over serviceextinfo properties for prop in properties: if getattr(service, prop) == '' and getattr(extinfo, prop) != '': setattr(service, prop, getattr(extinfo, prop))
python
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) == '' and getattr(extinfo, prop) != '': setattr(service, prop, getattr(extinfo, prop))
[ "def", "merge_extinfo", "(", "service", ",", "extinfo", ")", ":", "properties", "=", "[", "'notes'", ",", "'notes_url'", ",", "'icon_image'", ",", "'icon_image_alt'", "]", "# service properties have precedence over serviceextinfo properties", "for", "prop", "in", "prope...
Merge extended host information into a service :param service: the service to edit :type service: alignak.objects.service.Service :param extinfo: the external info we get data from :type extinfo: alignak.objects.serviceextinfo.ServiceExtInfo :return: None
[ "Merge", "extended", "host", "information", "into", "a", "service" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/serviceextinfo.py#L144-L157
21,127
Alignak-monitoring/alignak
alignak/commandcall.py
CommandCall.get_command_and_args
def get_command_and_args(self): r"""We want to get the command and the args with ! splitting. but don't forget to protect against the \! to avoid splitting on them Remember: A Nagios-like command is command_name!arg1!arg2!... :return: None """ # 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:]]
python
def get_command_and_args(self): r"""We want to get the command and the args with ! splitting. but don't forget to protect against the \! to avoid splitting on them Remember: A Nagios-like command is command_name!arg1!arg2!... :return: None """ # 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:]]
[ "def", "get_command_and_args", "(", "self", ")", ":", "# First protect", "p_call", "=", "self", ".", "call", ".", "replace", "(", "r'\\!'", ",", "'___PROTECT_EXCLAMATION___'", ")", "tab", "=", "p_call", ".", "split", "(", "'!'", ")", "return", "tab", "[", ...
r"""We want to get the command and the args with ! splitting. but don't forget to protect against the \! to avoid splitting on them Remember: A Nagios-like command is command_name!arg1!arg2!... :return: None
[ "r", "We", "want", "to", "get", "the", "command", "and", "the", "args", "with", "!", "splitting", ".", "but", "don", "t", "forget", "to", "protect", "against", "the", "\\", "!", "to", "avoid", "splitting", "on", "them" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/commandcall.py#L157-L169
21,128
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.get_a_satellite_link
def get_a_satellite_link(sat_type, sat_dict): """Get a SatelliteLink object for a given satellite type and a dictionary :param sat_type: type of satellite :param sat_dict: satellite configuration data :return: """ cls = get_alignak_class('alignak.objects.%slink.%sLink' % (sat_type, sat_type.capitalize())) return cls(params=sat_dict, parsing=False)
python
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)
[ "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", "=...
Get a SatelliteLink object for a given satellite type and a dictionary :param sat_type: type of satellite :param sat_dict: satellite configuration data :return:
[ "Get", "a", "SatelliteLink", "object", "for", "a", "given", "satellite", "type", "and", "a", "dictionary" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L306-L314
21,129
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.get_livestate
def get_livestate(self): """Get the SatelliteLink live state. The live state is a tuple information containing a state identifier and a message, where: state is: - 0 for an up and running satellite - 1 if the satellite is not reachale - 2 if the satellite is dead - 3 else (not active) :return: tuple """ livestate = 0 if self.active: if not self.reachable: livestate = 1 elif not self.alive: livestate = 2 else: livestate = 3 livestate_output = "%s/%s is %s" % (self.type, self.name, [ "up and running.", "warning because not reachable.", "critical because not responding.", "not active by configuration." ][livestate]) return (livestate, livestate_output)
python
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 = "%s/%s is %s" % (self.type, self.name, [ "up and running.", "warning because not reachable.", "critical because not responding.", "not active by configuration." ][livestate]) return (livestate, livestate_output)
[ "def", "get_livestate", "(", "self", ")", ":", "livestate", "=", "0", "if", "self", ".", "active", ":", "if", "not", "self", ".", "reachable", ":", "livestate", "=", "1", "elif", "not", "self", ".", "alive", ":", "livestate", "=", "2", "else", ":", ...
Get the SatelliteLink live state. The live state is a tuple information containing a state identifier and a message, where: state is: - 0 for an up and running satellite - 1 if the satellite is not reachale - 2 if the satellite is dead - 3 else (not active) :return: tuple
[ "Get", "the", "SatelliteLink", "live", "state", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L316-L344
21,130
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.get_and_clear_context
def get_and_clear_context(self): """Get and clean all of our broks, actions, external commands and homerun :return: list of all broks of the satellite link :rtype: list """ res = (self.broks, self.actions, self.wait_homerun, self.pushed_commands) self.broks = [] self.actions = {} self.wait_homerun = {} self.pushed_commands = [] return res
python
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
[ "def", "get_and_clear_context", "(", "self", ")", ":", "res", "=", "(", "self", ".", "broks", ",", "self", ".", "actions", ",", "self", ".", "wait_homerun", ",", "self", ".", "pushed_commands", ")", "self", ".", "broks", "=", "[", "]", "self", ".", "...
Get and clean all of our broks, actions, external commands and homerun :return: list of all broks of the satellite link :rtype: list
[ "Get", "and", "clean", "all", "of", "our", "broks", "actions", "external", "commands", "and", "homerun" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L363-L374
21,131
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.prepare_for_conf
def prepare_for_conf(self): """Initialize the pushed configuration dictionary with the inner properties that are to be propagated to the satellite link. :return: None """ logger.debug("- preparing: %s", self) self.cfg = { 'self_conf': self.give_satellite_cfg(), 'schedulers': {}, 'arbiters': {} } logger.debug("- prepared: %s", self.cfg)
python
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)
[ "def", "prepare_for_conf", "(", "self", ")", ":", "logger", ".", "debug", "(", "\"- preparing: %s\"", ",", "self", ")", "self", ".", "cfg", "=", "{", "'self_conf'", ":", "self", ".", "give_satellite_cfg", "(", ")", ",", "'schedulers'", ":", "{", "}", ","...
Initialize the pushed configuration dictionary with the inner properties that are to be propagated to the satellite link. :return: None
[ "Initialize", "the", "pushed", "configuration", "dictionary", "with", "the", "inner", "properties", "that", "are", "to", "be", "propagated", "to", "the", "satellite", "link", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L386-L398
21,132
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.give_satellite_cfg
def give_satellite_cfg(self): """Get the default information for a satellite. Overridden by the specific satellites links :return: dictionary of information common to all the links :rtype: dict """ # 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 for prop, entry in list(properties.items()): if hasattr(self, prop) and entry.to_send: res[prop] = getattr(self, prop) return res
python
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 for prop, entry in list(properties.items()): if hasattr(self, prop) and entry.to_send: res[prop] = getattr(self, prop) return res
[ "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__", ...
Get the default information for a satellite. Overridden by the specific satellites links :return: dictionary of information common to all the links :rtype: dict
[ "Get", "the", "default", "information", "for", "a", "satellite", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L400-L415
21,133
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.give_satellite_json
def give_satellite_json(self): """Get the json information for a satellite. This to provide information that will be exposed by a daemon on its HTTP interface. :return: dictionary of information common to all the links :rtype: dict """ daemon_properties = ['type', 'name', 'uri', 'spare', 'configuration_sent', 'realm_name', 'manage_sub_realms', 'active', 'reachable', 'alive', 'passive', 'last_check', 'polling_interval', 'max_check_attempts'] (livestate, livestate_output) = self.get_livestate() res = { "livestate": livestate, "livestate_output": livestate_output } for sat_prop in daemon_properties: res[sat_prop] = getattr(self, sat_prop, 'not_yet_defined') return res
python
def give_satellite_json(self): daemon_properties = ['type', 'name', 'uri', 'spare', 'configuration_sent', 'realm_name', 'manage_sub_realms', 'active', 'reachable', 'alive', 'passive', 'last_check', 'polling_interval', 'max_check_attempts'] (livestate, livestate_output) = self.get_livestate() res = { "livestate": livestate, "livestate_output": livestate_output } for sat_prop in daemon_properties: res[sat_prop] = getattr(self, sat_prop, 'not_yet_defined') return res
[ "def", "give_satellite_json", "(", "self", ")", ":", "daemon_properties", "=", "[", "'type'", ",", "'name'", ",", "'uri'", ",", "'spare'", ",", "'configuration_sent'", ",", "'realm_name'", ",", "'manage_sub_realms'", ",", "'active'", ",", "'reachable'", ",", "'a...
Get the json information for a satellite. This to provide information that will be exposed by a daemon on its HTTP interface. :return: dictionary of information common to all the links :rtype: dict
[ "Get", "the", "json", "information", "for", "a", "satellite", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L417-L437
21,134
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.manages
def manages(self, cfg_part): """Tell if the satellite is managing this configuration part The managed configuration is formed as a dictionary indexed on the link instance_id: { u'SchedulerLink_1': { u'hash': u'4d08630a3483e1eac7898e7a721bd5d7768c8320', u'push_flavor': u'4d08630a3483e1eac7898e7a721bd5d7768c8320', u'managed_conf_id': [u'Config_1'] } } Note that the managed configuration is a string array rather than a simple string... no special for this reason, probably due to the serialization when the configuration is pushed :/ :param cfg_part: configuration part as prepare by the Dispatcher :type cfg_part: Conf :return: True if the satellite manages this configuration :rtype: bool """ 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: logger.info("I (%s/%s) do not manage (yet) any configuration!", self.type, self.name) return False # Check in the schedulers list configurations for managed_cfg in list(self.cfg_managed.values()): # If not even the cfg_id in the managed_conf, bail out if managed_cfg['managed_conf_id'] == cfg_part.instance_id \ and managed_cfg['push_flavor'] == cfg_part.push_flavor: logger.debug("I do manage this configuration: %s", cfg_part) break else: logger.warning("I (%s/%s) do not manage this configuration: %s", self.type, self.name, cfg_part) return False return True
python
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: logger.info("I (%s/%s) do not manage (yet) any configuration!", self.type, self.name) return False # Check in the schedulers list configurations for managed_cfg in list(self.cfg_managed.values()): # If not even the cfg_id in the managed_conf, bail out if managed_cfg['managed_conf_id'] == cfg_part.instance_id \ and managed_cfg['push_flavor'] == cfg_part.push_flavor: logger.debug("I do manage this configuration: %s", cfg_part) break else: logger.warning("I (%s/%s) do not manage this configuration: %s", self.type, self.name, cfg_part) return False return True
[ "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", ")", "#...
Tell if the satellite is managing this configuration part The managed configuration is formed as a dictionary indexed on the link instance_id: { u'SchedulerLink_1': { u'hash': u'4d08630a3483e1eac7898e7a721bd5d7768c8320', u'push_flavor': u'4d08630a3483e1eac7898e7a721bd5d7768c8320', u'managed_conf_id': [u'Config_1'] } } Note that the managed configuration is a string array rather than a simple string... no special for this reason, probably due to the serialization when the configuration is pushed :/ :param cfg_part: configuration part as prepare by the Dispatcher :type cfg_part: Conf :return: True if the satellite manages this configuration :rtype: bool
[ "Tell", "if", "the", "satellite", "is", "managing", "this", "configuration", "part" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L439-L480
21,135
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.set_alive
def set_alive(self): """Set alive, reachable, and reset attempts. If we change state, raise a status brok update alive, means the daemon is prenset in the system reachable, means that the HTTP connection is valid With this function we confirm that the daemon is reachable and, thus, we assume it is alive! :return: None """ 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 satellite as alive :)", self.name) self.broks.append(self.get_update_status_brok())
python
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 satellite as alive :)", self.name) self.broks.append(self.get_update_status_brok())
[ "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", ...
Set alive, reachable, and reset attempts. If we change state, raise a status brok update alive, means the daemon is prenset in the system reachable, means that the HTTP connection is valid With this function we confirm that the daemon is reachable and, thus, we assume it is alive! :return: None
[ "Set", "alive", "reachable", "and", "reset", "attempts", ".", "If", "we", "change", "state", "raise", "a", "status", "brok", "update" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L504-L523
21,136
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.add_failed_check_attempt
def add_failed_check_attempt(self, reason=''): """Set the daemon as unreachable and add a failed attempt if we reach the maximum attempts, set the daemon as dead :param reason: the reason of adding an attempts (stack trace sometimes) :type reason: str :return: None """ 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) # Don't need to warn again and again if the satellite is already dead # Only warn when it is alive if self.alive: if not self.stopping: logger.warning("Add failed attempt for %s (%d/%d) - %s", self.name, self.attempt, self.max_check_attempts, reason) else: logger.info("Stopping... failed attempt for %s (%d/%d) - also probably stopping", self.name, self.attempt, self.max_check_attempts) # If we reached the maximum attempts, set the daemon as dead if self.attempt >= self.max_check_attempts: if not self.stopping: logger.warning("Set %s as dead, too much failed attempts (%d), last problem is: %s", self.name, self.max_check_attempts, reason) else: logger.info("Stopping... set %s as dead, too much failed attempts (%d)", self.name, self.max_check_attempts) self.set_dead()
python
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) # Don't need to warn again and again if the satellite is already dead # Only warn when it is alive if self.alive: if not self.stopping: logger.warning("Add failed attempt for %s (%d/%d) - %s", self.name, self.attempt, self.max_check_attempts, reason) else: logger.info("Stopping... failed attempt for %s (%d/%d) - also probably stopping", self.name, self.attempt, self.max_check_attempts) # If we reached the maximum attempts, set the daemon as dead if self.attempt >= self.max_check_attempts: if not self.stopping: logger.warning("Set %s as dead, too much failed attempts (%d), last problem is: %s", self.name, self.max_check_attempts, reason) else: logger.info("Stopping... set %s as dead, too much failed attempts (%d)", self.name, self.max_check_attempts) self.set_dead()
[ "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...
Set the daemon as unreachable and add a failed attempt if we reach the maximum attempts, set the daemon as dead :param reason: the reason of adding an attempts (stack trace sometimes) :type reason: str :return: None
[ "Set", "the", "daemon", "as", "unreachable", "and", "add", "a", "failed", "attempt", "if", "we", "reach", "the", "maximum", "attempts", "set", "the", "daemon", "as", "dead" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L543-L575
21,137
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.valid_connection
def valid_connection(*outer_args, **outer_kwargs): # pylint: disable=unused-argument, no-method-argument """Check if the daemon connection is established and valid""" def decorator(func): # pylint: disable=missing-docstring def decorated(*args, **kwargs): # pylint: disable=missing-docstring # outer_args and outer_kwargs are the decorator arguments # args and kwargs are the decorated function arguments link = args[0] if not link.con: raise LinkError("The connection is not created for %s" % link.name) if not link.running_id: raise LinkError("The connection is not initialized for %s" % link.name) return func(*args, **kwargs) return decorated return decorator
python
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 # outer_args and outer_kwargs are the decorator arguments # args and kwargs are the decorated function arguments link = args[0] if not link.con: raise LinkError("The connection is not created for %s" % link.name) if not link.running_id: raise LinkError("The connection is not initialized for %s" % link.name) return func(*args, **kwargs) return decorated return decorator
[ "def", "valid_connection", "(", "*", "outer_args", ",", "*", "*", "outer_kwargs", ")", ":", "# pylint: disable=unused-argument, no-method-argument", "def", "decorator", "(", "func", ")", ":", "# pylint: disable=missing-docstring", "def", "decorated", "(", "*", "args", ...
Check if the daemon connection is established and valid
[ "Check", "if", "the", "daemon", "connection", "is", "established", "and", "valid" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L577-L592
21,138
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.communicate
def communicate(*outer_args, **outer_kwargs): # pylint: disable=unused-argument, no-method-argument """Check if the daemon connection is authorized and valid""" def decorator(func): # pylint: disable=missing-docstring def decorated(*args, **kwargs): # pylint: disable=missing-docstring # outer_args and outer_kwargs are the decorator arguments # args and kwargs are the decorated function arguments fn_name = func.__name__ link = args[0] if not link.alive: logger.warning("%s is not alive for %s", link.name, fn_name) return None try: if not link.reachable: raise LinkError("The %s %s is not reachable" % (link.type, link.name)) logger.debug("[%s] Calling: %s, %s, %s", link.name, fn_name, args, kwargs) return func(*args, **kwargs) except HTTPClientConnectionException as exp: # A Connection error is raised when the daemon connection cannot be established # No way with the configuration parameters! if not link.stopping: logger.warning("A daemon (%s/%s) that we must be related with " "cannot be connected: %s", link.type, link.name, exp) else: logger.info("Stopping... daemon (%s/%s) cannot be connected. " "It is also probably stopping or yet stopped.", link.type, link.name) link.set_dead() except (LinkError, HTTPClientTimeoutException) as exp: link.add_failed_check_attempt("Connection timeout " "with '%s': %s" % (fn_name, str(exp))) return False except HTTPClientDataException as exp: # A Data error is raised when the daemon HTTP reponse is not 200! # No way with the communication if some problems exist in the daemon interface! # Abort all err = "Some daemons that we must be related with " \ "have some interface problems. Sorry, I bail out" logger.error(err) os.sys.exit(err) except HTTPClientException as exp: link.add_failed_check_attempt("Error with '%s': %s" % (fn_name, str(exp))) return None return decorated return decorator
python
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 # outer_args and outer_kwargs are the decorator arguments # args and kwargs are the decorated function arguments fn_name = func.__name__ link = args[0] if not link.alive: logger.warning("%s is not alive for %s", link.name, fn_name) return None try: if not link.reachable: raise LinkError("The %s %s is not reachable" % (link.type, link.name)) logger.debug("[%s] Calling: %s, %s, %s", link.name, fn_name, args, kwargs) return func(*args, **kwargs) except HTTPClientConnectionException as exp: # A Connection error is raised when the daemon connection cannot be established # No way with the configuration parameters! if not link.stopping: logger.warning("A daemon (%s/%s) that we must be related with " "cannot be connected: %s", link.type, link.name, exp) else: logger.info("Stopping... daemon (%s/%s) cannot be connected. " "It is also probably stopping or yet stopped.", link.type, link.name) link.set_dead() except (LinkError, HTTPClientTimeoutException) as exp: link.add_failed_check_attempt("Connection timeout " "with '%s': %s" % (fn_name, str(exp))) return False except HTTPClientDataException as exp: # A Data error is raised when the daemon HTTP reponse is not 200! # No way with the communication if some problems exist in the daemon interface! # Abort all err = "Some daemons that we must be related with " \ "have some interface problems. Sorry, I bail out" logger.error(err) os.sys.exit(err) except HTTPClientException as exp: link.add_failed_check_attempt("Error with '%s': %s" % (fn_name, str(exp))) return None return decorated return decorator
[ "def", "communicate", "(", "*", "outer_args", ",", "*", "*", "outer_kwargs", ")", ":", "# pylint: disable=unused-argument, no-method-argument", "def", "decorator", "(", "func", ")", ":", "# pylint: disable=missing-docstring", "def", "decorated", "(", "*", "args", ",",...
Check if the daemon connection is authorized and valid
[ "Check", "if", "the", "daemon", "connection", "is", "authorized", "and", "valid" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L594-L642
21,139
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.stop_request
def stop_request(self, stop_now=False): """Send a stop request to the daemon :param stop_now: stop now or go to stop wait mode :type stop_now: bool :return: the daemon response (True) """ 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
python
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
[ "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", "(", "'sto...
Send a stop request to the daemon :param stop_now: stop now or go to stop wait mode :type stop_now: bool :return: the daemon response (True)
[ "Send", "a", "stop", "request", "to", "the", "daemon" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L689-L699
21,140
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.update_infos
def update_infos(self, forced=False, test=False): """Update satellite info each self.polling_interval seconds so we smooth arbiter actions for just useful actions. Raise a satellite update status Brok If forced is True, then ignore the ping period. This is used when the configuration has not yet been dispatched to the Arbiter satellites. If test is True, do not really ping the daemon (useful for the unit tests only) :param forced: ignore the ping smoothing :type forced: bool :param test: :type test: bool :return: None if the last request is too recent, False if a timeout was raised during the request, else the managed configurations dictionary """ 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.polling_interval > now: logger.debug("Too early to ping %s, ping period is %ds!, last check: %d, now: %d", self.name, self.polling_interval, self.last_check, now) return None self.get_conf(test=test) # Update the daemon last check timestamp self.last_check = time.time() # Update the state of this element self.broks.append(self.get_update_status_brok()) return self.cfg_managed
python
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.polling_interval > now: logger.debug("Too early to ping %s, ping period is %ds!, last check: %d, now: %d", self.name, self.polling_interval, self.last_check, now) return None self.get_conf(test=test) # Update the daemon last check timestamp self.last_check = time.time() # Update the state of this element self.broks.append(self.get_update_status_brok()) return self.cfg_managed
[ "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", ".", "...
Update satellite info each self.polling_interval seconds so we smooth arbiter actions for just useful actions. Raise a satellite update status Brok If forced is True, then ignore the ping period. This is used when the configuration has not yet been dispatched to the Arbiter satellites. If test is True, do not really ping the daemon (useful for the unit tests only) :param forced: ignore the ping smoothing :type forced: bool :param test: :type test: bool :return: None if the last request is too recent, False if a timeout was raised during the request, else the managed configurations dictionary
[ "Update", "satellite", "info", "each", "self", ".", "polling_interval", "seconds", "so", "we", "smooth", "arbiter", "actions", "for", "just", "useful", "actions", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L703-L740
21,141
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLink.push_actions
def push_actions(self, actions, scheduler_instance_id): """Post the actions to execute to the satellite. Indeed, a scheduler post its checks to a poller and its actions to a reactionner. :param actions: Action list to send :type actions: list :param scheduler_instance_id: Scheduler instance identifier :type scheduler_instance_id: uuid :return: True on success, False on failure :rtype: bool """ logger.debug("Pushing %d actions from %s", len(actions), scheduler_instance_id) return self.con.post('_push_actions', {'actions': actions, 'scheduler_instance_id': scheduler_instance_id}, wait=True)
python
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, 'scheduler_instance_id': scheduler_instance_id}, wait=True)
[ "def", "push_actions", "(", "self", ",", "actions", ",", "scheduler_instance_id", ")", ":", "logger", ".", "debug", "(", "\"Pushing %d actions from %s\"", ",", "len", "(", "actions", ")", ",", "scheduler_instance_id", ")", "return", "self", ".", "con", ".", "p...
Post the actions to execute to the satellite. Indeed, a scheduler post its checks to a poller and its actions to a reactionner. :param actions: Action list to send :type actions: list :param scheduler_instance_id: Scheduler instance identifier :type scheduler_instance_id: uuid :return: True on success, False on failure :rtype: bool
[ "Post", "the", "actions", "to", "execute", "to", "the", "satellite", ".", "Indeed", "a", "scheduler", "post", "its", "checks", "to", "a", "poller", "and", "its", "actions", "to", "a", "reactionner", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L874-L888
21,142
Alignak-monitoring/alignak
alignak/objects/satellitelink.py
SatelliteLinks.linkify
def linkify(self, modules): """Link modules and Satellite links :param modules: Module object list :type modules: alignak.objects.module.Modules :return: None """ logger.debug("Linkify %s with %s", self, modules) self.linkify_s_by_module(modules)
python
def linkify(self, modules): logger.debug("Linkify %s with %s", self, modules) self.linkify_s_by_module(modules)
[ "def", "linkify", "(", "self", ",", "modules", ")", ":", "logger", ".", "debug", "(", "\"Linkify %s with %s\"", ",", "self", ",", "modules", ")", "self", ".", "linkify_s_by_module", "(", "modules", ")" ]
Link modules and Satellite links :param modules: Module object list :type modules: alignak.objects.module.Modules :return: None
[ "Link", "modules", "and", "Satellite", "links" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/satellitelink.py#L1005-L1013
21,143
Alignak-monitoring/alignak
alignak/notification.py
Notification.get_return_from
def get_return_from(self, notif): """Setter of exit_status and execution_time attributes :param notif: notification to get data from :type notif: alignak.notification.Notification :return: None """ self.exit_status = notif.exit_status self.execution_time = notif.execution_time
python
def get_return_from(self, notif): self.exit_status = notif.exit_status self.execution_time = notif.execution_time
[ "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 :param notif: notification to get data from :type notif: alignak.notification.Notification :return: None
[ "Setter", "of", "exit_status", "and", "execution_time", "attributes" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/notification.py#L164-L172
21,144
Alignak-monitoring/alignak
alignak/notification.py
Notification.get_initial_status_brok
def get_initial_status_brok(self): """Get a initial status brok :return: brok with wanted data :rtype: alignak.brok.Brok """ data = {'uuid': self.uuid} self.fill_data_brok_from(data, 'full_status') return Brok({'type': 'notification_raise', 'data': data})
python
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})
[ "def", "get_initial_status_brok", "(", "self", ")", ":", "data", "=", "{", "'uuid'", ":", "self", ".", "uuid", "}", "self", ".", "fill_data_brok_from", "(", "data", ",", "'full_status'", ")", "return", "Brok", "(", "{", "'type'", ":", "'notification_raise'",...
Get a initial status brok :return: brok with wanted data :rtype: alignak.brok.Brok
[ "Get", "a", "initial", "status", "brok" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/notification.py#L191-L199
21,145
Alignak-monitoring/alignak
alignak/daemons/brokerdaemon.py
Broker.manage_brok
def manage_brok(self, brok): """Get a brok. We put brok data to the modules :param brok: object with data :type brok: object :return: None """ # 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) statsmgr.timer('manage-broks.internal.%s' % module.get_name(), time.time() - _t0) except Exception as exp: # pylint: disable=broad-except logger.warning("The module %s raised an exception: %s, " "I'm tagging it to restart later", module.get_name(), str(exp)) logger.exception(exp) self.modules_manager.set_to_restart(module)
python
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) statsmgr.timer('manage-broks.internal.%s' % module.get_name(), time.time() - _t0) except Exception as exp: # pylint: disable=broad-except logger.warning("The module %s raised an exception: %s, " "I'm tagging it to restart later", module.get_name(), str(exp)) logger.exception(exp) self.modules_manager.set_to_restart(module)
[ "def", "manage_brok", "(", "self", ",", "brok", ")", ":", "# Unserialize the brok before consuming it", "brok", ".", "prepare", "(", ")", "for", "module", "in", "self", ".", "modules_manager", ".", "get_internal_instances", "(", ")", ":", "try", ":", "_t0", "=...
Get a brok. We put brok data to the modules :param brok: object with data :type brok: object :return: None
[ "Get", "a", "brok", ".", "We", "put", "brok", "data", "to", "the", "modules" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/brokerdaemon.py#L189-L209
21,146
Alignak-monitoring/alignak
alignak/daemons/brokerdaemon.py
Broker.get_internal_broks
def get_internal_broks(self): """Get all broks from self.broks_internal_raised and append them to our broks to manage :return: None """ 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 = []
python
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 = []
[ "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", "(", "s...
Get all broks from self.broks_internal_raised and append them to our broks to manage :return: None
[ "Get", "all", "broks", "from", "self", ".", "broks_internal_raised", "and", "append", "them", "to", "our", "broks", "to", "manage" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/brokerdaemon.py#L211-L220
21,147
Alignak-monitoring/alignak
alignak/daemons/brokerdaemon.py
Broker.get_arbiter_broks
def get_arbiter_broks(self): """Get the broks from the arbiters, but as the arbiter_broks list can be push by arbiter without Global lock, we must protect this with a lock TODO: really? check this arbiter behavior! :return: None """ 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) self.arbiter_broks = []
python
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) self.arbiter_broks = []
[ "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", ...
Get the broks from the arbiters, but as the arbiter_broks list can be push by arbiter without Global lock, we must protect this with a lock TODO: really? check this arbiter behavior! :return: None
[ "Get", "the", "broks", "from", "the", "arbiters", "but", "as", "the", "arbiter_broks", "list", "can", "be", "push", "by", "arbiter", "without", "Global", "lock", "we", "must", "protect", "this", "with", "a", "lock" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/brokerdaemon.py#L222-L235
21,148
Alignak-monitoring/alignak
alignak/daemons/brokerdaemon.py
Broker.get_new_broks
def get_new_broks(self): """Get new broks from our satellites :return: None """ 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) _t0 = time.time() try: tmp_broks = satellite_link.get_broks(self.name) except LinkError: logger.warning("Daemon %s connection failed, I could not get the broks!", satellite_link) else: if tmp_broks: logger.debug("Got %d Broks from %s in %s", len(tmp_broks), satellite_link.name, time.time() - _t0) statsmgr.gauge('get-new-broks-count.%s' % (satellite_link.name), len(tmp_broks)) statsmgr.timer('get-new-broks-time.%s' % (satellite_link.name), time.time() - _t0) for brok in tmp_broks: brok.instance_id = satellite_link.instance_id # Add the broks to our global list self.external_broks.extend(tmp_broks)
python
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) _t0 = time.time() try: tmp_broks = satellite_link.get_broks(self.name) except LinkError: logger.warning("Daemon %s connection failed, I could not get the broks!", satellite_link) else: if tmp_broks: logger.debug("Got %d Broks from %s in %s", len(tmp_broks), satellite_link.name, time.time() - _t0) statsmgr.gauge('get-new-broks-count.%s' % (satellite_link.name), len(tmp_broks)) statsmgr.timer('get-new-broks-time.%s' % (satellite_link.name), time.time() - _t0) for brok in tmp_broks: brok.instance_id = satellite_link.instance_id # Add the broks to our global list self.external_broks.extend(tmp_broks)
[ "def", "get_new_broks", "(", "self", ")", ":", "for", "satellites", "in", "[", "self", ".", "schedulers", ",", "self", ".", "pollers", ",", "self", ".", "reactionners", ",", "self", ".", "receivers", "]", ":", "for", "satellite_link", "in", "list", "(", ...
Get new broks from our satellites :return: None
[ "Get", "new", "broks", "from", "our", "satellites" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/brokerdaemon.py#L237-L264
21,149
Alignak-monitoring/alignak
alignak/objects/realm.py
Realm.add_group_members
def add_group_members(self, members): """Add a new group member to the groups list :param members: member name :type members: str :return: None """ if not isinstance(members, list): members = [members] if not getattr(self, 'group_members', None): self.group_members = members else: self.group_members.extend(members)
python
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)
[ "def", "add_group_members", "(", "self", ",", "members", ")", ":", "if", "not", "isinstance", "(", "members", ",", "list", ")", ":", "members", "=", "[", "members", "]", "if", "not", "getattr", "(", "self", ",", "'group_members'", ",", "None", ")", ":"...
Add a new group member to the groups list :param members: member name :type members: str :return: None
[ "Add", "a", "new", "group", "member", "to", "the", "groups", "list" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/realm.py#L221-L234
21,150
Alignak-monitoring/alignak
alignak/objects/realm.py
Realm.get_realms_by_explosion
def get_realms_by_explosion(self, realms): """Get all members of this realm including members of sub-realms on multi-levels :param realms: realms list, used to look for a specific one :type realms: alignak.objects.realm.Realms :return: list of members and add realm to realm_members attribute :rtype: list """ # 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_name()) return None # Ok, not in a loop, we tag the realm and parse its members self.rec_tag = True # Order realm members list by name self.realm_members = sorted(self.realm_members) for member in self.realm_members: realm = realms.find_by_name(member) if not realm: self.add_unknown_members(member) continue children = realm.get_realms_by_explosion(realms) if children is None: # We got a loop in our children definition self.all_sub_members = [] self.realm_members = [] return None # Return the list of all unique members return self.all_sub_members
python
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_name()) return None # Ok, not in a loop, we tag the realm and parse its members self.rec_tag = True # Order realm members list by name self.realm_members = sorted(self.realm_members) for member in self.realm_members: realm = realms.find_by_name(member) if not realm: self.add_unknown_members(member) continue children = realm.get_realms_by_explosion(realms) if children is None: # We got a loop in our children definition self.all_sub_members = [] self.realm_members = [] return None # Return the list of all unique members return self.all_sub_members
[ "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: ther...
Get all members of this realm including members of sub-realms on multi-levels :param realms: realms list, used to look for a specific one :type realms: alignak.objects.realm.Realms :return: list of members and add realm to realm_members attribute :rtype: list
[ "Get", "all", "members", "of", "this", "realm", "including", "members", "of", "sub", "-", "realms", "on", "multi", "-", "levels" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/realm.py#L274-L306
21,151
Alignak-monitoring/alignak
alignak/objects/realm.py
Realm.set_level
def set_level(self, level, realms): """Set the realm level in the realms hierarchy :return: None """ 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 = [] self.all_sub_members_names = [] for child in sorted(self.realm_members): child = realms.find_by_name(child) if not child: continue self.all_sub_members.append(child.uuid) self.all_sub_members_names.append(child.get_name()) grand_children = child.set_level(self.level + 1, realms) for grand_child in grand_children: if grand_child in self.all_sub_members_names: continue grand_child = realms.find_by_name(grand_child) if grand_child: self.all_sub_members_names.append(grand_child.get_name()) self.all_sub_members.append(grand_child.uuid) return self.all_sub_members_names
python
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 = [] self.all_sub_members_names = [] for child in sorted(self.realm_members): child = realms.find_by_name(child) if not child: continue self.all_sub_members.append(child.uuid) self.all_sub_members_names.append(child.get_name()) grand_children = child.set_level(self.level + 1, realms) for grand_child in grand_children: if grand_child in self.all_sub_members_names: continue grand_child = realms.find_by_name(grand_child) if grand_child: self.all_sub_members_names.append(grand_child.get_name()) self.all_sub_members.append(grand_child.uuid) return self.all_sub_members_names
[ "def", "set_level", "(", "self", ",", "level", ",", "realms", ")", ":", "self", ".", "level", "=", "level", "if", "not", "self", ".", "level", ":", "logger", ".", "info", "(", "\"- %s\"", ",", "self", ".", "get_name", "(", ")", ")", "else", ":", ...
Set the realm level in the realms hierarchy :return: None
[ "Set", "the", "realm", "level", "in", "the", "realms", "hierarchy" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/realm.py#L308-L335
21,152
Alignak-monitoring/alignak
alignak/objects/realm.py
Realm.get_all_subs_satellites_by_type
def get_all_subs_satellites_by_type(self, sat_type, realms): """Get all satellites of the wanted type in this realm recursively :param sat_type: satellite type wanted (scheduler, poller ..) :type sat_type: :param realms: all realms :type realms: list of realm object :return: list of satellite in this realm :rtype: list """ 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
python
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
[ "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", "...
Get all satellites of the wanted type in this realm recursively :param sat_type: satellite type wanted (scheduler, poller ..) :type sat_type: :param realms: all realms :type realms: list of realm object :return: list of satellite in this realm :rtype: list
[ "Get", "all", "satellites", "of", "the", "wanted", "type", "in", "this", "realm", "recursively" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/realm.py#L337-L350
21,153
Alignak-monitoring/alignak
alignak/objects/realm.py
Realm.get_links_for_a_broker
def get_links_for_a_broker(self, pollers, reactionners, receivers, realms, manage_sub_realms=False): """Get a configuration dictionary with pollers, reactionners and receivers links for a broker :param pollers: pollers :type pollers: :param reactionners: reactionners :type reactionners: :param receivers: receivers :type receivers: :param realms: realms :type realms: :param manage_sub_realms: :type manage_sub_realms: True if the borker manages sub realms :return: dict containing pollers, reactionners and receivers links (key is satellite id) :rtype: dict """ # Create void satellite links cfg = { 'pollers': {}, 'reactionners': {}, 'receivers': {}, } # Our self.daemons are only identifiers... that we use to fill the satellite links for poller_id in self.pollers: poller = pollers[poller_id] cfg['pollers'][poller.uuid] = poller.give_satellite_cfg() for reactionner_id in self.reactionners: reactionner = reactionners[reactionner_id] cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg() for receiver_id in self.receivers: receiver = receivers[receiver_id] cfg['receivers'][receiver.uuid] = receiver.give_satellite_cfg() # If the broker manages sub realms, fill the satellite links... if manage_sub_realms: # Now pollers for poller_id in self.get_all_subs_satellites_by_type('pollers', realms): poller = pollers[poller_id] cfg['pollers'][poller.uuid] = poller.give_satellite_cfg() # Now reactionners for reactionner_id in self.get_all_subs_satellites_by_type('reactionners', realms): reactionner = reactionners[reactionner_id] cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg() # Now receivers for receiver_id in self.get_all_subs_satellites_by_type('receivers', realms): receiver = receivers[receiver_id] cfg['receivers'][receiver.uuid] = receiver.give_satellite_cfg() return cfg
python
def get_links_for_a_broker(self, pollers, reactionners, receivers, realms, manage_sub_realms=False): # Create void satellite links cfg = { 'pollers': {}, 'reactionners': {}, 'receivers': {}, } # Our self.daemons are only identifiers... that we use to fill the satellite links for poller_id in self.pollers: poller = pollers[poller_id] cfg['pollers'][poller.uuid] = poller.give_satellite_cfg() for reactionner_id in self.reactionners: reactionner = reactionners[reactionner_id] cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg() for receiver_id in self.receivers: receiver = receivers[receiver_id] cfg['receivers'][receiver.uuid] = receiver.give_satellite_cfg() # If the broker manages sub realms, fill the satellite links... if manage_sub_realms: # Now pollers for poller_id in self.get_all_subs_satellites_by_type('pollers', realms): poller = pollers[poller_id] cfg['pollers'][poller.uuid] = poller.give_satellite_cfg() # Now reactionners for reactionner_id in self.get_all_subs_satellites_by_type('reactionners', realms): reactionner = reactionners[reactionner_id] cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg() # Now receivers for receiver_id in self.get_all_subs_satellites_by_type('receivers', realms): receiver = receivers[receiver_id] cfg['receivers'][receiver.uuid] = receiver.give_satellite_cfg() return cfg
[ "def", "get_links_for_a_broker", "(", "self", ",", "pollers", ",", "reactionners", ",", "receivers", ",", "realms", ",", "manage_sub_realms", "=", "False", ")", ":", "# Create void satellite links", "cfg", "=", "{", "'pollers'", ":", "{", "}", ",", "'reactionner...
Get a configuration dictionary with pollers, reactionners and receivers links for a broker :param pollers: pollers :type pollers: :param reactionners: reactionners :type reactionners: :param receivers: receivers :type receivers: :param realms: realms :type realms: :param manage_sub_realms: :type manage_sub_realms: True if the borker manages sub realms :return: dict containing pollers, reactionners and receivers links (key is satellite id) :rtype: dict
[ "Get", "a", "configuration", "dictionary", "with", "pollers", "reactionners", "and", "receivers", "links", "for", "a", "broker" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/realm.py#L415-L472
21,154
Alignak-monitoring/alignak
alignak/objects/realm.py
Realm.get_links_for_a_scheduler
def get_links_for_a_scheduler(self, pollers, reactionners, brokers): """Get a configuration dictionary with pollers, reactionners and brokers links for a scheduler :return: dict containing pollers, reactionners and brokers links (key is satellite id) :rtype: dict """ # Create void satellite links cfg = { 'pollers': {}, 'reactionners': {}, 'brokers': {}, } # Our self.daemons are only identifiers... that we use to fill the satellite links try: for poller in self.pollers + self.get_potential_satellites_by_type(pollers, "poller"): if poller in pollers: poller = pollers[poller] cfg['pollers'][poller.uuid] = poller.give_satellite_cfg() for reactionner in self.reactionners + self.get_potential_satellites_by_type( reactionners, "reactionner"): if reactionner in reactionners: reactionner = reactionners[reactionner] cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg() for broker in self.brokers + self.get_potential_satellites_by_type(brokers, "broker"): if broker in brokers: broker = brokers[broker] cfg['brokers'][broker.uuid] = broker.give_satellite_cfg() except Exception as exp: # pylint: disable=broad-except logger.exception("realm.get_links_for_a_scheduler: %s", exp) # for poller in self.get_potential_satellites_by_type(pollers, "poller"): # logger.info("Poller: %s", poller) # cfg['pollers'][poller.uuid] = poller.give_satellite_cfg() # # for reactionner in self.get_potential_satellites_by_type(reactionners, "reactionner"): # cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg() # # for broker in self.get_potential_satellites_by_type(brokers, "broker"): # cfg['brokers'][broker.uuid] = broker.give_satellite_cfg() return cfg
python
def get_links_for_a_scheduler(self, pollers, reactionners, brokers): # Create void satellite links cfg = { 'pollers': {}, 'reactionners': {}, 'brokers': {}, } # Our self.daemons are only identifiers... that we use to fill the satellite links try: for poller in self.pollers + self.get_potential_satellites_by_type(pollers, "poller"): if poller in pollers: poller = pollers[poller] cfg['pollers'][poller.uuid] = poller.give_satellite_cfg() for reactionner in self.reactionners + self.get_potential_satellites_by_type( reactionners, "reactionner"): if reactionner in reactionners: reactionner = reactionners[reactionner] cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg() for broker in self.brokers + self.get_potential_satellites_by_type(brokers, "broker"): if broker in brokers: broker = brokers[broker] cfg['brokers'][broker.uuid] = broker.give_satellite_cfg() except Exception as exp: # pylint: disable=broad-except logger.exception("realm.get_links_for_a_scheduler: %s", exp) # for poller in self.get_potential_satellites_by_type(pollers, "poller"): # logger.info("Poller: %s", poller) # cfg['pollers'][poller.uuid] = poller.give_satellite_cfg() # # for reactionner in self.get_potential_satellites_by_type(reactionners, "reactionner"): # cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg() # # for broker in self.get_potential_satellites_by_type(brokers, "broker"): # cfg['brokers'][broker.uuid] = broker.give_satellite_cfg() return cfg
[ "def", "get_links_for_a_scheduler", "(", "self", ",", "pollers", ",", "reactionners", ",", "brokers", ")", ":", "# Create void satellite links", "cfg", "=", "{", "'pollers'", ":", "{", "}", ",", "'reactionners'", ":", "{", "}", ",", "'brokers'", ":", "{", "}...
Get a configuration dictionary with pollers, reactionners and brokers links for a scheduler :return: dict containing pollers, reactionners and brokers links (key is satellite id) :rtype: dict
[ "Get", "a", "configuration", "dictionary", "with", "pollers", "reactionners", "and", "brokers", "links", "for", "a", "scheduler" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/realm.py#L474-L519
21,155
Alignak-monitoring/alignak
alignak/objects/realm.py
Realms.explode
def explode(self): """Explode realms with each realm_members and higher_realms to get all the realms sub realms. :return: None """ # 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) if higher_realm: # Add the realm to its parent realm members higher_realm.realm_members.append(realm.get_name()) for realm in self: # Set a recursion tag to protect against loop for tmp_realm in self: tmp_realm.rec_tag = False realm.get_realms_by_explosion(self) # Clean the recursion tag for tmp_realm in self: del tmp_realm.rec_tag
python
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) if higher_realm: # Add the realm to its parent realm members higher_realm.realm_members.append(realm.get_name()) for realm in self: # Set a recursion tag to protect against loop for tmp_realm in self: tmp_realm.rec_tag = False realm.get_realms_by_explosion(self) # Clean the recursion tag for tmp_realm in self: del tmp_realm.rec_tag
[ "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", ...
Explode realms with each realm_members and higher_realms to get all the realms sub realms. :return: None
[ "Explode", "realms", "with", "each", "realm_members", "and", "higher_realms", "to", "get", "all", "the", "realms", "sub", "realms", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/realm.py#L565-L587
21,156
Alignak-monitoring/alignak
alignak/objects/realm.py
Realms.get_default
def get_default(self, check=False): """Get the default realm :param check: check correctness if True :type check: bool :return: Default realm of Alignak configuration :rtype: alignak.objects.realm.Realm | None """ 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 first realm in name alphabetical order found_names = sorted([r.get_name() for r in self]) if not found_names: self.add_error("No realm is defined in this configuration! " "This should not be possible!") return None default_realm_name = found_names[0] default_realm = self.find_by_name(default_realm_name) default_realm.default = True found.append(default_realm) if check: self.add_error("No realm is defined as the default one! " "I set %s as the default realm" % default_realm_name) default_realm = found[0] if len(found) > 1: # Retain as default realm the first so-called default realms in name alphabetical order found_names = sorted([r.get_name() for r in found]) default_realm_name = found_names[0] default_realm = self.find_by_name(default_realm_name) # Set all found realms as non-default realms for realm in found: if realm.get_name() != default_realm_name: realm.default = False if check: self.add_warning("More than one realm is defined as the default one: %s. " "I set %s as the default realm." % (','.join(found_names), default_realm_name)) self.default = default_realm return default_realm
python
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 first realm in name alphabetical order found_names = sorted([r.get_name() for r in self]) if not found_names: self.add_error("No realm is defined in this configuration! " "This should not be possible!") return None default_realm_name = found_names[0] default_realm = self.find_by_name(default_realm_name) default_realm.default = True found.append(default_realm) if check: self.add_error("No realm is defined as the default one! " "I set %s as the default realm" % default_realm_name) default_realm = found[0] if len(found) > 1: # Retain as default realm the first so-called default realms in name alphabetical order found_names = sorted([r.get_name() for r in found]) default_realm_name = found_names[0] default_realm = self.find_by_name(default_realm_name) # Set all found realms as non-default realms for realm in found: if realm.get_name() != default_realm_name: realm.default = False if check: self.add_warning("More than one realm is defined as the default one: %s. " "I set %s as the default realm." % (','.join(found_names), default_realm_name)) self.default = default_realm return default_realm
[ "def", "get_default", "(", "self", ",", "check", "=", "False", ")", ":", "found", "=", "[", "]", "for", "realm", "in", "sorted", "(", "self", ",", "key", "=", "lambda", "r", ":", "r", ".", "level", ")", ":", "if", "getattr", "(", "realm", ",", ...
Get the default realm :param check: check correctness if True :type check: bool :return: Default realm of Alignak configuration :rtype: alignak.objects.realm.Realm | None
[ "Get", "the", "default", "realm" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/realm.py#L589-L637
21,157
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.reload_configuration
def reload_configuration(self): """Ask to the arbiter to reload the monitored configuration **Note** tha the arbiter will not reload its main configuration file (eg. alignak.ini) but it will reload the monitored objects from the Nagios legacy files or from the Alignak backend! In case of any error, this function returns an object containing some properties: '_status': 'ERR' because of the error `_message`: some more explanations about the error :return: True if configuration reload is accepted """ # 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 the Master arbiter, I ignore and continue to run." logger.warning(message) return {'_status': u'ERR', '_message': message} message = "I received a request to reload the monitored configuration" if self.app.loading_configuration: message = message + "and I am still reloading the monitored configuration ;)" else: self.app.need_config_reload = True logger.warning(message) return {'_status': u'OK', '_message': message}
python
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 the Master arbiter, I ignore and continue to run." logger.warning(message) return {'_status': u'ERR', '_message': message} message = "I received a request to reload the monitored configuration" if self.app.loading_configuration: message = message + "and I am still reloading the monitored configuration ;)" else: self.app.need_config_reload = True logger.warning(message) return {'_status': u'OK', '_message': message}
[ "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 t...
Ask to the arbiter to reload the monitored configuration **Note** tha the arbiter will not reload its main configuration file (eg. alignak.ini) but it will reload the monitored objects from the Nagios legacy files or from the Alignak backend! In case of any error, this function returns an object containing some properties: '_status': 'ERR' because of the error `_message`: some more explanations about the error :return: True if configuration reload is accepted
[ "Ask", "to", "the", "arbiter", "to", "reload", "the", "monitored", "configuration" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L52-L79
21,158
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.command
def command(self, command=None, timestamp=None, element=None, host=None, service=None, user=None, parameters=None): # pylint: disable=too-many-branches """ Request to execute an external command Allowed parameters are: `command`: mandatory parameter containing the whole command line or only the command name `timestamp`: optional parameter containing the timestamp. If not present, the current timestamp is added in the command line `element`: the targeted element that will be appended after the command name (`command`). If element contains a '/' character it is split to make an host and service. `host`, `service` or `user`: the targeted host, service or user. Takes precedence over the `element` to target a specific element `parameters`: the parameter that will be appended after all the arguments When using this endpoint with the HTTP GET method, the semi colons that are commonly used to separate the parameters must be replace with %3B! This because the ; is an accepted URL query parameters separator... Indeed, the recommended way of using this endpoint is to use the HTTP POST method. In case of any error, this function returns an object containing some properties: '_status': 'ERR' because of the error `_message`: some more explanations about the error The `_status` field is 'OK' with an according `_message` to explain what the Arbiter will do depending upon the notification. The `command` property contains the formatted external command. :return: dict """ if cherrypy.request.method in ["POST"]: if not cherrypy.request.json: return {'_status': u'ERR', '_message': u'You must POST parameters on this endpoint.'} if command is None: try: command = cherrypy.request.json.get('command', None) timestamp = cherrypy.request.json.get('timestamp', None) element = cherrypy.request.json.get('element', None) host = cherrypy.request.json.get('host', None) service = cherrypy.request.json.get('service', None) user = cherrypy.request.json.get('user', None) parameters = cherrypy.request.json.get('parameters', None) except AttributeError: return {'_status': u'ERR', '_message': u'Missing command parameters'} if not command: return {'_status': u'ERR', '_message': u'Missing command parameter'} fields = split_semicolon(command) command_line = command.replace(fields[0], fields[0].upper()) if timestamp: try: timestamp = int(timestamp) except ValueError: return {'_status': u'ERR', '_message': u'Timestamp must be an integer value'} command_line = '[%d] %s' % (timestamp, command_line) if host or service or user: if host: command_line = '%s;%s' % (command_line, host) if service: command_line = '%s;%s' % (command_line, service) if user: command_line = '%s;%s' % (command_line, user) elif element: if '/' in element: # Replace only the first / element = element.replace('/', ';', 1) command_line = '%s;%s' % (command_line, element) if parameters: command_line = '%s;%s' % (command_line, parameters) # Add a command to get managed logger.warning("Got an external command: %s", command_line) self.app.add(ExternalCommand(command_line)) return {'_status': u'OK', '_message': u"Got command: %s" % command_line, 'command': command_line}
python
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: return {'_status': u'ERR', '_message': u'You must POST parameters on this endpoint.'} if command is None: try: command = cherrypy.request.json.get('command', None) timestamp = cherrypy.request.json.get('timestamp', None) element = cherrypy.request.json.get('element', None) host = cherrypy.request.json.get('host', None) service = cherrypy.request.json.get('service', None) user = cherrypy.request.json.get('user', None) parameters = cherrypy.request.json.get('parameters', None) except AttributeError: return {'_status': u'ERR', '_message': u'Missing command parameters'} if not command: return {'_status': u'ERR', '_message': u'Missing command parameter'} fields = split_semicolon(command) command_line = command.replace(fields[0], fields[0].upper()) if timestamp: try: timestamp = int(timestamp) except ValueError: return {'_status': u'ERR', '_message': u'Timestamp must be an integer value'} command_line = '[%d] %s' % (timestamp, command_line) if host or service or user: if host: command_line = '%s;%s' % (command_line, host) if service: command_line = '%s;%s' % (command_line, service) if user: command_line = '%s;%s' % (command_line, user) elif element: if '/' in element: # Replace only the first / element = element.replace('/', ';', 1) command_line = '%s;%s' % (command_line, element) if parameters: command_line = '%s;%s' % (command_line, parameters) # Add a command to get managed logger.warning("Got an external command: %s", command_line) self.app.add(ExternalCommand(command_line)) return {'_status': u'OK', '_message': u"Got command: %s" % command_line, 'command': command_line}
[ "def", "command", "(", "self", ",", "command", "=", "None", ",", "timestamp", "=", "None", ",", "element", "=", "None", ",", "host", "=", "None", ",", "service", "=", "None", ",", "user", "=", "None", ",", "parameters", "=", "None", ")", ":", "# py...
Request to execute an external command Allowed parameters are: `command`: mandatory parameter containing the whole command line or only the command name `timestamp`: optional parameter containing the timestamp. If not present, the current timestamp is added in the command line `element`: the targeted element that will be appended after the command name (`command`). If element contains a '/' character it is split to make an host and service. `host`, `service` or `user`: the targeted host, service or user. Takes precedence over the `element` to target a specific element `parameters`: the parameter that will be appended after all the arguments When using this endpoint with the HTTP GET method, the semi colons that are commonly used to separate the parameters must be replace with %3B! This because the ; is an accepted URL query parameters separator... Indeed, the recommended way of using this endpoint is to use the HTTP POST method. In case of any error, this function returns an object containing some properties: '_status': 'ERR' because of the error `_message`: some more explanations about the error The `_status` field is 'OK' with an according `_message` to explain what the Arbiter will do depending upon the notification. The `command` property contains the formatted external command. :return: dict
[ "Request", "to", "execute", "an", "external", "command" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L138-L224
21,159
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.monitoring_problems
def monitoring_problems(self): """Get Alignak detailed monitoring status This will return an object containing the properties of the `identity`, plus a `problems` object which contains 2 properties for each known scheduler: - _freshness, which is the timestamp when the provided data were fetched - problems, which is an object with the scheduler known problems: { ... "problems": { "scheduler-master": { "_freshness": 1528903945, "problems": { "fdfc986d-4ab4-4562-9d2f-4346832745e6": { "last_state": "CRITICAL", "service": "dummy_critical", "last_state_type": "SOFT", "last_state_update": 1528902442, "last_hard_state": "CRITICAL", "last_hard_state_change": 1528902442, "last_state_change": 1528902381, "state": "CRITICAL", "state_type": "HARD", "host": "host-all-8", "output": "Hi, checking host-all-8/dummy_critical -> exit=2" }, "2445f2a3-2a3b-4b13-96ed-4cfb60790e7e": { "last_state": "WARNING", "service": "dummy_warning", "last_state_type": "SOFT", "last_state_update": 1528902463, "last_hard_state": "WARNING", "last_hard_state_change": 1528902463, "last_state_change": 1528902400, "state": "WARNING", "state_type": "HARD", "host": "host-all-6", "output": "Hi, checking host-all-6/dummy_warning -> exit=1" }, ... } } } } :return: schedulers live synthesis list :rtype: dict """ 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_link.name] = {} if '_freshness' in sched_res: res['problems'][scheduler_link.name].update({'_freshness': sched_res['_freshness']}) if 'problems' in sched_res: res['problems'][scheduler_link.name].update({'problems': sched_res['problems']}) res['_freshness'] = int(time.time()) return res
python
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_link.name] = {} if '_freshness' in sched_res: res['problems'][scheduler_link.name].update({'_freshness': sched_res['_freshness']}) if 'problems' in sched_res: res['problems'][scheduler_link.name].update({'problems': sched_res['problems']}) res['_freshness'] = int(time.time()) return res
[ "def", "monitoring_problems", "(", "self", ")", ":", "res", "=", "self", ".", "identity", "(", ")", "res", "[", "'problems'", "]", "=", "{", "}", "for", "scheduler_link", "in", "self", ".", "app", ".", "conf", ".", "schedulers", ":", "sched_res", "=", ...
Get Alignak detailed monitoring status This will return an object containing the properties of the `identity`, plus a `problems` object which contains 2 properties for each known scheduler: - _freshness, which is the timestamp when the provided data were fetched - problems, which is an object with the scheduler known problems: { ... "problems": { "scheduler-master": { "_freshness": 1528903945, "problems": { "fdfc986d-4ab4-4562-9d2f-4346832745e6": { "last_state": "CRITICAL", "service": "dummy_critical", "last_state_type": "SOFT", "last_state_update": 1528902442, "last_hard_state": "CRITICAL", "last_hard_state_change": 1528902442, "last_state_change": 1528902381, "state": "CRITICAL", "state_type": "HARD", "host": "host-all-8", "output": "Hi, checking host-all-8/dummy_critical -> exit=2" }, "2445f2a3-2a3b-4b13-96ed-4cfb60790e7e": { "last_state": "WARNING", "service": "dummy_warning", "last_state_type": "SOFT", "last_state_update": 1528902463, "last_hard_state": "WARNING", "last_hard_state_change": 1528902463, "last_state_change": 1528902400, "state": "WARNING", "state_type": "HARD", "host": "host-all-6", "output": "Hi, checking host-all-6/dummy_warning -> exit=1" }, ... } } } } :return: schedulers live synthesis list :rtype: dict
[ "Get", "Alignak", "detailed", "monitoring", "status" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L234-L295
21,160
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.livesynthesis
def livesynthesis(self): """Get Alignak live synthesis This will return an object containing the properties of the `identity`, plus a `livesynthesis` object which contains 2 properties for each known scheduler: - _freshness, which is the timestamp when the provided data were fetched - livesynthesis, which is an object with the scheduler live synthesis. An `_overall` fake scheduler is also contained in the schedulers list to provide the cumulated live synthesis. Before sending the results, the arbiter sums-up all its schedulers live synthesis counters in the `_overall` live synthesis. { ... "livesynthesis": { "_overall": { "_freshness": 1528947526, "livesynthesis": { "hosts_total": 11, "hosts_not_monitored": 0, "hosts_up_hard": 11, "hosts_up_soft": 0, "hosts_down_hard": 0, "hosts_down_soft": 0, "hosts_unreachable_hard": 0, "hosts_unreachable_soft": 0, "hosts_flapping": 0, "hosts_problems": 0, "hosts_acknowledged": 0, "hosts_in_downtime": 0, "services_total": 100, "services_not_monitored": 0, "services_ok_hard": 70, "services_ok_soft": 0, "services_warning_hard": 4, "services_warning_soft": 6, "services_critical_hard": 6, "services_critical_soft": 4, "services_unknown_hard": 3, "services_unknown_soft": 7, "services_unreachable_hard": 0, "services_unreachable_soft": 0, "services_flapping": 0, "services_problems": 0, "services_acknowledged": 0, "services_in_downtime": 0 } } }, "scheduler-master": { "_freshness": 1528947522, "livesynthesis": { "hosts_total": 11, "hosts_not_monitored": 0, "hosts_up_hard": 11, "hosts_up_soft": 0, "hosts_down_hard": 0, "hosts_down_soft": 0, "hosts_unreachable_hard": 0, "hosts_unreachable_soft": 0, "hosts_flapping": 0, "hosts_problems": 0, "hosts_acknowledged": 0, "hosts_in_downtime": 0, "services_total": 100, "services_not_monitored": 0, "services_ok_hard": 70, "services_ok_soft": 0, "services_warning_hard": 4, "services_warning_soft": 6, "services_critical_hard": 6, "services_critical_soft": 4, "services_unknown_hard": 3, "services_unknown_soft": 7, "services_unreachable_hard": 0, "services_unreachable_soft": 0, "services_flapping": 0, "services_problems": 0, "services_acknowledged": 0, "services_in_downtime": 0 } } } } } :return: scheduler live synthesis :rtype: dict """ res = self.identity() res.update(self.app.get_livesynthesis()) return res
python
def livesynthesis(self): res = self.identity() res.update(self.app.get_livesynthesis()) return res
[ "def", "livesynthesis", "(", "self", ")", ":", "res", "=", "self", ".", "identity", "(", ")", "res", ".", "update", "(", "self", ".", "app", ".", "get_livesynthesis", "(", ")", ")", "return", "res" ]
Get Alignak live synthesis This will return an object containing the properties of the `identity`, plus a `livesynthesis` object which contains 2 properties for each known scheduler: - _freshness, which is the timestamp when the provided data were fetched - livesynthesis, which is an object with the scheduler live synthesis. An `_overall` fake scheduler is also contained in the schedulers list to provide the cumulated live synthesis. Before sending the results, the arbiter sums-up all its schedulers live synthesis counters in the `_overall` live synthesis. { ... "livesynthesis": { "_overall": { "_freshness": 1528947526, "livesynthesis": { "hosts_total": 11, "hosts_not_monitored": 0, "hosts_up_hard": 11, "hosts_up_soft": 0, "hosts_down_hard": 0, "hosts_down_soft": 0, "hosts_unreachable_hard": 0, "hosts_unreachable_soft": 0, "hosts_flapping": 0, "hosts_problems": 0, "hosts_acknowledged": 0, "hosts_in_downtime": 0, "services_total": 100, "services_not_monitored": 0, "services_ok_hard": 70, "services_ok_soft": 0, "services_warning_hard": 4, "services_warning_soft": 6, "services_critical_hard": 6, "services_critical_soft": 4, "services_unknown_hard": 3, "services_unknown_soft": 7, "services_unreachable_hard": 0, "services_unreachable_soft": 0, "services_flapping": 0, "services_problems": 0, "services_acknowledged": 0, "services_in_downtime": 0 } } }, "scheduler-master": { "_freshness": 1528947522, "livesynthesis": { "hosts_total": 11, "hosts_not_monitored": 0, "hosts_up_hard": 11, "hosts_up_soft": 0, "hosts_down_hard": 0, "hosts_down_soft": 0, "hosts_unreachable_hard": 0, "hosts_unreachable_soft": 0, "hosts_flapping": 0, "hosts_problems": 0, "hosts_acknowledged": 0, "hosts_in_downtime": 0, "services_total": 100, "services_not_monitored": 0, "services_ok_hard": 70, "services_ok_soft": 0, "services_warning_hard": 4, "services_warning_soft": 6, "services_critical_hard": 6, "services_critical_soft": 4, "services_unknown_hard": 3, "services_unknown_soft": 7, "services_unreachable_hard": 0, "services_unreachable_soft": 0, "services_flapping": 0, "services_problems": 0, "services_acknowledged": 0, "services_in_downtime": 0 } } } } } :return: scheduler live synthesis :rtype: dict
[ "Get", "Alignak", "live", "synthesis" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L299-L392
21,161
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.object
def object(self, o_type, o_name=None): """Get a monitored object from the arbiter. Indeed, the arbiter requires the object from its schedulers. It will iterate in its schedulers list until a matching object is found. Else it will return a Json structure containing _status and _message properties. When found, the result is a serialized object which is a Json structure containing: - content: the serialized object content - __sys_python_module__: the python class of the returned object The Alignak unserialize function of the alignak.misc.serialization package allows to restore the initial object. .. code-block:: python from alignak.misc.serialization import unserialize from alignak.objects.hostgroup import Hostgroup raw_data = req.get("http://127.0.0.1:7768/object/hostgroup/allhosts") print("Got: %s / %s" % (raw_data.status_code, raw_data.content)) assert raw_data.status_code == 200 object = raw_data.json() group = unserialize(object, True) assert group.__class__ == Hostgroup assert group.get_name() == 'allhosts' As an example: { "__sys_python_module__": "alignak.objects.hostgroup.Hostgroup", "content": { "uuid": "32248642-97dd-4f39-aaa2-5120112a765d", "name": "", "hostgroup_name": "allhosts", "use": [], "tags": [], "alias": "All Hosts", "notes": "", "definition_order": 100, "register": true, "unknown_members": [], "notes_url": "", "action_url": "", "imported_from": "unknown", "conf_is_correct": true, "configuration_errors": [], "configuration_warnings": [], "realm": "", "downtimes": {}, "hostgroup_members": [], "members": [ "553d47bc-27aa-426c-a664-49c4c0c4a249", "f88093ca-e61b-43ff-a41e-613f7ad2cea2", "df1e2e13-552d-43de-ad2a-fe80ad4ba979", "d3d667dd-f583-4668-9f44-22ef3dcb53ad" ] } } :param o_type: searched object type :type o_type: str :param o_name: searched object name (or uuid) :type o_name: str :return: serialized object information :rtype: str """ 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 isinstance(sched_res, dict) and 'content' in sched_res: return sched_res return {'_status': u'ERR', '_message': u'Required %s not found.' % o_type}
python
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 isinstance(sched_res, dict) and 'content' in sched_res: return sched_res return {'_status': u'ERR', '_message': u'Required %s not found.' % o_type}
[ "def", "object", "(", "self", ",", "o_type", ",", "o_name", "=", "None", ")", ":", "for", "scheduler_link", "in", "self", ".", "app", ".", "conf", ".", "schedulers", ":", "sched_res", "=", "scheduler_link", ".", "con", ".", "get", "(", "'object'", ",",...
Get a monitored object from the arbiter. Indeed, the arbiter requires the object from its schedulers. It will iterate in its schedulers list until a matching object is found. Else it will return a Json structure containing _status and _message properties. When found, the result is a serialized object which is a Json structure containing: - content: the serialized object content - __sys_python_module__: the python class of the returned object The Alignak unserialize function of the alignak.misc.serialization package allows to restore the initial object. .. code-block:: python from alignak.misc.serialization import unserialize from alignak.objects.hostgroup import Hostgroup raw_data = req.get("http://127.0.0.1:7768/object/hostgroup/allhosts") print("Got: %s / %s" % (raw_data.status_code, raw_data.content)) assert raw_data.status_code == 200 object = raw_data.json() group = unserialize(object, True) assert group.__class__ == Hostgroup assert group.get_name() == 'allhosts' As an example: { "__sys_python_module__": "alignak.objects.hostgroup.Hostgroup", "content": { "uuid": "32248642-97dd-4f39-aaa2-5120112a765d", "name": "", "hostgroup_name": "allhosts", "use": [], "tags": [], "alias": "All Hosts", "notes": "", "definition_order": 100, "register": true, "unknown_members": [], "notes_url": "", "action_url": "", "imported_from": "unknown", "conf_is_correct": true, "configuration_errors": [], "configuration_warnings": [], "realm": "", "downtimes": {}, "hostgroup_members": [], "members": [ "553d47bc-27aa-426c-a664-49c4c0c4a249", "f88093ca-e61b-43ff-a41e-613f7ad2cea2", "df1e2e13-552d-43de-ad2a-fe80ad4ba979", "d3d667dd-f583-4668-9f44-22ef3dcb53ad" ] } } :param o_type: searched object type :type o_type: str :param o_name: searched object name (or uuid) :type o_name: str :return: serialized object information :rtype: str
[ "Get", "a", "monitored", "object", "from", "the", "arbiter", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L397-L468
21,162
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.status
def status(self, details=False): """Get the overall alignak status Returns a list of the satellites as in: { services: [ { livestate: { perf_data: "", timestamp: 1532106561, state: "ok", long_output: "", output: "all daemons are up and running." }, name: "arbiter-master" }, { livestate: { name: "poller_poller-master", timestamp: 1532106561, long_output: "Realm: (True). Listening on: http://127.0.0.1:7771/", state: "ok", output: "daemon is alive and reachable.", perf_data: "last_check=1532106560.17" }, name: "poller-master" }, ... ... ], variables: { }, livestate: { timestamp: 1532106561, long_output: "broker-master - daemon is alive and reachable. poller-master - daemon is alive and reachable. reactionner-master - daemon is alive and reachable. receiver-master - daemon is alive and reachable. receiver-nsca - daemon is alive and reachable. scheduler-master - daemon is alive and reachable. scheduler-master-2 - daemon is alive and reachable. scheduler-master-3 - daemon is alive and reachable.", state: "up", output: "All my daemons are up and running.", perf_data: " 'servicesextinfo'=0 'businessimpactmodulations'=0 'hostgroups'=2 'resultmodulations'=0 'escalations'=0 'schedulers'=3 'hostsextinfo'=0 'contacts'=2 'servicedependencies'=0 'servicegroups'=1 'pollers'=1 'arbiters'=1 'receivers'=2 'macromodulations'=0 'reactionners'=1 'contactgroups'=2 'brokers'=1 'realms'=3 'services'=32 'commands'=11 'notificationways'=2 'timeperiods'=4 'modules'=0 'checkmodulations'=0 'hosts'=6 'hostdependencies'=0" }, name: "My Alignak", template: { notes: "", alias: "My Alignak", _templates: [ "alignak", "important" ], active_checks_enabled: false, passive_checks_enabled: true } } :param details: Details are required (different from 0) :type details bool :return: dict with key *daemon_type* and value list of daemon name :rtype: dict """ if details is not False: details = bool(details) return self.app.get_alignak_status(details=details)
python
def status(self, details=False): if details is not False: details = bool(details) return self.app.get_alignak_status(details=details)
[ "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 Returns a list of the satellites as in: { services: [ { livestate: { perf_data: "", timestamp: 1532106561, state: "ok", long_output: "", output: "all daemons are up and running." }, name: "arbiter-master" }, { livestate: { name: "poller_poller-master", timestamp: 1532106561, long_output: "Realm: (True). Listening on: http://127.0.0.1:7771/", state: "ok", output: "daemon is alive and reachable.", perf_data: "last_check=1532106560.17" }, name: "poller-master" }, ... ... ], variables: { }, livestate: { timestamp: 1532106561, long_output: "broker-master - daemon is alive and reachable. poller-master - daemon is alive and reachable. reactionner-master - daemon is alive and reachable. receiver-master - daemon is alive and reachable. receiver-nsca - daemon is alive and reachable. scheduler-master - daemon is alive and reachable. scheduler-master-2 - daemon is alive and reachable. scheduler-master-3 - daemon is alive and reachable.", state: "up", output: "All my daemons are up and running.", perf_data: " 'servicesextinfo'=0 'businessimpactmodulations'=0 'hostgroups'=2 'resultmodulations'=0 'escalations'=0 'schedulers'=3 'hostsextinfo'=0 'contacts'=2 'servicedependencies'=0 'servicegroups'=1 'pollers'=1 'arbiters'=1 'receivers'=2 'macromodulations'=0 'reactionners'=1 'contactgroups'=2 'brokers'=1 'realms'=3 'services'=32 'commands'=11 'notificationways'=2 'timeperiods'=4 'modules'=0 'checkmodulations'=0 'hosts'=6 'hostdependencies'=0" }, name: "My Alignak", template: { notes: "", alias: "My Alignak", _templates: [ "alignak", "important" ], active_checks_enabled: false, passive_checks_enabled: true } } :param details: Details are required (different from 0) :type details bool :return: dict with key *daemon_type* and value list of daemon name :rtype: dict
[ "Get", "the", "overall", "alignak", "status" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L586-L660
21,163
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.events_log
def events_log(self, details=False, count=0, timestamp=0): """Get the most recent Alignak events If count is specifies it is the maximum number of events to return. If timestamp is specified, events older than this timestamp will not be returned The arbiter maintains a list of the most recent Alignak events. This endpoint provides this list. The default format is: [ "2018-07-23 15:14:43 - E - SERVICE NOTIFICATION: guest;host_0;dummy_random;CRITICAL;1; notify-service-by-log;Service internal check result: 2", "2018-07-23 15:14:43 - E - SERVICE NOTIFICATION: admin;host_0;dummy_random;CRITICAL;1; notify-service-by-log;Service internal check result: 2", "2018-07-23 15:14:42 - E - SERVICE ALERT: host_0;dummy_critical;CRITICAL;SOFT;1; host_0-dummy_critical-2", "2018-07-23 15:14:42 - E - SERVICE ALERT: host_0;dummy_random;CRITICAL;HARD;2; Service internal check result: 2", "2018-07-23 15:14:42 - I - SERVICE ALERT: host_0;dummy_unknown;UNKNOWN;HARD;2; host_0-dummy_unknown-3" ] If you request on this endpoint with the *details* parameter (whatever its value...), you will get a detailed JSON output: [ { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:35", message: "SERVICE ALERT: host_11;dummy_echo;UNREACHABLE;HARD;2;", level: "info" }, { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:32", message: "SERVICE NOTIFICATION: guest;host_0;dummy_random;OK;0; notify-service-by-log;Service internal check result: 0", level: "info" }, { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:32", message: "SERVICE NOTIFICATION: admin;host_0;dummy_random;OK;0; notify-service-by-log;Service internal check result: 0", level: "info" }, { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:32", message: "SERVICE ALERT: host_0;dummy_random;OK;HARD;2; Service internal check result: 0", level: "info" }, { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:19", message: "SERVICE ALERT: host_11;dummy_random;OK;HARD;2; Service internal check result: 0", level: "info" } ] In this example, only the 5 most recent events are provided whereas the default value is to provide the 100 last events. This default counter may be changed thanks to the ``events_log_count`` configuration variable or ``ALIGNAK_EVENTS_LOG_COUNT`` environment variable. The date format may also be changed thanks to the ``events_date_format`` configuration variable. :return: list of the most recent events :rtype: list """ if not count: count = 1 + int(os.environ.get('ALIGNAK_EVENTS_LOG_COUNT', self.app.conf.events_log_count)) count = int(count) timestamp = float(timestamp) logger.debug('Get max %d events, newer than %s out of %d', count, timestamp, len(self.app.recent_events)) res = [] for log in reversed(self.app.recent_events): if timestamp and timestamp > log['timestamp']: break if not count: break if details: # Exposes the full object res.append(log) else: res.append("%s - %s - %s" % (log['date'], log['level'][0].upper(), log['message'])) logger.debug('Got %d events', len(res)) return res
python
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) timestamp = float(timestamp) logger.debug('Get max %d events, newer than %s out of %d', count, timestamp, len(self.app.recent_events)) res = [] for log in reversed(self.app.recent_events): if timestamp and timestamp > log['timestamp']: break if not count: break if details: # Exposes the full object res.append(log) else: res.append("%s - %s - %s" % (log['date'], log['level'][0].upper(), log['message'])) logger.debug('Got %d events', len(res)) return res
[ "def", "events_log", "(", "self", ",", "details", "=", "False", ",", "count", "=", "0", ",", "timestamp", "=", "0", ")", ":", "if", "not", "count", ":", "count", "=", "1", "+", "int", "(", "os", ".", "environ", ".", "get", "(", "'ALIGNAK_EVENTS_LOG...
Get the most recent Alignak events If count is specifies it is the maximum number of events to return. If timestamp is specified, events older than this timestamp will not be returned The arbiter maintains a list of the most recent Alignak events. This endpoint provides this list. The default format is: [ "2018-07-23 15:14:43 - E - SERVICE NOTIFICATION: guest;host_0;dummy_random;CRITICAL;1; notify-service-by-log;Service internal check result: 2", "2018-07-23 15:14:43 - E - SERVICE NOTIFICATION: admin;host_0;dummy_random;CRITICAL;1; notify-service-by-log;Service internal check result: 2", "2018-07-23 15:14:42 - E - SERVICE ALERT: host_0;dummy_critical;CRITICAL;SOFT;1; host_0-dummy_critical-2", "2018-07-23 15:14:42 - E - SERVICE ALERT: host_0;dummy_random;CRITICAL;HARD;2; Service internal check result: 2", "2018-07-23 15:14:42 - I - SERVICE ALERT: host_0;dummy_unknown;UNKNOWN;HARD;2; host_0-dummy_unknown-3" ] If you request on this endpoint with the *details* parameter (whatever its value...), you will get a detailed JSON output: [ { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:35", message: "SERVICE ALERT: host_11;dummy_echo;UNREACHABLE;HARD;2;", level: "info" }, { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:32", message: "SERVICE NOTIFICATION: guest;host_0;dummy_random;OK;0; notify-service-by-log;Service internal check result: 0", level: "info" }, { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:32", message: "SERVICE NOTIFICATION: admin;host_0;dummy_random;OK;0; notify-service-by-log;Service internal check result: 0", level: "info" }, { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:32", message: "SERVICE ALERT: host_0;dummy_random;OK;HARD;2; Service internal check result: 0", level: "info" }, { timestamp: 1535517701.1817362, date: "2018-07-23 15:16:19", message: "SERVICE ALERT: host_11;dummy_random;OK;HARD;2; Service internal check result: 0", level: "info" } ] In this example, only the 5 most recent events are provided whereas the default value is to provide the 100 last events. This default counter may be changed thanks to the ``events_log_count`` configuration variable or ``ALIGNAK_EVENTS_LOG_COUNT`` environment variable. The date format may also be changed thanks to the ``events_date_format`` configuration variable. :return: list of the most recent events :rtype: list
[ "Get", "the", "most", "recent", "Alignak", "events" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L664-L760
21,164
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.satellites_list
def satellites_list(self, daemon_type=''): """Get the arbiter satellite names sorted by type Returns a list of the satellites as in: { reactionner: [ "reactionner-master" ], broker: [ "broker-master" ], arbiter: [ "arbiter-master" ], scheduler: [ "scheduler-master-3", "scheduler-master", "scheduler-master-2" ], receiver: [ "receiver-nsca", "receiver-master" ], poller: [ "poller-master" ] } If a specific daemon type is requested, the list is reduced to this unique daemon type: { scheduler: [ "scheduler-master-3", "scheduler-master", "scheduler-master-2" ] } :param daemon_type: daemon type to filter :type daemon_type: str :return: dict with key *daemon_type* and value list of daemon name :rtype: dict """ with self.app.conf_lock: res = {} for s_type in ['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']: if daemon_type and daemon_type != s_type: continue satellite_list = [] res[s_type] = satellite_list for daemon_link in getattr(self.app.conf, s_type + 's', []): satellite_list.append(daemon_link.name) return res
python
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: continue satellite_list = [] res[s_type] = satellite_list for daemon_link in getattr(self.app.conf, s_type + 's', []): satellite_list.append(daemon_link.name) return res
[ "def", "satellites_list", "(", "self", ",", "daemon_type", "=", "''", ")", ":", "with", "self", ".", "app", ".", "conf_lock", ":", "res", "=", "{", "}", "for", "s_type", "in", "[", "'arbiter'", ",", "'scheduler'", ",", "'poller'", ",", "'reactionner'", ...
Get the arbiter satellite names sorted by type Returns a list of the satellites as in: { reactionner: [ "reactionner-master" ], broker: [ "broker-master" ], arbiter: [ "arbiter-master" ], scheduler: [ "scheduler-master-3", "scheduler-master", "scheduler-master-2" ], receiver: [ "receiver-nsca", "receiver-master" ], poller: [ "poller-master" ] } If a specific daemon type is requested, the list is reduced to this unique daemon type: { scheduler: [ "scheduler-master-3", "scheduler-master", "scheduler-master-2" ] } :param daemon_type: daemon type to filter :type daemon_type: str :return: dict with key *daemon_type* and value list of daemon name :rtype: dict
[ "Get", "the", "arbiter", "satellite", "names", "sorted", "by", "type" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L764-L816
21,165
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.satellites_configuration
def satellites_configuration(self): """Return all the configuration data of satellites :return: dict containing satellites data Output looks like this :: {'arbiter' : [{'property1':'value1' ..}, {'property2', 'value11' ..}, ..], 'scheduler': [..], 'poller': [..], 'reactionner': [..], 'receiver': [..], 'broker: [..]' } :rtype: dict """ res = {} for s_type in ['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']: lst = [] res[s_type] = lst for daemon in getattr(self.app.conf, s_type + 's'): cls = daemon.__class__ env = {} all_props = [cls.properties, cls.running_properties] for props in all_props: for prop in props: if not hasattr(daemon, prop): continue if prop in ["realms", "conf", "con", "tags", "modules", "cfg", "broks", "cfg_to_manage"]: continue val = getattr(daemon, prop) # give a try to a json able object try: json.dumps(val) env[prop] = val except TypeError as exp: logger.warning('satellites_configuration, %s: %s', prop, str(exp)) lst.append(env) return res
python
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.conf, s_type + 's'): cls = daemon.__class__ env = {} all_props = [cls.properties, cls.running_properties] for props in all_props: for prop in props: if not hasattr(daemon, prop): continue if prop in ["realms", "conf", "con", "tags", "modules", "cfg", "broks", "cfg_to_manage"]: continue val = getattr(daemon, prop) # give a try to a json able object try: json.dumps(val) env[prop] = val except TypeError as exp: logger.warning('satellites_configuration, %s: %s', prop, str(exp)) lst.append(env) return res
[ "def", "satellites_configuration", "(", "self", ")", ":", "res", "=", "{", "}", "for", "s_type", "in", "[", "'arbiter'", ",", "'scheduler'", ",", "'poller'", ",", "'reactionner'", ",", "'receiver'", ",", "'broker'", "]", ":", "lst", "=", "[", "]", "res",...
Return all the configuration data of satellites :return: dict containing satellites data Output looks like this :: {'arbiter' : [{'property1':'value1' ..}, {'property2', 'value11' ..}, ..], 'scheduler': [..], 'poller': [..], 'reactionner': [..], 'receiver': [..], 'broker: [..]' } :rtype: dict
[ "Return", "all", "the", "configuration", "data", "of", "satellites" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L1098-L1139
21,166
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.external_commands
def external_commands(self): """Get the external commands from the daemon Use a lock for this function to protect :return: serialized external command list :rtype: str """ res = [] with self.app.external_commands_lock: for cmd in self.app.get_external_commands(): res.append(cmd.serialize()) return res
python
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
[ "def", "external_commands", "(", "self", ")", ":", "res", "=", "[", "]", "with", "self", ".", "app", ".", "external_commands_lock", ":", "for", "cmd", "in", "self", ".", "app", ".", "get_external_commands", "(", ")", ":", "res", ".", "append", "(", "cm...
Get the external commands from the daemon Use a lock for this function to protect :return: serialized external command list :rtype: str
[ "Get", "the", "external", "commands", "from", "the", "daemon" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L1143-L1155
21,167
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface.search
def search(self): # pylint: disable=no-self-use """ Request available queries Posted data: {u'target': u''} Return the list of available target queries :return: See upper comment :rtype: list """ 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' cherrypy.response.headers['Access-Control-Allow-Headers'] = 'Content-Type,Authorization' cherrypy.response.headers['Access-Control-Allow-Origin'] = '*' cherrypy.request.handler = None return {} if getattr(cherrypy.request, 'json', None): logger.debug("Posted data: %s", cherrypy.request.json) logger.debug("Grafana search returns: %s", GRAFANA_TARGETS) return GRAFANA_TARGETS
python
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' cherrypy.response.headers['Access-Control-Allow-Headers'] = 'Content-Type,Authorization' cherrypy.response.headers['Access-Control-Allow-Origin'] = '*' cherrypy.request.handler = None return {} if getattr(cherrypy.request, 'json', None): logger.debug("Posted data: %s", cherrypy.request.json) logger.debug("Grafana search returns: %s", GRAFANA_TARGETS) return GRAFANA_TARGETS
[ "def", "search", "(", "self", ")", ":", "# pylint: disable=no-self-use", "logger", ".", "debug", "(", "\"Grafana search... %s\"", ",", "cherrypy", ".", "request", ".", "method", ")", "if", "cherrypy", ".", "request", ".", "method", "==", "'OPTIONS'", ":", "che...
Request available queries Posted data: {u'target': u''} Return the list of available target queries :return: See upper comment :rtype: list
[ "Request", "available", "queries" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L1169-L1192
21,168
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface._build_host_livestate
def _build_host_livestate(self, host_name, livestate): # pylint: disable=no-self-use, too-many-locals """Build and notify the external command for an host livestate PROCESS_HOST_CHECK_RESULT;<host_name>;<status_code>;<plugin_output> :param host_name: the concerned host name :param livestate: livestate dictionary :return: external command line """ state = livestate.get('state', 'UP').upper() output = livestate.get('output', '') long_output = livestate.get('long_output', '') perf_data = livestate.get('perf_data', '') try: timestamp = int(livestate.get('timestamp', 'ABC')) except ValueError: timestamp = None host_state_to_id = { "UP": 0, "DOWN": 1, "UNREACHABLE": 2 } parameters = '%s;%s' % (host_state_to_id.get(state, 3), output) if long_output and perf_data: parameters = '%s|%s\n%s' % (parameters, perf_data, long_output) elif long_output: parameters = '%s\n%s' % (parameters, long_output) elif perf_data: parameters = '%s|%s' % (parameters, perf_data) command_line = 'PROCESS_HOST_CHECK_RESULT;%s;%s' % (host_name, parameters) if timestamp is not None: command_line = '[%d] %s' % (timestamp, command_line) else: command_line = '[%d] %s' % (int(time.time()), command_line) return command_line
python
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', '') perf_data = livestate.get('perf_data', '') try: timestamp = int(livestate.get('timestamp', 'ABC')) except ValueError: timestamp = None host_state_to_id = { "UP": 0, "DOWN": 1, "UNREACHABLE": 2 } parameters = '%s;%s' % (host_state_to_id.get(state, 3), output) if long_output and perf_data: parameters = '%s|%s\n%s' % (parameters, perf_data, long_output) elif long_output: parameters = '%s\n%s' % (parameters, long_output) elif perf_data: parameters = '%s|%s' % (parameters, perf_data) command_line = 'PROCESS_HOST_CHECK_RESULT;%s;%s' % (host_name, parameters) if timestamp is not None: command_line = '[%d] %s' % (timestamp, command_line) else: command_line = '[%d] %s' % (int(time.time()), command_line) return command_line
[ "def", "_build_host_livestate", "(", "self", ",", "host_name", ",", "livestate", ")", ":", "# pylint: disable=no-self-use, too-many-locals", "state", "=", "livestate", ".", "get", "(", "'state'", ",", "'UP'", ")", ".", "upper", "(", ")", "output", "=", "livestat...
Build and notify the external command for an host livestate PROCESS_HOST_CHECK_RESULT;<host_name>;<status_code>;<plugin_output> :param host_name: the concerned host name :param livestate: livestate dictionary :return: external command line
[ "Build", "and", "notify", "the", "external", "command", "for", "an", "host", "livestate" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L1390-L1428
21,169
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface._build_service_livestate
def _build_service_livestate(self, host_name, service_name, livestate): # pylint: disable=no-self-use, too-many-locals """Build and notify the external command for a service livestate PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<return_code>;<plugin_output> Create and post a logcheckresult to the backend for the livestate :param host_name: the concerned host name :param service_name: the concerned service name :param livestate: livestate dictionary :return: external command line """ state = livestate.get('state', 'OK').upper() output = livestate.get('output', '') long_output = livestate.get('long_output', '') perf_data = livestate.get('perf_data', '') try: timestamp = int(livestate.get('timestamp', 'ABC')) except ValueError: timestamp = None service_state_to_id = { "OK": 0, "WARNING": 1, "CRITICAL": 2, "UNKNOWN": 3, "UNREACHABLE": 4 } parameters = '%s;%s' % (service_state_to_id.get(state, 3), output) if long_output and perf_data: parameters = '%s|%s\n%s' % (parameters, perf_data, long_output) elif long_output: parameters = '%s\n%s' % (parameters, long_output) elif perf_data: parameters = '%s|%s' % (parameters, perf_data) command_line = 'PROCESS_SERVICE_CHECK_RESULT;%s;%s;%s' % \ (host_name, service_name, parameters) if timestamp is not None: command_line = '[%d] %s' % (timestamp, command_line) else: command_line = '[%d] %s' % (int(time.time()), command_line) return command_line
python
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_output', '') perf_data = livestate.get('perf_data', '') try: timestamp = int(livestate.get('timestamp', 'ABC')) except ValueError: timestamp = None service_state_to_id = { "OK": 0, "WARNING": 1, "CRITICAL": 2, "UNKNOWN": 3, "UNREACHABLE": 4 } parameters = '%s;%s' % (service_state_to_id.get(state, 3), output) if long_output and perf_data: parameters = '%s|%s\n%s' % (parameters, perf_data, long_output) elif long_output: parameters = '%s\n%s' % (parameters, long_output) elif perf_data: parameters = '%s|%s' % (parameters, perf_data) command_line = 'PROCESS_SERVICE_CHECK_RESULT;%s;%s;%s' % \ (host_name, service_name, parameters) if timestamp is not None: command_line = '[%d] %s' % (timestamp, command_line) else: command_line = '[%d] %s' % (int(time.time()), command_line) return command_line
[ "def", "_build_service_livestate", "(", "self", ",", "host_name", ",", "service_name", ",", "livestate", ")", ":", "# pylint: disable=no-self-use, too-many-locals", "state", "=", "livestate", ".", "get", "(", "'state'", ",", "'OK'", ")", ".", "upper", "(", ")", ...
Build and notify the external command for a service livestate PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<return_code>;<plugin_output> Create and post a logcheckresult to the backend for the livestate :param host_name: the concerned host name :param service_name: the concerned service name :param livestate: livestate dictionary :return: external command line
[ "Build", "and", "notify", "the", "external", "command", "for", "a", "service", "livestate" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L1430-L1474
21,170
Alignak-monitoring/alignak
alignak/http/arbiter_interface.py
ArbiterInterface._do_not_run
def _do_not_run(self): """The master arbiter tells to its spare arbiters to not run. A master arbiter will ignore this request and it will return an object containing some properties: '_status': 'ERR' because of the error `_message`: some more explanations about the error :return: None """ # If I'm the master, ignore the command and raise a log if self.app.is_master: message = "Received message to not run. " \ "I am the Master arbiter, ignore and continue to run." logger.warning(message) return {'_status': u'ERR', '_message': message} # Else, I'm just a spare, so I listen to my master logger.debug("Received message to not run. I am the spare, stopping.") self.app.last_master_speak = time.time() self.app.must_run = False return {'_status': u'OK', '_message': message}
python
def _do_not_run(self): # If I'm the master, ignore the command and raise a log if self.app.is_master: message = "Received message to not run. " \ "I am the Master arbiter, ignore and continue to run." logger.warning(message) return {'_status': u'ERR', '_message': message} # Else, I'm just a spare, so I listen to my master logger.debug("Received message to not run. I am the spare, stopping.") self.app.last_master_speak = time.time() self.app.must_run = False return {'_status': u'OK', '_message': message}
[ "def", "_do_not_run", "(", "self", ")", ":", "# If I'm the master, ignore the command and raise a log", "if", "self", ".", "app", ".", "is_master", ":", "message", "=", "\"Received message to not run. \"", "\"I am the Master arbiter, ignore and continue to run.\"", "logger", "....
The master arbiter tells to its spare arbiters to not run. A master arbiter will ignore this request and it will return an object containing some properties: '_status': 'ERR' because of the error `_message`: some more explanations about the error :return: None
[ "The", "master", "arbiter", "tells", "to", "its", "spare", "arbiters", "to", "not", "run", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/arbiter_interface.py#L1663-L1684
21,171
Alignak-monitoring/alignak
alignak/objects/commandcallitem.py
CommandCallItems.create_commandcall
def create_commandcall(prop, commands, command): """ Create CommandCall object with command :param prop: property :type prop: str :param commands: all commands :type commands: alignak.objects.command.Commands :param command: a command object :type command: str :return: a commandCall object :rtype: alignak.objects.commandcallitem.CommandCall """ cc = { 'commands': commands, 'call': command } if hasattr(prop, 'enable_environment_macros'): cc['enable_environment_macros'] = prop.enable_environment_macros if hasattr(prop, 'poller_tag'): cc['poller_tag'] = prop.poller_tag elif hasattr(prop, 'reactionner_tag'): cc['reactionner_tag'] = prop.reactionner_tag return CommandCall(cc)
python
def create_commandcall(prop, commands, command): cc = { 'commands': commands, 'call': command } if hasattr(prop, 'enable_environment_macros'): cc['enable_environment_macros'] = prop.enable_environment_macros if hasattr(prop, 'poller_tag'): cc['poller_tag'] = prop.poller_tag elif hasattr(prop, 'reactionner_tag'): cc['reactionner_tag'] = prop.reactionner_tag return CommandCall(cc)
[ "def", "create_commandcall", "(", "prop", ",", "commands", ",", "command", ")", ":", "cc", "=", "{", "'commands'", ":", "commands", ",", "'call'", ":", "command", "}", "if", "hasattr", "(", "prop", ",", "'enable_environment_macros'", ")", ":", "cc", "[", ...
Create CommandCall object with command :param prop: property :type prop: str :param commands: all commands :type commands: alignak.objects.command.Commands :param command: a command object :type command: str :return: a commandCall object :rtype: alignak.objects.commandcallitem.CommandCall
[ "Create", "CommandCall", "object", "with", "command" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/commandcallitem.py#L79-L105
21,172
Alignak-monitoring/alignak
alignak/http/broker_interface.py
BrokerInterface._push_broks
def _push_broks(self): """Push the provided broks objects to the broker daemon Only used on a Broker daemon by the Arbiter :param: broks :type: list :return: None """ data = cherrypy.request.json with self.app.arbiter_broks_lock: logger.debug("Pushing %d broks", len(data['broks'])) self.app.arbiter_broks.extend([unserialize(elem, True) for elem in data['broks']])
python
def _push_broks(self): data = cherrypy.request.json with self.app.arbiter_broks_lock: logger.debug("Pushing %d broks", len(data['broks'])) self.app.arbiter_broks.extend([unserialize(elem, True) for elem in data['broks']])
[ "def", "_push_broks", "(", "self", ")", ":", "data", "=", "cherrypy", ".", "request", ".", "json", "with", "self", ".", "app", ".", "arbiter_broks_lock", ":", "logger", ".", "debug", "(", "\"Pushing %d broks\"", ",", "len", "(", "data", "[", "'broks'", "...
Push the provided broks objects to the broker daemon Only used on a Broker daemon by the Arbiter :param: broks :type: list :return: None
[ "Push", "the", "provided", "broks", "objects", "to", "the", "broker", "daemon" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/http/broker_interface.py#L44-L56
21,173
Alignak-monitoring/alignak
alignak/objects/config.py
Config.load_params
def load_params(self, params): """Load parameters from main configuration file :param params: parameters list (converted right at the beginning) :type params: :return: None """ logger.debug("Alignak parameters:") for key, value in sorted(self.clean_params(params).items()): update_attribute = None # Maybe it's a variable as $USER$ or $ANOTHERVARIABLE$ # so look at the first character. If it's a $, it is a macro variable # if it ends with $ too if key[0] == '$' and key[-1] == '$': key = key[1:-1] # Update the macros list if key not in self.__class__.macros: logger.debug("New macro %s: %s - %s", self, key, value) self.__class__.macros[key] = '$%s$' % key key = '$%s$' % key logger.debug("- macro %s", key) update_attribute = value # Create a new property to store the macro value if isinstance(value, list): self.__class__.properties[key] = ListProp(default=value) else: self.__class__.properties[key] = StringProp(default=value) elif key in self.properties: update_attribute = self.properties[key].pythonize(value) elif key in self.running_properties: logger.warning("using a the running property %s in a config file", key) update_attribute = self.running_properties[key].pythonize(value) elif key.startswith('$') or key in ['cfg_file', 'cfg_dir']: # it's a macro or a useless now param, we don't touch this update_attribute = value else: logger.debug("Guessing the property '%s' type because it " "is not in %s object properties", key, self.__class__.__name__) update_attribute = ToGuessProp().pythonize(value) if update_attribute is not None: setattr(self, key, update_attribute) logger.debug("- update %s = %s", key, update_attribute) # Change Nagios2 names to Nagios3 ones (before using them) self.old_properties_names_to_new() # Fill default for myself - new properties entry becomes a self attribute self.fill_default()
python
def load_params(self, params): logger.debug("Alignak parameters:") for key, value in sorted(self.clean_params(params).items()): update_attribute = None # Maybe it's a variable as $USER$ or $ANOTHERVARIABLE$ # so look at the first character. If it's a $, it is a macro variable # if it ends with $ too if key[0] == '$' and key[-1] == '$': key = key[1:-1] # Update the macros list if key not in self.__class__.macros: logger.debug("New macro %s: %s - %s", self, key, value) self.__class__.macros[key] = '$%s$' % key key = '$%s$' % key logger.debug("- macro %s", key) update_attribute = value # Create a new property to store the macro value if isinstance(value, list): self.__class__.properties[key] = ListProp(default=value) else: self.__class__.properties[key] = StringProp(default=value) elif key in self.properties: update_attribute = self.properties[key].pythonize(value) elif key in self.running_properties: logger.warning("using a the running property %s in a config file", key) update_attribute = self.running_properties[key].pythonize(value) elif key.startswith('$') or key in ['cfg_file', 'cfg_dir']: # it's a macro or a useless now param, we don't touch this update_attribute = value else: logger.debug("Guessing the property '%s' type because it " "is not in %s object properties", key, self.__class__.__name__) update_attribute = ToGuessProp().pythonize(value) if update_attribute is not None: setattr(self, key, update_attribute) logger.debug("- update %s = %s", key, update_attribute) # Change Nagios2 names to Nagios3 ones (before using them) self.old_properties_names_to_new() # Fill default for myself - new properties entry becomes a self attribute self.fill_default()
[ "def", "load_params", "(", "self", ",", "params", ")", ":", "logger", ".", "debug", "(", "\"Alignak parameters:\"", ")", "for", "key", ",", "value", "in", "sorted", "(", "self", ".", "clean_params", "(", "params", ")", ".", "items", "(", ")", ")", ":",...
Load parameters from main configuration file :param params: parameters list (converted right at the beginning) :type params: :return: None
[ "Load", "parameters", "from", "main", "configuration", "file" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1000-L1050
21,174
Alignak-monitoring/alignak
alignak/objects/config.py
Config._cut_line
def _cut_line(line): """Split the line on whitespaces and remove empty chunks :param line: the line to split :type line: str :return: list of strings :rtype: list """ # punct = '"#$%&\'()*+/<=>?@[\\]^`{|}~' if re.search("([\t\n\r]+|[\x0b\x0c ]{3,})+", line): tmp = re.split("([\t\n\r]+|[\x0b\x0c ]{3,})+", line, 1) else: tmp = re.split("[" + string.whitespace + "]+", line, 1) res = [elt.strip() for elt in tmp if elt.strip() != ''] return res
python
def _cut_line(line): # punct = '"#$%&\'()*+/<=>?@[\\]^`{|}~' if re.search("([\t\n\r]+|[\x0b\x0c ]{3,})+", line): tmp = re.split("([\t\n\r]+|[\x0b\x0c ]{3,})+", line, 1) else: tmp = re.split("[" + string.whitespace + "]+", line, 1) res = [elt.strip() for elt in tmp if elt.strip() != ''] return res
[ "def", "_cut_line", "(", "line", ")", ":", "# punct = '\"#$%&\\'()*+/<=>?@[\\\\]^`{|}~'", "if", "re", ".", "search", "(", "\"([\\t\\n\\r]+|[\\x0b\\x0c ]{3,})+\"", ",", "line", ")", ":", "tmp", "=", "re", ".", "split", "(", "\"([\\t\\n\\r]+|[\\x0b\\x0c ]{3,})+\"", ",",...
Split the line on whitespaces and remove empty chunks :param line: the line to split :type line: str :return: list of strings :rtype: list
[ "Split", "the", "line", "on", "whitespaces", "and", "remove", "empty", "chunks" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1053-L1067
21,175
Alignak-monitoring/alignak
alignak/objects/config.py
Config.add_self_defined_objects
def add_self_defined_objects(raw_objects): """Add self defined command objects for internal processing ; bp_rule, _internal_host_up, _echo, _internal_host_check, _interna_service_check :param raw_objects: Raw config objects dict :type raw_objects: dict :return: raw_objects with some more commands :rtype: dict """ logger.info("- creating internally defined commands...") if 'command' not in raw_objects: raw_objects['command'] = [] # Business rule raw_objects['command'].append({ 'command_name': 'bp_rule', 'command_line': 'bp_rule', 'imported_from': 'alignak-self' }) # Internal host checks raw_objects['command'].append({ 'command_name': '_internal_host_up', 'command_line': '_internal_host_up', 'imported_from': 'alignak-self' }) raw_objects['command'].append({ 'command_name': '_internal_host_check', # Command line must contain: state_id;output 'command_line': '_internal_host_check;$ARG1$;$ARG2$', 'imported_from': 'alignak-self' }) # Internal service check raw_objects['command'].append({ 'command_name': '_echo', 'command_line': '_echo', 'imported_from': 'alignak-self' }) raw_objects['command'].append({ 'command_name': '_internal_service_check', # Command line must contain: state_id;output 'command_line': '_internal_service_check;$ARG1$;$ARG2$', 'imported_from': 'alignak-self' })
python
def add_self_defined_objects(raw_objects): logger.info("- creating internally defined commands...") if 'command' not in raw_objects: raw_objects['command'] = [] # Business rule raw_objects['command'].append({ 'command_name': 'bp_rule', 'command_line': 'bp_rule', 'imported_from': 'alignak-self' }) # Internal host checks raw_objects['command'].append({ 'command_name': '_internal_host_up', 'command_line': '_internal_host_up', 'imported_from': 'alignak-self' }) raw_objects['command'].append({ 'command_name': '_internal_host_check', # Command line must contain: state_id;output 'command_line': '_internal_host_check;$ARG1$;$ARG2$', 'imported_from': 'alignak-self' }) # Internal service check raw_objects['command'].append({ 'command_name': '_echo', 'command_line': '_echo', 'imported_from': 'alignak-self' }) raw_objects['command'].append({ 'command_name': '_internal_service_check', # Command line must contain: state_id;output 'command_line': '_internal_service_check;$ARG1$;$ARG2$', 'imported_from': 'alignak-self' })
[ "def", "add_self_defined_objects", "(", "raw_objects", ")", ":", "logger", ".", "info", "(", "\"- creating internally defined commands...\"", ")", "if", "'command'", "not", "in", "raw_objects", ":", "raw_objects", "[", "'command'", "]", "=", "[", "]", "# Business ru...
Add self defined command objects for internal processing ; bp_rule, _internal_host_up, _echo, _internal_host_check, _interna_service_check :param raw_objects: Raw config objects dict :type raw_objects: dict :return: raw_objects with some more commands :rtype: dict
[ "Add", "self", "defined", "command", "objects", "for", "internal", "processing", ";", "bp_rule", "_internal_host_up", "_echo", "_internal_host_check", "_interna_service_check" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1374-L1415
21,176
Alignak-monitoring/alignak
alignak/objects/config.py
Config.early_create_objects
def early_create_objects(self, raw_objects): """Create the objects needed for the post configuration file initialization :param raw_objects: dict with all object with str values :type raw_objects: dict :return: None """ types_creations = self.__class__.types_creations early_created_types = self.__class__.early_created_types logger.info("Creating objects...") for o_type in sorted(types_creations): if o_type in early_created_types: self.create_objects_for_type(raw_objects, o_type) logger.info("Done")
python
def early_create_objects(self, raw_objects): types_creations = self.__class__.types_creations early_created_types = self.__class__.early_created_types logger.info("Creating objects...") for o_type in sorted(types_creations): if o_type in early_created_types: self.create_objects_for_type(raw_objects, o_type) logger.info("Done")
[ "def", "early_create_objects", "(", "self", ",", "raw_objects", ")", ":", "types_creations", "=", "self", ".", "__class__", ".", "types_creations", "early_created_types", "=", "self", ".", "__class__", ".", "early_created_types", "logger", ".", "info", "(", "\"Cre...
Create the objects needed for the post configuration file initialization :param raw_objects: dict with all object with str values :type raw_objects: dict :return: None
[ "Create", "the", "objects", "needed", "for", "the", "post", "configuration", "file", "initialization" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1417-L1431
21,177
Alignak-monitoring/alignak
alignak/objects/config.py
Config.create_objects
def create_objects(self, raw_objects): """Create all the objects got after the post configuration file initialization :param raw_objects: dict with all object with str values :type raw_objects: dict :return: None """ types_creations = self.__class__.types_creations early_created_types = self.__class__.early_created_types logger.info("Creating objects...") # Before really creating the objects, we add some ghost # ones like the bp_rule for correlation self.add_self_defined_objects(raw_objects) for o_type in sorted(types_creations): if o_type not in early_created_types: self.create_objects_for_type(raw_objects, o_type) logger.info("Done")
python
def create_objects(self, raw_objects): types_creations = self.__class__.types_creations early_created_types = self.__class__.early_created_types logger.info("Creating objects...") # Before really creating the objects, we add some ghost # ones like the bp_rule for correlation self.add_self_defined_objects(raw_objects) for o_type in sorted(types_creations): if o_type not in early_created_types: self.create_objects_for_type(raw_objects, o_type) logger.info("Done")
[ "def", "create_objects", "(", "self", ",", "raw_objects", ")", ":", "types_creations", "=", "self", ".", "__class__", ".", "types_creations", "early_created_types", "=", "self", ".", "__class__", ".", "early_created_types", "logger", ".", "info", "(", "\"Creating ...
Create all the objects got after the post configuration file initialization :param raw_objects: dict with all object with str values :type raw_objects: dict :return: None
[ "Create", "all", "the", "objects", "got", "after", "the", "post", "configuration", "file", "initialization" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1433-L1452
21,178
Alignak-monitoring/alignak
alignak/objects/config.py
Config.create_objects_for_type
def create_objects_for_type(self, raw_objects, o_type): """Generic function to create objects regarding the o_type This function create real Alignak objects from the raw data got from the configuration. :param raw_objects: Raw objects :type raw_objects: dict :param o_type: the object type we want to create :type o_type: object :return: None """ # Ex: the above code do for timeperiods: # timeperiods = [] # for timeperiodcfg in objects['timeperiod']: # t = Timeperiod(timeperiodcfg) # timeperiods.append(t) # self.timeperiods = Timeperiods(timeperiods) types_creations = self.__class__.types_creations (cls, clss, prop, initial_index, _) = types_creations[o_type] # List to store the created objects lst = [] try: logger.info("- creating '%s' objects", o_type) for obj_cfg in raw_objects[o_type]: # We create the object my_object = cls(obj_cfg) # and append it to the list lst.append(my_object) if not lst: logger.info(" none.") except KeyError: logger.info(" no %s objects in the configuration", o_type) # Create the objects list and set it in our properties setattr(self, prop, clss(lst, initial_index))
python
def create_objects_for_type(self, raw_objects, o_type): # Ex: the above code do for timeperiods: # timeperiods = [] # for timeperiodcfg in objects['timeperiod']: # t = Timeperiod(timeperiodcfg) # timeperiods.append(t) # self.timeperiods = Timeperiods(timeperiods) types_creations = self.__class__.types_creations (cls, clss, prop, initial_index, _) = types_creations[o_type] # List to store the created objects lst = [] try: logger.info("- creating '%s' objects", o_type) for obj_cfg in raw_objects[o_type]: # We create the object my_object = cls(obj_cfg) # and append it to the list lst.append(my_object) if not lst: logger.info(" none.") except KeyError: logger.info(" no %s objects in the configuration", o_type) # Create the objects list and set it in our properties setattr(self, prop, clss(lst, initial_index))
[ "def", "create_objects_for_type", "(", "self", ",", "raw_objects", ",", "o_type", ")", ":", "# Ex: the above code do for timeperiods:", "# timeperiods = []", "# for timeperiodcfg in objects['timeperiod']:", "# t = Timeperiod(timeperiodcfg)", "# timeperiods.append(t)", "# self.tim...
Generic function to create objects regarding the o_type This function create real Alignak objects from the raw data got from the configuration. :param raw_objects: Raw objects :type raw_objects: dict :param o_type: the object type we want to create :type o_type: object :return: None
[ "Generic", "function", "to", "create", "objects", "regarding", "the", "o_type" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1454-L1491
21,179
Alignak-monitoring/alignak
alignak/objects/config.py
Config.early_arbiter_linking
def early_arbiter_linking(self, arbiter_name, params): """ Prepare the arbiter for early operations :param arbiter_name: default arbiter name if no arbiter exist in the configuration :type arbiter_name: str :return: None """ if not self.arbiters: params.update({ 'name': arbiter_name, 'arbiter_name': arbiter_name, 'host_name': socket.gethostname(), 'address': '127.0.0.1', 'port': 7770, 'spare': '0' }) logger.warning("There is no arbiter, I add myself (%s) reachable on %s:%d", arbiter_name, params['address'], params['port']) arb = ArbiterLink(params, parsing=True) self.arbiters = ArbiterLinks([arb]) # First fill default self.arbiters.fill_default() self.modules.fill_default() self.arbiters.linkify(modules=self.modules) self.modules.linkify()
python
def early_arbiter_linking(self, arbiter_name, params): if not self.arbiters: params.update({ 'name': arbiter_name, 'arbiter_name': arbiter_name, 'host_name': socket.gethostname(), 'address': '127.0.0.1', 'port': 7770, 'spare': '0' }) logger.warning("There is no arbiter, I add myself (%s) reachable on %s:%d", arbiter_name, params['address'], params['port']) arb = ArbiterLink(params, parsing=True) self.arbiters = ArbiterLinks([arb]) # First fill default self.arbiters.fill_default() self.modules.fill_default() self.arbiters.linkify(modules=self.modules) self.modules.linkify()
[ "def", "early_arbiter_linking", "(", "self", ",", "arbiter_name", ",", "params", ")", ":", "if", "not", "self", ".", "arbiters", ":", "params", ".", "update", "(", "{", "'name'", ":", "arbiter_name", ",", "'arbiter_name'", ":", "arbiter_name", ",", "'host_na...
Prepare the arbiter for early operations :param arbiter_name: default arbiter name if no arbiter exist in the configuration :type arbiter_name: str :return: None
[ "Prepare", "the", "arbiter", "for", "early", "operations" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1493-L1518
21,180
Alignak-monitoring/alignak
alignak/objects/config.py
Config.linkify_one_command_with_commands
def linkify_one_command_with_commands(self, commands, prop): """ Link a command :param commands: object commands :type commands: object :param prop: property name :type prop: str :return: None """ if not hasattr(self, prop): return command = getattr(self, prop).strip() if not command: setattr(self, prop, None) return data = {"commands": commands, "call": command} if hasattr(self, 'poller_tag'): data.update({"poller_tag": self.poller_tag}) if hasattr(self, 'reactionner_tag'): data.update({"reactionner_tag": self.reactionner_tag}) setattr(self, prop, CommandCall(data))
python
def linkify_one_command_with_commands(self, commands, prop): if not hasattr(self, prop): return command = getattr(self, prop).strip() if not command: setattr(self, prop, None) return data = {"commands": commands, "call": command} if hasattr(self, 'poller_tag'): data.update({"poller_tag": self.poller_tag}) if hasattr(self, 'reactionner_tag'): data.update({"reactionner_tag": self.reactionner_tag}) setattr(self, prop, CommandCall(data))
[ "def", "linkify_one_command_with_commands", "(", "self", ",", "commands", ",", "prop", ")", ":", "if", "not", "hasattr", "(", "self", ",", "prop", ")", ":", "return", "command", "=", "getattr", "(", "self", ",", "prop", ")", ".", "strip", "(", ")", "if...
Link a command :param commands: object commands :type commands: object :param prop: property name :type prop: str :return: None
[ "Link", "a", "command" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1520-L1545
21,181
Alignak-monitoring/alignak
alignak/objects/config.py
Config.linkify
def linkify(self): """ Make 'links' between elements, like a host got a services list with all its services in it :return: None """ self.services.optimize_service_search(self.hosts) # First linkify myself like for some global commands self.linkify_one_command_with_commands(self.commands, 'host_perfdata_command') self.linkify_one_command_with_commands(self.commands, 'service_perfdata_command') self.linkify_one_command_with_commands(self.commands, 'global_host_event_handler') self.linkify_one_command_with_commands(self.commands, 'global_service_event_handler') # link hosts with timeperiods and commands self.hosts.linkify(self.timeperiods, self.commands, self.contacts, self.realms, self.resultmodulations, self.businessimpactmodulations, self.escalations, self.hostgroups, self.checkmodulations, self.macromodulations) self.hostsextinfo.merge(self.hosts) # Do the simplify AFTER explode groups # link hostgroups with hosts self.hostgroups.linkify(self.hosts, self.realms, self.forced_realms_hostgroups) # link services with other objects self.services.linkify(self.hosts, self.commands, self.timeperiods, self.contacts, self.resultmodulations, self.businessimpactmodulations, self.escalations, self.servicegroups, self.checkmodulations, self.macromodulations) self.servicesextinfo.merge(self.services) # link servicegroups members with services self.servicegroups.linkify(self.hosts, self.services) # link notificationways with timeperiods and commands self.notificationways.linkify(self.timeperiods, self.commands) # link notificationways with timeperiods and commands self.checkmodulations.linkify(self.timeperiods, self.commands) # Link with timeperiods self.macromodulations.linkify(self.timeperiods) # link contacgroups with contacts self.contactgroups.linkify(self.contacts) # link contacts with timeperiods and commands self.contacts.linkify(self.commands, self.notificationways) # link timeperiods with timeperiods (exclude part) self.timeperiods.linkify() self.servicedependencies.linkify(self.hosts, self.services, self.timeperiods) self.hostdependencies.linkify(self.hosts, self.timeperiods) self.resultmodulations.linkify(self.timeperiods) self.businessimpactmodulations.linkify(self.timeperiods) self.escalations.linkify(self.timeperiods, self.contacts, self.services, self.hosts) # Link all satellite links with modules self.schedulers.linkify(self.modules) self.brokers.linkify(self.modules) self.receivers.linkify(self.modules) self.reactionners.linkify(self.modules) self.pollers.linkify(self.modules) # Ok, now update all realms with back links of satellites satellites = {} for sat in self.schedulers: satellites[sat.uuid] = sat for sat in self.pollers: satellites[sat.uuid] = sat for sat in self.reactionners: satellites[sat.uuid] = sat for sat in self.receivers: satellites[sat.uuid] = sat for sat in self.brokers: satellites[sat.uuid] = sat self.realms.prepare_satellites(satellites)
python
def linkify(self): self.services.optimize_service_search(self.hosts) # First linkify myself like for some global commands self.linkify_one_command_with_commands(self.commands, 'host_perfdata_command') self.linkify_one_command_with_commands(self.commands, 'service_perfdata_command') self.linkify_one_command_with_commands(self.commands, 'global_host_event_handler') self.linkify_one_command_with_commands(self.commands, 'global_service_event_handler') # link hosts with timeperiods and commands self.hosts.linkify(self.timeperiods, self.commands, self.contacts, self.realms, self.resultmodulations, self.businessimpactmodulations, self.escalations, self.hostgroups, self.checkmodulations, self.macromodulations) self.hostsextinfo.merge(self.hosts) # Do the simplify AFTER explode groups # link hostgroups with hosts self.hostgroups.linkify(self.hosts, self.realms, self.forced_realms_hostgroups) # link services with other objects self.services.linkify(self.hosts, self.commands, self.timeperiods, self.contacts, self.resultmodulations, self.businessimpactmodulations, self.escalations, self.servicegroups, self.checkmodulations, self.macromodulations) self.servicesextinfo.merge(self.services) # link servicegroups members with services self.servicegroups.linkify(self.hosts, self.services) # link notificationways with timeperiods and commands self.notificationways.linkify(self.timeperiods, self.commands) # link notificationways with timeperiods and commands self.checkmodulations.linkify(self.timeperiods, self.commands) # Link with timeperiods self.macromodulations.linkify(self.timeperiods) # link contacgroups with contacts self.contactgroups.linkify(self.contacts) # link contacts with timeperiods and commands self.contacts.linkify(self.commands, self.notificationways) # link timeperiods with timeperiods (exclude part) self.timeperiods.linkify() self.servicedependencies.linkify(self.hosts, self.services, self.timeperiods) self.hostdependencies.linkify(self.hosts, self.timeperiods) self.resultmodulations.linkify(self.timeperiods) self.businessimpactmodulations.linkify(self.timeperiods) self.escalations.linkify(self.timeperiods, self.contacts, self.services, self.hosts) # Link all satellite links with modules self.schedulers.linkify(self.modules) self.brokers.linkify(self.modules) self.receivers.linkify(self.modules) self.reactionners.linkify(self.modules) self.pollers.linkify(self.modules) # Ok, now update all realms with back links of satellites satellites = {} for sat in self.schedulers: satellites[sat.uuid] = sat for sat in self.pollers: satellites[sat.uuid] = sat for sat in self.reactionners: satellites[sat.uuid] = sat for sat in self.receivers: satellites[sat.uuid] = sat for sat in self.brokers: satellites[sat.uuid] = sat self.realms.prepare_satellites(satellites)
[ "def", "linkify", "(", "self", ")", ":", "self", ".", "services", ".", "optimize_service_search", "(", "self", ".", "hosts", ")", "# First linkify myself like for some global commands", "self", ".", "linkify_one_command_with_commands", "(", "self", ".", "commands", ",...
Make 'links' between elements, like a host got a services list with all its services in it :return: None
[ "Make", "links", "between", "elements", "like", "a", "host", "got", "a", "services", "list", "with", "all", "its", "services", "in", "it" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1547-L1635
21,182
Alignak-monitoring/alignak
alignak/objects/config.py
Config.clean
def clean(self): """Wrapper for calling the clean method of services attribute :return: None """ logger.debug("Cleaning configuration objects before configuration sending:") types_creations = self.__class__.types_creations for o_type in types_creations: (_, _, inner_property, _, _) = types_creations[o_type] logger.debug(" . for %s", inner_property, ) inner_object = getattr(self, inner_property) inner_object.clean()
python
def clean(self): logger.debug("Cleaning configuration objects before configuration sending:") types_creations = self.__class__.types_creations for o_type in types_creations: (_, _, inner_property, _, _) = types_creations[o_type] logger.debug(" . for %s", inner_property, ) inner_object = getattr(self, inner_property) inner_object.clean()
[ "def", "clean", "(", "self", ")", ":", "logger", ".", "debug", "(", "\"Cleaning configuration objects before configuration sending:\"", ")", "types_creations", "=", "self", ".", "__class__", ".", "types_creations", "for", "o_type", "in", "types_creations", ":", "(", ...
Wrapper for calling the clean method of services attribute :return: None
[ "Wrapper", "for", "calling", "the", "clean", "method", "of", "services", "attribute" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1637-L1648
21,183
Alignak-monitoring/alignak
alignak/objects/config.py
Config.warn_about_unmanaged_parameters
def warn_about_unmanaged_parameters(self): """used to raise warning if the user got parameter that we do not manage from now :return: None """ properties = self.__class__.properties unmanaged = [] for prop, entry in list(properties.items()): if not entry.managed and hasattr(self, prop): if entry.help: line = "%s: %s" % (prop, entry.help) else: line = prop unmanaged.append(line) if unmanaged: logger.warning("The following Nagios legacy parameter(s) are not currently " "managed by Alignak:") for line in unmanaged: logger.warning('- %s', line) logger.warning("Those are unmanaged configuration statements, do you really need it? " "Create an issue on the Alignak repository or submit a pull " "request: http://www.github.com/Alignak-monitoring/alignak")
python
def warn_about_unmanaged_parameters(self): properties = self.__class__.properties unmanaged = [] for prop, entry in list(properties.items()): if not entry.managed and hasattr(self, prop): if entry.help: line = "%s: %s" % (prop, entry.help) else: line = prop unmanaged.append(line) if unmanaged: logger.warning("The following Nagios legacy parameter(s) are not currently " "managed by Alignak:") for line in unmanaged: logger.warning('- %s', line) logger.warning("Those are unmanaged configuration statements, do you really need it? " "Create an issue on the Alignak repository or submit a pull " "request: http://www.github.com/Alignak-monitoring/alignak")
[ "def", "warn_about_unmanaged_parameters", "(", "self", ")", ":", "properties", "=", "self", ".", "__class__", ".", "properties", "unmanaged", "=", "[", "]", "for", "prop", ",", "entry", "in", "list", "(", "properties", ".", "items", "(", ")", ")", ":", "...
used to raise warning if the user got parameter that we do not manage from now :return: None
[ "used", "to", "raise", "warning", "if", "the", "user", "got", "parameter", "that", "we", "do", "not", "manage", "from", "now" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1650-L1674
21,184
Alignak-monitoring/alignak
alignak/objects/config.py
Config.apply_dependencies
def apply_dependencies(self): """Creates dependencies links between elements. :return: None """ self.hosts.apply_dependencies() self.services.apply_dependencies(self.hosts)
python
def apply_dependencies(self): self.hosts.apply_dependencies() self.services.apply_dependencies(self.hosts)
[ "def", "apply_dependencies", "(", "self", ")", ":", "self", ".", "hosts", ".", "apply_dependencies", "(", ")", "self", ".", "services", ".", "apply_dependencies", "(", "self", ".", "hosts", ")" ]
Creates dependencies links between elements. :return: None
[ "Creates", "dependencies", "links", "between", "elements", "." ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1715-L1721
21,185
Alignak-monitoring/alignak
alignak/objects/config.py
Config.fill_default_configuration
def fill_default_configuration(self): """Fill objects properties with default value if necessary :return: None """ logger.debug("Filling the unset properties with their default value:") types_creations = self.__class__.types_creations for o_type in types_creations: (_, _, inner_property, _, _) = types_creations[o_type] # Not yet for the realms and daemons links if inner_property in ['realms', 'arbiters', 'schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']: continue logger.debug(" . for %s", inner_property,) inner_object = getattr(self, inner_property, None) if inner_object is None: logger.debug("No %s to fill with default values", inner_property) continue inner_object.fill_default() # We have all monitored elements, we can create a default realm if none is defined if getattr(self, 'realms', None) is not None: self.fill_default_realm() self.realms.fill_default() # Then we create missing satellites, so no other satellites will be created after self.fill_default_satellites(self.launch_missing_daemons) types_creations = self.__class__.types_creations for o_type in types_creations: (_, _, inner_property, _, _) = types_creations[o_type] if getattr(self, inner_property, None) is None: logger.debug("No %s to fill with default values", inner_property) continue # Only for the daemons links if inner_property in ['schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']: logger.debug(" . for %s", inner_property,) inner_object = getattr(self, inner_property) inner_object.fill_default() # Now fill some fields we can predict (like address for hosts) self.hosts.fill_predictive_missing_parameters() self.services.fill_predictive_missing_parameters()
python
def fill_default_configuration(self): logger.debug("Filling the unset properties with their default value:") types_creations = self.__class__.types_creations for o_type in types_creations: (_, _, inner_property, _, _) = types_creations[o_type] # Not yet for the realms and daemons links if inner_property in ['realms', 'arbiters', 'schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']: continue logger.debug(" . for %s", inner_property,) inner_object = getattr(self, inner_property, None) if inner_object is None: logger.debug("No %s to fill with default values", inner_property) continue inner_object.fill_default() # We have all monitored elements, we can create a default realm if none is defined if getattr(self, 'realms', None) is not None: self.fill_default_realm() self.realms.fill_default() # Then we create missing satellites, so no other satellites will be created after self.fill_default_satellites(self.launch_missing_daemons) types_creations = self.__class__.types_creations for o_type in types_creations: (_, _, inner_property, _, _) = types_creations[o_type] if getattr(self, inner_property, None) is None: logger.debug("No %s to fill with default values", inner_property) continue # Only for the daemons links if inner_property in ['schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']: logger.debug(" . for %s", inner_property,) inner_object = getattr(self, inner_property) inner_object.fill_default() # Now fill some fields we can predict (like address for hosts) self.hosts.fill_predictive_missing_parameters() self.services.fill_predictive_missing_parameters()
[ "def", "fill_default_configuration", "(", "self", ")", ":", "logger", ".", "debug", "(", "\"Filling the unset properties with their default value:\"", ")", "types_creations", "=", "self", ".", "__class__", ".", "types_creations", "for", "o_type", "in", "types_creations", ...
Fill objects properties with default value if necessary :return: None
[ "Fill", "objects", "properties", "with", "default", "value", "if", "necessary" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1767-L1810
21,186
Alignak-monitoring/alignak
alignak/objects/config.py
Config.log_daemons_list
def log_daemons_list(self): """Log Alignak daemons list :return: """ daemons = [self.arbiters, self.schedulers, self.pollers, self.brokers, self.reactionners, self.receivers] for daemons_list in daemons: if not daemons_list: logger.debug("- %ss: None", daemons_list.inner_class.my_type) else: logger.debug("- %ss: %s", daemons_list.inner_class.my_type, ','.join([daemon.get_name() for daemon in daemons_list]))
python
def log_daemons_list(self): daemons = [self.arbiters, self.schedulers, self.pollers, self.brokers, self.reactionners, self.receivers] for daemons_list in daemons: if not daemons_list: logger.debug("- %ss: None", daemons_list.inner_class.my_type) else: logger.debug("- %ss: %s", daemons_list.inner_class.my_type, ','.join([daemon.get_name() for daemon in daemons_list]))
[ "def", "log_daemons_list", "(", "self", ")", ":", "daemons", "=", "[", "self", ".", "arbiters", ",", "self", ".", "schedulers", ",", "self", ".", "pollers", ",", "self", ".", "brokers", ",", "self", ".", "reactionners", ",", "self", ".", "receivers", "...
Log Alignak daemons list :return:
[ "Log", "Alignak", "daemons", "list" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L1830-L1842
21,187
Alignak-monitoring/alignak
alignak/objects/config.py
Config.got_broker_module_type_defined
def got_broker_module_type_defined(self, module_type): """Check if a module type is defined in one of the brokers :param module_type: module type to search for :type module_type: str :return: True if mod_type is found else False :rtype: bool """ for broker_link in self.brokers: for module in broker_link.modules: if module.is_a_module(module_type): return True return False
python
def got_broker_module_type_defined(self, module_type): for broker_link in self.brokers: for module in broker_link.modules: if module.is_a_module(module_type): return True return False
[ "def", "got_broker_module_type_defined", "(", "self", ",", "module_type", ")", ":", "for", "broker_link", "in", "self", ".", "brokers", ":", "for", "module", "in", "broker_link", ".", "modules", ":", "if", "module", ".", "is_a_module", "(", "module_type", ")",...
Check if a module type is defined in one of the brokers :param module_type: module type to search for :type module_type: str :return: True if mod_type is found else False :rtype: bool
[ "Check", "if", "a", "module", "type", "is", "defined", "in", "one", "of", "the", "brokers" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2083-L2095
21,188
Alignak-monitoring/alignak
alignak/objects/config.py
Config.got_scheduler_module_type_defined
def got_scheduler_module_type_defined(self, module_type): """Check if a module type is defined in one of the schedulers :param module_type: module type to search for :type module_type: str :return: True if mod_type is found else False :rtype: bool TODO: Factorize it with got_broker_module_type_defined """ for scheduler_link in self.schedulers: for module in scheduler_link.modules: if module.is_a_module(module_type): return True return False
python
def got_scheduler_module_type_defined(self, module_type): for scheduler_link in self.schedulers: for module in scheduler_link.modules: if module.is_a_module(module_type): return True return False
[ "def", "got_scheduler_module_type_defined", "(", "self", ",", "module_type", ")", ":", "for", "scheduler_link", "in", "self", ".", "schedulers", ":", "for", "module", "in", "scheduler_link", ".", "modules", ":", "if", "module", ".", "is_a_module", "(", "module_t...
Check if a module type is defined in one of the schedulers :param module_type: module type to search for :type module_type: str :return: True if mod_type is found else False :rtype: bool TODO: Factorize it with got_broker_module_type_defined
[ "Check", "if", "a", "module", "type", "is", "defined", "in", "one", "of", "the", "schedulers" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2097-L2110
21,189
Alignak-monitoring/alignak
alignak/objects/config.py
Config.got_arbiter_module_type_defined
def got_arbiter_module_type_defined(self, module_type): """Check if a module type is defined in one of the arbiters Also check the module name :param module_type: module type to search for :type module_type: str :return: True if mod_type is found else False :rtype: bool TODO: Factorize it with got_broker_module_type_defined: """ for arbiter in self.arbiters: # Do like the linkify will do after.... for module in getattr(arbiter, 'modules', []): # So look at what the arbiter try to call as module module_name = module.get_name() # Ok, now look in modules... for mod in self.modules: # try to see if this module is the good type if getattr(mod, 'python_name', '').strip() == module_type.strip(): # if so, the good name? if getattr(mod, 'name', '').strip() == module_name: return True return False
python
def got_arbiter_module_type_defined(self, module_type): for arbiter in self.arbiters: # Do like the linkify will do after.... for module in getattr(arbiter, 'modules', []): # So look at what the arbiter try to call as module module_name = module.get_name() # Ok, now look in modules... for mod in self.modules: # try to see if this module is the good type if getattr(mod, 'python_name', '').strip() == module_type.strip(): # if so, the good name? if getattr(mod, 'name', '').strip() == module_name: return True return False
[ "def", "got_arbiter_module_type_defined", "(", "self", ",", "module_type", ")", ":", "for", "arbiter", "in", "self", ".", "arbiters", ":", "# Do like the linkify will do after....", "for", "module", "in", "getattr", "(", "arbiter", ",", "'modules'", ",", "[", "]",...
Check if a module type is defined in one of the arbiters Also check the module name :param module_type: module type to search for :type module_type: str :return: True if mod_type is found else False :rtype: bool TODO: Factorize it with got_broker_module_type_defined:
[ "Check", "if", "a", "module", "type", "is", "defined", "in", "one", "of", "the", "arbiters", "Also", "check", "the", "module", "name" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2112-L2134
21,190
Alignak-monitoring/alignak
alignak/objects/config.py
Config.create_business_rules
def create_business_rules(self): """Create business rules for hosts and services :return: None """ self.hosts.create_business_rules(self.hosts, self.services, self.hostgroups, self.servicegroups, self.macromodulations, self.timeperiods) self.services.create_business_rules(self.hosts, self.services, self.hostgroups, self.servicegroups, self.macromodulations, self.timeperiods)
python
def create_business_rules(self): self.hosts.create_business_rules(self.hosts, self.services, self.hostgroups, self.servicegroups, self.macromodulations, self.timeperiods) self.services.create_business_rules(self.hosts, self.services, self.hostgroups, self.servicegroups, self.macromodulations, self.timeperiods)
[ "def", "create_business_rules", "(", "self", ")", ":", "self", ".", "hosts", ".", "create_business_rules", "(", "self", ".", "hosts", ",", "self", ".", "services", ",", "self", ".", "hostgroups", ",", "self", ".", "servicegroups", ",", "self", ".", "macrom...
Create business rules for hosts and services :return: None
[ "Create", "business", "rules", "for", "hosts", "and", "services" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2136-L2146
21,191
Alignak-monitoring/alignak
alignak/objects/config.py
Config.create_business_rules_dependencies
def create_business_rules_dependencies(self): """Create business rules dependencies for hosts and services :return: None """ for item in itertools.chain(self.hosts, self.services): if not item.got_business_rule: continue bp_items = item.business_rule.list_all_elements() for bp_item_uuid in bp_items: if bp_item_uuid in self.hosts: bp_item = self.hosts[bp_item_uuid] notif_options = item.business_rule_host_notification_options else: # We have a service bp_item = self.services[bp_item_uuid] notif_options = item.business_rule_service_notification_options if notif_options: bp_item.notification_options = notif_options bp_item.act_depend_of_me.append((item.uuid, ['d', 'u', 's', 'f', 'c', 'w', 'x'], '', True)) # TODO: Is it necessary? We already have this info in act_depend_* attributes item.parent_dependencies.add(bp_item.uuid) bp_item.child_dependencies.add(item.uuid)
python
def create_business_rules_dependencies(self): for item in itertools.chain(self.hosts, self.services): if not item.got_business_rule: continue bp_items = item.business_rule.list_all_elements() for bp_item_uuid in bp_items: if bp_item_uuid in self.hosts: bp_item = self.hosts[bp_item_uuid] notif_options = item.business_rule_host_notification_options else: # We have a service bp_item = self.services[bp_item_uuid] notif_options = item.business_rule_service_notification_options if notif_options: bp_item.notification_options = notif_options bp_item.act_depend_of_me.append((item.uuid, ['d', 'u', 's', 'f', 'c', 'w', 'x'], '', True)) # TODO: Is it necessary? We already have this info in act_depend_* attributes item.parent_dependencies.add(bp_item.uuid) bp_item.child_dependencies.add(item.uuid)
[ "def", "create_business_rules_dependencies", "(", "self", ")", ":", "for", "item", "in", "itertools", ".", "chain", "(", "self", ".", "hosts", ",", "self", ".", "services", ")", ":", "if", "not", "item", ".", "got_business_rule", ":", "continue", "bp_items",...
Create business rules dependencies for hosts and services :return: None
[ "Create", "business", "rules", "dependencies", "for", "hosts", "and", "services" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2148-L2175
21,192
Alignak-monitoring/alignak
alignak/objects/config.py
Config.propagate_timezone_option
def propagate_timezone_option(self): """Set our timezone value and give it too to unset satellites :return: None """ if self.use_timezone: # first apply myself os.environ['TZ'] = self.use_timezone time.tzset() tab = [self.schedulers, self.pollers, self.brokers, self.receivers, self.reactionners] for sat_list in tab: for sat in sat_list: if sat.use_timezone == 'NOTSET': setattr(sat, 'use_timezone', self.use_timezone)
python
def propagate_timezone_option(self): if self.use_timezone: # first apply myself os.environ['TZ'] = self.use_timezone time.tzset() tab = [self.schedulers, self.pollers, self.brokers, self.receivers, self.reactionners] for sat_list in tab: for sat in sat_list: if sat.use_timezone == 'NOTSET': setattr(sat, 'use_timezone', self.use_timezone)
[ "def", "propagate_timezone_option", "(", "self", ")", ":", "if", "self", ".", "use_timezone", ":", "# first apply myself", "os", ".", "environ", "[", "'TZ'", "]", "=", "self", ".", "use_timezone", "time", ".", "tzset", "(", ")", "tab", "=", "[", "self", ...
Set our timezone value and give it too to unset satellites :return: None
[ "Set", "our", "timezone", "value", "and", "give", "it", "too", "to", "unset", "satellites" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2291-L2305
21,193
Alignak-monitoring/alignak
alignak/objects/config.py
Config.linkify_templates
def linkify_templates(self): """ Like for normal object, we link templates with each others :return: None """ self.hosts.linkify_templates() self.contacts.linkify_templates() self.services.linkify_templates() self.servicedependencies.linkify_templates() self.hostdependencies.linkify_templates() self.timeperiods.linkify_templates() self.hostsextinfo.linkify_templates() self.servicesextinfo.linkify_templates() self.escalations.linkify_templates() # But also old srv and host escalations self.serviceescalations.linkify_templates() self.hostescalations.linkify_templates()
python
def linkify_templates(self): self.hosts.linkify_templates() self.contacts.linkify_templates() self.services.linkify_templates() self.servicedependencies.linkify_templates() self.hostdependencies.linkify_templates() self.timeperiods.linkify_templates() self.hostsextinfo.linkify_templates() self.servicesextinfo.linkify_templates() self.escalations.linkify_templates() # But also old srv and host escalations self.serviceescalations.linkify_templates() self.hostescalations.linkify_templates()
[ "def", "linkify_templates", "(", "self", ")", ":", "self", ".", "hosts", ".", "linkify_templates", "(", ")", "self", ".", "contacts", ".", "linkify_templates", "(", ")", "self", ".", "services", ".", "linkify_templates", "(", ")", "self", ".", "servicedepend...
Like for normal object, we link templates with each others :return: None
[ "Like", "for", "normal", "object", "we", "link", "templates", "with", "each", "others" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2307-L2323
21,194
Alignak-monitoring/alignak
alignak/objects/config.py
Config.remove_templates
def remove_templates(self): """Clean useless elements like templates because they are not needed anymore :return: None """ self.hosts.remove_templates() self.contacts.remove_templates() self.services.remove_templates() self.servicedependencies.remove_templates() self.hostdependencies.remove_templates() self.timeperiods.remove_templates()
python
def remove_templates(self): self.hosts.remove_templates() self.contacts.remove_templates() self.services.remove_templates() self.servicedependencies.remove_templates() self.hostdependencies.remove_templates() self.timeperiods.remove_templates()
[ "def", "remove_templates", "(", "self", ")", ":", "self", ".", "hosts", ".", "remove_templates", "(", ")", "self", ".", "contacts", ".", "remove_templates", "(", ")", "self", ".", "services", ".", "remove_templates", "(", ")", "self", ".", "servicedependenci...
Clean useless elements like templates because they are not needed anymore :return: None
[ "Clean", "useless", "elements", "like", "templates", "because", "they", "are", "not", "needed", "anymore" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2566-L2576
21,195
Alignak-monitoring/alignak
alignak/objects/config.py
Config.show_errors
def show_errors(self): """ Loop over configuration warnings and log them as INFO log Loop over configuration errors and log them as INFO log Note that the warnings and errors are logged on the fly during the configuration parsing. It is not necessary to log as WARNING and ERROR in this function which is used as a sum-up on the end of configuration parsing when an error has been detected. :return: None """ if self.configuration_warnings: logger.warning("Configuration warnings:") for msg in self.configuration_warnings: logger.warning(msg) if self.configuration_errors: logger.warning("Configuration errors:") for msg in self.configuration_errors: logger.warning(msg)
python
def show_errors(self): if self.configuration_warnings: logger.warning("Configuration warnings:") for msg in self.configuration_warnings: logger.warning(msg) if self.configuration_errors: logger.warning("Configuration errors:") for msg in self.configuration_errors: logger.warning(msg)
[ "def", "show_errors", "(", "self", ")", ":", "if", "self", ".", "configuration_warnings", ":", "logger", ".", "warning", "(", "\"Configuration warnings:\"", ")", "for", "msg", "in", "self", ".", "configuration_warnings", ":", "logger", ".", "warning", "(", "ms...
Loop over configuration warnings and log them as INFO log Loop over configuration errors and log them as INFO log Note that the warnings and errors are logged on the fly during the configuration parsing. It is not necessary to log as WARNING and ERROR in this function which is used as a sum-up on the end of configuration parsing when an error has been detected. :return: None
[ "Loop", "over", "configuration", "warnings", "and", "log", "them", "as", "INFO", "log", "Loop", "over", "configuration", "errors", "and", "log", "them", "as", "INFO", "log" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L2578-L2596
21,196
Alignak-monitoring/alignak
alignak/objects/config.py
Config.prepare_for_sending
def prepare_for_sending(self): """The configuration needs to be serialized before being sent to a spare arbiter :return: None """ if [arbiter_link for arbiter_link in self.arbiters if arbiter_link.spare]: logger.info('Serializing the configuration for my spare arbiter...') # Now serialize the whole configuration, for sending to spare arbiters self.spare_arbiter_conf = serialize(self)
python
def prepare_for_sending(self): if [arbiter_link for arbiter_link in self.arbiters if arbiter_link.spare]: logger.info('Serializing the configuration for my spare arbiter...') # Now serialize the whole configuration, for sending to spare arbiters self.spare_arbiter_conf = serialize(self)
[ "def", "prepare_for_sending", "(", "self", ")", ":", "if", "[", "arbiter_link", "for", "arbiter_link", "in", "self", ".", "arbiters", "if", "arbiter_link", ".", "spare", "]", ":", "logger", ".", "info", "(", "'Serializing the configuration for my spare arbiter...'",...
The configuration needs to be serialized before being sent to a spare arbiter :return: None
[ "The", "configuration", "needs", "to", "be", "serialized", "before", "being", "sent", "to", "a", "spare", "arbiter" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L3042-L3051
21,197
Alignak-monitoring/alignak
alignak/objects/config.py
Config.dump
def dump(self, dump_file_name=None): """Dump configuration to a file in a JSON format :param dump_file_name: the file to dump configuration to :type dump_file_name: str :return: None """ config_dump = {} for _, _, category, _, _ in list(self.types_creations.values()): try: objs = [jsonify_r(i) for i in getattr(self, category)] except (TypeError, AttributeError): # pragma: no cover, simple protection logger.warning("Dumping configuration, '%s' not present in the configuration", category) continue container = getattr(self, category) if category == "services": objs = sorted(objs, key=lambda o: "%s/%s" % (o["host_name"], o["service_description"])) elif hasattr(container, "name_property"): name_prop = container.name_property objs = sorted(objs, key=lambda o, prop=name_prop: getattr(o, prop, '')) config_dump[category] = objs if not dump_file_name: dump_file_name = os.path.join(tempfile.gettempdir(), 'alignak-%s-cfg-dump-%d.json' % (self.name, int(time.time()))) try: logger.info('Dumping configuration to: %s', dump_file_name) fd = open(dump_file_name, "w") fd.write(json.dumps(config_dump, indent=4, separators=(',', ': '), sort_keys=True)) fd.close() logger.info('Dumped') except (OSError, IndexError) as exp: # pragma: no cover, should never happen... logger.critical("Error when dumping configuration to %s: %s", dump_file_name, str(exp))
python
def dump(self, dump_file_name=None): config_dump = {} for _, _, category, _, _ in list(self.types_creations.values()): try: objs = [jsonify_r(i) for i in getattr(self, category)] except (TypeError, AttributeError): # pragma: no cover, simple protection logger.warning("Dumping configuration, '%s' not present in the configuration", category) continue container = getattr(self, category) if category == "services": objs = sorted(objs, key=lambda o: "%s/%s" % (o["host_name"], o["service_description"])) elif hasattr(container, "name_property"): name_prop = container.name_property objs = sorted(objs, key=lambda o, prop=name_prop: getattr(o, prop, '')) config_dump[category] = objs if not dump_file_name: dump_file_name = os.path.join(tempfile.gettempdir(), 'alignak-%s-cfg-dump-%d.json' % (self.name, int(time.time()))) try: logger.info('Dumping configuration to: %s', dump_file_name) fd = open(dump_file_name, "w") fd.write(json.dumps(config_dump, indent=4, separators=(',', ': '), sort_keys=True)) fd.close() logger.info('Dumped') except (OSError, IndexError) as exp: # pragma: no cover, should never happen... logger.critical("Error when dumping configuration to %s: %s", dump_file_name, str(exp))
[ "def", "dump", "(", "self", ",", "dump_file_name", "=", "None", ")", ":", "config_dump", "=", "{", "}", "for", "_", ",", "_", ",", "category", ",", "_", ",", "_", "in", "list", "(", "self", ".", "types_creations", ".", "values", "(", ")", ")", ":...
Dump configuration to a file in a JSON format :param dump_file_name: the file to dump configuration to :type dump_file_name: str :return: None
[ "Dump", "configuration", "to", "a", "file", "in", "a", "JSON", "format" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/config.py#L3053-L3090
21,198
Alignak-monitoring/alignak
alignak/daemons/arbiterdaemon.py
Arbiter.push_broks_to_broker
def push_broks_to_broker(self): # pragma: no cover - not used! """Send all broks from arbiter internal list to broker The arbiter get some broks and then pushes them to all the brokers. :return: None """ someone_is_concerned = False sent = False for broker_link in self.conf.brokers: # Send only if the broker is concerned... if not broker_link.manage_arbiters: continue someone_is_concerned = True if broker_link.reachable: logger.debug("Sending %d broks to the broker %s", len(self.broks), broker_link.name) if broker_link.push_broks(self.broks): statsmgr.counter('broks.pushed.count', len(self.broks)) sent = True if not someone_is_concerned or sent: # No one is anymore interested with... del self.broks[:]
python
def push_broks_to_broker(self): # pragma: no cover - not used! someone_is_concerned = False sent = False for broker_link in self.conf.brokers: # Send only if the broker is concerned... if not broker_link.manage_arbiters: continue someone_is_concerned = True if broker_link.reachable: logger.debug("Sending %d broks to the broker %s", len(self.broks), broker_link.name) if broker_link.push_broks(self.broks): statsmgr.counter('broks.pushed.count', len(self.broks)) sent = True if not someone_is_concerned or sent: # No one is anymore interested with... del self.broks[:]
[ "def", "push_broks_to_broker", "(", "self", ")", ":", "# pragma: no cover - not used!", "someone_is_concerned", "=", "False", "sent", "=", "False", "for", "broker_link", "in", "self", ".", "conf", ".", "brokers", ":", "# Send only if the broker is concerned...", "if", ...
Send all broks from arbiter internal list to broker The arbiter get some broks and then pushes them to all the brokers. :return: None
[ "Send", "all", "broks", "from", "arbiter", "internal", "list", "to", "broker" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/arbiterdaemon.py#L268-L291
21,199
Alignak-monitoring/alignak
alignak/daemons/arbiterdaemon.py
Arbiter.push_external_commands_to_schedulers
def push_external_commands_to_schedulers(self): # pragma: no cover - not used! """Send external commands to schedulers :return: None """ # Now get all external commands and push them to the schedulers for external_command in self.external_commands: self.external_commands_manager.resolve_command(external_command) # Now for all reachable schedulers, send the commands sent = False for scheduler_link in self.conf.schedulers: ext_cmds = scheduler_link.external_commands if ext_cmds and scheduler_link.reachable: logger.debug("Sending %d commands to the scheduler %s", len(ext_cmds), scheduler_link.name) if scheduler_link.push_external_commands(ext_cmds): statsmgr.counter('external-commands.pushed.count', len(ext_cmds)) sent = True if sent: # Clean the pushed commands scheduler_link.external_commands.clear()
python
def push_external_commands_to_schedulers(self): # pragma: no cover - not used! # Now get all external commands and push them to the schedulers for external_command in self.external_commands: self.external_commands_manager.resolve_command(external_command) # Now for all reachable schedulers, send the commands sent = False for scheduler_link in self.conf.schedulers: ext_cmds = scheduler_link.external_commands if ext_cmds and scheduler_link.reachable: logger.debug("Sending %d commands to the scheduler %s", len(ext_cmds), scheduler_link.name) if scheduler_link.push_external_commands(ext_cmds): statsmgr.counter('external-commands.pushed.count', len(ext_cmds)) sent = True if sent: # Clean the pushed commands scheduler_link.external_commands.clear()
[ "def", "push_external_commands_to_schedulers", "(", "self", ")", ":", "# pragma: no cover - not used!", "# Now get all external commands and push them to the schedulers", "for", "external_command", "in", "self", ".", "external_commands", ":", "self", ".", "external_commands_manager...
Send external commands to schedulers :return: None
[ "Send", "external", "commands", "to", "schedulers" ]
f3c145207e83159b799d3714e4241399c7740a64
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/daemons/arbiterdaemon.py#L293-L314