alignak.misc package

Submodules

alignak.misc.common module

This module is used for common variables in Alignak. Previously some of those variables were linked to a specific class which made no sense.

class alignak.misc.common.ModAttr

Bases: tuple

ModAttr(modattr, attribute, value)

attribute

Alias for field number 1

modattr

Alias for field number 0

value

Alias for field number 2

alignak.misc.custom_module module

This module provides CustomModule class. Used to customize a module namespace

class alignak.misc.custom_module.CustomModule(name, orig_mod_globals)[source]

Bases: module

Custom module that can be used to customize a module namespace,

example usage:

>>> import sys
>>> assert __name__ == 'custom_module'  # required for the import after
>>> class MyCustomModule(CustomModule):
...     count = 0
...     @property
...     def an_attribute(self):
...         self.count += 1
...         return "hey ! I'm a module attribute but also a property !"
>>> sys.modules[__name__] = MyCustomModule(__name__, globals())

# then, in another module: >>> import custom_module >>> assert custom_module.count == 0 >>> custom_module.an_attribute “hey ! I’m a module attribute but also a property !” >>> assert custom_module.count == 1

alignak.misc.datamanager module

datamanager module provide DataManager class : a simple class providing accessor to various Alignak object” Used by module such as Livestatus and Webui

class alignak.misc.datamanager.DataManager[source]

Bases: object

DataManager provide a set of accessor to Alignak objects (host, services) through a regenerator object.

get_all_hosts_and_services()[source]

Get all host and all service in a single list

Returns:A list containing all host and service
Return type:list
get_all_impacts()[source]

Get all non managed impacts

Returns:A list of host and service
Return type:list
get_all_problems(to_sort=True, get_acknowledged=False)[source]

Get hosts and services with:

  • not OK state
  • is_impact flag false
  • Do not include acknowledged items by default
  • Sort items by default
Parameters:
  • to_sort (bool) – if false, won’t sort results
  • get_acknowledged (bool) – if true will include acknowledged items
Returns:

A list of host and service

Return type:

list

get_brokers()[source]

Get all brokers

Returns:List of all brokers
Return type:list
get_business_parents(obj, levels=3)[source]

Get the dependencies tree of a specific host or service up to a specific dept Tree only include non OK state_id

Parameters:
Returns:

A dict with the following structure

{ 'node': obj,
  'fathers': [
              {'node': Host_Object1, fathers: [...]},
              {'node': Host_Object2, fathers: [...]},
             ]
}
Return type:dict
get_contact(name)[source]

Get a specific contact

Parameters:name (str) – A contact name
Returns:the Contact object with contact_name=name
Return type:alignak.objects.contact.Contact
get_contactgroup(name)[source]

Get a specific contact group

Parameters:name (str) – A contactgroup name
Returns:the Contact object with contactgroup_name=name
Return type:alignak.objects.contactgroup.Contactgroup
get_contacts()[source]

Get all contacts

Returns:List of all contacts
Return type:list
get_host(hname)[source]

Get a specific host from Alignak

Parameters:hname (str) – A host name (a casual string)
Returns:the Host object with host_name=hname
Return type:alignak.objects.host.Host
get_host_tags_sorted()[source]

Get hosts tags sorted by names, and zero size in the end

Returns:list of hosts tags
Return type:list
get_hostgroup(name)[source]

Get a specific host group

Parameters:name (str) – A hostgroup name
Returns:the Contact object with hostgroup_name=name
Return type:alignak.objects.hostgroup.Hostgroup
get_hostgroups()[source]

Get all hostgroups

Returns:List of all hostgroups
Return type:list
get_hostgroups_sorted(selected='')[source]

Get hostgroups sorted by names, and zero size in the end if selected one, put it in the first place

Parameters:selected (str) – A hostgroup name
Returns:A sorted hostgroup list
Return type:list
get_hosts()[source]

Get all hosts

Returns:List of all hosts
Return type:list
get_hosts_tagged_with(tag)[source]

Get hosts tagged with a specific tag

