Code stringlengths 103 85.9k | Summary listlengths 0 94 |
|---|---|
Please provide a description of the function:def flush(self, log=False): # pylint:disable=too-many-branches, too-many-nested-blocks
if not self.my_metrics:
logger.debug("Flushing - no metrics to send")
return True
now = int(time.time())
if self.last_failure and... | [
"Send inner stored metrics to the configured Graphite or InfluxDB\n\n Returns False if the sending failed with a warning log if log parameter is set\n\n :param log: to log information or not\n :type log: bool\n\n :return: bool\n "
] |
Please provide a description of the function:def send_to_tsdb(self, realm, host, service, metrics, ts, path):
if ts is None:
ts = int(time.time())
data = {
"measurement": service,
"tags": {
"host": host,
"service": service,
... | [
"Send performance data to time series database\n\n Indeed this function stores metrics in the internal cache and checks if the flushing\n is necessary and then flushes.\n\n :param realm: concerned realm\n :type: string\n :param host: concerned host\n :type: string\n ... |
Please provide a description of the function:def manage_initial_service_status_brok(self, b):
host_name = b.data['host_name']
service_description = b.data['service_description']
service_id = host_name+"/"+service_description
logger.debug("got initial service status: %s", service... | [
"Prepare the known services cache"
] |
Please provide a description of the function:def manage_initial_host_status_brok(self, b):
host_name = b.data['host_name']
logger.debug("got initial host status: %s", host_name)
self.hosts_cache[host_name] = {
'realm_name':
sanitize_name(b.data.get('realm_na... | [
"Prepare the known hosts cache"
] |
Please provide a description of the function:def manage_service_check_result_brok(self, b): # pylint: disable=too-many-branches
host_name = b.data.get('host_name', None)
service_description = b.data.get('service_description', None)
if not host_name or not service_description:
... | [
"A service check result brok has just arrived ..."
] |
Please provide a description of the function:def manage_host_check_result_brok(self, b): # pylint: disable=too-many-branches
host_name = b.data.get('host_name', None)
if not host_name:
return
logger.debug("host check result: %s", host_name)
# If host initial status... | [
"An host check result brok has just arrived..."
] |
Please provide a description of the function:def get_comment_brok(self, host_name, service_name=''):
data = self.serialize()
data['host'] = host_name
if service_name:
data['service'] = service_name
return Brok({'type': 'comment', 'data': data}) | [
"Get a comment brok\n\n :param host_name:\n :param service_name:\n :return: brok with wanted data\n :rtype: alignak.brok.Brok\n "
] |
Please provide a description of the function:def main():
try:
args = parse_daemon_args()
daemon = Alignak(**args.__dict__)
daemon.main()
except Exception as exp: # pylint: disable=broad-except
sys.stderr.write("*** Daemon exited because: %s" % str(exp))
traceback.pr... | [
"Parse args and run main daemon function\n\n :return: None\n "
] |
Please provide a description of the function:def want_service_notification(self, timeperiods, timestamp, state, n_type,
business_impact, cmd=None):
# pylint: disable=too-many-return-statements
if not self.service_notifications_enabled:
return False
... | [
"Check if notification options match the state of the service\n Notification is NOT wanted in ONE of the following case::\n\n * service notifications are disabled\n * cmd is not in service_notification_commands\n * business_impact < self.min_business_impact\n * service_notificatio... |
Please provide a description of the function:def want_host_notification(self, timperiods, timestamp,
state, n_type, business_impact, cmd=None):
# pylint: disable=too-many-return-statements
if not self.host_notifications_enabled:
return False
#... | [
"Check if notification options match the state of the host\n Notification is NOT wanted in ONE of the following case::\n\n * host notifications are disabled\n * cmd is not in host_notification_commands\n * business_impact < self.min_business_impact\n * host_notification_period is ... |
Please provide a description of the function:def get_notification_commands(self, o_type):
# service_notification_commands for service
notif_commands_prop = o_type + '_notification_commands'
notif_commands = getattr(self, notif_commands_prop)
return notif_commands | [
"Get notification commands for object type\n\n :param o_type: object type (host or service)\n :type o_type: str\n :return: command list\n :rtype: list[alignak.objects.command.Command]\n "
] |
Please provide a description of the function:def is_correct(self):
# pylint: disable=too-many-branches
state = True
# Do not execute checks if notifications are disabled
if (hasattr(self, 'service_notification_options') and
self.service_notification_options == [... | [
"Check if this object configuration is correct ::\n\n * Check our own specific properties\n * Call our parent class is_correct checker\n\n :return: True if the configuration is correct, otherwise False\n :rtype: bool\n "
] |
Please provide a description of the function:def linkify(self, timeperiods, commands):
self.linkify_with_timeperiods(timeperiods, 'service_notification_period')
self.linkify_with_timeperiods(timeperiods, 'host_notification_period')
self.linkify_command_list_with_commands(commands, 'serv... | [
"Create link between objects::\n\n * notificationways -> timeperiods\n * notificationways -> commands\n\n :param timeperiods: timeperiods to link\n :type timeperiods: alignak.objects.timeperiod.Timeperiods\n :param commands: commands to link\n :type commands: alignak.obje... |
Please provide a description of the function:def new_inner_member(self, name, params):
params['notificationway_name'] = name
self.add_item(NotificationWay(params)) | [
"Create new instance of NotificationWay with given name and parameters\n and add it to the item list\n\n :param name: notification way name\n :type name: str\n :param params: notification wat parameters\n :type params: dict\n :return: None\n "
] |
Please provide a description of the function:def is_correct(self):
state = True
# Ok just put None as modulation_period, means 24x7
if not hasattr(self, 'modulation_period'):
self.modulation_period = None
if not hasattr(self, 'customs') or not self.customs:
... | [
"\n Check if this object configuration is correct ::\n\n * Call our parent class is_correct checker\n\n :return: True if the configuration is correct, otherwise False\n :rtype: bool\n "
] |
Please provide a description of the function:def serialize(obj, no_dump=False):
# print("Serialize (%s): %s" % (no_dump, obj))
if hasattr(obj, "serialize") and isinstance(obj.serialize, collections.Callable):
o_dict = {
'__sys_python_module__': "%s.%s" % (obj.__class__.__module__, obj.... | [
"\n Serialize an object.\n\n Returns a dict containing an `_error` property if a MemoryError happens during the\n object serialization. See #369.\n\n :param obj: the object to serialize\n :type obj: alignak.objects.item.Item | dict | list | str\n :param no_dump: if True return dict, otherwise retu... |
Please provide a description of the function:def unserialize(j_obj, no_load=False):
if not j_obj:
return j_obj
# print("Unserialize (%s): %s" % (no_load, j_obj))
if no_load:
data = j_obj
else:
data = json.loads(j_obj)
if isinstance(data, dict):
if '__sys_python... | [
"\n Un-serialize object. If we have __sys_python_module__ we try to safely get the alignak class\n Then we re-instantiate the alignak object\n\n :param j_obj: json object, dict\n :type j_obj: str (before loads)\n :param no_load: if True, j_obj is a dict, otherwise it's a json and need loads it\n :... |
Please provide a description of the function:def get_alignak_class(python_path):
a_module, a_class = python_path.rsplit('.', 1)
if not a_module.startswith('alignak'): # pragma: no cover - should never happen!
raise AlignakClassLookupException("Can't recreate object in module: %s. "
... | [
" Get the alignak class the in safest way I could imagine.\n Return None if (cumulative conditions) ::\n\n * the module does not start with alignak\n * above is false and the module is not is sys.modules\n * above is false and the module does not have the wanted class\n * above is false and the class... |
Please provide a description of the function:def get_event(self):
self.prepare()
return (self.creation_time, self.data['level'], self.data['message']) | [
"This function returns an Event from a Brok\n\n If the type is monitoring_log then the Brok contains a monitoring event\n (alert, notification, ...) information. This function will return a tuple\n with the creation time, the level and message information\n\n :return: tuple with date, le... |
Please provide a description of the function:def serialize(self):
return {
"uuid": self.uuid, "type": self.type, "instance_id": self.instance_id,
"prepared": self.prepared, "creation_time": self.creation_time,
"data": self.data
} | [
"This function serialize into a simple dict object.\n It is used when transferring data to other daemons over the network (http)\n\n Here we directly return all attributes\n\n :return: json representation of a Brok\n :rtype: dict\n "
] |
Please provide a description of the function:def prepare(self):
# Maybe the Brok is a old daemon one or was already prepared
# if so, the data is already ok
if hasattr(self, 'prepared') and not self.prepared:
self.data = unserialize(self.data)
if self.instance_id... | [
"Un-serialize data from data attribute and add instance_id key if necessary\n\n :return: None\n "
] |
Please provide a description of the function:def resolve_elements(self):
# If it's a leaf, we just need to dump a set with the content of the node
if self.leaf:
if not self.content:
return set()
return set(self.content)
# first got the not ones ... | [
"Get element of this node recursively\n Compute rules with OR or AND rule then NOT rules.\n\n :return: set of element\n :rtype: set\n "
] |
Please provide a description of the function:def eval_cor_pattern(self, pattern): # pylint:disable=too-many-branches
pattern = pattern.strip()
complex_node = False
# Look if it's a complex pattern (with rule) or
# if it's a leaf of it, like a host/service
for char in '... | [
"Parse and build recursively a tree of ComplexExpressionNode from pattern\n\n :param pattern: pattern to parse\n :type pattern: str\n :return: root node of parsed tree\n :type: alignak.complexexpression.ComplexExpressionNode\n "
] |
Please provide a description of the function:def find_object(self, pattern):
obj = None
error = None
pattern = pattern.strip()
if pattern == '*':
obj = [h.host_name for h in list(self.all_elements.items.values())
if getattr(h, 'host_name', '') != ... | [
"Get a list of host corresponding to the pattern regarding the context\n\n :param pattern: pattern to find\n :type pattern: str\n :return: Host list matching pattern (hostgroup name, template, all)\n :rtype: list[alignak.objects.host.Host]\n "
] |
Please provide a description of the function:def reset(self):
# pylint: disable=not-context-manager
logger.info("Scheduling loop reset")
with self.waiting_results.mutex:
self.waiting_results.queue.clear()
self.checks.clear()
self.actions.clear() | [
"Reset scheduler::\n\n * Remove waiting results\n * Clear checks and actions lists\n\n :return: None\n "
] |
Please provide a description of the function:def all_my_hosts_and_services(self):
for what in (self.hosts, self.services):
for item in what:
yield item | [
"Create an iterator for all my known hosts and services\n\n :return: None\n "
] |
Please provide a description of the function:def load_conf(self, instance_id, instance_name, conf):
self.pushed_conf = conf
logger.info("loading my configuration (%s / %s):",
instance_id, self.pushed_conf.instance_id)
logger.debug("Properties:")
for key in s... | [
"Load configuration received from Arbiter and pushed by our Scheduler daemon\n\n :param instance_name: scheduler instance name\n :type instance_name: str\n :param instance_id: scheduler instance id\n :type instance_id: str\n :param conf: configuration to load\n :type conf: ... |
Please provide a description of the function:def update_recurrent_works_tick(self, conf):
for key in self.recurrent_works:
(name, fun, _) = self.recurrent_works[key]
if isinstance(conf, dict):
new_tick = conf.get('tick_%s' % name, None)
else:
... | [
"Modify the tick value for the scheduler recurrent work\n\n A tick is an amount of loop of the scheduler before executing the recurrent work\n\n The provided configuration may contain some tick-function_name keys that contain\n a tick value to be updated. Those parameters are defined in the ali... |
Please provide a description of the function:def dump_objects(self):
path = os.path.join(tempfile.gettempdir(),
'dump-obj-scheduler-%s-%d.json' % (self.name, int(time.time())))
logger.info('Dumping scheduler objects to: %s', path)
try:
fd = open(... | [
"Dump scheduler objects into a dump (temp) file\n\n :return: None\n "
] |
Please provide a description of the function:def dump_config(self):
path = os.path.join(tempfile.gettempdir(),
'dump-cfg-scheduler-%s-%d.json' % (self.name, int(time.time())))
try:
self.pushed_conf.dump(path)
except (OSError, IndexError) as exp: ... | [
"Dump scheduler configuration into a temporary file\n\n The dumped content is JSON formatted\n\n :return: None\n "
] |
Please provide a description of the function:def run_external_commands(self, cmds):
if not self.external_commands_manager:
return
try:
_t0 = time.time()
logger.debug("Scheduler '%s' got %d commands", self.name, len(cmds))
for command in cmds:
... | [
"Run external commands Arbiter/Receiver sent\n\n :param cmds: commands to run\n :type cmds: list\n :return: None\n "
] |
Please provide a description of the function:def add_brok(self, brok, broker_uuid=None):
# We tag the brok with our instance_id
brok.instance_id = self.instance_id
if brok.type == 'monitoring_log':
# The brok is a monitoring event
with self.my_daemon.events_lock:... | [
"Add a brok into brokers list\n It can be for a specific one, all brokers or none (startup)\n\n :param brok: brok to add\n :type brok: alignak.brok.Brok\n :param broker_uuid: broker uuid for the brok\n :type broker_uuid: str\n :return: None\n "
] |
Please provide a description of the function:def add_notification(self, notification):
if notification.uuid in self.actions:
logger.warning("Already existing notification: %s", notification)
return
logger.debug("Adding a notification: %s", notification)
self.act... | [
"Add a notification into actions list\n\n :param notification: notification to add\n :type notification: alignak.notification.Notification\n :return: None\n "
] |
Please provide a description of the function:def add_check(self, check):
if check is None:
return
if check.uuid in self.checks:
logger.debug("Already existing check: %s", check)
return
logger.debug("Adding a check: %s", check)
# Add a new che... | [
"Add a check into the scheduler checks list\n\n :param check: check to add\n :type check: alignak.check.Check\n :return: None\n "
] |
Please provide a description of the function:def add_event_handler(self, action):
if action.uuid in self.actions:
logger.info("Already existing event handler: %s", action)
return
self.actions[action.uuid] = action
self.nb_event_handlers += 1 | [
"Add a event handler into actions list\n\n :param action: event handler to add\n :type action: alignak.eventhandler.EventHandler\n :return: None\n "
] |
Please provide a description of the function:def add(self, elt):
if elt is None:
return
logger.debug("Adding: %s / %s", elt.my_type, elt.__dict__)
fun = self.__add_actions.get(elt.__class__, None)
if fun:
fun(self, elt)
else:
logger.wa... | [
"Generic function to add objects into the scheduler daemon internal lists::\n Brok -> self.broks\n Check -> self.checks\n Notification -> self.actions\n EventHandler -> self.actions\n\n For an ExternalCommand, tries to resolve the command\n\n :param elt: element to add\n ... |
Please provide a description of the function:def hook_point(self, hook_name):
self.my_daemon.hook_point(hook_name=hook_name, handle=self) | [
"Generic function to call modules methods if such method is avalaible\n\n :param hook_name: function name to call\n :type hook_name: str\n :return:None\n "
] |
Please provide a description of the function:def clean_queues(self):
# pylint: disable=too-many-locals
# If we set the interval at 0, we bail out
if getattr(self.pushed_conf, 'tick_clean_queues', 0) == 0:
logger.debug("No queues cleaning...")
return
max_... | [
"Reduces internal list size to max allowed\n\n * checks and broks : 5 * length of hosts + services\n * actions : 5 * length of hosts + services + contacts\n\n :return: None\n "
] |
Please provide a description of the function:def update_business_values(self):
for elt in self.all_my_hosts_and_services():
if not elt.is_problem:
was = elt.business_impact
elt.update_business_impact_value(self.hosts, self.services,
... | [
"Iter over host and service and update business_impact\n\n :return: None\n "
] |
Please provide a description of the function:def scatter_master_notifications(self):
now = time.time()
# We only want the master scheduled notifications that are immediately launchable
notifications = [a for a in self.actions.values()
if a.is_a == u'notification... | [
"Generate children notifications from a master notification\n Also update notification number\n\n Master notification are raised when a notification must be sent out. They are not\n launched by reactionners (only children are) but they are used to build the\n children notifications.\n\n ... |
Please provide a description of the function:def get_to_run_checks(self, do_checks=False, do_actions=False,
poller_tags=None, reactionner_tags=None,
worker_name='none', module_types=None):
# pylint: disable=too-many-branches
res = []
n... | [
"Get actions/checks for reactionner/poller\n\n Called by the poller to get checks (do_checks=True) and\n by the reactionner (do_actions=True) to get actions\n\n :param do_checks: do we get checks ?\n :type do_checks: bool\n :param do_actions: do we get actions ?\n :type do_... |
Please provide a description of the function:def manage_results(self, action): # pylint: disable=too-many-branches,too-many-statements
logger.debug('manage_results: %s ', action)
if action.is_a == 'notification':
try:
_ = self.actions[action.uuid]
except... | [
"Get result from pollers/reactionners (actives ones)\n\n :param action: check / action / event handler to handle\n :type action:\n :return: None\n "
] |
Please provide a description of the function:def push_actions_to_passive_satellites(self):
# We loop for our passive pollers or reactionners
for satellites in [self.my_daemon.pollers, self.my_daemon.reactionners]:
s_type = 'poller'
if satellites is self.my_daemon.reactio... | [
"Send actions/checks to passive poller/reactionners\n\n :return: None\n "
] |
Please provide a description of the function:def get_results_from_passive_satellites(self):
# pylint: disable=broad-except
# We loop for our passive pollers or reactionners
for satellites in [self.my_daemon.pollers, self.my_daemon.reactionners]:
s_type = 'poller'
... | [
"Get actions/checks results from passive poller/reactionners\n\n :return: None\n "
] |
Please provide a description of the function:def manage_internal_checks(self):
if os.getenv('ALIGNAK_MANAGE_INTERNAL', '1') != '1':
return
now = time.time()
for chk in list(self.checks.values()):
if not chk.internal:
# Exclude checks that are not ... | [
"Run internal checks\n\n :return: None\n "
] |
Please provide a description of the function:def reset_topology_change_flag(self):
for i in self.hosts:
i.topology_change = False
for i in self.services:
i.topology_change = False | [
"Set topology_change attribute to False in all hosts and services\n\n :return: None\n "
] |
Please provide a description of the function:def update_retention(self):
# If we set the retention update to 0, we do not want to manage retention
# If we are not forced (like at stopping)
if self.pushed_conf.retention_update_interval == 0:
logger.debug("Should have saved re... | [
"Call hook point 'save_retention'.\n Retention modules will write back retention (to file, db etc)\n\n :param forced: is update forced?\n :type forced: bool\n :return: None\n "
] |
Please provide a description of the function:def retention_load(self, forced=False):
# If we set the retention update to 0, we do not want to manage retention
# If we are not forced (like at stopping)
if self.pushed_conf.retention_update_interval == 0 and not forced:
logger.... | [
"Call hook point 'load_retention'.\n Retention modules will read retention (from file, db etc)\n\n :param forced: is load forced?\n :type forced: bool\n :return: None\n "
] |
Please provide a description of the function:def log_initial_states(self):
# Raise hosts initial status broks
for elt in self.hosts:
elt.raise_initial_state()
# And then services initial status broks
for elt in self.services:
elt.raise_initial_state() | [
"Raise hosts and services initial status logs\n\n First, raise hosts status and then services. This to allow the events log\n to be a little sorted.\n\n :return: None\n "
] |
Please provide a description of the function:def get_retention_data(self): # pylint: disable=too-many-branches,too-many-statements
# pylint: disable=too-many-locals
retention_data = {
'hosts': {}, 'services': {}
}
for host in self.hosts:
h_dict = {}
... | [
"Get all hosts and services data to be sent to the retention storage.\n\n This function only prepares the data because a module is in charge of making\n the data survive to the scheduler restart.\n\n todo: Alignak scheduler creates two separate dictionaries: hosts and services\n It would... |
Please provide a description of the function:def restore_retention_data(self, data):
if 'hosts' not in data:
logger.warning("Retention data are not correct, no 'hosts' property!")
return
for host_name in data['hosts']:
# We take the dict of our value to load... | [
"Restore retention data\n\n Data coming from retention will override data coming from configuration\n It is kinda confusing when you modify an attribute (external command) and it get saved\n by retention\n\n :param data: data from retention\n :type data: dict\n :return: Non... |
Please provide a description of the function:def restore_retention_data_item(self, data, item):
# pylint: disable=too-many-branches, too-many-locals
# Manage the properties and running properties
properties = item.__class__.properties
properties.update(item.__class__.running_pro... | [
"\n Restore data in item\n\n :param data: retention data of the item\n :type data: dict\n :param item: host or service item\n :type item: alignak.objects.host.Host | alignak.objects.service.Service\n :return: None\n "
] |
Please provide a description of the function:def fill_initial_broks(self, broker_name):
# pylint: disable=too-many-branches
broker_uuid = None
logger.debug("My brokers: %s", self.my_daemon.brokers)
for broker_link in list(self.my_daemon.brokers.values()):
logger.debu... | [
"Create initial broks for a specific broker\n\n :param broker_name: broker name\n :type broker_name: str\n :return: number of created broks\n "
] |
Please provide a description of the function:def consume_results(self): # pylint: disable=too-many-branches
# All results are in self.waiting_results
# We need to get them first
queue_size = self.waiting_results.qsize()
for _ in range(queue_size):
self.manage_result... | [
"Handle results waiting in waiting_results list.\n Check ref will call consume result and update their status\n\n :return: None\n "
] |
Please provide a description of the function:def delete_zombie_checks(self):
id_to_del = []
for chk in list(self.checks.values()):
if chk.status == ACT_STATUS_ZOMBIE:
id_to_del.append(chk.uuid)
# une petite tape dans le dos et tu t'en vas, merci...
# ... | [
"Remove checks that have a zombie status (usually timeouts)\n\n :return: None\n "
] |
Please provide a description of the function:def delete_zombie_actions(self):
id_to_del = []
for act in list(self.actions.values()):
if act.status == ACT_STATUS_ZOMBIE:
id_to_del.append(act.uuid)
# une petite tape dans le dos et tu t'en vas, merci...
... | [
"Remove actions that have a zombie status (usually timeouts)\n\n :return: None\n "
] |
Please provide a description of the function:def update_downtimes_and_comments(self):
# pylint: disable=too-many-branches
broks = []
now = time.time()
# Check maintenance periods
for elt in self.all_my_hosts_and_services():
if not elt.maintenance_period:
... | [
"Iter over all hosts and services::\n\n TODO: add some unit tests for the maintenance period feature.\n\n * Update downtime status (start / stop) regarding maintenance period\n * Register new comments in comments list\n\n :return: None\n "
] |
Please provide a description of the function:def schedule(self, elements=None):
if not elements:
elements = self.all_my_hosts_and_services()
# ask for service and hosts their next check
for elt in elements:
logger.debug("Add check for: %s", elt)
self... | [
"Iterate over all hosts and services and call schedule method\n (schedule next check)\n\n If elements is None all our hosts and services are scheduled for a check.\n\n :param elements: None or list of host / services to schedule\n :type elements: None | list\n :return: None\n ... |
Please provide a description of the function:def get_new_actions(self):
_t0 = time.time()
self.hook_point('get_new_actions')
statsmgr.timer('hook.get-new-actions', time.time() - _t0)
# ask for service and hosts their next check
for elt in self.all_my_hosts_and_services()... | [
"Call 'get_new_actions' hook point\n Iter over all hosts and services to add new actions in internal lists\n\n :return: None\n "
] |
Please provide a description of the function:def get_new_broks(self):
# ask for service and hosts their broks waiting
# be eaten
for elt in self.all_my_hosts_and_services():
for brok in elt.broks:
self.add(brok)
# We got all, clear item broks list... | [
"Iter over all hosts and services to add new broks in internal lists\n\n :return: None\n "
] |
Please provide a description of the function:def check_orphaned(self):
orphans_count = {}
now = int(time.time())
actions = list(self.checks.values()) + list(self.actions.values())
for chk in actions:
if chk.status not in [ACT_STATUS_POLLED]:
continue
... | [
"Check for orphaned checks/actions::\n\n * status == 'in_poller' and t_to_go < now - time_to_orphanage (300 by default)\n\n if so raise a warning log.\n\n :return: None\n "
] |
Please provide a description of the function:def send_broks_to_modules(self):
t00 = time.time()
nb_sent = 0
broks = []
for broker_link in list(self.my_daemon.brokers.values()):
for brok in broker_link.broks:
if not getattr(brok, 'sent_to_externals', F... | [
"Put broks into module queues\n Only broks without sent_to_externals to True are sent\n Only modules that ask for broks will get some\n\n :return: None\n "
] |
Please provide a description of the function:def get_scheduler_stats(self, details=False): # pylint: disable=unused-argument
# pylint: disable=too-many-locals, too-many-branches
m_solver = MacroResolver()
res = {
'_freshness': int(time.time()),
'counters': {},
... | [
"Get the scheduler statistics\n\n :return: A dict with the following structure\n ::\n\n { 'modules': [\n {'internal': {'name': \"MYMODULE1\", 'state': 'ok'},\n {'external': {'name': \"MYMODULE2\", 'state': 'stopped'},\n ]... |
Please provide a description of the function:def get_latency_average_percentile(self):
(_, _, time_interval) = self.recurrent_works[21]
last_time = time.time() - time_interval
latencies = [s.latency for s in self.services if s.last_chk > last_time]
lat_avg, lat_min, lat_max = av... | [
"\n Get a overview of the latencies with just a 95 percentile + min/max values\n\n :return: None\n "
] |
Please provide a description of the function:def get_checks_status_counts(self, checks=None):
if checks is None:
checks = self.checks
res = defaultdict(int)
res["total"] = len(checks)
for chk in checks.values():
res[chk.status] += 1
return res | [
" Compute the counts of the different checks status and\n return it as a defaultdict(int) with the keys being the different\n status and the values being the count of the checks in that status.\n\n :checks: None or the checks you want to count their statuses.\n If None then self... |
Please provide a description of the function:def find_item_by_id(self, object_id):
# Item id may be an item
if isinstance(object_id, Item):
return object_id
# Item id should be a uuid string
if not isinstance(object_id, string_types):
logger.debug("Find ... | [
"Get item based on its id or uuid\n\n :param object_id:\n :type object_id: int | str\n :return:\n :rtype: alignak.objects.item.Item | None\n "
] |
Please provide a description of the function:def before_run(self):
# Actions and checks counters
self.nb_checks = 0
self.nb_internal_checks = 0
self.nb_checks_launched = 0
self.nb_actions_launched = 0
self.nb_checks_results = 0
self.nb_checks_results_tim... | [
"Initialize the scheduling process"
] |
Please provide a description of the function:def run(self): # pylint: disable=too-many-locals, too-many-statements, too-many-branches
if not self.must_schedule:
logger.warning("#%d - scheduler is not active...",
self.my_daemon.loop_count)
return
... | [
"Main scheduler function::\n\n * Load retention\n * Call 'pre_scheduler_mod_start' hook point\n * Start modules\n * Schedule first checks\n * Init connection with pollers/reactionners\n * Run main loop\n\n * Do recurrent works\n * Push/Get actions to p... |
Please provide a description of the function:def add(self, elt):
# external commands may be received as a dictionary when pushed from the WebUI
if isinstance(elt, dict) and 'my_type' in elt and elt['my_type'] == "externalcommand":
if 'cmd_line' not in elt:
logger.deb... | [
"Generic function to add objects to the daemon internal lists.\n Manage Broks, External commands\n\n :param elt: object to add\n :type elt: alignak.AlignakObject\n :return: None\n "
] |
Please provide a description of the function:def setup_new_conf(self):
# Execute the base class treatment...
super(Receiver, self).setup_new_conf()
# ...then our own specific treatment!
with self.conf_lock:
# self_conf is our own configuration from the alignak envir... | [
"Receiver custom setup_new_conf method\n\n This function calls the base satellite treatment and manages the configuration needed\n for a receiver daemon:\n - get and configure its satellites\n - configure the modules\n\n :return: None\n "
] |
Please provide a description of the function: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 ge... | [
"Get external commands from our arbiters\n\n As of now, only the arbiter are requested to provide their external commands that\n the receiver will push to all the known schedulers to make them being executed.\n\n :return: None\n "
] |
Please provide a description of the function: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... | [
"Push received external commands to the schedulers\n\n :return: None\n "
] |
Please provide a description of the function: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...")... | [
"Receiver daemon main loop\n\n :return: None\n "
] |
Please provide a description of the function:def get_daemon_stats(self, details=False):
# Call the base Daemon one
res = super(Receiver, self).get_daemon_stats(details=details)
res.update({'name': self.name, 'type': self.type})
counters = res['counters']
counters['exte... | [
"Increase the stats provided by the Daemon base class\n\n :return: stats dictionary\n :rtype: dict\n "
] |
Please provide a description of the function:def get_return_from(self, check):
for prop in ['exit_status', 'output', 'long_output', 'check_time', 'execution_time',
'perf_data', 'u_time', 's_time']:
setattr(self, prop, getattr(check, prop)) | [
"Update check data from action (notification for instance)\n\n :param check: action to get data from\n :type check: alignak.action.Action\n :return: None\n "
] |
Please provide a description of the function: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 | [
"This function serializes into a simple dict object.\n\n The only usage is to send to poller, and it does not need to have the\n depend_on and depend_on_me properties.\n\n :return: json representation of a Check\n :rtype: dict\n "
] |
Please provide a description of the function: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, ... | [
"This function serializes into a simple dictionary object.\n\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 of the object.\n\n Note that a SetProp property... |
Please provide a description of the function: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 ... | [
"\n Define the object properties with a default value when the property is not yet defined\n\n :return: None\n "
] |
Please provide a description of the function:def convert_conf_for_unreachable(params):
if params is None:
return
for prop in ['flap_detection_options', 'notification_options',
'snapshot_criteria', 'stalking_options']:
if prop in params:
... | [
"\n The 'u' state for UNREACHABLE has been rewritten in 'x' in:\n * flap_detection_options\n * notification_options\n * snapshot_criteria\n\n So convert value from config file to keep compatibility with Nagios\n\n :param params: parameters of the host before put in properti... |
Please provide a description of the function: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_n... | [
"Fill address with host_name if not already set\n and define state with initial_state\n\n :return: None\n "
] |
Please provide a description of the function:def is_correct(self):
state = True
# Internal checks before executing inherited function...
cls = self.__class__
if hasattr(self, 'host_name'):
for char in cls.illegal_object_name_chars:
if char in self.ho... | [
"Check if this object configuration is correct ::\n\n * Check our own specific properties\n * Call our parent class is_correct checker\n\n :return: True if the configuration is correct, otherwise False\n :rtype: bool\n "
] |
Please provide a description of the function:def get_name(self):
if not self.is_tpl():
try:
return self.host_name
except AttributeError: # outch, no hostname
return 'UNNAMEDHOST'
else:
try:
return self.name
... | [
"Get the host name.\n Try several attributes before returning UNNAMED*\n\n :return: The name of the host\n :rtype: str\n "
] |
Please provide a description of the function: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)) | [
"Get names of the host's hostgroups\n\n :return: comma separated names of hostgroups alphabetically sorted\n :rtype: str\n "
] |
Please provide a description of the function: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)) | [
"Get aliases of the host's hostgroups\n\n :return: comma separated aliases of hostgroups alphabetically sorted\n :rtype: str\n "
] |
Please provide a description of the function:def is_excluded_for_sdesc(self, sdesc, is_tpl=False):
if not is_tpl and self.service_includes:
return sdesc not in self.service_includes
if self.service_excludes:
return sdesc in self.service_excludes
return False | [
" Check whether this host should have the passed service *description*\n be \"excluded\" or \"not included\".\n\n :param sdesc: service description\n :type sdesc:\n :param is_tpl: True if service is template, otherwise False\n :type is_tpl: bool\n :return: True if servi... |
Please provide a description of the function: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... | [
"Set the state in UP, DOWN, or UNREACHABLE according to the status of a check result.\n\n :param status: integer between 0 and 3 (but not 1)\n :type status: int\n :return: None\n "
] |
Please provide a description of the function: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
... | [
"Return if status match the current host status\n\n :param status: status to compare ( \"o\", \"d\", \"x\"). Usually comes from config files\n :type status: str\n :return: True if status <=> self.status, otherwise False\n :rtype: bool\n "
] |
Please provide a description of the function: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:
... | [
"Get the last time the host was in a non-OK state\n\n :return: self.last_time_down if self.last_time_down > self.last_time_up, 0 otherwise\n :rtype: int\n "
] |
Please provide a description of the function:def raise_check_result(self):
if not self.__class__.log_active_checks:
return
log_level = 'info'
if self.state == 'DOWN':
log_level = 'error'
elif self.state == 'UNREACHABLE':
log_level = 'warning'... | [
"Raise ACTIVE CHECK RESULT entry\n Example : \"ACTIVE HOST CHECK: server;DOWN;HARD;1;I don't know what to say...\"\n\n :return: None\n "
] |
Please provide a description of the function:def raise_alert_log_entry(self):
if self.__class__.log_alerts:
log_level = 'info'
if self.state == 'DOWN':
log_level = 'error'
if self.state == 'UNREACHABLE':
log_level = 'warning'
... | [
"Raise HOST ALERT entry\n Format is : \"HOST ALERT: *get_name()*;*state*;*state_type*;*attempt*;*output*\"\n Example : \"HOST ALERT: server;DOWN;HARD;1;I don't know what to say...\"\n\n :return: None\n "
] |
Please provide a description of the function:def raise_initial_state(self):
if not self.__class__.log_initial_states:
return
log_level = 'info'
if self.state == 'DOWN':
log_level = 'error'
if self.state == 'UNREACHABLE':
log_level = 'warning'... | [
"Raise CURRENT HOST ALERT entry (info level)\n Format is : \"CURRENT HOST STATE: *get_name()*;*state*;*state_type*;*attempt*;*output*\"\n Example : \"CURRENT HOST STATE: server;DOWN;HARD;1;I don't know what to say...\"\n\n :return: None\n "
] |
Please provide a description of the function:def raise_snapshot_log_entry(self, command):
if not self.__class__.log_snapshots:
return
log_level = 'info'
if self.state == 'UNREACHABLE':
log_level = 'warning'
if self.state == 'DOWN':
log_level ... | [
"Raise HOST SNAPSHOT entry (critical level)\n Format is : \"HOST SNAPSHOT: *self.get_name()*;*state*;*state_type*;*attempt*;\n *command.get_name()*\"\n Example : \"HOST SNAPSHOT: server;UP;HARD;1;notify-by-rss\"\n\n :param command: Snapshot command launched\n :type com... |
Please provide a description of the function:def raise_flapping_start_log_entry(self, change_ratio, threshold):
if not self.__class__.log_flappings:
return
brok = make_monitoring_log(
'info',
"HOST FLAPPING ALERT: %s;STARTED; Host appears to have started "
... | [
"Raise HOST FLAPPING ALERT START entry (critical level)\n Format is : \"HOST FLAPPING ALERT: *self.get_name()*;STARTED;\n Host appears to have started\n flapping (*change_ratio*% change >= *threshold*% threshold)\"\n Example : \"HOST FLAPPING ALERT: server;START... |
Please provide a description of the function:def raise_acknowledge_log_entry(self):
if not self.__class__.log_acknowledgements:
return
brok = make_monitoring_log(
'info', "HOST ACKNOWLEDGE ALERT: %s;STARTED; "
"Host problem has been acknowledged" % s... | [
"Raise HOST ACKNOWLEDGE ALERT entry (critical level)\n\n :return: None\n "
] |
Please provide a description of the function:def raise_enter_downtime_log_entry(self):
if not self.__class__.log_downtimes:
return
brok = make_monitoring_log(
'info', "HOST DOWNTIME ALERT: %s;STARTED; "
"Host has entered a period of scheduled downtim... | [
"Raise HOST DOWNTIME ALERT entry (critical level)\n Format is : \"HOST DOWNTIME ALERT: *get_name()*;STARTED;\n Host has entered a period of scheduled downtime\"\n Example : \"HOST DOWNTIME ALERT: test_host_0;STARTED;\n Host has entered a period of scheduled downtim... |
Please provide a description of the function:def manage_stalking(self, check):
need_stalk = False
if check.status == u'waitconsume':
if check.exit_status == 0 and 'o' in self.stalking_options:
need_stalk = True
elif check.exit_status == 1 and 'd' in self.... | [
"Check if the host need stalking or not (immediate recheck)\n If one stalking_options matches the exit_status ('o' <=> 0 ...) then stalk is needed\n Raise a log entry (info level) if stalk is needed\n\n :param check: finished check (check.status == 'waitconsume')\n :type check: alignak.c... |
Please provide a description of the function: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,
... | [
"Check if the notification is blocked by this contact.\n\n :param notif: notification created earlier\n :type notif: alignak.notification.Notification\n :param contact: contact we want to notify\n :type notif: alignak.objects.contact.Contact\n :return: True if the notification is ... |
Please provide a description of the function:def get_duration(self):
mins, secs = divmod(self.duration_sec, 60)
hours, mins = divmod(mins, 60)
return "%02dh %02dm %02ds" % (hours, mins, secs) | [
"Get duration formatted\n Format is : \"HHh MMm SSs\"\n Example : \"10h 20m 40s\"\n\n :return: Formatted duration\n :rtype: str\n "
] |
Please provide a description of the function: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\n\n :param state: state to filter service\n :type state:\n :return: number of service with s.state_id == state\n :rtype: int\n "
] |
Please provide a description of the function:def get_status(self, hosts, services):
if self.got_business_rule:
mapping = {
0: "UP",
1: "DOWN",
4: "UNREACHABLE",
}
return mapping.get(self.business_rule.get_state(hosts, s... | [
"Get the status of this host\n\n :return: \"UP\", \"DOWN\", \"UNREACHABLE\" or \"n/a\" based on host state_id or business_rule state\n :rtype: str\n "
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.