idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
19,500 | def set_log_level ( self , log_level = None ) : if log_level is None : log_level = cherrypy . request . json [ 'log_level' ] if log_level not in [ 'DEBUG' , 'INFO' , 'WARNING' , 'ERROR' , 'CRITICAL' ] : return { '_status' : u'ERR' , '_message' : u"Required log level is not allowed: %s" % log_level } alignak_logger = lo... | Set the current log level for the daemon |
19,501 | def stats ( self , details = False ) : if details is not False : details = bool ( details ) res = self . identity ( ) res . update ( self . app . get_daemon_stats ( details = details ) ) return res | Get statistics and information from the daemon |
19,502 | def _have_conf ( self , magic_hash = None ) : self . app . have_conf = getattr ( self . app , 'cur_conf' , None ) not in [ None , { } ] if magic_hash is not None : magic_hash = int ( magic_hash ) return self . app . have_conf and self . app . cur_conf . magic_hash == magic_hash return self . app . have_conf | Get the daemon current configuration state |
19,503 | def _results ( self , scheduler_instance_id ) : with self . app . lock : res = self . app . get_results_from_passive ( scheduler_instance_id ) return serialize ( res , True ) | Get the results of the executed actions for the scheduler which instance id is provided |
19,504 | def _broks ( self , broker_name ) : with self . app . broks_lock : res = self . app . get_broks ( ) return serialize ( res , True ) | Get the broks from the daemon |
19,505 | def _events ( self ) : with self . app . events_lock : res = self . app . get_events ( ) return serialize ( res , True ) | Get the monitoring events from the daemon |
19,506 | def get_state ( self , hosts , services ) : if self . operand == 'host' : host = hosts [ self . sons [ 0 ] ] return self . get_host_node_state ( host . last_hard_state_id , host . problem_has_been_acknowledged , host . in_scheduled_downtime ) if self . operand == 'service' : service = services [ self . sons [ 0 ] ] ret... | Get node state by looking recursively over sons and applying operand |
19,507 | def eval_cor_pattern ( self , pattern , hosts , services , hostgroups , servicegroups , running = False ) : pattern = pattern . strip ( ) complex_node = False for char in '()&|' : if char in pattern : complex_node = True if complex_node is False : return self . eval_simple_cor_pattern ( pattern , hosts , services , hos... | Parse and build recursively a tree of DependencyNode from pattern |
19,508 | def eval_complex_cor_pattern ( self , pattern , hosts , services , hostgroups , servicegroups , running = False ) : node = DependencyNode ( ) pattern = self . eval_xof_pattern ( node , pattern ) in_par = False tmp = '' son_is_not = False stacked_parenthesis = 0 for char in pattern : if char == '(' : stacked_parenthesis... | Parse and build recursively a tree of DependencyNode from a complex pattern |
19,509 | def eval_simple_cor_pattern ( self , pattern , hosts , services , hostgroups , servicegroups , running = False ) : node = DependencyNode ( ) pattern = self . eval_xof_pattern ( node , pattern ) if pattern . startswith ( '!' ) : node . not_value = True pattern = pattern [ 1 : ] if re . search ( r"^([%s]+|\*):" % self . ... | Parse and build recursively a tree of DependencyNode from a simple pattern |
19,510 | def find_object ( self , pattern , hosts , services ) : obj = None error = None is_service = False elts = pattern . split ( ',' ) host_name = elts [ 0 ] . strip ( ) if not host_name : host_name = self . bound_item . host_name if len ( elts ) > 1 : is_service = True service_description = elts [ 1 ] . strip ( ) if is_ser... | Find object from pattern |
19,511 | def is_time_valid ( self , timestamp ) : if hasattr ( self , 'exclude' ) : for daterange in self . exclude : if daterange . is_time_valid ( timestamp ) : return False for daterange in self . dateranges : if daterange . is_time_valid ( timestamp ) : return True return False | Check if a time is valid or not |
19,512 | def get_min_from_t ( self , timestamp ) : mins_incl = [ ] for daterange in self . dateranges : mins_incl . append ( daterange . get_min_from_t ( timestamp ) ) return min ( mins_incl ) | Get the first time > timestamp which is valid |
19,513 | def clean_cache ( self ) : now = int ( time . time ( ) ) t_to_del = [ ] for timestamp in self . cache : if timestamp < now : t_to_del . append ( timestamp ) for timestamp in t_to_del : del self . cache [ timestamp ] t_to_del = [ ] for timestamp in self . invalid_cache : if timestamp < now : t_to_del . append ( timestam... | Clean cache with entries older than now because not used in future ; ) |
19,514 | def get_next_valid_time_from_t ( self , timestamp ) : timestamp = int ( timestamp ) original_t = timestamp res_from_cache = self . find_next_valid_time_from_cache ( timestamp ) if res_from_cache is not None : return res_from_cache still_loop = True while still_loop : local_min = None dr_mins = [ ] for daterange in self... | Get next valid time . If it s in cache get it otherwise define it . The limit to find it is 1 year . |
19,515 | def get_next_invalid_time_from_t ( self , timestamp ) : timestamp = int ( timestamp ) original_t = timestamp dr_mins = [ ] for daterange in self . dateranges : timestamp = original_t cont = True while cont : start = daterange . get_next_valid_time_from_t ( timestamp ) if start is not None : end = daterange . get_next_i... | Get the next invalid time |
19,516 | def explode ( self ) : for entry in self . unresolved : self . resolve_daterange ( self . dateranges , entry ) self . unresolved = [ ] | Try to resolve all unresolved elements |
19,517 | def linkify ( self , timeperiods ) : new_exclude = [ ] if hasattr ( self , 'exclude' ) and self . exclude != [ ] : logger . debug ( "[timeentry::%s] have excluded %s" , self . get_name ( ) , self . exclude ) excluded_tps = self . exclude for tp_name in excluded_tps : timepriod = timeperiods . find_by_name ( tp_name . s... | Will make timeperiod in exclude with id of the timeperiods |
19,518 | def check_exclude_rec ( self ) : if self . rec_tag : msg = "[timeentry::%s] is in a loop in exclude parameter" % ( self . get_name ( ) ) self . add_error ( msg ) return False self . rec_tag = True for timeperiod in self . exclude : timeperiod . check_exclude_rec ( ) return True | Check if this timeperiod is tagged |
19,519 | def explode ( self ) : for t_id in self . items : timeperiod = self . items [ t_id ] timeperiod . explode ( ) | Try to resolve each timeperiod |
19,520 | def linkify ( self ) : for t_id in self . items : timeperiod = self . items [ t_id ] timeperiod . linkify ( self ) | Check exclusion for each timeperiod |
19,521 | def apply_inheritance ( self ) : self . apply_partial_inheritance ( 'exclude' ) for i in self : self . get_customs_properties_by_inheritance ( i ) for timeperiod in self : self . get_unresolved_properties_by_inheritance ( timeperiod ) | The only interesting property to inherit is exclude |
19,522 | def is_correct ( self ) : valid = True for timeperiod in list ( self . items . values ( ) ) : timeperiod . rec_tag = False for timeperiod in list ( self . items . values ( ) ) : for tmp_tp in list ( self . items . values ( ) ) : tmp_tp . rec_tag = False valid = timeperiod . check_exclude_rec ( ) and valid for timeperio... | check if each properties of timeperiods are valid |
19,523 | def check_status_and_get_events ( self ) : statistics = { } events = [ ] for daemon_link in self . all_daemons_links : if daemon_link == self . arbiter_link : continue if not daemon_link . active : continue try : daemon_link . statistics = daemon_link . get_daemon_stats ( details = False ) if daemon_link . statistics :... | Get all the daemons status |
19,524 | def get_scheduler_ordered_list ( self , realm ) : scheduler_links = [ ] for scheduler_link_uuid in realm . schedulers : scheduler_links . append ( self . schedulers [ scheduler_link_uuid ] ) alive = [ ] spare = [ ] deads = [ ] for sdata in scheduler_links : if sdata . alive and not sdata . spare : alive . append ( sdat... | Get sorted scheduler list for a specific realm |
19,525 | def dispatch ( self , test = False ) : if not self . new_to_dispatch : raise DispatcherError ( "Dispatcher cannot dispatch, " "because no configuration is prepared!" ) if self . first_dispatch_done : raise DispatcherError ( "Dispatcher cannot dispatch, " "because the configuration is still dispatched!" ) if self . disp... | Send configuration to satellites |
19,526 | def stop_request ( self , stop_now = False ) : all_ok = True for daemon_link in self . all_daemons_links : logger . debug ( "Stopping: %s (%s)" , daemon_link , stop_now ) if daemon_link == self . arbiter_link : continue if not daemon_link . active : continue try : stop_ok = daemon_link . stop_request ( stop_now = stop_... | Send a stop request to all the daemons |
19,527 | def pythonize ( self , val ) : __boolean_states__ = { '1' : True , 'yes' : True , 'true' : True , 'on' : True , '0' : False , 'no' : False , 'false' : False , 'off' : False } if isinstance ( val , bool ) : return val val = unique_value ( val ) . lower ( ) if val in list ( __boolean_states__ . keys ( ) ) : return __bool... | Convert value into a boolean |
19,528 | def pythonize ( self , val ) : if isinstance ( val , list ) and len ( set ( val ) ) == 1 : return val [ 0 ] return val | If value is a single list element just return the element does nothing otherwise |
19,529 | def login ( self , username , password ) : logger . debug ( "login for: %s" , username ) if not username and not password : self . set_token ( token = None ) return False if not username or not password : logger . error ( "Username or password cannot be None!" ) self . set_token ( token = None ) return False endpoint =... | Log into the WS interface and get the authentication token |
19,530 | def logout ( self ) : logger . debug ( "request backend logout" ) if not self . authenticated : logger . warning ( "Unnecessary logout ..." ) return True endpoint = 'logout' _ = self . get_response ( method = 'POST' , endpoint = endpoint ) self . session . close ( ) self . set_token ( token = None ) return True | Logout from the backend |
19,531 | def get ( self , endpoint , params = None ) : response = self . get_response ( method = 'GET' , endpoint = endpoint , params = params ) resp = self . decode ( response = response ) if '_status' not in resp : resp [ '_status' ] = u'OK' return resp | Get items or item in alignak backend |
19,532 | def post ( self , endpoint , data , files = None , headers = None ) : response = self . get_response ( method = 'POST' , endpoint = endpoint , json = data , headers = headers ) resp = self . decode ( response = response ) return resp | Create a new item |
19,533 | def patch ( self , endpoint , data ) : response = self . get_response ( method = 'PATCH' , endpoint = endpoint , json = data , headers = { 'Content-Type' : 'application/json' } ) if response . status_code == 200 : return self . decode ( response = response ) return response | Method to update an item |
19,534 | def init ( self , conf ) : self . my_conf = conf self . lists_on_demand = [ ] self . hosts = self . my_conf . hosts self . host_class = self . hosts . inner_class self . lists_on_demand . append ( self . hosts ) self . services = self . my_conf . services self . contacts = self . my_conf . contacts self . lists_on_dema... | Initialize MacroResolver instance with conf . Must be called at least once . |
19,535 | def _get_value_from_element ( self , elt , prop ) : args = None if isinstance ( prop , tuple ) : prop , args = prop value = getattr ( elt , prop , None ) if value is None : return 'n/a' try : if isinstance ( value , list ) : return "[%s]" % ',' . join ( value ) if not isinstance ( value , collections . Callable ) : ret... | Get value from an element s property . |
19,536 | def _delete_unwanted_caracters ( self , chain ) : try : chain = chain . decode ( 'utf8' , 'replace' ) except UnicodeEncodeError : pass except AttributeError : pass for char in self . illegal_macro_output_chars : chain = chain . replace ( char , '' ) return chain | Remove not wanted char from chain unwanted char are illegal_macro_output_chars attribute |
19,537 | def resolve_command ( self , com , data , macromodulations , timeperiods ) : logger . debug ( "Resolving: macros in: %s, arguments: %s" , com . command . command_line , com . args ) return self . resolve_simple_macros_in_string ( com . command . command_line , data , macromodulations , timeperiods , args = com . args ) | Resolve command macros with data |
19,538 | def _get_type_of_macro ( macros , objs ) : r for macro in macros : if re . match ( r'ARG\d' , macro ) : macros [ macro ] [ 'type' ] = 'ARGN' continue elif re . match ( r'_HOST\w' , macro ) : macros [ macro ] [ 'type' ] = 'CUSTOM' macros [ macro ] [ 'class' ] = 'HOST' continue elif re . match ( r'_SERVICE\w' , macro ) :... | r Set macros types |
19,539 | def _resolve_ondemand ( self , macro , data ) : elts = macro . split ( ':' ) nb_parts = len ( elts ) macro_name = elts [ 0 ] if nb_parts == 3 : val = '' ( host_name , service_description ) = ( elts [ 1 ] , elts [ 2 ] ) if host_name == '' : for elt in data : if elt is not None and elt . __class__ == self . host_class : ... | Get on demand macro value |
19,540 | def _tot_hosts_by_state ( self , state = None , state_type = None ) : if state is None and state_type is None : return len ( self . hosts ) if state_type : return sum ( 1 for h in self . hosts if h . state == state and h . state_type == state_type ) return sum ( 1 for h in self . hosts if h . state == state ) | Generic function to get the number of host in the specified state |
19,541 | def _tot_unhandled_hosts_by_state ( self , state ) : return sum ( 1 for h in self . hosts if h . state == state and h . state_type == u'HARD' and h . is_problem and not h . problem_has_been_acknowledged ) | Generic function to get the number of unhandled problem hosts in the specified state |
19,542 | def _tot_services_by_state ( self , state = None , state_type = None ) : if state is None and state_type is None : return len ( self . services ) if state_type : return sum ( 1 for s in self . services if s . state == state and s . state_type == state_type ) return sum ( 1 for s in self . services if s . state == state... | Generic function to get the number of services in the specified state |
19,543 | def _tot_unhandled_services_by_state ( self , state ) : return sum ( 1 for s in self . services if s . state == state and s . is_problem and not s . problem_has_been_acknowledged ) | Generic function to get the number of unhandled problem services in the specified state |
19,544 | def _get_total_services_problems_unhandled ( self ) : return sum ( 1 for s in self . services if s . is_problem and not s . problem_has_been_acknowledged ) | Get the number of services that are a problem and that are not acknowledged |
19,545 | def _get_total_services_problems_handled ( self ) : return sum ( 1 for s in self . services if s . is_problem and s . problem_has_been_acknowledged ) | Get the number of service problems not handled |
19,546 | def add_data ( self , metric , value , ts = None ) : if not ts : ts = time . time ( ) if self . __data_lock . acquire ( ) : self . __data . append ( ( metric , ( ts , value ) ) ) self . __data_lock . release ( ) return True return False | Add data to queue |
19,547 | def set_daemon_name ( self , daemon_name ) : self . daemon_name = daemon_name for instance in self . instances : instance . set_loaded_into ( daemon_name ) | Set the daemon name of the daemon which this manager is attached to and propagate this daemon name to our managed modules |
19,548 | def load_and_init ( self , modules ) : self . load ( modules ) self . get_instances ( ) return len ( self . configuration_errors ) == 0 | Import instantiate & init the modules we manage |
19,549 | def load ( self , modules ) : self . modules_assoc = [ ] for module in modules : if not module . enabled : logger . info ( "Module %s is declared but not enabled" , module . name ) self . modules [ module . uuid ] = module continue logger . info ( "Importing Python module '%s' for %s..." , module . python_name , module... | Load Python modules and check their usability |
19,550 | def try_instance_init ( self , instance , late_start = False ) : try : instance . init_try += 1 if not late_start and instance . init_try > 1 : if instance . last_init_try > time . time ( ) - MODULE_INIT_PERIOD : logger . info ( "Too early to retry initialization, retry period is %d seconds" , MODULE_INIT_PERIOD ) retu... | Try to initialize the given module instance . |
19,551 | def clear_instances ( self , instances = None ) : if instances is None : instances = self . instances [ : ] for instance in instances : self . remove_instance ( instance ) | Request to remove the given instances list or all if not provided |
19,552 | def set_to_restart ( self , instance ) : self . to_restart . append ( instance ) if instance . is_external : instance . proc = None | Put an instance to the restart queue |
19,553 | def get_instances ( self ) : self . clear_instances ( ) for ( alignak_module , python_module ) in self . modules_assoc : alignak_module . properties = python_module . properties . copy ( ) alignak_module . my_daemon = self . daemon logger . info ( "Alignak starting module '%s'" , alignak_module . get_name ( ) ) if geta... | Create init and then returns the list of module instances that the caller needs . |
19,554 | def start_external_instances ( self , late_start = False ) : for instance in [ i for i in self . instances if i . is_external ] : if not self . try_instance_init ( instance , late_start = late_start ) : logger . warning ( "The module '%s' failed to init, I will try to restart it later" , instance . name ) self . set_to... | Launch external instances that are load correctly |
19,555 | def remove_instance ( self , instance ) : if instance . is_external : logger . info ( "Request external process to stop for %s" , instance . name ) instance . stop_process ( ) logger . info ( "External process stopped." ) instance . clear_queues ( self . daemon . sync_manager ) self . instances . remove ( instance ) | Request to cleanly remove the given instance . If instance is external also shutdown it cleanly |
19,556 | def check_alive_instances ( self ) : for instance in self . instances : if instance in self . to_restart : continue if instance . is_external and instance . process and not instance . process . is_alive ( ) : logger . error ( "The external module %s died unexpectedly!" , instance . name ) logger . info ( "Setting the m... | Check alive instances . If not log error and try to restart it |
19,557 | def try_to_restart_deads ( self ) : to_restart = self . to_restart [ : ] del self . to_restart [ : ] for instance in to_restart : logger . warning ( "Trying to restart module: %s" , instance . name ) if self . try_instance_init ( instance ) : logger . warning ( "Restarting %s..." , instance . name ) instance . process ... | Try to reinit and restart dead instances |
19,558 | def stop_all ( self ) : logger . info ( 'Shutting down modules...' ) for instance in self . get_internal_instances ( ) : if hasattr ( instance , 'quit' ) and isinstance ( instance . quit , collections . Callable ) : instance . quit ( ) self . clear_instances ( [ instance for instance in self . instances if instance . i... | Stop all module instances |
19,559 | def parse ( self ) : sub_directory = 'alignak.d' dir_name = os . path . dirname ( self . configuration_file ) dir_name = os . path . join ( dir_name , sub_directory ) self . cfg_files = [ self . configuration_file ] if os . path . exists ( dir_name ) : for root , _ , walk_files in os . walk ( dir_name , followlinks = T... | Check if some extra configuration files are existing in an alignak . d sub directory near the found configuration file . |
19,560 | def write ( self , env_file ) : try : with open ( env_file , "w" ) as out_file : self . config . write ( out_file ) except Exception as exp : print ( "Dumping environment file raised an error: %s. " % exp ) | Write the Alignak configuration to a file |
19,561 | def get_alignak_macros ( self ) : macros = self . get_alignak_configuration ( macros = True ) sections = self . _search_sections ( 'pack.' ) for name , _ in list ( sections . items ( ) ) : section_macros = self . get_alignak_configuration ( section = name , macros = True ) macros . update ( section_macros ) return macr... | Get the Alignak macros . |
19,562 | def get_alignak_configuration ( self , section = SECTION_CONFIGURATION , legacy_cfg = False , macros = False ) : configuration = self . _search_sections ( section ) if section not in configuration : return [ ] for prop , _ in list ( configuration [ section ] . items ( ) ) : if legacy_cfg : if not prop . startswith ( 'c... | Get the Alignak configuration parameters . All the variables included in the SECTION_CONFIGURATION section except the variables starting with cfg and the macros . |
19,563 | def get_daemons ( self , daemon_name = None , daemon_type = None ) : if daemon_name is not None : sections = self . _search_sections ( 'daemon.%s' % daemon_name ) if 'daemon.%s' % daemon_name in sections : return sections [ 'daemon.' + daemon_name ] return { } if daemon_type is not None : sections = self . _search_sect... | Get the daemons configuration parameters |
19,564 | def get_modules ( self , name = None , daemon_name = None , names_only = True ) : if name is not None : sections = self . _search_sections ( 'module.' + name ) if 'module.' + name in sections : return sections [ 'module.' + name ] return { } if daemon_name is not None : section = self . get_daemons ( daemon_name ) if '... | Get the modules configuration parameters |
19,565 | def copy_shell ( self ) : cls = self . __class__ new_i = cls ( ) new_i . uuid = self . uuid for prop in cls . properties : if hasattr ( self , prop ) : if prop in [ 'members' , 'unknown_members' ] : setattr ( new_i , prop , [ ] ) else : setattr ( new_i , prop , getattr ( self , prop ) ) return new_i | Copy the group properties EXCEPT the members . Members need to be filled after manually |
19,566 | def add_members ( self , members ) : if not isinstance ( members , list ) : members = [ members ] if not getattr ( self , 'members' , None ) : self . members = members else : self . members . extend ( members ) | Add a new member to the members list |
19,567 | def add_unknown_members ( self , members ) : if not isinstance ( members , list ) : members = [ members ] if not hasattr ( self , 'unknown_members' ) : self . unknown_members = members else : self . unknown_members . extend ( members ) | Add a new member to the unknown members list |
19,568 | def is_correct ( self ) : state = True if self . members : self . members = list ( set ( self . members ) ) if self . unknown_members : for member in self . unknown_members : msg = "[%s::%s] as %s, got unknown member '%s'" % ( self . my_type , self . get_name ( ) , self . __class__ . my_type , member ) self . add_error... | Check if a group is valid . Valid mean all members exists so list of unknown_members is empty |
19,569 | def get_initial_status_brok ( self , extra = None ) : if extra and isinstance ( extra , Items ) : members = [ ] for member_id in self . members : member = extra [ member_id ] members . append ( ( member . uuid , member . get_name ( ) ) ) extra = { 'members' : members } return super ( Itemgroup , self ) . get_initial_st... | Get a brok with the group properties |
19,570 | def check_dir ( self , dirname ) : try : os . makedirs ( dirname ) dir_stat = os . stat ( dirname ) print ( "Created the directory: %s, stat: %s" % ( dirname , dir_stat ) ) if not dir_stat . st_uid == self . uid : os . chown ( dirname , self . uid , self . gid ) os . chmod ( dirname , 0o775 ) dir_stat = os . stat ( dir... | Check and create directory |
19,571 | def request_stop ( self , message = '' , exit_code = 0 ) : if exit_code : if message : logger . error ( message ) try : sys . stderr . write ( message ) except Exception : pass logger . error ( "Sorry, I bail out, exit code: %d" , exit_code ) try : sys . stderr . write ( "Sorry, I bail out, exit code: %d" % exit_code )... | Remove pid and stop daemon |
19,572 | def daemon_connection_init ( self , s_link , set_wait_new_conf = False ) : logger . debug ( "Daemon connection initialization: %s %s" , s_link . type , s_link . name ) if not s_link . active : logger . warning ( "%s '%s' is not active, do not initialize its connection!" , s_link . type , s_link . name ) return False s_... | Initialize a connection with the daemon for the provided satellite link |
19,573 | def do_load_modules ( self , modules ) : _ts = time . time ( ) logger . info ( "Loading modules..." ) if self . modules_manager . load_and_init ( modules ) : if self . modules_manager . instances : logger . info ( "I correctly loaded my modules: [%s]" , ',' . join ( [ inst . name for inst in self . modules_manager . in... | Wrapper for calling load_and_init method of modules_manager attribute |
19,574 | def dump_environment ( self ) : path = os . path . join ( tempfile . gettempdir ( ) , 'dump-env-%s-%s-%d.ini' % ( self . type , self . name , int ( time . time ( ) ) ) ) try : with open ( path , "w" ) as out_file : self . alignak_env . write ( out_file ) except Exception as exp : logger . error ( "Dumping daemon enviro... | Try to dump memory |
19,575 | def change_to_workdir ( self ) : logger . info ( "Changing working directory to: %s" , self . workdir ) self . check_dir ( self . workdir ) try : os . chdir ( self . workdir ) except OSError as exp : self . exit_on_error ( "Error changing to working directory: %s. Error: %s. " "Check the existence of %s and the %s/%s a... | Change working directory to working attribute |
19,576 | def unlink ( self ) : logger . debug ( "Unlinking %s" , self . pid_filename ) try : os . unlink ( self . pid_filename ) except OSError as exp : logger . debug ( "Got an error unlinking our pid file: %s" , exp ) | Remove the daemon s pid file |
19,577 | def __open_pidfile ( self , write = False ) : try : self . pre_log . append ( ( "DEBUG" , "Opening %s pid file: %s" % ( 'existing' if os . path . exists ( self . pid_filename ) else 'missing' , self . pid_filename ) ) ) if not write and os . path . exists ( self . pid_filename ) : self . fpid = open ( self . pid_filena... | Open pid file in read or write mod |
19,578 | def write_pid ( self , pid ) : self . fpid . seek ( 0 ) self . fpid . truncate ( ) self . fpid . write ( "%d" % pid ) self . fpid . close ( ) del self . fpid | Write pid to the pid file |
19,579 | def close_fds ( self , skip_close_fds ) : max_fds = resource . getrlimit ( resource . RLIMIT_NOFILE ) [ 1 ] if max_fds == resource . RLIM_INFINITY : max_fds = 1024 self . pre_log . append ( ( "DEBUG" , "Maximum file descriptors: %d" % max_fds ) ) for file_d in range ( 0 , max_fds ) : if file_d in skip_close_fds : self ... | Close all the process file descriptors . Skip the descriptors present in the skip_close_fds list |
19,580 | def do_daemon_init_and_start ( self , set_proc_title = True ) : if set_proc_title : self . set_proctitle ( self . name ) self . change_to_user_group ( ) self . change_to_workdir ( ) self . check_parallel_run ( ) if self . is_daemon : if not self . daemonize ( ) : logger . error ( "I could not daemonize myself :(" ) ret... | Main daemon function . Clean allocates initializes and starts all necessary resources to go in daemon mode . |
19,581 | def setup_communication_daemon ( self ) : ca_cert = ssl_cert = ssl_key = server_dh = None if self . use_ssl : ssl_cert = os . path . abspath ( self . server_cert ) if not os . path . exists ( ssl_cert ) : self . exit_on_error ( "The configured SSL server certificate file '%s' " "does not exist." % ssl_cert , exit_code ... | Setup HTTP server daemon to listen for incoming HTTP requests from other Alignak daemons |
19,582 | def set_proctitle ( self , daemon_name = None ) : logger . debug ( "Setting my process name: %s" , daemon_name ) if daemon_name : setproctitle ( "alignak-%s %s" % ( self . type , daemon_name ) ) if self . modules_manager : self . modules_manager . set_daemon_name ( daemon_name ) else : setproctitle ( "alignak-%s" % sel... | Set the proctitle of the daemon |
19,583 | def http_daemon_thread ( self ) : logger . debug ( "HTTP thread running" ) try : self . http_daemon . run ( ) except PortNotFree as exp : logger . exception ( 'The HTTP daemon port is not free: %s' , exp ) raise except Exception as exp : self . exit_on_exception ( exp ) logger . debug ( "HTTP thread exiting" ) | Main function of the http daemon thread will loop forever unless we stop the root daemon |
19,584 | def make_a_pause ( self , timeout = 0.0001 , check_time_change = True ) : if timeout == 0 : timeout = 0.0001 if not check_time_change : time . sleep ( timeout ) self . sleep_time += timeout return 0 , 0 before = time . time ( ) time_changed = self . check_for_system_time_change ( ) after = time . time ( ) elapsed = aft... | Wait up to timeout and check for system time change . |
19,585 | def wait_for_initial_conf ( self , timeout = 1.0 ) : logger . info ( "Waiting for initial configuration" ) _ts = time . time ( ) while not self . new_conf and not self . interrupted : _ , _ = self . make_a_pause ( timeout , check_time_change = True ) if not self . interrupted : logger . info ( "Got initial configuratio... | Wait initial configuration from the arbiter . Basically sleep 1 . 0 and check if new_conf is here |
19,586 | def watch_for_new_conf ( self , timeout = 0 ) : logger . debug ( "Watching for a new configuration, timeout: %s" , timeout ) self . make_a_pause ( timeout = timeout , check_time_change = False ) return any ( self . new_conf ) | Check if a new configuration was sent to the daemon |
19,587 | def hook_point ( self , hook_name , handle = None ) : full_hook_name = 'hook_' + hook_name for module in self . modules_manager . instances : _ts = time . time ( ) if not hasattr ( module , full_hook_name ) : continue fun = getattr ( module , full_hook_name ) try : fun ( handle if handle is not None else self ) except ... | Used to call module function that may define a hook function for hook_name |
19,588 | def get_id ( self , details = False ) : res = { "alignak" : getattr ( self , 'alignak_name' , 'unknown' ) , "type" : getattr ( self , 'type' , 'unknown' ) , "name" : getattr ( self , 'name' , 'unknown' ) , "version" : VERSION } return res | Get daemon identification information |
19,589 | def exit_ok ( self , message , exit_code = None ) : logger . info ( "Exiting..." ) if message : logger . info ( "-----" ) logger . error ( "Exit message: %s" , message ) logger . info ( "-----" ) self . request_stop ( ) if exit_code is not None : exit ( exit_code ) | Log a message and exit |
19,590 | def exit_on_error ( self , message , exit_code = 1 ) : log = "I got an unrecoverable error. I have to exit." if message : log += "\n-----\nError message: %s" % message print ( "Error message: %s" % message ) log += "-----\n" log += "You can get help at https://github.com/Alignak-monitoring/alignak\n" log += "If you thi... | Log generic message when getting an error and exit |
19,591 | def exit_on_exception ( self , raised_exception , message = '' , exit_code = 99 ) : self . exit_on_error ( message = message , exit_code = None ) logger . critical ( "-----\nException: %s\nBack trace of the error:\n%s" , str ( raised_exception ) , traceback . format_exc ( ) ) exit ( exit_code ) | Log generic message when getting an unrecoverable error |
19,592 | def get_objects_from_from_queues ( self ) : _t0 = time . time ( ) had_some_objects = False for module in self . modules_manager . get_external_instances ( ) : queue = module . from_q if not queue : continue while True : queue_size = queue . qsize ( ) if queue_size : statsmgr . gauge ( 'queues.from.%s.count' % module . ... | Get objects from from queues and add them . |
19,593 | def add_automatic_comment ( self , ref ) : if self . fixed is True : text = ( DOWNTIME_FIXED_MESSAGE % ( ref . my_type , time . strftime ( "%Y-%m-%d %H:%M:%S" , time . localtime ( self . start_time ) ) , time . strftime ( "%Y-%m-%d %H:%M:%S" , time . localtime ( self . end_time ) ) , ref . my_type ) ) else : hours , re... | Add comment on ref for downtime |
19,594 | def get_raise_brok ( self , host_name , service_name = '' ) : data = self . serialize ( ) data [ 'host' ] = host_name if service_name != '' : data [ 'service' ] = service_name return Brok ( { 'type' : 'downtime_raise' , 'data' : data } ) | Get a start downtime brok |
19,595 | def get_expire_brok ( self , host_name , service_name = '' ) : data = self . serialize ( ) data [ 'host' ] = host_name if service_name != '' : data [ 'service' ] = service_name return Brok ( { 'type' : 'downtime_expire' , 'data' : data } ) | Get an expire downtime brok |
19,596 | def fill_data_brok_from ( self , data , brok_type ) : cls = self . __class__ for prop , entry in list ( cls . properties . items ( ) ) : if brok_type in entry . fill_brok : if hasattr ( self , prop ) : data [ prop ] = getattr ( self , prop ) | Add properties to data if fill_brok of these class properties is same as brok_type |
19,597 | def get_name ( self ) : return getattr ( self , 'dependent_host_name' , '' ) + '/' + getattr ( self , 'dependent_service_description' , '' ) + '..' + getattr ( self , 'host_name' , '' ) + '/' + getattr ( self , 'service_description' , '' ) | Get name based on 4 class attributes Each attribute is substituted by if attribute does not exist |
19,598 | def explode_hostgroup ( self , svc_dep , hostgroups ) : snames = [ d . strip ( ) for d in svc_dep . service_description . split ( ',' ) ] dep_snames = [ d . strip ( ) for d in svc_dep . dependent_service_description . split ( ',' ) ] hg_names = [ n . strip ( ) for n in svc_dep . hostgroup_name . split ( ',' ) ] for hg_... | Explode a service dependency for each member of hostgroup |
19,599 | def linkify_sd_by_s ( self , hosts , services ) : to_del = [ ] errors = self . configuration_errors warns = self . configuration_warnings for servicedep in self : try : s_name = servicedep . dependent_service_description hst_name = servicedep . dependent_host_name serv = services . find_srv_by_name_and_hostname ( hst_n... | Replace dependent_service_description and service_description in service dependency by the real object |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.