(checkType = "basic")
| 339 | } |
| 340 | |
| 341 | def main(checkType = "basic"): |
| 342 | startTime = time.time() |
| 343 | ''' |
| 344 | Step1 : Get Services Config |
| 345 | ''' |
| 346 | printd("monitoring started") |
| 347 | configDict = getServicesConfig() |
| 348 | |
| 349 | ''' |
| 350 | Step2: Monitor services and Raise Alerts |
| 351 | ''' |
| 352 | monitResult = {} |
| 353 | failingChecks = [] |
| 354 | if checkType == "basic": |
| 355 | monitResult, failingChecks = monitProcess(configDict) |
| 356 | |
| 357 | ''' |
| 358 | Step3: Run health check scripts as needed |
| 359 | ''' |
| 360 | hc_data = getHealthChecksData() |
| 361 | |
| 362 | if hc_data is not None and "health_checks_enabled" in hc_data and hc_data['health_checks_enabled']: |
| 363 | hc_exclude = hc_data["excluded_health_checks"] if "excluded_health_checks" in hc_data else [] |
| 364 | for f in os.listdir(Config.HEALTH_CHECKS_DIR): |
| 365 | if f in hc_exclude: |
| 366 | continue |
| 367 | fpath = path.join(Config.HEALTH_CHECKS_DIR, f) |
| 368 | if path.isfile(fpath) and os.access(fpath, os.X_OK): |
| 369 | ret = execute(fpath, checkType) |
| 370 | if len(ret) == 0: |
| 371 | continue |
| 372 | if "success" in ret and ret["success"].upper() == RouterHealthStatus.FAILED: |
| 373 | failingChecks.append(f) |
| 374 | monitResult[f] = ret |
| 375 | |
| 376 | ''' |
| 377 | Step4: Write results to the json file for admins/management server to read |
| 378 | ''' |
| 379 | |
| 380 | endTime = time.time() |
| 381 | monitResult["lastRun"] = { |
| 382 | "start": str(datetime.fromtimestamp(startTime)), |
| 383 | "end": str(datetime.fromtimestamp(endTime)), |
| 384 | "duration": str(endTime - startTime) |
| 385 | } |
| 386 | |
| 387 | with open(checkType + "_" + Config.MONITOR_RESULT_FILE_SUFFIX, 'w') as f: |
| 388 | json.dump(monitResult, f, ensure_ascii=False) |
| 389 | |
| 390 | failChecksFile = checkType + "_" + Config.FAILING_CHECKS_FILE |
| 391 | if len(failingChecks) > 0: |
| 392 | fcs = "" |
| 393 | for fc in failingChecks: |
| 394 | fcs = fcs + fc + "," |
| 395 | fcs = fcs[0:-1] |
| 396 | with open(failChecksFile, 'w') as f: |
| 397 | f.write(fcs) |
| 398 | elif path.isfile(failChecksFile): |
no test coverage detected