def refresh_specific_checks(self, hostname, checksd, checks): """take a set of checks and for each of them: - remove it from the init_failed_checks if it was there - load a fresh config for it - replace its old config with the new one in initialized_checks if there was one - disable the check if no new config was found - otherwise, append it to initialized_checks """ for check_name in checks: idx = None for num, check in enumerate(checksd['initialized_checks']): if check.name == check_name: idx = num # stop the existing check before reloading it check.stop() if not idx and check_name in checksd['init_failed_checks']: # if the check previously failed to load, pop it from init_failed_checks checksd['init_failed_checks'].pop(check_name) fresh_check = load_check(self._agentConfig, hostname, check_name) # this is an error dict # checks that failed to load are added to init_failed_checks # and poped from initialized_checks if isinstance(fresh_check, dict) and 'error' in fresh_check.keys(): checksd['init_failed_checks'][fresh_check.keys() [0]] = fresh_check.values()[0] if idx: checksd['initialized_checks'].pop(idx) elif not fresh_check: # no instance left of it to monitor so the check was not loaded if idx: checksd['initialized_checks'].pop(idx) # the check was not previously running so we were trying to instantiate it and it failed else: log.error( "Configuration for check %s was not found, it won't be reloaded." % check_name) # successfully reloaded check are added to initialized_checks # (appended or replacing a previous version) else: if idx is not None: checksd['initialized_checks'][idx] = fresh_check # it didn't exist before and doesn't need to be replaced so we append it else: checksd['initialized_checks'].append(fresh_check)
def refresh_specific_checks(self, hostname, checksd, checks): """take a list of checks and for each of them: - remove it from the init_failed_checks if it was there - load a fresh config for it - replace its old config with the new one in initialized_checks if there was one - disable the check if no new config was found - otherwise, append it to initialized_checks """ for check_name in checks: idx = None for num, check in enumerate(checksd['initialized_checks']): if check.name == check_name: idx = num # stop the existing check before reloading it check.stop() if not idx and check_name in checksd['init_failed_checks']: # if the check previously failed to load, pop it from init_failed_checks checksd['init_failed_checks'].pop(check_name) fresh_check = load_check(self._agentConfig, hostname, check_name) # this is an error dict # checks that failed to load are added to init_failed_checks # and poped from initialized_checks if isinstance(fresh_check, dict) and 'error' in fresh_check.keys(): checksd['init_failed_checks'][fresh_check.keys()[0]] = fresh_check.values()[0] if idx: checksd['initialized_checks'].pop(idx) elif not fresh_check: # no instance left of it to monitor so the check was not loaded if idx: checksd['initialized_checks'].pop(idx) # the check was not previously running so we were trying to instantiate it and it failed else: log.error("Configuration for check %s was not found, it won't be reloaded." % check_name) # successfully reloaded check are added to initialized_checks # (appended or replacing a previous version) else: if idx is not None: checksd['initialized_checks'][idx] = fresh_check # it didn't exist before and doesn't need to be replaced so we append it else: checksd['initialized_checks'].append(fresh_check)