@@ -274,24 +274,35 @@ def monitProcess( processes_info ):
274274 printd ("---------------------------\n checking the service %s\n ---------------------------- " % process )
275275 serviceName = process + ".service"
276276 processStatus , wasRestarted = checkProcessStatus (properties )
277- if processStatus != StatusCodes .RUNNING :
278- printd ( "\n Service %s is not Running" % process )
279- checkEndTime = time .time ()
280- service_status [serviceName ] = {
281- "success" : "false" ,
282- "lastUpdate" : str (int (checkStartTime * 1000 )),
283- "lastRunDuration" : str ((checkEndTime - checkStartTime ) * 1000 ),
284- "message" : "service down at last check " + str (csec )
285- }
277+ routerHealth = RouterHealthStatus .UNKNOWN
278+
279+ match processStatus :
280+ case StatusCodes .RUNNING :
281+ routerHealth = RouterHealthStatus .SUCCESS
282+ routerMessage = "service is running" + (", was restarted" if wasRestarted else "" )
283+ case StatusCodes .STARTING :
284+ routerHealth = RouterHealthStatus .WARNING
285+ routerMessage = "service is starting at " + str (csec )
286+ case StatusCodes .STOPPED :
287+ routerHealth = RouterHealthStatus .WARNING
288+ routerMessage = "service down at last check " + str (csec )
289+ case StatusCodes .SUCCESS :
290+ routerHealth = RouterHealthStatus .UNKNOWN
291+ routerMessage = "service exisits but no status"
292+ case StatusCodes .FAILED | StatusCodes .INVALID_INP :
293+ routerHealth = RouterHealthStatus .FAILED
294+ routerMessage = "service down at last check " + str (csec )
295+
296+ printd ( "\n Service %s is status == " % routerHealth )
297+ checkEndTime = time .time ()
298+ service_status [serviceName ] = {
299+ "success" : routerHealth ,
300+ "lastUpdate" : str (int (checkStartTime * 1000 )),
301+ "lastRunDuration" : str ((checkEndTime - checkStartTime ) * 1000 ),
302+ "message" : routerMessage
303+ }
304+ if routerHealth != RouterHealthStatus .SUCCESS :
286305 failing_services .append (serviceName )
287- else :
288- checkEndTime = time .time ()
289- service_status [serviceName ] = {
290- "success" : "true" ,
291- "lastUpdate" : str (int (checkStartTime * 1000 )),
292- "lastRunDuration" : str ((checkEndTime - checkStartTime ) * 1000 ),
293- "message" : "service is running" + (", was restarted" if wasRestarted else "" )
294- }
295306
296307 return service_status , failing_services
297308
0 commit comments