Commit 8d736972 authored by Adrian's avatar Adrian
Browse files

Ignore result if host/service unreachable"

parent 1553590a
......@@ -18,10 +18,12 @@ namespace
{
constexpr const char* HOST_INFO_URL =
"https://bigsister.fem.tu-ilmenau.de:5665/v1/objects/"
"hosts?attrs=acknowledgement&attrs=last_check_result&attrs=downtime_depth&attrs=vars&attrs=state_type";
"hosts?attrs=acknowledgement&attrs=last_check_result&attrs=downtime_depth&attrs=vars&attrs=state_"
"type&attrs=last_reachable";
constexpr const char* SERVICE_INFO_URL =
"https://bigsister.fem.tu-ilmenau.de:5665/v1/objects/"
"services?attrs=acknowledgement&attrs=last_check_result&attrs=downtime_depth&attrs=vars&attrs=state_type";
"services?attrs=acknowledgement&attrs=last_check_result&attrs=downtime_depth&attrs=vars&attrs="
"state_type&attrs=last_reachable";
constexpr bool SKIP_CERT_VERIFICATION = true;
constexpr int RETURN_OK = 0;
......@@ -36,7 +38,6 @@ std::ostringstream output_buf;
using json = nlohmann::json;
using health_data_t = std::tuple<unsigned long, unsigned long>;
using health_data_map_t = std::unordered_map<std::string, health_data_t>;
} // namespace
void print_plugin_output(int return_code, std::string status_message)
{
......@@ -56,13 +57,14 @@ void print_plugin_output(int return_code, std::string status_message)
}
}
void print_health(int return_code, float health, float threshold_warning, float threshold_critical, const std::string& group_name)
void print_health(int return_code, float health, float threshold_warning, float threshold_critical,
const std::string& group_name)
{
std::string health_as_str = std::to_string(health);
print_plugin_output(return_code, "Health " + health_as_str + " (group "
+ group_name + ") | health=" + health_as_str + "%;" +
std::to_string(threshold_warning) + ":;" +
std::to_string(threshold_critical) + ":;0;100");
print_plugin_output(return_code, "Health " + health_as_str + " (group " + group_name
+ ") | health=" + health_as_str + "%;"
+ std::to_string(threshold_warning) + ":;"
+ std::to_string(threshold_critical) + ":;0;100");
}
#ifndef NDEBUG
......@@ -96,6 +98,11 @@ inline bool is_in_soft_state(json object)
return object["attrs"]["state_type"] == 0;
}
inline bool is_unreachable(json object)
{
return !(object["attrs"]["last_reachable"].get<bool>());
}
void parse_result(health_data_map_t& output, const std::string& raw_data)
{
json data = json::parse(raw_data);
......@@ -103,7 +110,7 @@ void parse_result(health_data_map_t& output, const std::string& raw_data)
for (auto& object : results) {
if (is_in_soft_state(object) || is_acknowledged(object) || is_in_downtime(object)
|| ignored_by_config(object)) {
|| ignored_by_config(object) || is_unreachable(object)) {
continue;
}
......@@ -148,6 +155,8 @@ size_t write_memory_cb(void* content, size_t size, size_t n_memb, void* userdata
return real_size;
}
} // namespace
int main(int argc, char** argv)
{
if (argc < 4) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment