@@ -20,7 +20,7 @@ import lib.shell # pylint: disable=C0413
2020from lib .globals import (STATE_CRIT , STATE_OK , STATE_UNKNOWN )
2121
2222__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
23- __version__ = '2023112901 '
23+ __version__ = '2025040401 '
2424
2525DESCRIPTION = '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