diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-06-19 01:15:37 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-06-19 01:15:37 +0200 |
commit | 20e938bb542d361ad1468ab24330f554445aefb1 (patch) | |
tree | cba8a180be5e889d6293bb821f3b9f686fbe4614 /plugins-root/check_icmp.c | |
parent | b71cb430cb79e89b5d8bf56990919b6c753cd271 (diff) | |
download | monitoring-plugins-20e938bb542d361ad1468ab24330f554445aefb1.tar.gz |
Override state with min_hosts_alive
Diffstat (limited to 'plugins-root/check_icmp.c')
-rw-r--r-- | plugins-root/check_icmp.c | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index b97a68ed..7360b435 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -1515,9 +1515,6 @@ static void finish(int sig, check_icmp_mode_switches modes, int min_hosts_alive, | |||
1515 | targets_alive(number_of_targets, program_state->targets_down)); | 1515 | targets_alive(number_of_targets, program_state->targets_down)); |
1516 | } | 1516 | } |
1517 | 1517 | ||
1518 | mp_subcheck sc_single_targets = mp_subcheck_init(); | ||
1519 | xasprintf(&sc_single_targets.output, "Individual Hosts"); | ||
1520 | |||
1521 | // loop over targets to evaluate each one | 1518 | // loop over targets to evaluate each one |
1522 | int targets_ok = 0; | 1519 | int targets_ok = 0; |
1523 | int targets_warn = 0; | 1520 | int targets_warn = 0; |
@@ -1527,29 +1524,16 @@ static void finish(int sig, check_icmp_mode_switches modes, int min_hosts_alive, | |||
1527 | targets_ok += host_check.targets_ok; | 1524 | targets_ok += host_check.targets_ok; |
1528 | targets_warn += host_check.targets_warn; | 1525 | targets_warn += host_check.targets_warn; |
1529 | 1526 | ||
1530 | if (min_hosts_alive > -1) { | 1527 | mp_add_subcheck_to_check(overall, host_check.sc_host); |
1531 | mp_add_subcheck_to_subcheck(&sc_single_targets, host_check.sc_host); | ||
1532 | } else { | ||
1533 | mp_add_subcheck_to_check(overall, host_check.sc_host); | ||
1534 | } | ||
1535 | } | ||
1536 | |||
1537 | if (min_hosts_alive > -1) { | ||
1538 | mp_add_subcheck_to_check(overall, sc_single_targets); | ||
1539 | } | ||
1540 | |||
1541 | if (number_of_hosts == 1) { | ||
1542 | // Exit early here, since the other checks only make sense for multiple hosts | ||
1543 | return; | ||
1544 | } | 1528 | } |
1545 | 1529 | ||
1546 | /* this is inevitable */ | 1530 | /* this is inevitable */ |
1547 | if (targets_alive(number_of_targets, program_state->targets_down) == 0) { | 1531 | // if (targets_alive(number_of_targets, program_state->targets_down) == 0) { |
1548 | mp_subcheck sc_no_target_alive = mp_subcheck_init(); | 1532 | // mp_subcheck sc_no_target_alive = mp_subcheck_init(); |
1549 | sc_no_target_alive = mp_set_subcheck_state(sc_no_target_alive, STATE_CRITICAL); | 1533 | // sc_no_target_alive = mp_set_subcheck_state(sc_no_target_alive, STATE_CRITICAL); |
1550 | sc_no_target_alive.output = strdup("No target is alive!"); | 1534 | // sc_no_target_alive.output = strdup("No target is alive!"); |
1551 | mp_add_subcheck_to_check(overall, sc_no_target_alive); | 1535 | // mp_add_subcheck_to_check(overall, sc_no_target_alive); |
1552 | } | 1536 | // } |
1553 | 1537 | ||
1554 | if (min_hosts_alive > -1) { | 1538 | if (min_hosts_alive > -1) { |
1555 | mp_subcheck sc_min_targets_alive = mp_subcheck_init(); | 1539 | mp_subcheck sc_min_targets_alive = mp_subcheck_init(); |
@@ -1557,16 +1541,21 @@ static void finish(int sig, check_icmp_mode_switches modes, int min_hosts_alive, | |||
1557 | 1541 | ||
1558 | if (targets_ok >= min_hosts_alive) { | 1542 | if (targets_ok >= min_hosts_alive) { |
1559 | sc_min_targets_alive = mp_set_subcheck_state(sc_min_targets_alive, STATE_OK); | 1543 | sc_min_targets_alive = mp_set_subcheck_state(sc_min_targets_alive, STATE_OK); |
1560 | xasprintf(&sc_min_targets_alive.output, "%u targets OK of a minimum of %u", | 1544 | xasprintf(&sc_min_targets_alive.output, "%u targets OK of a minimum of %u", targets_ok, |
1561 | targets_ok, min_hosts_alive); | 1545 | min_hosts_alive); |
1546 | |||
1547 | // Overwrite main state here | ||
1548 | overall->evaluation_function = &mp_eval_ok; | ||
1562 | } else if ((targets_ok + targets_warn) >= min_hosts_alive) { | 1549 | } else if ((targets_ok + targets_warn) >= min_hosts_alive) { |
1563 | sc_min_targets_alive = mp_set_subcheck_state(sc_min_targets_alive, STATE_WARNING); | 1550 | sc_min_targets_alive = mp_set_subcheck_state(sc_min_targets_alive, STATE_WARNING); |
1564 | xasprintf(&sc_min_targets_alive.output, "%u targets OK or Warning of a minimum of %u", | 1551 | xasprintf(&sc_min_targets_alive.output, "%u targets OK or Warning of a minimum of %u", |
1565 | targets_ok + targets_warn, min_hosts_alive); | 1552 | targets_ok + targets_warn, min_hosts_alive); |
1553 | overall->evaluation_function = &mp_eval_warning; | ||
1566 | } else { | 1554 | } else { |
1567 | sc_min_targets_alive = mp_set_subcheck_state(sc_min_targets_alive, STATE_CRITICAL); | 1555 | sc_min_targets_alive = mp_set_subcheck_state(sc_min_targets_alive, STATE_CRITICAL); |
1568 | xasprintf(&sc_min_targets_alive.output, "%u targets OK or Warning of a minimum of %u", | 1556 | xasprintf(&sc_min_targets_alive.output, "%u targets OK or Warning of a minimum of %u", |
1569 | targets_ok + targets_warn, min_hosts_alive); | 1557 | targets_ok + targets_warn, min_hosts_alive); |
1558 | overall->evaluation_function = &mp_eval_critical; | ||
1570 | } | 1559 | } |
1571 | 1560 | ||
1572 | mp_add_subcheck_to_check(overall, sc_min_targets_alive); | 1561 | mp_add_subcheck_to_check(overall, sc_min_targets_alive); |