Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Celebrating as our community reaches 100,000 members! Thank you!
Labels (1)
avatar
Master Mentor

- 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.

10766-service-check-payload-hdfs.png

- 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.

.

1,774 Views
Comments
avatar
Expert Contributor

@Jay SenSharma It seems like your article is almost the same topic as the first section in this article from @Jonas Straub

https://community.hortonworks.com/articles/11852/ambari-api-run-all-service-checks-bulk.html

However it seems the request payload stated in both articles is not working. It complains about the property "Requests/resource_filters" not being supported for this service type:

curl -u admin:'****' -H 'X-Requested-By: ambari' -X POST http://localhost:8080/api/v1/clusters/mycluster/services/HDFS -d '{"RequestInfo":{"context":"HDFS Service Check","command":"HDFS_SERVICE_CHECK"},"Requests/resource_filters":[{"service_name":"HDFS"}]}'
....
{
  "status" : 400,
  "message" : "The properties [Requests/resource_filters] specified in the request or predicate are not supported for the resource type Service."

The same command is working with other payload types (like "ServiceInfo").

May be I'm missing some subtle detail?

avatar
Expert Contributor

@Jay SenSharma Forgive me, I used the browser's debug tool and I found out by myself I was using the wrong URL (copy/paste error). I replaced "services" by "requests" as should be and Now it's working as you stated. Sorry and thank you.