def check_condition(self, response): """ Checks status and returns relevant nagios messages and codes. """ perf_string = performance_data(label = "requestTimer", value = self._request_timer, uom = "s", mini = 0) perf_string = " |" + perf_string message_params = dict(dial_first=self.dial_first, timeout=self.timeout, timer=self._request_timer) base_message = "Call to %(dial_first)i %(status)s - switchvox timeout %(timeout)i sec, timer %(timer)f" results = {} errors = self.get_errors(response) if errors: # Errors we don't want base_err_message = "unexpected error code: %(code)s; error message: %(message)s" error_message_str = "; ".join([base_err_message % err for err in errors]) base_message = error_message_str + base_message results["code"] = "CRITICAL" message_params['status'] = "failed" else: results["code"] = "OK" message_params['status'] = "completed" results["response"] = (base_message % message_params) + perf_string return results
def check_condition(self, response): "Checks status and returns relevant nagios messages and codes." errors = self.get_errors(response) expected_errors = set([41591]) perf_string = performance_data(label = "requestTimer", value = self._request_timer, uom = "s", mini = 0) perf_string = " |" + perf_string #### # Check for unexpected errors #### bad_errors = [err for err in errors if err["code"] not in expected_errors] base_message = "Call to %(dial_first)i %(status)s - switchvox timeout %(timeout)i sec, timer %(timer)f" message_params = dict(dial_first=self.dial_first, timeout=self.timeout, timer=self._request_timer) results = {} if bad_errors: # Errors we don't want base_err_message = "unexpected error code: %(code)s; error message: %(message)s" error_message_str = "; ".join([base_err_message % err for err in bad_errors]) results["code"] = "CRITICAL" message_params['status'] = "failed" base_message = error_message_str + base_message elif not errors: # No errors at all. We want our expected errors. ## FIXME: Must write tests for this. results["code"] = "CRITICAL" message_params['status'] = "completed" elif self._request_timer < self.timeout: # Errors that we do want but timers are wrong. results["code"] = "CRITICAL" message_params['status'] = "failed before specified timeout" else: # Errors we do want. Timers are good. results["code"] = "OK" message_params['status'] = "failed (as expected)" results["response"] = (base_message % message_params) + perf_string return results
def check_condition(self, response): """ Checks status and returns relevant nagios messages and codes. """ alarm_states = self._process_response_alarms(response) errors = self.get_errors(response) perf_strings = [] for label in (NO_ALARM, ALARM): perf = performance_data(label=label, value=alarm_states[label], mini=0) perf_strings.append(perf) perf_string = " |" + " ".join(perf_strings) if not alarm_states[NO_ALARM] >= 1: # 0 non-alarm channels return {"code": "CRITICAL", "response": "No channels available in non-alarm state" + perf_string} elif alarm_states[ALARM]: # 1 or more alarmed channels. Really non-zero alarmed channels. return {"code": "WARNING", "response": "Some channels in non-alarm state" + perf_string} else: return {"code": "OK", "response": "All channels OK" + perf_string}