Community Articles
Find and share helpful community-sourced technical articles
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.
Labels (1)
Super 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.

.

813 Views
Comments
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?

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.

Don't have an account?
Coming from Hortonworks? Activate your account here
Version history
Revision #:
2 of 2
Last update:
‎08-17-2019 07:08 AM
Updated by:
 
Contributors
Top Kudoed Authors