Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Partial Request and Ambari REST API

avatar
New Member

Hello everyone,

I am trying to get a list of alerts via REST API but I want it to be limited to only specific fields.

I am currently able to get all available information from the alerts, ie:

{
  "href" : "http://ambari_server:8080/api/v1/clusters/appslogs/alerts?Alert/state.in(WARNING,CRITICAL,UNKNOWN)&Alert/maintenance_state=OFF&fields=*",
  "items" : [
    {
      "href" : "http://ambari_server:8080/api/v1/clusters/appslogs/alerts/23",
      "Alert" : {
        "cluster_name" : "appslogs",
        "component_name" : "AMBARI_AGENT",
        "definition_id" : 50,
        "definition_name" : "ambari_agent_disk_usage",
        "host_name" : "host1.local",
        "id" : 23,
        "instance" : null,
        "label" : "Host Disk Usage",
        "latest_timestamp" : 1456931060177,
        "maintenance_state" : "OFF",
        "original_timestamp" : 1454589680156,
        "scope" : "HOST",
        "service_name" : "AMBARI",
        "state" : "WARNING",
        "text" : "Capacity Used: [71.56%, 6.0 GB], Capacity Total: [8.3 GB], path=/usr/hdp. Total free space is less than 2.0 GB"
      }

Does anybody know how to get ONLY state,host and text fields in response?

I tried the following request but it does not work:

http://ambari_server:8080/api/v1/clusters/appslogs/alerts?Alert/state.in(WARNING,CRITICAL,UNKNOWN)&A...

What am I missing?

Apache Ambari Version: 2.2.0.0

1 ACCEPTED SOLUTION

avatar

@Sunella Zag It looks like alerts resource doesn't allow filtering of fields. Only fields=* seems to be working. Specifying any fields results in default fields.

http://ambari_server:8080/api/v1/clusters/appslogs/alerts?Alert/state.in(WARNING,CRITICAL,UNKNOWN)&A...

For services resource, I was able to specify a list of fields and get only required fields in my response.

http://ambari_server:8080/api/v1/clusters/hdp_dev/services/HDFS?fields=alerts_summary

so this seems to be a problem only with alert resource.

View solution in original post

2 REPLIES 2

avatar

@Sunella Zag It looks like alerts resource doesn't allow filtering of fields. Only fields=* seems to be working. Specifying any fields results in default fields.

http://ambari_server:8080/api/v1/clusters/appslogs/alerts?Alert/state.in(WARNING,CRITICAL,UNKNOWN)&A...

For services resource, I was able to specify a list of fields and get only required fields in my response.

http://ambari_server:8080/api/v1/clusters/hdp_dev/services/HDFS?fields=alerts_summary

so this seems to be a problem only with alert resource.

avatar

@Sunella Zag Following fields are defaults and will be included in all responses

"cluster_name" , "definition_id", "definition_name" , "host_name" , "id" , "service_name" 

You can include any additional fields using

http://ambari_server:8080/api/v1/clusters/appslogs/alerts?Alert/state.in(WARNING,CRITICAL,UNKNOWN)&A...lert/state,Alert/text