Authored by chunhua.zhang

bug fix

... ... @@ -21,10 +21,10 @@ JENKINS_UPDATE_VAR_URL = "http://jenkins.yohops.com/job/yoho-ansible-roles/build
JENKINS_TOKEN = "607f13cd5f7ff5bdf5813f9745d7da49"
def main_handler(event, context):
if not event['queryString']
return
print("start to process mysql alarm: %s" % event['queryString'])
return_str = "OK"
if "auth" not in event['queryString'] or "host" not in event['queryString'] or "alarm" not in event['queryString'] :
return_str = "Request params failed"
elif event['queryString']['auth'] != 'yohomysqlfailover123456887':
return_str = "Auth Failed"
else:
... ... @@ -38,16 +38,16 @@ def main_handler(event, context):
def ansible_tower_process(down_host, alarm):
if not down_host:
return
if "mysql" not in alarm.lower() or "is down" not in alarm.lower()
if "mysql" not in alarm.lower() or "is down" not in alarm.lower():
print("ignore this alarm :%s" % alarm)
return
## az1, az2, az3
for inventory in [ 6, 5, 4]:
INVENTORY_ENV = {6: "az1", 5: "az2", 4: "az3"}
keys = []
values = []
for inventory in [ 4]:
extra_var = {}
## for update git
keys = []
values = []
r = requests.get(ansible_url + "/inventories/%i/" %inventory, auth=(ansible_user, ansible_password))
inventory_vars = json.loads( r.json()['variables'])
for key in inventory_vars:
... ... @@ -84,9 +84,11 @@ def ansible_tower_process(down_host, alarm):
job_id = r_cobar.json()['job']
make_sure_job_success(job_id)
#update git
#last: update git
if not keys and not values:
jenkins_param = {"token": JENKINS_TOKEN, "MODIFY_ENV": INVENTORY_ENV[inventory], "key": ",".join(keys), "value": ",".join(values)}
requests.get(JENKINS_UPDATE_VAR_URL, params = jenkins_param)
print("start to update ansible git variables : %s" % jenkins_param)
return 0
... ... @@ -120,4 +122,4 @@ def alert_to_dingding(down_host, alarm, ret):
r = requests.post(url = DING, json = ding_req)
print("Send DingDing message result:%s, request: %s " %(r, ding_req))
return("SUCCESS")
\ No newline at end of file
... ...