def get_checks_as_dict(cls): from sauna.plugins.base import Plugin from sauna import check_results_lock, check_results checks = {} with check_results_lock: for service_check in check_results.values(): checks[service_check.name] = { 'status': Plugin.status_code_to_str(service_check.status), 'code': service_check.status, 'timestamp': service_check.timestamp, 'output': service_check.output } return deepcopy(checks)
def get_current_status(cls): """Get the worse status of all check results. :returns: (status as str, code) :rtype: tuple """ from sauna.plugins.base import Plugin from sauna import check_results_lock, check_results def reduce_status(accumulated, update_value): if update_value.status > Plugin.STATUS_CRIT: return accumulated return accumulated if accumulated > update_value.status else \ update_value.status with check_results_lock: code = reduce(reduce_status, check_results.values(), 0) return Plugin.status_code_to_str(code), code
def _get_current_status(self): from sauna.plugins.base import Plugin def reduce_status(accumulated, update_value): if update_value.status > Plugin.STATUS_CRIT: return accumulated return accumulated if accumulated > update_value.status else \ update_value.status with check_results_lock: res = reduce(reduce_status, check_results.values(), 0) if res == Plugin.STATUS_OK: status = b'OK\n' elif res == Plugin.STATUS_WARN: status = b'WARNING\n' elif res == Plugin.STATUS_CRIT: status = b'CRITICAL\n' else: status = b'UNKNOWN\n' return status