@@ -34,6 +34,13 @@ class StatusCodes:
3434 STOPPED = 4
3535 STARTING = 5
3636
37+ # see com.cloud.network.VirtualNetworkApplianceService.RouterHealthStatus and make sure to keep it alligned
38+ class RouterHealthStatus :
39+ SUCCESS = "SUCCESS"
40+ FAILED = "FAILED"
41+ WARNING = "WARNING"
42+ UNKNOWN = "UNKNOWN"
43+
3744class Log :
3845 INFO = 'INFO'
3946 ALERT = 'ALERT'
@@ -299,24 +306,25 @@ def execute(script, checkType = "basic"):
299306 output = pout .communicate ()[0 ].decode ().strip ()
300307 checkEndTime = time .time ()
301308
302- if exitStatus == 0 :
303- if len (output ) > 0 :
304- printd ("Successful execution of " + script )
305- return {
306- "success" : "true" ,
307- "lastUpdate" : str (int (checkStartTime * 1000 )),
308- "lastRunDuration" : str ((checkEndTime - checkStartTime ) * 1000 ),
309- "message" : output
310- }
311- return {} #Skip script if no output is received
312- else :
313- printd ("Script execution failed " + script )
314- return {
315- "success" : "false" ,
316- "lastUpdate" : str (int (checkStartTime * 1000 )),
317- "lastRunDuration" : str ((checkEndTime - checkStartTime ) * 1000 ),
318- "message" : output
319- }
309+ if not len (output ) > 0 :
310+ output = ""
311+
312+ routerHealth = RouterHealthStatus .SUCCESS
313+ match exitStatus :
314+ case 1 :
315+ routerHealth = RouterHealthStatus .FAILED
316+ case 2 :
317+ routerHealth = RouterHealthStatus .WARNING
318+ case 3 :
319+ routerHealth = RouterHealthStatus .UNKNOWN
320+
321+ printd ("Ended execution of " + script )
322+ return {
323+ "success" : routerHealth ,
324+ "lastUpdate" : str (int (checkStartTime * 1000 )),
325+ "lastRunDuration" : str ((checkEndTime - checkStartTime ) * 1000 ),
326+ "message" : output
327+ }
320328
321329def main (checkType = "basic" ):
322330 startTime = time .time ()
@@ -349,7 +357,7 @@ def main(checkType = "basic"):
349357 ret = execute (fpath , checkType )
350358 if len (ret ) == 0 :
351359 continue
352- if "success" in ret and ret ["success" ].lower () == "false" :
360+ if "success" in ret and ret ["success" ].upper () == RouterHealthStatus . FAILED :
353361 failingChecks .append (f )
354362 monitResult [f ] = ret
355363
0 commit comments