idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
19,700
def reload_configuration ( self ) : if not self . app . is_master : message = u"I received a request to reload the monitored configuration. " u"I am not the Master arbiter, I ignore and continue to run." logger . warning ( message ) return { '_status' : u'ERR' , '_message' : message } message = "I received a request to...
Ask to the arbiter to reload the monitored configuration
19,701
def command ( self , command = None , timestamp = None , element = None , host = None , service = None , user = None , parameters = None ) : if cherrypy . request . method in [ "POST" ] : if not cherrypy . request . json : return { '_status' : u'ERR' , '_message' : u'You must POST parameters on this endpoint.' } if com...
Request to execute an external command
19,702
def monitoring_problems ( self ) : res = self . identity ( ) res [ 'problems' ] = { } for scheduler_link in self . app . conf . schedulers : sched_res = scheduler_link . con . get ( 'monitoring_problems' , wait = True ) res [ 'problems' ] [ scheduler_link . name ] = { } if '_freshness' in sched_res : res [ 'problems' ]...
Get Alignak detailed monitoring status
19,703
def livesynthesis ( self ) : res = self . identity ( ) res . update ( self . app . get_livesynthesis ( ) ) return res
Get Alignak live synthesis
19,704
def object ( self , o_type , o_name = None ) : for scheduler_link in self . app . conf . schedulers : sched_res = scheduler_link . con . get ( 'object' , { 'o_type' : o_type , 'o_name' : o_name } , wait = True ) if isinstance ( sched_res , dict ) and 'content' in sched_res : return sched_res return { '_status' : u'ERR'...
Get a monitored object from the arbiter .
19,705
def status ( self , details = False ) : if details is not False : details = bool ( details ) return self . app . get_alignak_status ( details = details )
Get the overall alignak status
19,706
def events_log ( self , details = False , count = 0 , timestamp = 0 ) : if not count : count = 1 + int ( os . environ . get ( 'ALIGNAK_EVENTS_LOG_COUNT' , self . app . conf . events_log_count ) ) count = int ( count ) timestamp = float ( timestamp ) logger . debug ( 'Get max %d events, newer than %s out of %d' , count ...
Get the most recent Alignak events
19,707
def satellites_list ( self , daemon_type = '' ) : with self . app . conf_lock : res = { } for s_type in [ 'arbiter' , 'scheduler' , 'poller' , 'reactionner' , 'receiver' , 'broker' ] : if daemon_type and daemon_type != s_type : continue satellite_list = [ ] res [ s_type ] = satellite_list for daemon_link in getattr ( s...
Get the arbiter satellite names sorted by type
19,708
def satellites_configuration ( self ) : res = { } for s_type in [ 'arbiter' , 'scheduler' , 'poller' , 'reactionner' , 'receiver' , 'broker' ] : lst = [ ] res [ s_type ] = lst for daemon in getattr ( self . app . conf , s_type + 's' ) : cls = daemon . __class__ env = { } all_props = [ cls . properties , cls . running_p...
Return all the configuration data of satellites
19,709
def external_commands ( self ) : res = [ ] with self . app . external_commands_lock : for cmd in self . app . get_external_commands ( ) : res . append ( cmd . serialize ( ) ) return res
Get the external commands from the daemon
19,710
def search ( self ) : logger . debug ( "Grafana search... %s" , cherrypy . request . method ) if cherrypy . request . method == 'OPTIONS' : cherrypy . response . headers [ 'Access-Control-Allow-Methods' ] = 'GET,POST,PATCH,PUT,DELETE' cherrypy . response . headers [ 'Access-Control-Allow-Headers' ] = 'Content-Type,Auth...
Request available queries
19,711
def _build_host_livestate ( self , host_name , livestate ) : state = livestate . get ( 'state' , 'UP' ) . upper ( ) output = livestate . get ( 'output' , '' ) long_output = livestate . get ( 'long_output' , '' ) perf_data = livestate . get ( 'perf_data' , '' ) try : timestamp = int ( livestate . get ( 'timestamp' , 'AB...
Build and notify the external command for an host livestate
19,712
def _build_service_livestate ( self , host_name , service_name , livestate ) : state = livestate . get ( 'state' , 'OK' ) . upper ( ) output = livestate . get ( 'output' , '' ) long_output = livestate . get ( 'long_output' , '' ) perf_data = livestate . get ( 'perf_data' , '' ) try : timestamp = int ( livestate . get (...
Build and notify the external command for a service livestate
19,713
def _do_not_run ( self ) : if self . app . is_master : message = "Received message to not run. " "I am the Master arbiter, ignore and continue to run." logger . warning ( message ) return { '_status' : u'ERR' , '_message' : message } logger . debug ( "Received message to not run. I am the spare, stopping." ) self . app...
The master arbiter tells to its spare arbiters to not run .
19,714
def create_commandcall ( prop , commands , command ) : cc = { 'commands' : commands , 'call' : command } if hasattr ( prop , 'enable_environment_macros' ) : cc [ 'enable_environment_macros' ] = prop . enable_environment_macros if hasattr ( prop , 'poller_tag' ) : cc [ 'poller_tag' ] = prop . poller_tag elif hasattr ( p...
Create CommandCall object with command
19,715
def _push_broks ( self ) : data = cherrypy . request . json with self . app . arbiter_broks_lock : logger . debug ( "Pushing %d broks" , len ( data [ 'broks' ] ) ) self . app . arbiter_broks . extend ( [ unserialize ( elem , True ) for elem in data [ 'broks' ] ] )
Push the provided broks objects to the broker daemon
19,716
def load_params ( self , params ) : logger . debug ( "Alignak parameters:" ) for key , value in sorted ( self . clean_params ( params ) . items ( ) ) : update_attribute = None if key [ 0 ] == '$' and key [ - 1 ] == '$' : key = key [ 1 : - 1 ] if key not in self . __class__ . macros : logger . debug ( "New macro %s: %s ...
Load parameters from main configuration file
19,717
def _cut_line ( line ) : if re . search ( "([\t\n\r]+|[\x0b\x0c ]{3,})+" , line ) : tmp = re . split ( "([\t\n\r]+|[\x0b\x0c ]{3,})+" , line , 1 ) else : tmp = re . split ( "[" + string . whitespace + "]+" , line , 1 ) res = [ elt . strip ( ) for elt in tmp if elt . strip ( ) != '' ] return res
Split the line on whitespaces and remove empty chunks
19,718
def add_self_defined_objects ( raw_objects ) : logger . info ( "- creating internally defined commands..." ) if 'command' not in raw_objects : raw_objects [ 'command' ] = [ ] raw_objects [ 'command' ] . append ( { 'command_name' : 'bp_rule' , 'command_line' : 'bp_rule' , 'imported_from' : 'alignak-self' } ) raw_objects...
Add self defined command objects for internal processing ; bp_rule _internal_host_up _echo _internal_host_check _interna_service_check
19,719
def early_create_objects ( self , raw_objects ) : types_creations = self . __class__ . types_creations early_created_types = self . __class__ . early_created_types logger . info ( "Creating objects..." ) for o_type in sorted ( types_creations ) : if o_type in early_created_types : self . create_objects_for_type ( raw_o...
Create the objects needed for the post configuration file initialization
19,720
def create_objects ( self , raw_objects ) : types_creations = self . __class__ . types_creations early_created_types = self . __class__ . early_created_types logger . info ( "Creating objects..." ) self . add_self_defined_objects ( raw_objects ) for o_type in sorted ( types_creations ) : if o_type not in early_created_...
Create all the objects got after the post configuration file initialization
19,721
def create_objects_for_type ( self , raw_objects , o_type ) : types_creations = self . __class__ . types_creations ( cls , clss , prop , initial_index , _ ) = types_creations [ o_type ] lst = [ ] try : logger . info ( "- creating '%s' objects" , o_type ) for obj_cfg in raw_objects [ o_type ] : my_object = cls ( obj_cfg...
Generic function to create objects regarding the o_type
19,722
def early_arbiter_linking ( self , arbiter_name , params ) : if not self . arbiters : params . update ( { 'name' : arbiter_name , 'arbiter_name' : arbiter_name , 'host_name' : socket . gethostname ( ) , 'address' : '127.0.0.1' , 'port' : 7770 , 'spare' : '0' } ) logger . warning ( "There is no arbiter, I add myself (%s...
Prepare the arbiter for early operations
19,723
def linkify_one_command_with_commands ( self , commands , prop ) : if not hasattr ( self , prop ) : return command = getattr ( self , prop ) . strip ( ) if not command : setattr ( self , prop , None ) return data = { "commands" : commands , "call" : command } if hasattr ( self , 'poller_tag' ) : data . update ( { "poll...
Link a command
19,724
def linkify ( self ) : self . services . optimize_service_search ( self . hosts ) self . linkify_one_command_with_commands ( self . commands , 'host_perfdata_command' ) self . linkify_one_command_with_commands ( self . commands , 'service_perfdata_command' ) self . linkify_one_command_with_commands ( self . commands , ...
Make links between elements like a host got a services list with all its services in it
19,725
def clean ( self ) : logger . debug ( "Cleaning configuration objects before configuration sending:" ) types_creations = self . __class__ . types_creations for o_type in types_creations : ( _ , _ , inner_property , _ , _ ) = types_creations [ o_type ] logger . debug ( " . for %s" , inner_property , ) inner_object = ge...
Wrapper for calling the clean method of services attribute
19,726
def warn_about_unmanaged_parameters ( self ) : properties = self . __class__ . properties unmanaged = [ ] for prop , entry in list ( properties . items ( ) ) : if not entry . managed and hasattr ( self , prop ) : if entry . help : line = "%s: %s" % ( prop , entry . help ) else : line = prop unmanaged . append ( line ) ...
used to raise warning if the user got parameter that we do not manage from now
19,727
def apply_dependencies ( self ) : self . hosts . apply_dependencies ( ) self . services . apply_dependencies ( self . hosts )
Creates dependencies links between elements .
19,728
def fill_default_configuration ( self ) : logger . debug ( "Filling the unset properties with their default value:" ) types_creations = self . __class__ . types_creations for o_type in types_creations : ( _ , _ , inner_property , _ , _ ) = types_creations [ o_type ] if inner_property in [ 'realms' , 'arbiters' , 'sched...
Fill objects properties with default value if necessary
19,729
def log_daemons_list ( self ) : daemons = [ self . arbiters , self . schedulers , self . pollers , self . brokers , self . reactionners , self . receivers ] for daemons_list in daemons : if not daemons_list : logger . debug ( "- %ss: None" , daemons_list . inner_class . my_type ) else : logger . debug ( "- %ss: %s" , d...
Log Alignak daemons list
19,730
def got_broker_module_type_defined ( self , module_type ) : for broker_link in self . brokers : for module in broker_link . modules : if module . is_a_module ( module_type ) : return True return False
Check if a module type is defined in one of the brokers
19,731
def got_scheduler_module_type_defined ( self , module_type ) : for scheduler_link in self . schedulers : for module in scheduler_link . modules : if module . is_a_module ( module_type ) : return True return False
Check if a module type is defined in one of the schedulers
19,732
def got_arbiter_module_type_defined ( self , module_type ) : for arbiter in self . arbiters : for module in getattr ( arbiter , 'modules' , [ ] ) : module_name = module . get_name ( ) for mod in self . modules : if getattr ( mod , 'python_name' , '' ) . strip ( ) == module_type . strip ( ) : if getattr ( mod , 'name' ,...
Check if a module type is defined in one of the arbiters Also check the module name
19,733
def create_business_rules ( self ) : self . hosts . create_business_rules ( self . hosts , self . services , self . hostgroups , self . servicegroups , self . macromodulations , self . timeperiods ) self . services . create_business_rules ( self . hosts , self . services , self . hostgroups , self . servicegroups , sel...
Create business rules for hosts and services
19,734
def create_business_rules_dependencies ( self ) : for item in itertools . chain ( self . hosts , self . services ) : if not item . got_business_rule : continue bp_items = item . business_rule . list_all_elements ( ) for bp_item_uuid in bp_items : if bp_item_uuid in self . hosts : bp_item = self . hosts [ bp_item_uuid ]...
Create business rules dependencies for hosts and services
19,735
def propagate_timezone_option ( self ) : if self . use_timezone : os . environ [ 'TZ' ] = self . use_timezone time . tzset ( ) tab = [ self . schedulers , self . pollers , self . brokers , self . receivers , self . reactionners ] for sat_list in tab : for sat in sat_list : if sat . use_timezone == 'NOTSET' : setattr ( ...
Set our timezone value and give it too to unset satellites
19,736
def linkify_templates ( self ) : self . hosts . linkify_templates ( ) self . contacts . linkify_templates ( ) self . services . linkify_templates ( ) self . servicedependencies . linkify_templates ( ) self . hostdependencies . linkify_templates ( ) self . timeperiods . linkify_templates ( ) self . hostsextinfo . linkif...
Like for normal object we link templates with each others
19,737
def remove_templates ( self ) : self . hosts . remove_templates ( ) self . contacts . remove_templates ( ) self . services . remove_templates ( ) self . servicedependencies . remove_templates ( ) self . hostdependencies . remove_templates ( ) self . timeperiods . remove_templates ( )
Clean useless elements like templates because they are not needed anymore
19,738
def show_errors ( self ) : if self . configuration_warnings : logger . warning ( "Configuration warnings:" ) for msg in self . configuration_warnings : logger . warning ( msg ) if self . configuration_errors : logger . warning ( "Configuration errors:" ) for msg in self . configuration_errors : logger . warning ( msg )
Loop over configuration warnings and log them as INFO log Loop over configuration errors and log them as INFO log
19,739
def prepare_for_sending ( self ) : if [ arbiter_link for arbiter_link in self . arbiters if arbiter_link . spare ] : logger . info ( 'Serializing the configuration for my spare arbiter...' ) self . spare_arbiter_conf = serialize ( self )
The configuration needs to be serialized before being sent to a spare arbiter
19,740
def dump ( self , dump_file_name = None ) : config_dump = { } for _ , _ , category , _ , _ in list ( self . types_creations . values ( ) ) : try : objs = [ jsonify_r ( i ) for i in getattr ( self , category ) ] except ( TypeError , AttributeError ) : logger . warning ( "Dumping configuration, '%s' not present in the co...
Dump configuration to a file in a JSON format
19,741
def push_broks_to_broker ( self ) : someone_is_concerned = False sent = False for broker_link in self . conf . brokers : if not broker_link . manage_arbiters : continue someone_is_concerned = True if broker_link . reachable : logger . debug ( "Sending %d broks to the broker %s" , len ( self . broks ) , broker_link . na...
Send all broks from arbiter internal list to broker
19,742
def push_external_commands_to_schedulers ( self ) : for external_command in self . external_commands : self . external_commands_manager . resolve_command ( external_command ) sent = False for scheduler_link in self . conf . schedulers : ext_cmds = scheduler_link . external_commands if ext_cmds and scheduler_link . reac...
Send external commands to schedulers
19,743
def get_broks_from_satellites ( self ) : for satellites in [ self . conf . brokers , self . conf . schedulers , self . conf . pollers , self . conf . reactionners , self . conf . receivers ] : for satellite in satellites : if not satellite . reachable : continue logger . debug ( "Getting broks from: %s" , satellite . n...
Get broks from my all internal satellite links
19,744
def get_initial_broks_from_satellites ( self ) : for satellites in [ self . conf . brokers , self . conf . schedulers , self . conf . pollers , self . conf . reactionners , self . conf . receivers ] : for satellite in satellites : if not satellite . reachable : continue logger . debug ( "Getting initial brok from: %s" ...
Get initial broks from my internal satellite links
19,745
def load_modules_configuration_objects ( self , raw_objects ) : for instance in self . modules_manager . instances : logger . debug ( "Getting objects from the module: %s" , instance . name ) if not hasattr ( instance , 'get_objects' ) : logger . debug ( "The module '%s' do not provide any objects." , instance . name )...
Load configuration objects from arbiter modules If module implements get_objects arbiter will call it and add create objects
19,746
def load_modules_alignak_configuration ( self ) : alignak_cfg = { } for instance in self . modules_manager . instances : if not hasattr ( instance , 'get_alignak_configuration' ) : return try : logger . info ( "Getting Alignak global configuration from module '%s'" , instance . name ) cfg = instance . get_alignak_confi...
Load Alignak configuration from the arbiter modules If module implements get_alignak_configuration call this function
19,747
def request_stop ( self , message = '' , exit_code = 0 ) : if self . is_master : self . daemons_stop ( timeout = self . conf . daemons_stop_timeout ) super ( Arbiter , self ) . request_stop ( message , exit_code )
Stop the Arbiter daemon
19,748
def start_daemon ( self , satellite ) : logger . info ( " launching a daemon for: %s/%s..." , satellite . type , satellite . name ) daemon_script_location = getattr ( self . conf , 'daemons_script_location' , self . bindir ) if not daemon_script_location : daemon_script_location = "alignak-%s" % satellite . type else ...
Manage the list of detected missing daemons
19,749
def daemons_start ( self , run_daemons = True ) : result = True if run_daemons : logger . info ( "Alignak configured daemons start:" ) else : logger . info ( "Alignak configured daemons check:" ) for satellites_list in [ self . conf . arbiters , self . conf . receivers , self . conf . reactionners , self . conf . polle...
Manage the list of the daemons in the configuration
19,750
def daemons_stop ( self , timeout = 30 , kill_children = False ) : def on_terminate ( proc ) : logger . debug ( "process %s terminated with exit code %s" , proc . pid , proc . returncode ) result = True if self . my_daemons : logger . info ( "Alignak self-launched daemons stop:" ) start = time . time ( ) for daemon in ...
Stop the Alignak daemons
19,751
def setup_new_conf ( self ) : super ( Arbiter , self ) . setup_new_conf ( ) with self . conf_lock : logger . info ( "I received a new configuration from my master" ) self . cur_conf = self . new_conf self_conf = self . cur_conf . get ( 'self_conf' , None ) if not self_conf : self_conf = self . conf whole_conf = self . ...
Setup a new configuration received from a Master arbiter .
19,752
def wait_for_master_death ( self ) : logger . info ( "Waiting for master death" ) timeout = 1.0 self . last_master_ping = time . time ( ) master_timeout = 300 for arbiter_link in self . conf . arbiters : if not arbiter_link . spare : master_timeout = arbiter_link . spare_check_interval * arbiter_link . spare_max_check_...
Wait for a master timeout and take the lead if necessary
19,753
def manage_signal ( self , sig , frame ) : if sig in [ signal . SIGINT , signal . SIGTERM ] : logger . info ( "received a signal: %s" , SIGNALS_TO_NAMES_DICT [ sig ] ) self . kill_request = True self . kill_timestamp = time . time ( ) logger . info ( "request to stop in progress" ) else : Daemon . manage_signal ( self ...
Manage signals caught by the process Specific behavior for the arbiter when it receives a sigkill or sigterm
19,754
def configuration_dispatch ( self , not_configured = None ) : if not not_configured : self . dispatcher = Dispatcher ( self . conf , self . link_to_myself ) self . cur_conf = self . conf first_connection_try_count = 0 logger . info ( "Connecting to my satellites..." ) while True : first_connection_try_count += 1 self ....
Monitored configuration preparation and dispatch
19,755
def do_before_loop ( self ) : logger . info ( "I am the arbiter: %s" , self . link_to_myself . name ) if not self . is_master : logger . debug ( "Waiting for my master death..." ) return if not self . daemons_start ( run_daemons = True ) : self . request_stop ( message = "Some Alignak daemons did not started correctly....
Called before the main daemon loop .
19,756
def get_monitoring_problems ( self ) : res = self . get_id ( ) res [ 'problems' ] = { } if getattr ( self , 'dispatcher' , None ) is None : return res for satellite in self . dispatcher . all_daemons_links : if satellite . type not in [ 'scheduler' ] : continue if not satellite . active : continue if satellite . statis...
Get the schedulers satellites problems list
19,757
def get_livesynthesis ( self ) : res = self . get_id ( ) res [ 'livesynthesis' ] = { '_overall' : { '_freshness' : int ( time . time ( ) ) , 'livesynthesis' : { 'hosts_total' : 0 , 'hosts_not_monitored' : 0 , 'hosts_up_hard' : 0 , 'hosts_up_soft' : 0 , 'hosts_down_hard' : 0 , 'hosts_down_soft' : 0 , 'hosts_unreachable_...
Get the schedulers satellites live synthesis
19,758
def overall_state_id ( self ) : overall_state = 0 if not self . monitored : overall_state = 5 elif self . acknowledged : overall_state = 1 elif self . downtimed : overall_state = 2 elif self . state_type == 'HARD' : if self . state == 'WARNING' : overall_state = 3 elif self . state == 'CRITICAL' : overall_state = 4 eli...
Get the service overall state .
19,759
def fill_predictive_missing_parameters ( self ) : if self . initial_state == 'w' : self . state = u'WARNING' elif self . initial_state == 'u' : self . state = u'UNKNOWN' elif self . initial_state == 'c' : self . state = u'CRITICAL' elif self . initial_state == 'x' : self . state = u'UNREACHABLE'
define state with initial_state
19,760
def get_name ( self ) : if hasattr ( self , 'service_description' ) : return self . service_description if hasattr ( self , 'name' ) : return self . name return 'SERVICE-DESCRIPTION-MISSING'
Accessor to service_description attribute or name if first not defined
19,761
def get_groupnames ( self , sgs ) : return ',' . join ( [ sgs [ sg ] . get_name ( ) for sg in self . servicegroups ] )
Get servicegroups list
19,762
def duplicate ( self , host ) : duplicates = [ ] prop = self . duplicate_foreach . strip ( ) . upper ( ) if prop not in host . customs : return duplicates entry = host . customs [ prop ] not_entry = host . customs . get ( '_' + '!' + prop [ 1 : ] , '' ) . split ( ',' ) not_keys = strip_and_uniq ( not_entry ) default_va...
For a given host look for all copy we must create for for_each property
19,763
def set_state_from_exit_status ( self , status , notif_period , hosts , services ) : now = time . time ( ) cls = self . __class__ if cls . enable_problem_impacts_states_change and self . is_impact and not self . state_changed_since_impact : self . last_state = self . state_before_impact else : self . last_state = self ...
Set the state in UP WARNING CRITICAL UNKNOWN or UNREACHABLE according to the status of a check result .
19,764
def is_state ( self , status ) : if status == self . state : return True if status == 'o' and self . state == u'OK' : return True if status == 'c' and self . state == u'CRITICAL' : return True if status == 'w' and self . state == u'WARNING' : return True if status == 'u' and self . state == u'UNKNOWN' : return True if ...
Return True if status match the current service status
19,765
def last_time_non_ok_or_up ( self ) : non_ok_times = [ x for x in [ self . last_time_warning , self . last_time_critical , self . last_time_unknown ] if x > self . last_time_ok ] if not non_ok_times : last_time_non_ok = 0 else : last_time_non_ok = min ( non_ok_times ) return last_time_non_ok
Get the last time the service was in a non - OK state
19,766
def get_data_for_notifications ( self , contact , notif , host_ref ) : if not host_ref : return [ self , contact , notif ] return [ host_ref , self , contact , notif ]
Get data for a notification
19,767
def get_short_status ( self , hosts , services ) : mapping = { 0 : "O" , 1 : "W" , 2 : "C" , 3 : "U" , 4 : "N" , } if self . got_business_rule : return mapping . get ( self . business_rule . get_state ( hosts , services ) , "n/a" ) return mapping . get ( self . state_id , "n/a" )
Get the short status of this host
19,768
def add_template ( self , tpl ) : objcls = self . inner_class . my_type name = getattr ( tpl , 'name' , '' ) sdesc = getattr ( tpl , 'service_description' , '' ) hname = getattr ( tpl , 'host_name' , '' ) logger . debug ( "Adding a %s template: host_name: %s, name: %s, service_description: %s" , objcls , hname , name ,...
Adds and index a template into the templates container .
19,769
def find_srvs_by_hostname ( self , host_name ) : if hasattr ( self , 'hosts' ) : host = self . hosts . find_by_name ( host_name ) if host is None : return None return host . get_services ( ) return None
Get all services from a host based on a host_name
19,770
def find_srv_by_name_and_hostname ( self , host_name , sdescr ) : key = ( host_name , sdescr ) return self . name_to_item . get ( key , None )
Get a specific service based on a host_name and service_description
19,771
def linkify_s_by_hst ( self , hosts ) : for serv in self : if not hasattr ( serv , 'host_name' ) : serv . host = None continue try : hst_name = serv . host_name hst = hosts . find_by_name ( hst_name ) if hst is not None : serv . host = hst . uuid hst . add_service_link ( serv . uuid ) else : err = "Warning: the service...
Link services with their parent host
19,772
def linkify_s_by_sg ( self , servicegroups ) : for serv in self : new_servicegroups = [ ] if hasattr ( serv , 'servicegroups' ) and serv . servicegroups != '' : for sg_name in serv . servicegroups : sg_name = sg_name . strip ( ) servicegroup = servicegroups . find_by_name ( sg_name ) if servicegroup is not None : new_s...
Link services with servicegroups
19,773
def clean ( self ) : to_del = [ ] for serv in self : if not serv . host : to_del . append ( serv . uuid ) for service_uuid in to_del : del self . items [ service_uuid ]
Remove services without host object linked to
19,774
def explode_services_from_hosts ( self , hosts , service , hnames ) : duplicate_for_hosts = [ ] not_hosts = [ ] for hname in hnames : hname = hname . strip ( ) if hname . startswith ( '!' ) : not_hosts . append ( hname [ 1 : ] ) else : duplicate_for_hosts . append ( hname ) duplicate_for_hosts = list ( set ( duplicate_...
Explodes a service based on a list of hosts .
19,775
def _local_create_service ( self , hosts , host_name , service ) : host = hosts . find_by_name ( host_name . strip ( ) ) if host . is_excluded_for ( service ) : return None new_s = service . copy ( ) new_s . host_name = host_name new_s . register = 1 self . add_item ( new_s ) return new_s
Create a new service based on a host_name and service instance .
19,776
def explode_services_from_templates ( self , hosts , service_template ) : hname = getattr ( service_template , "host_name" , None ) if not hname : logger . debug ( "Service template %s is declared without an host_name" , service_template . get_name ( ) ) return logger . debug ( "Explode services %s for the host: %s" , ...
Explodes services from templates . All hosts holding the specified templates are bound with the service .
19,777
def explode_services_duplicates ( self , hosts , service ) : hname = getattr ( service , "host_name" , None ) if hname is None : return host = hosts . find_by_name ( hname . strip ( ) ) if host is None : service . add_error ( 'Error: The hostname %s is unknown for the service %s!' % ( hname , service . get_name ( ) ) )...
Explodes services holding a duplicate_foreach clause .
19,778
def register_service_into_servicegroups ( service , servicegroups ) : if hasattr ( service , 'service_description' ) : sname = service . service_description shname = getattr ( service , 'host_name' , '' ) if hasattr ( service , 'servicegroups' ) : if isinstance ( service . servicegroups , list ) : sgs = service . servi...
Registers a service into the service groups declared in its servicegroups attribute .
19,779
def register_service_dependencies ( service , servicedependencies ) : sdeps = [ d . strip ( ) for d in getattr ( service , "service_dependencies" , [ ] ) ] i = 0 hname = '' for elt in sdeps : if i % 2 == 0 : hname = elt else : desc = elt if hasattr ( service , 'service_description' ) and hasattr ( service , 'host_name'...
Registers a service dependencies .
19,780
def explode ( self , hosts , hostgroups , contactgroups , servicegroups , servicedependencies ) : itemkeys = list ( self . items . keys ( ) ) for s_id in itemkeys : serv = self . items [ s_id ] self . explode_host_groups_into_hosts ( serv , hosts , hostgroups ) self . explode_contact_groups_into_contacts ( serv , conta...
Explodes services from host hostgroups contactgroups servicegroups and dependencies .
19,781
def get_next_notif_time ( self , t_wished , status , creation_time , interval , escal_period ) : short_states = { u'WARNING' : 'w' , u'UNKNOWN' : 'u' , u'CRITICAL' : 'c' , u'RECOVERY' : 'r' , u'FLAPPING' : 'f' , u'DOWNTIME' : 's' , u'DOWN' : 'd' , u'UNREACHABLE' : 'u' , u'OK' : 'o' , u'UP' : 'o' } if not self . time_ba...
Get the next notification time for the escalation Only legit for time based escalation
19,782
def linkify_es_by_s ( self , services ) : for escalation in self : if not hasattr ( escalation , 'host_name' ) : continue es_hname , sdesc = escalation . host_name , escalation . service_description if not es_hname . strip ( ) or not sdesc . strip ( ) : continue for hname in strip_and_uniq ( es_hname . split ( ',' ) ) ...
Add each escalation object into service . escalation attribute
19,783
def linkify_es_by_h ( self , hosts ) : for escal in self : if ( not hasattr ( escal , 'host_name' ) or escal . host_name . strip ( ) == '' or ( hasattr ( escal , 'service_description' ) and escal . service_description . strip ( ) != '' ) ) : continue for hname in strip_and_uniq ( escal . host_name . split ( ',' ) ) : h...
Add each escalation object into host . escalation attribute
19,784
def explode ( self , hosts , hostgroups , contactgroups ) : for i in self : self . explode_host_groups_into_hosts ( i , hosts , hostgroups ) self . explode_contact_groups_into_contacts ( i , contactgroups )
Loop over all escalation and explode hostsgroups in host and contactgroups in contacts
19,785
def get_hosts_by_explosion ( self , hostgroups ) : self . already_exploded = True if self . rec_tag : logger . error ( "[hostgroup::%s] got a loop in hostgroup definition" , self . get_name ( ) ) return self . get_hosts ( ) self . rec_tag = True hg_mbrs = self . get_hostgroup_members ( ) for hg_mbr in hg_mbrs : hostgro...
Get hosts of this group
19,786
def add_member ( self , host_name , hostgroup_name ) : hostgroup = self . find_by_name ( hostgroup_name ) if not hostgroup : hostgroup = Hostgroup ( { 'hostgroup_name' : hostgroup_name , 'alias' : hostgroup_name , 'members' : host_name } ) self . add ( hostgroup ) else : hostgroup . add_members ( host_name )
Add a host string to a hostgroup member if the host group do not exist create it
19,787
def linkify ( self , hosts = None , realms = None , forced_realms_hostgroups = True ) : self . linkify_hostgroups_hosts ( hosts ) self . linkify_hostgroups_realms_hosts ( realms , hosts , forced_realms_hostgroups )
Link hostgroups with hosts and realms
19,788
def linkify_hostgroups_hosts ( self , hosts ) : for hostgroup in self : members = hostgroup . get_hosts ( ) new_members = [ ] for member in members : member = member . strip ( ) if not member : continue if member == '*' : new_members . extend ( list ( hosts . items . keys ( ) ) ) else : host = hosts . find_by_name ( me...
We just search for each hostgroup the id of the hosts and replace the names by the found identifiers
19,789
def explode ( self ) : for tmp_hg in list ( self . items . values ( ) ) : tmp_hg . already_exploded = False for hostgroup in list ( self . items . values ( ) ) : if hostgroup . already_exploded : continue for tmp_hg in list ( self . items . values ( ) ) : tmp_hg . rec_tag = False hostgroup . get_hosts_by_explosion ( se...
Fill members with hostgroup_members
19,790
def run ( self ) : def _started_callback ( ) : cherrypy . log ( "CherryPy engine started and listening..." ) self . cherrypy_thread = None try : cherrypy . log ( "Starting CherryPy engine on %s" % ( self . uri ) ) self . cherrypy_thread = cherrypy . engine . start_with_callback ( _started_callback ) cherrypy . engine ....
Wrapper to start the CherryPy server
19,791
def stop ( self ) : cherrypy . log ( "Stopping CherryPy engine (current state: %s)..." % cherrypy . engine . state ) try : cherrypy . engine . exit ( ) except RuntimeWarning : pass except SystemExit : cherrypy . log ( 'SystemExit raised: shutting down bus' ) cherrypy . log ( "Stopped" )
Wrapper to stop the CherryPy server
19,792
def create_queues ( self , manager = None ) : self . clear_queues ( manager ) if not manager : self . from_q = Queue ( ) self . to_q = Queue ( ) else : self . from_q = manager . Queue ( ) self . to_q = manager . Queue ( )
Create the shared queues that will be used by alignak daemon process and this module process . But clear queues if they were already set before recreating new one .
19,793
def clear_queues ( self , manager ) : for queue in ( self . to_q , self . from_q ) : if queue is None : continue if not manager : try : queue . close ( ) queue . join_thread ( ) except AttributeError : pass self . to_q = self . from_q = None
Release the resources associated to the queues of this instance
19,794
def start_module ( self ) : try : self . _main ( ) except Exception as exp : logger . exception ( '%s' , traceback . format_exc ( ) ) raise Exception ( exp )
Wrapper for _main function . Catch and raise any exception occurring in the main function
19,795
def start ( self , http_daemon = None ) : if not self . is_external : return if self . process : self . stop_process ( ) logger . info ( "Starting external process for module %s..." , self . name ) proc = Process ( target = self . start_module , args = ( ) , group = None ) try : del self . properties [ 'process' ] exce...
Actually restart the process if the module is external Try first to stop the process and create a new Process instance with target start_module . Finally start process .
19,796
def stop_process ( self ) : if not self . process : return logger . info ( "I'm stopping module %r (pid=%d)" , self . name , self . process . pid ) self . kill ( ) self . process = None
Request the module process to stop and release it
19,797
def manage_brok ( self , brok ) : manage = getattr ( self , 'manage_' + brok . type + '_brok' , None ) if not manage : return False brok . prepare ( ) return manage ( brok )
Request the module to manage the given brok . There are a lot of different possible broks to manage . The list is defined in the Brok class .
19,798
def manage_signal ( self , sig , frame ) : logger . info ( "received a signal: %s" , SIGNALS_TO_NAMES_DICT [ sig ] ) if sig == signal . SIGHUP : logger . info ( "Modules are not able to reload their configuration. " "Stopping the module..." ) logger . info ( "Request to stop the module" ) self . interrupted = True
Generic function to handle signals
19,799
def _main ( self ) : self . set_proctitle ( self . name ) self . set_signal_handler ( ) logger . info ( "process for module %s is now running (pid=%d)" , self . name , os . getpid ( ) ) try : self . main ( ) except ( IOError , EOFError ) : pass except Exception as exp : logger . exception ( 'main function exception: %s...
module main method . Only used by external modules .