Showing
1 changed file
with
12 additions
and
10 deletions
@@ -21,10 +21,10 @@ JENKINS_UPDATE_VAR_URL = "http://jenkins.yohops.com/job/yoho-ansible-roles/build | @@ -21,10 +21,10 @@ JENKINS_UPDATE_VAR_URL = "http://jenkins.yohops.com/job/yoho-ansible-roles/build | ||
21 | JENKINS_TOKEN = "607f13cd5f7ff5bdf5813f9745d7da49" | 21 | JENKINS_TOKEN = "607f13cd5f7ff5bdf5813f9745d7da49" |
22 | 22 | ||
23 | def main_handler(event, context): | 23 | def main_handler(event, context): |
24 | - if not event['queryString'] | ||
25 | - return | ||
26 | print("start to process mysql alarm: %s" % event['queryString']) | 24 | print("start to process mysql alarm: %s" % event['queryString']) |
27 | return_str = "OK" | 25 | return_str = "OK" |
26 | + if "auth" not in event['queryString'] or "host" not in event['queryString'] or "alarm" not in event['queryString'] : | ||
27 | + return_str = "Request params failed" | ||
28 | elif event['queryString']['auth'] != 'yohomysqlfailover123456887': | 28 | elif event['queryString']['auth'] != 'yohomysqlfailover123456887': |
29 | return_str = "Auth Failed" | 29 | return_str = "Auth Failed" |
30 | else: | 30 | else: |
@@ -38,16 +38,16 @@ def main_handler(event, context): | @@ -38,16 +38,16 @@ def main_handler(event, context): | ||
38 | def ansible_tower_process(down_host, alarm): | 38 | def ansible_tower_process(down_host, alarm): |
39 | if not down_host: | 39 | if not down_host: |
40 | return | 40 | return |
41 | - if "mysql" not in alarm.lower() or "is down" not in alarm.lower() | 41 | + if "mysql" not in alarm.lower() or "is down" not in alarm.lower(): |
42 | print("ignore this alarm :%s" % alarm) | 42 | print("ignore this alarm :%s" % alarm) |
43 | return | 43 | return |
44 | + | ||
44 | ## az1, az2, az3 | 45 | ## az1, az2, az3 |
45 | - | ||
46 | - for inventory in [ 6, 5, 4]: | 46 | + INVENTORY_ENV = {6: "az1", 5: "az2", 4: "az3"} |
47 | + keys = [] | ||
48 | + values = [] | ||
49 | + for inventory in [ 4]: | ||
47 | extra_var = {} | 50 | extra_var = {} |
48 | - ## for update git | ||
49 | - keys = [] | ||
50 | - values = [] | ||
51 | r = requests.get(ansible_url + "/inventories/%i/" %inventory, auth=(ansible_user, ansible_password)) | 51 | r = requests.get(ansible_url + "/inventories/%i/" %inventory, auth=(ansible_user, ansible_password)) |
52 | inventory_vars = json.loads( r.json()['variables']) | 52 | inventory_vars = json.loads( r.json()['variables']) |
53 | for key in inventory_vars: | 53 | for key in inventory_vars: |
@@ -84,9 +84,11 @@ def ansible_tower_process(down_host, alarm): | @@ -84,9 +84,11 @@ def ansible_tower_process(down_host, alarm): | ||
84 | job_id = r_cobar.json()['job'] | 84 | job_id = r_cobar.json()['job'] |
85 | make_sure_job_success(job_id) | 85 | make_sure_job_success(job_id) |
86 | 86 | ||
87 | - #update git | 87 | + #last: update git |
88 | + if not keys and not values: | ||
88 | jenkins_param = {"token": JENKINS_TOKEN, "MODIFY_ENV": INVENTORY_ENV[inventory], "key": ",".join(keys), "value": ",".join(values)} | 89 | jenkins_param = {"token": JENKINS_TOKEN, "MODIFY_ENV": INVENTORY_ENV[inventory], "key": ",".join(keys), "value": ",".join(values)} |
89 | requests.get(JENKINS_UPDATE_VAR_URL, params = jenkins_param) | 90 | requests.get(JENKINS_UPDATE_VAR_URL, params = jenkins_param) |
91 | + print("start to update ansible git variables : %s" % jenkins_param) | ||
90 | return 0 | 92 | return 0 |
91 | 93 | ||
92 | 94 | ||
@@ -120,4 +122,4 @@ def alert_to_dingding(down_host, alarm, ret): | @@ -120,4 +122,4 @@ def alert_to_dingding(down_host, alarm, ret): | ||
120 | r = requests.post(url = DING, json = ding_req) | 122 | r = requests.post(url = DING, json = ding_req) |
121 | print("Send DingDing message result:%s, request: %s " %(r, ding_req)) | 123 | print("Send DingDing message result:%s, request: %s " %(r, ding_req)) |
122 | return("SUCCESS") | 124 | return("SUCCESS") |
123 | - | ||
125 | + |
-
Please register or login to post a comment