diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-06-19 00:55:41 +0200 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-06-19 00:55:41 +0200 |
| commit | ca954e4f765ea336e4aef633b38c31a7c6a99d75 (patch) | |
| tree | 4929dd623d32f91608a5b8b9e5b4ebf39e8da350 | |
| parent | 43ae5fbe2df66c6c3169528431b6b0c9c6bfd67c (diff) | |
| download | monitoring-plugins-ca954e4f765ea336e4aef633b38c31a7c6a99d75.tar.gz | |
Reintroduce min_hosts_alive
| -rw-r--r-- | plugins-root/check_icmp.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 7ee08ad9..b97a68ed 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
| @@ -1515,6 +1515,9 @@ 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 | |||
| 1518 | // loop over targets to evaluate each one | 1521 | // loop over targets to evaluate each one |
| 1519 | int targets_ok = 0; | 1522 | int targets_ok = 0; |
| 1520 | int targets_warn = 0; | 1523 | int targets_warn = 0; |
| @@ -1524,7 +1527,15 @@ static void finish(int sig, check_icmp_mode_switches modes, int min_hosts_alive, | |||
| 1524 | targets_ok += host_check.targets_ok; | 1527 | targets_ok += host_check.targets_ok; |
| 1525 | targets_warn += host_check.targets_warn; | 1528 | targets_warn += host_check.targets_warn; |
| 1526 | 1529 | ||
| 1527 | mp_add_subcheck_to_check(overall, host_check.sc_host); | 1530 | if (min_hosts_alive > -1) { |
| 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); | ||
| 1528 | } | 1539 | } |
| 1529 | 1540 | ||
| 1530 | if (number_of_hosts == 1) { | 1541 | if (number_of_hosts == 1) { |
| @@ -1545,11 +1556,20 @@ static void finish(int sig, check_icmp_mode_switches modes, int min_hosts_alive, | |||
| 1545 | sc_min_targets_alive = mp_set_subcheck_default_state(sc_min_targets_alive, STATE_OK); | 1556 | sc_min_targets_alive = mp_set_subcheck_default_state(sc_min_targets_alive, STATE_OK); |
| 1546 | 1557 | ||
| 1547 | if (targets_ok >= min_hosts_alive) { | 1558 | if (targets_ok >= min_hosts_alive) { |
| 1548 | // TODO this should overwrite the main state | ||
| 1549 | sc_min_targets_alive = mp_set_subcheck_state(sc_min_targets_alive, STATE_OK); | 1559 | 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", | ||
| 1561 | targets_ok, min_hosts_alive); | ||
| 1550 | } else if ((targets_ok + targets_warn) >= min_hosts_alive) { | 1562 | } else if ((targets_ok + targets_warn) >= min_hosts_alive) { |
| 1551 | sc_min_targets_alive = mp_set_subcheck_state(sc_min_targets_alive, STATE_WARNING); | 1563 | 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", | ||
| 1565 | targets_ok + targets_warn, min_hosts_alive); | ||
| 1566 | } else { | ||
| 1567 | 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", | ||
| 1569 | targets_ok + targets_warn, min_hosts_alive); | ||
| 1552 | } | 1570 | } |
| 1571 | |||
| 1572 | mp_add_subcheck_to_check(overall, sc_min_targets_alive); | ||
| 1553 | } | 1573 | } |
| 1554 | 1574 | ||
| 1555 | /* finish with an empty line */ | 1575 | /* finish with an empty line */ |
