diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a725abd4..ea57df907 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,9 @@ ### Bugs -*Downtime* +*Anomalydetection* -Change downtime limits start/end dates to 2145916799 -(31/12/2037 23:59:59) max. +Add unit to anomaly thresholds curves *logs* diff --git a/src/anomalydetection.cc b/src/anomalydetection.cc index ca2636e69..397b0b99f 100755 --- a/src/anomalydetection.cc +++ b/src/anomalydetection.cc @@ -612,7 +612,8 @@ int anomalydetection::run_async_check(int check_options, << " is " << std::get<1>(pd) << std::get<2>(pd); if (!std::isnan(std::get<3>(pd)) && !std::isnan(std::get<4>(pd))) oss << " which is outside the forecasting range [" << std::get<3>(pd) - << " ; " << std::get<4>(pd) << "] |"; + << std::get<2>(pd) << " ; " << std::get<4>(pd) << std::get<2>(pd) + << "] |"; else oss << " and the forecasting range is unknown |"; } @@ -767,8 +768,7 @@ void anomalydetection::init_thresholds() { nlohmann::json json; try { json = nlohmann::json::parse(buffer.str()); - } - catch (const nlohmann::json::parse_error& e) { + } catch (const nlohmann::json::parse_error& e) { logger(log_config_error, basic) << "Error: the file '" << _thresholds_file << "' contains errors: " << e.what(); return; @@ -842,8 +842,9 @@ int anomalydetection::update_thresholds(const std::string& filename) { try { json = nlohmann::json::parse(buffer.str()); } catch (const nlohmann::json::parse_error& e) { - logger(log_config_error, basic) << "Error: The thresholds file '" - << filename << "' should be a json file: " << e.what(); + logger(log_config_error, basic) + << "Error: The thresholds file '" << filename + << "' should be a json file: " << e.what(); return -2; } diff --git a/tests/checks/anomalydetection.cc b/tests/checks/anomalydetection.cc index 0f07331a6..447e8ff62 100644 --- a/tests/checks/anomalydetection.cc +++ b/tests/checks/anomalydetection.cc @@ -19,9 +19,9 @@ #include "com/centreon/engine/configuration/applier/anomalydetection.hh" +#include #include #include -#include #include #include @@ -199,8 +199,10 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { set_time(51000); now = std::time(nullptr); - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;1;service warning| " - "metric=50;25;60", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;1;service warning| " + "metric=50;25;60", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::soft); @@ -224,8 +226,11 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { now = std::time(nullptr); time_t previous = now; - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;2;service critical| " - "metric=110foo;25;60", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;2;service " + "critical| " + "metric=110foo;25;60", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::hard); @@ -240,7 +245,7 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { ASSERT_EQ(_ad->get_state_type(), checkable::hard); ASSERT_EQ(_ad->get_plugin_output(), "NON-OK: Unusual activity, the actual value of metric is 110.00foo " - "which is outside the forecasting range [71.93 : 81.78]"); + "which is outside the forecasting range [71.93foo : 81.78foo]"); ASSERT_EQ(_ad->get_perf_data(), "metric=110foo metric_lower_thresholds=71.93foo " "metric_upper_thresholds=81.78foo"); @@ -249,8 +254,10 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { set_time(52000); now = std::time(nullptr); - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;1;service warning| " - "metric=30%;25;60", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;1;service warning| " + "metric=30%;25;60", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::hard); @@ -265,7 +272,7 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { ASSERT_EQ(_ad->get_last_hard_state_change(), previous); ASSERT_EQ(_ad->get_plugin_output(), "NON-OK: Unusual activity, the actual value of metric is 30.00% " - "which is outside the forecasting range [71.24 : 81.04]"); + "which is outside the forecasting range [71.24% : 81.04%]"); ASSERT_EQ(_ad->get_perf_data(), "metric=30% metric_lower_thresholds=71.24% " "metric_upper_thresholds=81.04%"); @@ -275,8 +282,10 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { previous = now; now = std::time(nullptr); - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;1;service warning| " - "metric=35%;25;60", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;1;service warning| " + "metric=35%;25;60", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::hard); @@ -292,7 +301,7 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { ASSERT_EQ(_ad->get_current_state(), engine::service::state_critical); ASSERT_EQ(_ad->get_plugin_output(), "NON-OK: Unusual activity, the actual value of metric is 35.00% " - "which is outside the forecasting range [70.55 : 80.30]"); + "which is outside the forecasting range [70.55% : 80.30%]"); ASSERT_EQ(_ad->get_perf_data(), "metric=35% metric_lower_thresholds=70.55% " "metric_upper_thresholds=80.30%"); @@ -302,8 +311,10 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { previous = now; now = std::time(nullptr); - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;0;service ok| " - "metric=70%;80;90", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;0;service ok| " + "metric=70%;80;90", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::hard); @@ -326,8 +337,10 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { previous = now; now = std::time(nullptr); - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;0;service ok| " - "metric=71%;80;90", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;0;service ok| " + "metric=71%;80;90", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::hard); @@ -350,7 +363,9 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { previous = now; now = std::time(nullptr); - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;4;service unknown", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;4;service unknown", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::soft); @@ -372,8 +387,10 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { previous = now; now = std::time(nullptr); - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;0;service ok| " - "metric=72%;80;90", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;0;service ok| " + "metric=72%;80;90", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::soft); @@ -396,8 +413,10 @@ TEST_F(AnomalydetectionCheck, StatusChanges) { previous = now; now = std::time(nullptr); - cmd = fmt::format("[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;0;service ok| " - "metric=71.7%;80;90;10;100", now); + cmd = fmt::format( + "[{}] PROCESS_SERVICE_CHECK_RESULT;test_host;test_svc;0;service ok| " + "metric=71.7%;80;90;10;100", + now); process_external_command(cmd.c_str()); checks::checker::instance().reap(); ASSERT_EQ(_svc->get_state_type(), checkable::hard); @@ -476,7 +495,7 @@ TEST_F(AnomalydetectionCheck, MetricWithQuotes) { ASSERT_EQ(_ad->get_current_attempt(), 1); ASSERT_EQ(_ad->get_plugin_output(), "NON-OK: Unusual activity, the actual value of metric is 90.00MT " - "which is outside the forecasting range [73.31 : 83.26]"); + "which is outside the forecasting range [73.31MT : 83.26MT]"); ASSERT_EQ(_ad->get_perf_data(), "'metric'=90MT;;;0;100 metric_lower_thresholds=73.31MT;;;0;100 " "metric_upper_thresholds=83.26MT;;;0;100");