| 308 | |
| 309 | |
| 310 | def execute(script, checkType = "basic"): |
| 311 | checkStartTime = time.time() |
| 312 | cmd = "./" + script + " " + checkType |
| 313 | printd ("Executing health check script command: " + cmd) |
| 314 | |
| 315 | pout = Popen(cmd, shell=True, stdout=PIPE) |
| 316 | exitStatus = pout.wait() |
| 317 | output = pout.communicate()[0].decode().strip() |
| 318 | checkEndTime = time.time() |
| 319 | |
| 320 | # we run all scripts and have to ignore the ones that do nothing |
| 321 | if not len(output) > 0 and exitStatus == 0: |
| 322 | return {} |
| 323 | |
| 324 | routerHealth = RouterHealthStatus.SUCCESS |
| 325 | match exitStatus: |
| 326 | case 1: |
| 327 | routerHealth = RouterHealthStatus.FAILED |
| 328 | case 2: |
| 329 | routerHealth = RouterHealthStatus.WARNING |
| 330 | case 3: |
| 331 | routerHealth = RouterHealthStatus.UNKNOWN |
| 332 | |
| 333 | printd("Ended execution of " + script) |
| 334 | return { |
| 335 | "success": routerHealth, |
| 336 | "lastUpdate": str(int(checkStartTime * 1000)), |
| 337 | "lastRunDuration": str((checkEndTime - checkStartTime) * 1000), |
| 338 | "message": output |
| 339 | } |
| 340 | |
| 341 | def main(checkType = "basic"): |
| 342 | startTime = time.time() |