Monitors the processes which got from the config file
( processes_info )
| 255 | |
| 256 | |
| 257 | def monitProcess( processes_info ): |
| 258 | """ |
| 259 | Monitors the processes which got from the config file |
| 260 | """ |
| 261 | checkStartTime = time.time() |
| 262 | service_status = {} |
| 263 | failing_services = [] |
| 264 | if len( processes_info ) == 0: |
| 265 | printd("No config items provided - means a redundant VR or a VPC Router") |
| 266 | return service_status, failing_services |
| 267 | |
| 268 | print("[Process Info] " + json.dumps(processes_info)) |
| 269 | |
| 270 | #time for noting process down time |
| 271 | csec = repr(time.time()).split('.')[0] |
| 272 | |
| 273 | for process,properties in list(processes_info.items()): |
| 274 | printd ("---------------------------\nchecking the service %s\n---------------------------- " %process) |
| 275 | serviceName = process + ".service" |
| 276 | processStatus, wasRestarted = checkProcessStatus(properties) |
| 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: |
| 305 | failing_services.append(serviceName) |
| 306 | |
| 307 | return service_status, failing_services |
| 308 | |
| 309 | |
| 310 | def execute(script, checkType = "basic"): |
no test coverage detected