Parameters:name (str) – A tag name
Returns:Hosts list with tag in host tags
Return type:alignak.objects.host.Host
get_important_elements()[source]

Get hosts and services with : * business impact > 2 * 0 <= my_own_business_impact <= 2

Returns:list of host and services
Return type:list
get_important_impacts()[source]

Get hosts and services with : * not OK state * business impact > 2 * is_impact flag true

Returns:list of host and services
Return type:list
get_len_overall_state()[source]

Get the number of hosts and services with: * business impact > 2 * is_impact flag true * state_id equals 1 or 2 (warning or critical state) Used for aggregation

Returns:An integer representing the number of hosts and services fulfilling the above condition :rtype: int
get_nb_all_problems(user)[source]

Get the number of problems (host or service) including acknowledged ones for a specific user

Parameters:user (str) – A contact (Ui user maybe)
Returns:A list of host and service with acknowledged problem for contact=user
Return type:list
get_nb_elements()[source]

Get the number of hosts and services (sum)

Returns:An integer representing the number of items
Return type:int
get_nb_impacts()[source]

Get the number of impacts (host or service)

Returns:An integer representing the number of impact items
Return type:int
get_nb_problems()[source]

Get the number of problems (host or service)

Returns:An integer representing the number of non acknowledged problems
Return type:int
get_overall_it_state()[source]

Get the worst state of all hosts and services with: * is_impact flag true * state_id equals 1 or 2 (warning or critical state) Used for aggregation

Returns:An integer between 0 and 2
Return type:int
get_overall_state()[source]

Get the worst state of all hosts and service with: * business impact > 2 * is_impact flag true * state_id equals 1 or 2 (warning or critical state) Used for aggregation

Returns:An integer between 0 and 2
Return type:int
get_per_hosts_state()[source]

Get the percentage of hosts with : * is_impact flag false * not OK state

Returns:An integer representing the percentage of hosts fulfilling the above condition
Return type:int
get_per_service_state()[source]

Get the percentage of services with : * is_impact flag false * not OK state

Returns:An integer representing the percentage of services fulfilling the above condition
Return type:int
get_pollers()[source]

Get all pollers

Returns:List of all pollers
Return type:list
get_problems_time_sorted()[source]

Get all problems with the most recent before

Returns:A list of host and service
Return type:list
get_program_start()[source]

Get program start time

Returns:Timestamp representing start time
Return type:int | None
get_reactionners()[source]

Get all reactionners

Returns:List of all reactionners
Return type:list
get_realm(realm)[source]

Get a specific realm, but this will return None always

Parameters:name (str) – A realm name
Returns:the Realm object with realm_name=name (that’s not true)
Return type:alignak.objects.realm.Realm | None

TODO: Remove this

get_realms()[source]

Get all realms

Returns:List of all realms
Return type:list
get_receivers()[source]

Get all receivers

Returns:List of all receivers
Return type:list
get_schedulers()[source]

Get all schedulers

Returns:List of all schedulers
Return type:list
get_service(hname, sdesc)[source]
Parameters:
  • hname (str) – A host name
  • sdesc (str) – A service description
Returns:

the Service object with host_name=hname and service_description=sdec

Return type:

alignak.objects.service.Service

get_service_tags_sorted()[source]

Get services tags sorted by names, and zero size in the end

Returns:list of services tags
Return type:list
get_servicegroup(name)[source]

Get a specific service group

Parameters:name (str) – A servicegroup name
Returns:the Contact object with servicegroup_name=name
Return type:alignak.objects.servicegroup.Servicegroup
get_servicegroups()[source]

Get all servicegroups

Returns:List of all servicegroups
Return type:list
get_services()[source]

Get all services

Returns:List of all services
Return type:list
guess_root_problems(obj)[source]

Get the list of services with : * a state_id != 0 (not OK state) * linked to the same host for a given service.

Parameters:obj (alignak.objects.schedulingitem.SchedulingItem) – service we want to get non OK services linked to its host
Returns:A service list with state_id != 0
Return type:list
load(regenerator)[source]

Set the regenerator attribute

Parameters:regenerator (alignak.misc.regenerator.Regenerator) – regenerator object
Returns:None
rg[source]

