How to run service checks for various services using Ambari Rest APIs.
- If we want to run a service check for a particular service using Ambari APIs then one most important thins we will need to know in order to perform the service check using the APIs, that is the request payload. For every service the Payload of the request can be something in the following format:
{
"RequestInfo":
{
"context":"HDFS Service Check",
"command":"HDFS_SERVICE_CHECK"
},
"Requests/resource_filters":[
{
"service_name":"HDFS"
}
]
}
.
If we do not know what will be the exact payload for different services then we can simply get it by using the "Browser Debugger Tools". It should show the "Form Data" section.

- Now once we know the payload that we can use to POST for the service check execution to ambari then we can simply tun the command as following:
Syntax:
curl -u admin:admin -H "X-Requested-By: ambari" -X POST -d @/PATH/TO/hdfs_service_check_payload.txt http://AMBARI_HOST:8080/api/v1/clusters/CLUSTER_NAME/requests
.
Example:
$ curl -u admin:admin -H "X-Requested-By: ambari" -X POST -d @/Users/jsensharma/Cases/Articles/Service_Checks_Using_APIs/hdfs_service_check_payload.txt http://erie1.example.com:8080/api/v1/clusters/ErieCluster/requests
{
"href" : "http://erie1.example.com:8080/api/v1/clusters/ErieCluster/requests/424",
"Requests" : {
"id" : 424,
"status" : "Accepted"
}
}
.
Here the file "hdfs_service_check_payload.txt" contains the payload mentioned above.
.

