@@ -88,14 +88,18 @@ def check(self, store=True):
88
88
command = [
89
89
'fping' ,
90
90
'-e' , # show elapsed (round-trip) time of packets
91
- '-c %s' % count , # count of pings to send to each target,
92
- '-p %s' % interval , # interval between sending pings(in ms)
93
- '-b %s' % bytes_ , # amount of ping data to send
94
- '-t %s' % timeout , # individual target initial timeout (in ms)
91
+ '-c' , str ( count ) , # count of pings to send to each target
92
+ '-p' , str ( interval ) , # interval between sending pings (in ms)
93
+ '-b' , str ( bytes_ ) , # amount of ping data to send
94
+ '-t' , str ( timeout ) , # individual target initial timeout (in ms)
95
95
'-q' ,
96
- ip ,
96
+ ip
97
97
]
98
- stdout , stderr = self ._command (command )
98
+ stdout , stderr , returncode = self ._command (command )
99
+ # Check the return code and raise an exception if it's not zero
100
+ if returncode not in [0 , 1 ]:
101
+ message = f'fping command failed with return code { returncode } :\n \n { stderr .decode ("utf8" )} '
102
+ raise OperationalError (message )
99
103
# fpings shows statistics on stderr
100
104
output = stderr .decode ('utf8' )
101
105
try :
@@ -148,8 +152,12 @@ def _command(self, command):
148
152
"""
149
153
Executes command (easier to mock)
150
154
"""
151
- p = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
152
- return p .stdout , p .stderr
155
+ try :
156
+ p = subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
157
+ stdout , stderr = p .communicate ()
158
+ return stdout , stderr , p .returncode
159
+ except Exception as e :
160
+ return None , str (e ), 99
153
161
154
162
def _get_metric (self ):
155
163
"""
0 commit comments