Getter for rg, raise deprecation warning

Returns:self.reg

alignak.misc.filter module

Helper functions for some filtering, like for user based

Get only user relevant items. The item needs the following attributes :
contacts source_problems impacts
Parameters:
  • lst (list) – A list of items
  • user (str) – A contact defined in Alignak
Returns:

A list of items (unique values)

Return type:

list

alignak.misc.logevent module

This module lists provide facilities to parse log type Broks. The supported event are listed in the event_type variable

class alignak.misc.logevent.LogEvent(log)[source]

Class for parsing event logs Populates self.data with the log type’s properties

alignak.misc.perfdata module

This module provide classes to handle performance data from monitoring plugin output

class alignak.misc.perfdata.Metric(string)[source]

Class providing a small abstraction for one metric of a Perfdatas class

class alignak.misc.perfdata.PerfDatas(string)[source]

Class providing performance data extracted from a check output

alignak.misc.perfdata.guess_int_or_float(val)[source]

Wrapper for Util.to_best_int_float Basically cast into float or int and compare value If they are equal then there is no coma so return integer

Parameters:val – value to cast
Returns:value casted into int, float or None
Return type:int | float | NoneType

alignak.misc.regenerator module

This module provide Regenerator class used in several Alignak modules to manage and regenerate objects

class alignak.misc.regenerator.Regenerator[source]

Bases: object

Class for a Regenerator. It gets broks, and “regenerate” real objects from them

all_done_linking(inst_id)[source]

Link all data (objects) in a specific instance

Parameters:inst_id (int) – Instance id from a config object
Returns:None
before_after_hook(brok, obj)[source]

This can be used by derived classes to compare the data in the brok with the object which will be updated by these data. For example, it is possible to find out in this method whether the state of a host or service has changed.

linkify_a_command(obj, prop)[source]

Replace the command_name by the command object in obj.prop

Parameters:
Returns:

None

linkify_a_timeperiod(obj, prop)[source]

Replace the timeperiod_name by the timeperiod object in obj.prop

Parameters:
Returns:

None

linkify_a_timeperiod_by_name(obj, prop)[source]

Replace the timeperiod_name by the timeperiod object in obj.prop

Parameters:
  • obj (alignak.objects.SchedulingItem) – A host or a service
  • prop (str) – an attribute to replace (‘notification_period’ or ‘check_period’)
Returns:

None

linkify_commands(obj, prop)[source]

Replace the command_name by the command object in obj.prop

Parameters:
Returns:

None

linkify_contacts(obj, prop)[source]

Replace the contact_name by the contact object in obj.prop

Parameters:
  • obj (alignak.objects.SchedulingItem) – A host or a service
  • prop (str) – an attribute to replace (‘contacts’)
Returns:

None

linkify_dict_srv_and_hosts(obj, prop)[source]

Replace the dict with host and service name by the host or service object in obj.prop

Parameters:
  • obj (alignak.objects.SchedulingItem) – A host or a service
  • prop (str) – an attribute to replace (‘impacts’, ‘source_problems’, ‘parent_dependencies’ or ‘child_dependencies’))
Returns:

None

linkify_host_and_hosts(obj, prop)[source]

Replace the host_name by the host object in obj.prop

Parameters:
  • obj (alignak.objects.SchedulingItem) – A host or a service
  • prop (str) – an attribute to replace (‘’parents’ ‘childs’)
Returns:

None

load_external_queue(from_q)[source]

Load an external queue for sending messages Basically a from_q setter method.

Parameters:from_q (multiprocessing.Queue or Queue.Queue) – queue to set
Returns:None
load_from_scheduler(sched)[source]

Load data from a scheduler

Parameters:sched (alignak.scheduler.Scheduler) – the scheduler obj
Returns:None
manage_brok(brok)[source]

Look for a manager function for a brok, and call it

Parameters:brok (object) –
Returns:
Return type:
manage_host_check_result_brok(brok)[source]

Manage host_check_result brok : Update host object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_host_next_schedule_brok(brok)[source]

