From c6b5a1f2e40f640ea88bd2d6769a2dc22e7a5c4d Mon Sep 17 00:00:00 2001 From: saqib-perwaiz_navi Date: Fri, 29 Sep 2023 19:14:48 +0530 Subject: [PATCH] INFRA-2270 | Saqib | Change type from string to number --- scripts/update_threshold_value_to_numbers.py | 46 +++++++++++--------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/scripts/update_threshold_value_to_numbers.py b/scripts/update_threshold_value_to_numbers.py index 9f152b64..83e5ced9 100644 --- a/scripts/update_threshold_value_to_numbers.py +++ b/scripts/update_threshold_value_to_numbers.py @@ -1,31 +1,37 @@ import time import requests -url = "" # deployment portal url + + +url = "" #deployment portal url s = requests.Session() -cookie = "" # cookie -x_xsrf_token = "" # token -s.headers.update({"cookie": cookie, "x-xsrf-token": x_xsrf_token}) +cookie = "" #cookie +x_xsrf_token = "" # token +s.headers.update({'cookie': cookie, 'x-xsrf-token': x_xsrf_token}) list_manifest_path = "/api/manifest/list" r = s.get(url + list_manifest_path) manifest_list = r.json() for i in manifest_list: perform_post = False - r = s.get(url + "/api/manifest/" + str(i["id"])) + r = s.get(url + "/api/manifest/" + str(i['id'])) manifest = r.json() - if "deployment" in manifest: - deployment = manifest["deployment"] - if "alerts" in deployment: - alerts = deployment["alerts"] - for alert_type, alert_list in alerts.items(): - for alert in alert_list: - if ( - "threshold" in alert - and isinstance(alert["threshold"], str) - and alert["threshold"].isdigit() - ): - alert["threshold"] = int(alert["threshold"]) - response = s.post(url + "/api/manifest", json=manifest) - print("{} response of post is {}".format(i["id"], response.json())) - time.sleep(2) \ No newline at end of file + if manifest['name'] == 'deployment-test': + if 'deployment' in manifest: + deployment = manifest['deployment'] + if 'alerts' in deployment: + alerts = deployment['alerts'] + for alert_type, alert_list in alerts.items(): + for alert in alert_list: + if isinstance(alert, dict) and 'threshold' in alert and isinstance(alert['threshold'], str) and alert['threshold'].isdigit(): + alert['threshold'] = int(alert['threshold']) + + if 'elasticSearch' in deployment: + elasticSearch = deployment['elasticSearch'] + if 'instance' in elasticSearch: + instance = elasticSearch['instance'] + instance['cpu'] = int(instance['cpu']) + + response = s.post(url + "/api/manifest", json=manifest) + print("{} response of post is {}".format(i['id'], response.text)) + time.sleep(2)