Created
September 25, 2017 11:16
-
-
Save ebuildy/c85b60e91d4c56d11aa6a8455c848911 to your computer and use it in GitHub Desktop.
Run Ambari service check for all services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, requests, os | |
from requests.auth import HTTPBasicAuth | |
cluster = os.environ["CLUSTER"] | |
url = "%s/api/v1/clusters/%s/services" % (os.environ["AMBARI_SERVER"], cluster) | |
respServices = requests.get(url, auth=HTTPBasicAuth(os.environ["AMBARI_LOGIN"], os.environ["AMBARI_PASSWORD"])).json() | |
requestServices = [] | |
index = 1 | |
for service in respServices['items']: | |
serviceName = service['ServiceInfo']['service_name'] | |
requestServices.append({ | |
"order_id": index, | |
"type":"POST", | |
"uri":"/api/v1/clusters/%s/requests" % cluster, | |
"RequestBodyInfo":{ | |
"RequestInfo":{ | |
"context":"%s Service Check (batch %d of %d)" % (serviceName, index, len(respServices['items'])), | |
"command":"%s_SERVICE_CHECK" % serviceName | |
}, | |
"Requests/resource_filters":[ | |
{ | |
"service_name": serviceName | |
} | |
] | |
} | |
}) | |
index += 1 | |
payload = [ | |
{ | |
"RequestSchedule":{ | |
"batch":[ | |
{ | |
"requests": requestServices | |
} | |
] | |
} | |
} | |
] | |
url = "%s/api/v1/clusters/%s/request_schedules" % (os.environ["AMBARI_SERVER"], cluster) | |
respServices = requests.post(url, auth=HTTPBasicAuth(os.environ["AMBARI_LOGIN"], os.environ["AMBARI_PASSWORD"]), headers={'X-Requested-By': os.environ["AMBARI_LOGIN"]}, data=json.dumps(payload)).json() | |
print respServices |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment