Code stringlengths 103 85.9k | Summary listlengths 0 94 |
|---|---|
Please provide a description of the function:def get_results_from_passive(self, scheduler_instance_id):
# Do I know this scheduler?
# logger.info("My schedulers: %s %s", self.schedulers, type(self.schedulers))
if not self.schedulers:
# Probably not yet configured ...
... | [
"Get executed actions results from a passive satellite for a specific scheduler\n\n :param scheduler_instance_id: scheduler id\n :type scheduler_instance_id: int\n :return: Results list\n :rtype: list\n "
] |
Please provide a description of the function:def clean_previous_run(self):
# Clean all lists
self.arbiters.clear()
self.schedulers.clear()
with self.external_commands_lock:
self.external_commands = self.external_commands[:] | [
"Clean variables from previous configuration,\n such as schedulers, broks and external commands\n\n :return: None\n "
] |
Please provide a description of the function:def setup_new_conf(self):
# pylint: disable=too-many-locals, too-many-branches
with self.conf_lock:
# No more configuration now!
self.have_conf = False
logger.info("Received a new configuration (arbiters / schedul... | [
"Setup the new configuration received from Arbiter\n\n This function is the generic treatment needed for every Alignak daemon when it receivss\n a new configuration from the Arbiter:\n - save the new configuration\n - dump the main configuration elements\n - get its own configurat... |
Please provide a description of the function:def get_events(self):
res = copy.copy(self.events)
del self.events[:]
return res | [
"Get event list from satellite\n\n :return: A copy of the events list\n :rtype: list\n "
] |
Please provide a description of the function:def get_daemon_stats(self, details=False):
# call the daemon one
res = super(BaseSatellite, self).get_daemon_stats(details=details)
counters = res['counters']
counters['external-commands'] = len(self.external_commands)
counte... | [
"Increase the stats provided by the Daemon base class\n\n :return: stats dictionary\n :rtype: dict\n "
] |
Please provide a description of the function:def manage_action_return(self, action):
# Maybe our workers send us something else than an action
# if so, just add this in other queues and return
# todo: test a class instance
if action.__class__.my_type not in ['check', 'notificati... | [
"Manage action return from Workers\n We just put them into the corresponding sched\n and we clean unused properties like my_scheduler\n\n :param action: the action to manage\n :type action: alignak.action.Action\n :return: None\n "
] |
Please provide a description of the function:def push_results(self):
# For all schedulers, we check for wait_homerun
# and we send back results
for scheduler_link_uuid in self.schedulers:
scheduler_link = self.schedulers[scheduler_link_uuid]
if not scheduler_link... | [
"Push the checks/actions results to our schedulers\n\n :return: None\n "
] |
Please provide a description of the function:def create_and_launch_worker(self, module_name='fork'):
logger.info("Allocating new '%s' worker...", module_name)
# If we are in the fork module, we do not specify a target
target = None
__warned = []
if module_name == 'fork'... | [
"Create and launch a new worker, and put it into self.workers\n It can be mortal or not\n\n :param module_name: the module name related to the worker\n default is \"fork\" for no module\n Indeed, it is actually the module 'python_name'\n :t... |
Please provide a description of the function:def do_stop_workers(self):
logger.info("Stopping all workers (%d)", len(self.workers))
for worker in list(self.workers.values()):
try:
logger.info(" - stopping '%s'", worker.get_id())
worker.terminate()
... | [
"Stop all workers\n\n :return: None\n "
] |
Please provide a description of the function:def get_broks(self):
res = copy.copy(self.broks)
del self.broks[:]
return res | [
"Get brok list from satellite\n\n :return: A copy of the broks list\n :rtype: list\n "
] |
Please provide a description of the function:def check_and_del_zombie_workers(self): # pragma: no cover, not with unit tests...
# pylint: disable= not-callable
# Active children make a join with everyone, useful :)
# active_children()
for p in active_children():
log... | [
"Check if worker are fine and kill them if not.\n Dispatch the actions in the worker to another one\n\n TODO: see if unit tests would allow to check this code?\n\n :return: None\n "
] |
Please provide a description of the function:def adjust_worker_number_by_load(self):
if self.interrupted:
logger.debug("Trying to adjust worker number. Ignoring because we are stopping.")
return
to_del = []
logger.debug("checking worker count."
... | [
"Try to create the minimum workers specified in the configuration\n\n :return: None\n "
] |
Please provide a description of the function:def _get_queue_for_the_action(self, action):
# get the module name, if not, take fork
mod = getattr(action, 'module_type', 'fork')
queues = list(self.q_by_mod[mod].items())
# Maybe there is no more queue, it's very bad!
if no... | [
"Find action queue for the action depending on the module.\n The id is found with action modulo on action id\n\n :param a: the action that need action queue to be assigned\n :type action: object\n :return: worker id and queue. (0, None) if no queue for the module_type\n :rtype: tu... |
Please provide a description of the function:def add_actions(self, actions_list, scheduler_instance_id):
# We check for new check in each schedulers and put the result in new_checks
scheduler_link = None
for scheduler_id in self.schedulers:
logger.debug("Trying to add an act... | [
"Add a list of actions to the satellite queues\n\n :param actions_list: Actions list to add\n :type actions_list: list\n :param scheduler_instance_id: sheduler link to assign the actions to\n :type scheduler_instance_id: SchedulerLink\n :return: None\n "
] |
Please provide a description of the function:def assign_to_a_queue(self, action):
(worker_id, queue) = self._get_queue_for_the_action(action)
if not worker_id:
return
# Tag the action as "in the worker i"
action.my_worker = worker_id
action.status = ACT_STAT... | [
"Take an action and put it to a worker actions queue\n\n :param action: action to put\n :type action: alignak.action.Action\n :return: None\n "
] |
Please provide a description of the function:def get_new_actions(self):
try:
_t0 = time.time()
self.do_get_new_actions()
statsmgr.timer('actions.got.time', time.time() - _t0)
except RuntimeError:
logger.error("Exception like issue #1007") | [
" Wrapper function for do_get_new_actions\n For stats purpose\n\n :return: None\n TODO: Use a decorator for timing this function\n "
] |
Please provide a description of the function:def do_get_new_actions(self):
# Here are the differences between a poller and a reactionner:
# Poller will only do checks,
# Reactionner will do actions (notifications and event handlers)
do_checks = self.__class__.do_checks
d... | [
"Get new actions from schedulers\n Create a Message and put into the module queue\n REF: doc/alignak-action-queues.png (1)\n\n :return: None\n "
] |
Please provide a description of the function:def clean_previous_run(self):
# Execute the base class treatment...
super(Satellite, self).clean_previous_run()
# Clean my lists
del self.broks[:]
del self.events[:] | [
"Clean variables from previous configuration,\n such as schedulers, broks and external commands\n\n :return: None\n "
] |
Please provide a description of the function:def do_loop_turn(self): # pylint: disable=too-many-branches
# Try to see if one of my module is dead, and restart previously dead modules
self.check_and_del_zombie_modules()
# Also if some zombie workers exist...
self.check_and_del_... | [
"Satellite main loop::\n\n * Check and delete zombies actions / modules\n * Get returns from queues\n * Adjust worker number\n * Get new actions\n\n :return: None\n "
] |
Please provide a description of the function:def setup_new_conf(self):
# pylint: disable=too-many-branches
# Execute the base class treatment...
super(Satellite, self).setup_new_conf()
# ...then our own specific treatment!
with self.conf_lock:
logger.info("R... | [
"Setup the new configuration received from Arbiter\n\n This function calls the base satellite treatment and manages the configuration needed\n for a simple satellite daemon that executes some actions (eg. poller or reactionner):\n - configure the passive mode\n - configure the workers\n ... |
Please provide a description of the function:def get_daemon_stats(self, details=False):
# call the daemon one
res = super(Satellite, self).get_daemon_stats(details=details)
counters = res['counters']
counters['broks'] = len(self.broks)
counters['events'] = len(self.even... | [
"Increase the stats provided by the Daemon base class\n\n :return: stats dictionary\n :rtype: dict\n "
] |
Please provide a description of the function:def main(self):
try:
# Start the daemon mode
if not self.do_daemon_init_and_start():
self.exit_on_error(message="Daemon initialization error", exit_code=3)
self.do_post_daemon_init()
# We wait... | [
"Main satellite function. Do init and then mainloop\n\n :return: None\n "
] |
Please provide a description of the function:def check_activation(self, contacts):
now = time.time()
was_is_in_effect = self.is_in_effect
self.is_in_effect = (self.start_time <= now <= self.end_time)
# Raise a log entry when we get in the downtime
if not was_is_in_effec... | [
"Enter or exit downtime if necessary\n\n :return: None\n "
] |
Please provide a description of the function:def exit(self, contacts):
contact = contacts[self.ref]
contact.raise_exit_downtime_log_entry()
self.can_be_deleted = True | [
"Wrapper to call raise_exit_downtime_log_entry for ref (host/service)\n set can_be_deleted to True\n\n :return: None\n "
] |
Please provide a description of the function:def cancel(self, contacts):
self.is_in_effect = False
contact = contacts[self.ref]
contact.raise_cancel_downtime_log_entry()
self.can_be_deleted = True | [
"Wrapper to call raise_cancel_downtime_log_entry for ref (host/service)\n set can_be_deleted to True\n set is_in_effect to False\n\n :return: None\n "
] |
Please provide a description of the function:def split_semicolon(line, maxsplit=None):
r
# Split on ';' character
split_line = line.split(';')
split_line_size = len(split_line)
# if maxsplit is not specified, we set it to the number of part
if maxsplit is None or maxsplit < 0:
maxsplit... | [
"Split a line on semicolons characters but not on the escaped semicolons\n\n :param line: line to split\n :type line: str\n :param maxsplit: maximal number of split (if None, no limit)\n :type maxsplit: None | int\n :return: split line\n :rtype: list\n\n >>> split_semicolon('a,b;c;;g')\n ['a... |
Please provide a description of the function:def jsonify_r(obj): # pragma: no cover, not for unit tests...
# pylint: disable=too-many-branches
res = {}
cls = obj.__class__
if not hasattr(cls, 'properties'):
try:
json.dumps(obj)
return obj
except TypeError:
... | [
"Convert an object into json (recursively on attribute)\n\n :param obj: obj to jsonify\n :type obj: object\n :return: json representation of obj\n :rtype: dict\n "
] |
Please provide a description of the function:def format_t_into_dhms_format(timestamp):
mins, timestamp = divmod(timestamp, 60)
hour, mins = divmod(mins, 60)
day, hour = divmod(hour, 24)
return '%sd %sh %sm %ss' % (day, hour, mins, timestamp) | [
" Convert an amount of second into day, hour, min and sec\n\n :param timestamp: seconds\n :type timestamp: int\n :return: 'Ad Bh Cm Ds'\n :rtype: str\n\n >>> format_t_into_dhms_format(456189)\n '5d 6h 43m 9s'\n\n >>> format_t_into_dhms_format(3600)\n '0d 1h 0m 0s'\n\n "
] |
Please provide a description of the function:def merge_periods(data):
# sort by start date
newdata = sorted(data, key=lambda drange: drange[0])
end = 0
for period in newdata:
if period[0] != end and period[0] != (end - 1):
end = period[1]
# dat = np.array(newdata)
dat =... | [
"\n Merge periods to have better continous periods.\n Like 350-450, 400-600 => 350-600\n\n :param data: list of periods\n :type data: list\n :return: better continous periods\n :rtype: list\n "
] |
Please provide a description of the function:def to_split(val, split_on_comma=True):
if isinstance(val, list):
return val
if not split_on_comma:
return [val]
val = val.split(',')
if val == ['']:
val = []
return val | [
"Try to split a string with comma separator.\n If val is already a list return it\n If we don't have to split just return [val]\n If split gives only [''] empty it\n\n :param val: value to split\n :type val:\n :param split_on_comma:\n :type split_on_comma: bool\n :return: split value on comm... |
Please provide a description of the function:def list_split(val, split_on_comma=True):
if not split_on_comma:
return val
new_val = []
for subval in val:
# This may happen when re-serializing
if isinstance(subval, list):
continue
new_val.extend(subval.split(',... | [
"Try to split each member of a list with comma separator.\n If we don't have to split just return val\n\n :param val: value to split\n :type val:\n :param split_on_comma:\n :type split_on_comma: bool\n :return: list with members split on comma\n :rtype: list\n\n >>> list_split(['a,b,c'], Fal... |
Please provide a description of the function:def to_best_int_float(val):
integer = int(float(val))
flt = float(val)
# If the f is a .0 value,
# best match is int
if integer == flt:
return integer
return flt | [
"Get best type for value between int and float\n\n :param val: value\n :type val:\n :return: int(float(val)) if int(float(val)) == float(val), else float(val)\n :rtype: int | float\n\n >>> to_best_int_float(\"20.1\")\n 20.1\n\n >>> to_best_int_float(\"20.0\")\n 20\n\n >>> to_best_int_floa... |
Please provide a description of the function:def dict_to_serialized_dict(ref, the_dict):
result = {}
for elt in list(the_dict.values()):
if not getattr(elt, 'serialize', None):
continue
result[elt.uuid] = elt.serialize()
return result | [
"Serialize the list of elements to a dictionary\n\n Used for the retention store\n\n :param ref: Not used\n :type ref:\n :param the_dict: dictionary to convert\n :type the_dict: dict\n :return: dict of serialized\n :rtype: dict\n "
] |
Please provide a description of the function:def list_to_serialized(ref, the_list):
result = []
for elt in the_list:
if not getattr(elt, 'serialize', None):
continue
result.append(elt.serialize())
return result | [
"Serialize the list of elements\n\n Used for the retention store\n\n :param ref: Not used\n :type ref:\n :param the_list: dictionary to convert\n :type the_list: dict\n :return: dict of serialized\n :rtype: dict\n "
] |
Please provide a description of the function:def to_hostnames_list(ref, tab): # pragma: no cover, to be deprecated?
res = []
for host in tab:
if hasattr(host, 'host_name'):
res.append(host.host_name)
return res | [
"Convert Host list into a list of host_name\n\n :param ref: Not used\n :type ref:\n :param tab: Host list\n :type tab: list[alignak.objects.host.Host]\n :return: host_name list\n :rtype: list\n "
] |
Please provide a description of the function:def to_svc_hst_distinct_lists(ref, tab): # pragma: no cover, to be deprecated?
res = {'hosts': [], 'services': []}
for elem in tab:
cls = elem.__class__
name = elem.get_full_name()
if cls.my_type == 'service':
res['services']... | [
"create a dict with 2 lists::\n\n * services: all services of the tab\n * hosts: all hosts of the tab\n\n :param ref: Not used\n :type ref:\n :param tab: list of Host and Service\n :type tab: list\n :return: dict with hosts and services names\n :rtype: dict\n "
] |
Please provide a description of the function:def master_then_spare(data):
master = []
spare = []
for sdata in data:
if sdata.spare:
spare.append(sdata)
else:
master.append(sdata)
rdata = []
rdata.extend(master)
rdata.extend(spare)
return rdata | [
"Return the provided satellites list sorted as:\n - alive first,\n - then spare\n - then dead\n satellites.\n\n :param data: the SatelliteLink list\n :type data: list\n :return: sorted list\n :rtype: list\n "
] |
Please provide a description of the function:def sort_by_number_values(x00, y00): # pragma: no cover, looks like not used!
if len(x00) < len(y00):
return 1
if len(x00) > len(y00):
return -1
# So is equal
return 0 | [
"Compare x00, y00 base on number of values\n\n :param x00: first elem to compare\n :type x00: list\n :param y00: second elem to compare\n :type y00: list\n :return: x00 > y00 (-1) if len(x00) > len(y00), x00 == y00 (0) if id equals, x00 < y00 (1) else\n :rtype: int\n "
] |
Please provide a description of the function:def average_percentile(values):
if not values:
return None, None, None
value_avg = round(float(sum(values)) / len(values), 2)
value_max = round(percentile(values, 95), 2)
value_min = round(percentile(values, 5), 2)
return value_avg, value_mi... | [
"\n Get the average, min percentile (5%) and\n max percentile (95%) of a list of values.\n\n :param values: list of value to compute\n :type values: list\n :return: tuple containing average, min and max value\n :rtype: tuple\n "
] |
Please provide a description of the function:def strip_and_uniq(tab):
_list = []
for elt in tab:
val = elt.strip()
if val and val not in _list:
_list.append(val)
return _list | [
"Strip every element of a list and keep a list of ordered unique values\n\n :param tab: list to strip\n :type tab: list\n :return: stripped list with unique values\n :rtype: list\n "
] |
Please provide a description of the function:def expand_ranges(value):
match_dict = RANGE_REGEX.match(value).groupdict() # the regex is supposed to always match..
before = match_dict['before']
after = match_dict['after']
from_value = match_dict['from']
if from_value is None:
yield valu... | [
"\n :param str value: The value to be \"expanded\".\n :return: A generator to yield the different resulting values from expanding\n the eventual ranges present in the input value.\n\n >>> tuple(expand_ranges(\"Item [1-3] - Bla\"))\n ('Item 1 - Bla', 'Item 2 - Bla', 'Item 3 - Bla')\n >>> t... |
Please provide a description of the function:def generate_key_value_sequences(entry, default_value):
no_one_yielded = True
for value in entry.split(','):
value = value.strip()
if not value:
continue
full_match = KEY_VALUES_REGEX.match(value)
if full_match is None... | [
"Parse a key value config entry (used in duplicate foreach)\n\n If we have a key that look like [X-Y] we will expand it into Y-X+1 keys\n\n :param str entry: The config line to be parsed.\n :param str default_value: The default value to be used when none is available.\n :return: a generator yielding dic... |
Please provide a description of the function:def filter_host_by_name(name):
def inner_filter(items):
host = items["host"]
if host is None:
return False
return host.host_name == name
return inner_filter | [
"Filter for host\n Filter on name\n\n :param name: name to filter\n :type name: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for host. Accept if host_name == name"
] |
Please provide a description of the function:def filter_host_by_regex(regex):
host_re = re.compile(regex)
def inner_filter(items):
host = items["host"]
if host is None:
return False
return host_re.match(host.host_name) is not None
return inner_filter | [
"Filter for host\n Filter on regex\n\n :param regex: regex to filter\n :type regex: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for host. Accept if regex match host_name"
] |
Please provide a description of the function:def filter_host_by_group(group):
def inner_filter(items):
host = items["host"]
if host is None:
return False
return group in [items["hostgroups"][g].hostgroup_name for g in host.hostgroups]
return inner_filter | [
"Filter for host\n Filter on group\n\n :param group: group name to filter\n :type group: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for host. Accept if group in host.hostgroups"
] |
Please provide a description of the function:def filter_host_by_tag(tpl):
def inner_filter(items):
host = items["host"]
if host is None:
return False
return tpl in [t.strip() for t in host.tags]
return inner_filter | [
"Filter for host\n Filter on tag\n\n :param tpl: tag to filter\n :type tpl: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for host. Accept if tag in host.tags"
] |
Please provide a description of the function:def filter_service_by_name(name):
def inner_filter(items):
service = items["service"]
if service is None:
return False
return service.service_description == name
return inner_filter | [
"Filter for service\n Filter on name\n\n :param name: name to filter\n :type name: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if service_description == name"
] |
Please provide a description of the function:def filter_service_by_regex_name(regex):
host_re = re.compile(regex)
def inner_filter(items):
service = items["service"]
if service is None:
return False
return host_re.match(service.service_description) is not None
... | [
"Filter for service\n Filter on regex\n\n :param regex: regex to filter\n :type regex: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if regex match service_description"
] |
Please provide a description of the function:def filter_service_by_host_name(host_name):
def inner_filter(items):
service = items["service"]
host = items["hosts"][service.host]
if service is None or host is None:
return False
return host.host_name == host_n... | [
"Filter for service\n Filter on host_name\n\n :param host_name: host_name to filter\n :type host_name: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if service.host.host_name == host_name"
] |
Please provide a description of the function:def filter_service_by_regex_host_name(regex):
host_re = re.compile(regex)
def inner_filter(items):
service = items["service"]
host = items["hosts"][service.host]
if service is None or host is None:
return False
... | [
"Filter for service\n Filter on regex host_name\n\n :param regex: regex to filter\n :type regex: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if regex match service.host.host_name"
] |
Please provide a description of the function:def filter_service_by_hostgroup_name(group):
def inner_filter(items):
service = items["service"]
host = items["hosts"][service.host]
if service is None or host is None:
return False
return group in [items["hostgr... | [
"Filter for service\n Filter on hostgroup\n\n :param group: hostgroup to filter\n :type group: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if hostgroup in service.host.hostgroups"
] |
Please provide a description of the function:def filter_service_by_host_tag_name(tpl):
def inner_filter(items):
service = items["service"]
host = items["hosts"][service.host]
if service is None or host is None:
return False
return tpl in [t.strip() for t in... | [
"Filter for service\n Filter on tag\n\n :param tpl: tag to filter\n :type tpl: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if tpl in service.host.tags"
] |
Please provide a description of the function:def filter_service_by_servicegroup_name(group):
def inner_filter(items):
service = items["service"]
if service is None:
return False
return group in [items["servicegroups"][g].servicegroup_name for g in service.servicegr... | [
"Filter for service\n Filter on group\n\n :param group: group to filter\n :type group: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if group in service.servicegroups"
] |
Please provide a description of the function:def filter_host_by_bp_rule_label(label):
def inner_filter(items):
host = items["host"]
if host is None:
return False
return label in host.labels
return inner_filter | [
"Filter for host\n Filter on label\n\n :param label: label to filter\n :type label: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for host. Accept if label in host.labels"
] |
Please provide a description of the function:def filter_service_by_host_bp_rule_label(label):
def inner_filter(items):
service = items["service"]
host = items["hosts"][service.host]
if service is None or host is None:
return False
return label in host.label... | [
"Filter for service\n Filter on label\n\n :param label: label to filter\n :type label: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if label in service.host.labels"
] |
Please provide a description of the function:def filter_service_by_bp_rule_label(label):
def inner_filter(items):
service = items["service"]
if service is None:
return False
return label in service.labels
return inner_filter | [
"Filter for service\n Filter on label\n\n :param label: label to filter\n :type label: str\n :return: Filter\n :rtype: bool\n ",
"Inner filter for service. Accept if label in service.labels"
] |
Please provide a description of the function:def parse_daemon_args(arbiter=False):
parser = argparse.ArgumentParser(description="Alignak version %s daemon parameters" % VERSION,
epilog="And that's it!")
if arbiter:
parser.add_argument('-a', '--arbiter', action='... | [
"Generic parsing function for daemons\n\n All daemons:\n '-n', \"--name\": Set the name of the daemon to pick in the configuration files.\n This allows an arbiter to find its own configuration in the whole Alignak configuration\n Using this parameter is mandatory for all the daemons except f... |
Please provide a description of the function:def manage_signal(self, sig, frame): # pylint: disable=unused-argument
logger.info("worker '%s' (pid=%d) received a signal: %s",
self._id, os.getpid(), SIGNALS_TO_NAMES_DICT[sig])
# Do not do anything... our master daemon is mana... | [
"Manage signals caught by the process but I do not do anything...\n our master daemon is managing our termination.\n\n :param sig: signal caught by daemon\n :type sig: str\n :param frame: current stack frame\n :type frame:\n :return: None\n "
] |
Please provide a description of the function:def set_exit_handler(self):
signal.signal(signal.SIGINT, self.manage_signal)
signal.signal(signal.SIGTERM, self.manage_signal)
signal.signal(signal.SIGHUP, self.manage_signal)
signal.signal(signal.SIGQUIT, self.manage_signal) | [
"Set the signal handler to manage_signal (defined in this class)\n Only set handlers for signal.SIGTERM, signal.SIGINT, signal.SIGUSR1, signal.SIGUSR2\n\n :return: None\n "
] |
Please provide a description of the function:def get_new_checks(self, queue, return_queue):
try:
logger.debug("get_new_checks: %s / %s", len(self.checks), self.processes_by_worker)
while len(self.checks) < self.processes_by_worker:
msg = queue.get_nowait()
... | [
"Get new checks if less than nb_checks_max\n If no new checks got and no check in queue, sleep for 1 sec\n REF: doc/alignak-action-queues.png (3)\n\n :return: None\n "
] |
Please provide a description of the function:def launch_new_checks(self):
# queue
for chk in self.checks:
if chk.status not in [ACT_STATUS_QUEUED]:
continue
logger.debug("Launch check: %s", chk.uuid)
self._idletime = 0
self.actions... | [
"Launch checks that are in status\n REF: doc/alignak-action-queues.png (4)\n\n :return: None\n "
] |
Please provide a description of the function:def manage_finished_checks(self, queue):
to_del = []
wait_time = 1.0
now = time.time()
logger.debug("--- manage finished checks")
for action in self.checks:
logger.debug("--- checking: last poll: %s, now: %s, wait_... | [
"Check the status of checks\n if done, return message finished :)\n REF: doc/alignak-action-queues.png (5)\n\n :return: None\n "
] |
Please provide a description of the function:def check_for_system_time_change(self): # pragma: no cover, hardly testable with unit tests...
now = time.time()
difference = now - self.t_each_loop
# Now set the new value for the tick loop
self.t_each_loop = now
# If we h... | [
"Check if our system time change. If so, change our\n\n :return: 0 if the difference < 900, difference else\n :rtype: int\n "
] |
Please provide a description of the function:def work(self, actions_queue, returns_queue, control_queue=None): # pragma: no cover
try:
logger.info("[%s] (pid=%d) starting my job...", self._id, os.getpid())
self.do_work(actions_queue, returns_queue, control_queue)
lo... | [
"Wrapper function for do_work in order to catch the exception\n to see the real work, look at do_work\n\n :param actions_queue: Global Queue Master->Slave\n :type actions_queue: Queue.Queue\n :param returns_queue: queue managed by manager\n :type returns_queue: Queue.Queue\n ... |
Please provide a description of the function:def do_work(self, actions_queue, returns_queue, control_queue=None): # pragma: no cover
# restore default signal handler for the workers:
# signal.signal(signal.SIGTERM, signal.SIG_DFL)
self.interrupted = False
self.set_exit_handler(... | [
"Main function of the worker.\n * Get checks\n * Launch new checks\n * Manage finished checks\n\n :param actions_queue: Global Queue Master->Slave\n :type actions_queue: Queue.Queue\n :param returns_queue: queue managed by manager\n :type returns_queue: Queue.Queue\n... |
Please provide a description of the function:def read_requirements(filename='requirements.txt'):
# allow for some leeway with the argument
if not filename.startswith('requirements'):
filename = 'requirements-' + filename
if not os.path.splitext(filename)[1]:
filename += '.txt' # no ext... | [
"Reads the list of requirements from given file.\n\n :param filename: Filename to read the requirements from.\n Uses ``'requirements.txt'`` by default.\n\n :return: Requirments as list of strings.\n "
] |
Please provide a description of the function:def init_running_properties(self):
for prop, entry in list(self.__class__.running_properties.items()):
val = entry.default
# Make a copy of the value for complex iterable types
# As such, each instance has its own copy and... | [
"\n Initialize the running_properties.\n Each instance have own property.\n\n :return: None\n "
] |
Please provide a description of the function:def copy(self):
# New dummy item with it's own running properties
copied_item = self.__class__({})
# Now, copy the properties
for prop in self.__class__.properties:
if prop in ['uuid']:
continue
... | [
"\n Get a copy of this item but with a new id\n\n :return: copy of this object with a new id\n :rtype: object\n "
] |
Please provide a description of the function:def clean(self):
for prop in ('imported_from', 'use', 'plus', 'templates', 'register'):
try:
delattr(self, prop)
except AttributeError:
pass
for prop in ('configuration_warnings', 'configuration... | [
"\n Clean properties only needed for initialization and configuration\n\n :return: None\n "
] |
Please provide a description of the function:def serialize(self):
cls = self.__class__
# id is not in *_properties
res = {'uuid': self.uuid}
for prop in cls.properties:
if hasattr(self, prop) and getattr(self, prop, None) is not None:
res[prop] = seri... | [
"This function serialize into a simple dict object.\n It is used when transferring data to other daemons over the network (http)\n\n Here is the generic function that simply export attributes declared in the\n properties dictionary and the running_properties of the object.\n\n :return: D... |
Please provide a description of the function:def load_global_conf(cls, global_configuration):
logger.debug("Propagate global parameter for %s:", cls)
for prop, entry in global_configuration.properties.items():
# If some global managed configuration properties have a class_inherit cl... | [
"\n Apply global Alignak configuration.\n\n Some objects inherit some properties from the global configuration if they do not\n define their own value. E.g. the global 'accept_passive_service_checks' is inherited\n by the services as 'accept_passive_checks'\n\n :param cls: parent ... |
Please provide a description of the function:def get_templates(self):
use = getattr(self, 'use', '')
if isinstance(use, list):
return [n.strip() for n in use if n.strip()]
return [n.strip() for n in use.split(',') if n.strip()] | [
"\n Get list of templates this object use\n\n :return: list of templates\n :rtype: list\n "
] |
Please provide a description of the function:def get_all_plus_and_delete(self):
res = {}
props = list(self.plus.keys()) # we delete entries, so no for ... in ...
for prop in props:
res[prop] = self.get_plus_and_delete(prop)
return res | [
"\n Get all self.plus items of list. We copy it, delete the original and return the copy list\n\n :return: list of self.plus\n :rtype: list\n "
] |
Please provide a description of the function:def get_plus_and_delete(self, prop):
val = self.plus[prop]
del self.plus[prop]
return val | [
"\n get a copy of the property (parameter) in self.plus, delete the original and return the\n value of copy\n\n :param prop: a property\n :type prop: str\n :return: return the value of the property\n :rtype: str\n "
] |
Please provide a description of the function:def add_error(self, txt):
self.configuration_errors.append(txt)
self.conf_is_correct = False | [
"Add a message in the configuration errors list so we can print them\n all in one place\n\n Set the object configuration as not correct\n\n :param txt: error message\n :type txt: str\n :return: None\n "
] |
Please provide a description of the function:def is_correct(self):
state = self.conf_is_correct
properties = self.__class__.properties
for prop, entry in list(properties.items()):
if hasattr(self, 'special_properties') and prop in getattr(self, 'special_properties'):
... | [
"\n Check if this object is correct\n\n This function:\n - checks if the required properties are defined, ignoring special_properties if some exist\n - logs the previously found warnings and errors\n\n :return: True if it's correct, otherwise False\n :rtype: bool\n "... |
Please provide a description of the function:def old_properties_names_to_new(self):
old_properties = getattr(self.__class__, "old_properties", {})
for old_name, new_name in list(old_properties.items()):
# Ok, if we got old_name and NO new name,
# we switch the name
... | [
"\n This function is used by service and hosts to transform Nagios2 parameters to Nagios3\n ones, like normal_check_interval to check_interval. There is a old_parameters tab\n in Classes that give such modifications to do.\n\n :return: None\n "
] |
Please provide a description of the function:def get_raw_import_values(self): # pragma: no cover, never used
res = {}
properties = list(self.__class__.properties.keys())
# Register is not by default in the properties
if 'register' not in properties:
properties.appen... | [
"\n Get properties => values of this object\n\n TODO: never called anywhere, still useful?\n\n :return: dictionary of properties => values\n :rtype: dict\n "
] |
Please provide a description of the function:def del_downtime(self, downtime_id):
if downtime_id in self.downtimes:
self.downtimes[downtime_id].can_be_deleted = True
del self.downtimes[downtime_id] | [
"\n Delete a downtime in this object\n\n :param downtime_id: id of the downtime to delete\n :type downtime_id: int\n :return: None\n "
] |
Please provide a description of the function:def get_property_value_for_brok(self, prop, tab):
entry = tab[prop]
# Get the current value, or the default if need
value = getattr(self, prop, entry.default)
# Apply brok_transformation if need
# Look if we must preprocess t... | [
"\n Get the property of an object and brok_transformation if needed and return the value\n\n :param prop: property name\n :type prop: str\n :param tab: object with all properties of an object\n :type tab: object\n :return: value of the property original or brok converted\n ... |
Please provide a description of the function:def fill_data_brok_from(self, data, brok_type):
cls = self.__class__
# Configuration properties
for prop, entry in list(cls.properties.items()):
# Is this property intended for broking?
if brok_type in entry.fill_brok:... | [
"\n Add properties to 'data' parameter with properties of this object when 'brok_type'\n parameter is defined in fill_brok of these properties\n\n :param data: object to fill\n :type data: object\n :param brok_type: name of brok_type\n :type brok_type: var\n :return:... |
Please provide a description of the function:def get_initial_status_brok(self, extra=None):
data = {'uuid': self.uuid}
self.fill_data_brok_from(data, 'full_status')
if extra:
data.update(extra)
return Brok({'type': 'initial_' + self.my_type + '_status', 'data': data}... | [
"\n Create an initial status brok\n\n :param extra: some extra information to be added in the brok data\n :type extra: dict\n :return: Brok object\n :rtype: alignak.Brok\n "
] |
Please provide a description of the function:def get_update_status_brok(self):
data = {'uuid': self.uuid}
self.fill_data_brok_from(data, 'full_status')
return Brok({'type': 'update_' + self.my_type + '_status', 'data': data}) | [
"\n Create an update item brok\n\n :return: Brok object\n :rtype: alignak.Brok\n "
] |
Please provide a description of the function:def get_check_result_brok(self):
data = {'uuid': self.uuid}
self.fill_data_brok_from(data, 'check_result')
return Brok({'type': self.my_type + '_check_result', 'data': data}) | [
"\n Create check_result brok\n\n :return: Brok object\n :rtype: alignak.Brok\n "
] |
Please provide a description of the function:def get_next_schedule_brok(self):
data = {'uuid': self.uuid}
self.fill_data_brok_from(data, 'next_schedule')
return Brok({'type': self.my_type + '_next_schedule', 'data': data}) | [
"\n Create next_schedule (next check) brok\n\n :return: Brok object\n :rtype: alignak.Brok\n "
] |
Please provide a description of the function:def get_snapshot_brok(self, snap_output, exit_status):
data = {
'uuid': self.uuid,
'snapshot_output': snap_output,
'snapshot_time': int(time.time()),
'snapshot_exit_status': exit_status,
}
self.... | [
"\n Create snapshot (check_result type) brok\n\n :param snap_output: value of output\n :type snap_output: str\n :param exit_status: status of exit\n :type exit_status: integer\n :return: Brok object\n :rtype: alignak.Brok\n "
] |
Please provide a description of the function:def dump(self, dump_file_name=None): # pragma: no cover, never called
# pylint: disable=unused-argument
dump = {}
for prop in self.properties:
if not hasattr(self, prop):
continue
attr = getattr(self, ... | [
"\n Dump Item object properties\n\n :return: dictionary with properties\n :rtype: dict\n "
] |
Please provide a description of the function:def add_items(self, items, index_items):
count_templates = 0
count_items = 0
generated_items = []
for item in items:
if item.is_tpl():
self.add_template(item)
count_templates = count_templat... | [
"\n Add items to template if is template, else add in item list\n\n :param items: items list to add\n :type items: alignak.objects.item.Items\n :param index_items: Flag indicating if the items should be indexed on the fly.\n :type index_items: bool\n :return: None\n ... |
Please provide a description of the function:def manage_conflict(self, item, name):
if item.is_tpl():
existing = self.name_to_template[name]
else:
existing = self.name_to_item[name]
if existing == item:
return item
existing_prio = getattr(
... | [
"\n Checks if an object holding the same name already exists in the index.\n\n If so, it compares their definition order: the lowest definition order\n is kept. If definition order equal, an error is risen.Item\n\n The method returns the item that should be added after it has decided\n ... |
Please provide a description of the function:def add_template(self, tpl):
tpl = self.index_template(tpl)
self.templates[tpl.uuid] = tpl | [
"\n Add and index a template into the `templates` container.\n\n :param tpl: The template to add\n :type tpl: alignak.objects.item.Item\n :return: None\n "
] |
Please provide a description of the function:def index_template(self, tpl):
objcls = self.inner_class.my_type
name = getattr(tpl, 'name', '')
if not name:
mesg = "a %s template has been defined without name, from: %s" % \
(objcls, tpl.imported_from)
... | [
"\n Indexes a template by `name` into the `name_to_template` dictionary.\n\n :param tpl: The template to index\n :type tpl: alignak.objects.item.Item\n :return: None\n "
] |
Please provide a description of the function:def remove_template(self, tpl):
try:
del self.templates[tpl.uuid]
except KeyError: # pragma: no cover, simple protection
pass
self.unindex_template(tpl) | [
"\n Removes and un-index a template from the `templates` container.\n\n :param tpl: The template to remove\n :type tpl: alignak.objects.item.Item\n :return: None\n "
] |
Please provide a description of the function:def unindex_template(self, tpl):
name = getattr(tpl, 'name', '')
try:
del self.name_to_template[name]
except KeyError: # pragma: no cover, simple protection
pass | [
"\n Unindex a template from the `templates` container.\n\n :param tpl: The template to un-index\n :type tpl: alignak.objects.item.Item\n :return: None\n "
] |
Please provide a description of the function:def add_item(self, item, index=True):
# pylint: disable=too-many-branches, too-many-locals, too-many-nested-blocks
name_property = getattr(self.__class__, "name_property", None)
# Check if some hosts are to be self-generated...
gener... | [
"\n Add an item into our containers, and index it depending on the `index` flag.\n\n :param item: object to add\n :type item: alignak.objects.item.Item\n :param index: Flag indicating if the item should be indexed\n :type index: bool\n :return: the new items created\n ... |
Please provide a description of the function:def remove_item(self, item):
self.unindex_item(item)
self.items.pop(item.uuid, None) | [
"\n Remove (and un-index) an object\n\n :param item: object to remove\n :type item: alignak.objects.item.Item\n :return: None\n "
] |
Please provide a description of the function:def index_item(self, item):
name_property = getattr(self.__class__, "name_property", None)
if name_property is None:
return None
name = getattr(item, name_property, None)
if name is None:
item.add_error("a %s i... | [
"\n Index an item into our `name_to_item` dictionary.\n If an object holding the same item's name/key already exists in the index\n then the conflict is managed by the `manage_conflict` method.\n\n :param item: item to index\n :type item: alignak.objects.item.Item\n :return... |
Please provide a description of the function:def unindex_item(self, item):
name_property = getattr(self.__class__, "name_property", None)
if name_property is None:
return
name = getattr(item, name_property, None)
if name is None:
return
self.name_... | [
"\n Un-index an item from our name_to_item dict.\n :param item: the item to un-index\n :type item: alignak.objects.item.Item\n :return: None\n "
] |
Please provide a description of the function:def old_properties_names_to_new(self): # pragma: no cover, never called
for i in itertools.chain(iter(list(self.items.values())),
iter(list(self.templates.values()))):
i.old_properties_names_to_new() | [
"Convert old Nagios2 names to Nagios3 new names\n\n TODO: still useful?\n\n :return: None\n "
] |
Please provide a description of the function:def get_all_tags(self, item):
all_tags = item.get_templates()
for template_id in item.templates:
template = self.templates[template_id]
all_tags.append(template.name)
all_tags.extend(self.get_all_tags(template))
... | [
"\n Get all tags of an item\n\n :param item: an item\n :type item: Item\n :return: list of tags\n :rtype: list\n "
] |
Please provide a description of the function:def linkify_item_templates(self, item):
tpls = []
tpl_names = item.get_templates()
for name in tpl_names:
template = self.find_tpl_by_name(name)
if not template:
# TODO: Check if this should not be bet... | [
"\n Link templates\n\n :param item: an item\n :type item: alignak.objects.item.Item\n :return: None\n "
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.