Manage initial_timeperiod_status brok : Same as manage_host_check_result_brok

Returns:None
manage_initial_broker_status_brok(brok)[source]

Manage initial_broker_status brok : Update broker object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_broks_done_brok(brok)[source]

Manage initial_broks_done brok : Call all_done_linking with the instance_id in the brok

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_command_status_brok(brok)[source]

Manage initial_command_status brok : Update command object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_contact_status_brok(brok)[source]

Manage initial_contact_status brok : Update contact object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_contactgroup_status_brok(brok)[source]

Manage initial_contactgroup_status brok : Update contactgroup object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_host_status_brok(brok)[source]

Manage initial_host_status brok : Update host object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_hostgroup_status_brok(brok)[source]

Manage initial_hostgroup_status brok : Update hostgroup object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_poller_status_brok(brok)[source]

Manage initial_poller_status brok : Update poller object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_reactionner_status_brok(brok)[source]

Manage initial_reactionner_status brok : Update reactionner object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_receiver_status_brok(brok)[source]

Manage initial_receiver_status brok : Update receiver object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_scheduler_status_brok(brok)[source]

Manage initial_scheduler_status brok : Update scheduler object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_service_status_brok(brok)[source]

Manage initial_service_status brok : Update service object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_servicegroup_status_brok(brok)[source]

Manage initial_servicegroup_status brok : Update servicegroup object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_initial_timeperiod_status_brok(brok)[source]

Manage initial_timeperiod_status brok : Update timeperiod object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_program_status_brok(brok)[source]

Manage program_status brok : Reset objects for the given config id

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new config
Returns:None
manage_service_check_result_brok(brok)[source]

Manage service_check_result brok : Update service object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_service_next_schedule_brok(brok)[source]

Manage service_next_schedule brok : Same as manage_service_check_result_brok A service check update have just arrived, we UPDATE data info with this

Returns:None
manage_update_broker_status_brok(brok)[source]

Manage update_broker_status brok : Update broker object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_update_host_status_brok(brok)[source]

Manage update_host_status brok : Update host object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_update_poller_status_brok(brok)[source]

Manage update_poller_status brok : Update poller object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_update_program_status_brok(brok)[source]

Manage update_program_status brok : Update config object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_update_reactionner_status_brok(brok)[source]

Manage update_reactionner_status brok : Update reactionner object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_update_receiver_status_brok(brok)[source]

Manage update_receiver_status brok : Update receiver object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_update_scheduler_status_brok(brok)[source]

Manage update_scheduler_status brok : Update scheduler object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
manage_update_service_status_brok(brok)[source]

Manage update_service_status brok : Update service object

Parameters:brok (alignak.objects.brok.Brok) – Brok containing new data
Returns:None
update_element(item, data)[source]

Update object attibute with value contained in data keys

Parameters:
  • item (alignak.object.Item) – A alignak object
  • data (dict) – the dict containing attribute to update
Returns:

None

want_brok(brok)[source]

Function to tell whether we need a specific type of brok or not. Return always true if not in scheduler mode

Parameters:brok (alignak.objects.brok.Brok) – The brok to check
Returns:A boolean meaning that we this brok
Return type:bool

alignak.misc.sorter module

Helper functions for some sorting

alignak.misc.sorter.hst_srv_sort(s01, s02)[source]

Sort host and service by impact then state then name

Parameters:
Returns:

  • -1 if s01 > s02
  • 0 if s01 == s02 (not true)
  • 1 if s01 < s02

Return type:

int

alignak.misc.sorter.last_state_change_earlier(s01, s02)[source]

Sort host and service by last_state_change

Parameters:
Returns:

  • -1 if s01 > s02
  • 0 if s01 == s02 (not true)
  • 1 if s01 < s02

Return type:

int

alignak.misc.sorter.worse_first(s01, s02)[source]

Sort host and service by state then impact then name

Parameters:
Returns:

  • -1 if s01 > s02
  • 0 if s01 == s02 (not true)
  • 1 if s01 < s02

Return type:

int

Module contents

Init of alignak.misc, nothing to do here.