Skip to content

Commit 9e85c35

Browse files
committed
fix(ping): '10 received' cointains '0 received' (closes #860)
1 parent 02b0a1d commit 9e85c35

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ and this project does NOT adhere to [Semantic Versioning](https://semver.org/spe
1111

1212
## [Unreleased]
1313

14+
### Fixed ("fix")
15+
16+
Monitoring Plugins:
17+
18+
* ping: '10 received' contains '0 received' ([#860](https://github.com/Linuxfabrik/monitoring-plugins/issues/860))
19+
20+
1421
### Changed ("refactor", "chore" etc.)
1522

1623
Monitoring Plugins:

check-plugins/ping/ping

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import lib.shell # pylint: disable=C0413
2020
from lib.globals import (STATE_CRIT, STATE_OK, STATE_UNKNOWN)
2121

2222
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
23-
__version__ = '2023112901'
23+
__version__ = '2025040401'
2424

2525
DESCRIPTION = 'Sends ICMP ECHO_REQUEST to network hosts using the built-in `ping` command.'
2626

@@ -111,6 +111,12 @@ def main():
111111
stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(cmd))
112112
if stderr or retc == 2:
113113
lib.base.cu(stderr)
114+
# stdout:
115+
# PING 192.0.2.10 (192.0.2.10) 56(84) bytes of data.
116+
#
117+
# --- 192.0.2.10 ping statistics ---
118+
# 5 packets transmitted, 5 received, 0% packet loss, time 803ms
119+
# rtt min/avg/max/mdev = 6.724/13.682/15.856/3.488 ms
114120

115121
# If ping does not receive any reply packets at all it will exit with code 1.
116122
# If a packet count and deadline are both specified, and fewer than count packets are received
@@ -125,14 +131,14 @@ def main():
125131
# init some vars
126132
# Throwing CRIT instead of WARN beacuse of the fact that this check will mainly be used
127133
# for checking host-liveliness [OK=UP, CRIT=DOWN].
128-
state = STATE_CRIT if '0 received' in stdout else STATE_OK
134+
state = STATE_CRIT if re.search(r'\b0 received', stdout) else STATE_OK
129135
if state == STATE_OK:
130136
msg = ''
131137
else:
132138
msg = 'Destination host unreachable. '
133139
perfdata = ''
134140

135-
# analyze data
141+
# analyze data:
136142
result = stdout.splitlines()
137143
if not result[0] or not result[3]:
138144
lib.base.cu('Unexpected output from ping.')

0 commit comments

Comments
 (0)