Is there any way to create a custom script in bash to retrieve or get the custom alerts(Critical etc) from Ambari UI?
Using Ambari API calls you can get the alerts based on the alert state (like CRITICAL, WARNING ...etc)
You can write that login inside the Shell Script as it can be triggered using simple curl commands and then parse the JSON data based on your convenient.
For example based on the CRITICAL Or WARNING state you can capture all the alerts that are triggered as following (where component/host are not in maintenance mode):
# curl -k -H "X-Requested-By: ambari" -u admin:admin -X GET "http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/alerts?fields=Alert/component_name,Alert/definition_id,Alert/definition_name,Alert/host_name,Alert/id,Alert/instance,Alert/label,Alert/latest_timestamp,Alert/maintenance_state,Alert/original_timestamp,Alert/scope,Alert/service_name,Alert/state,Alert/text,Alert/repeat_tolerance,Alert/repeat_tolerance_remaining&Alert/state.in(CRITICAL,WARNING)&Alert/maintenance_state.in(OFF)"
In the above API call you will need to replace the following:
$AMBARI_HOST:8080 = Your Ambari Server FQDN/Hostname and Port
$CLUSTER_NAME = Your cluster name
admin:admin = with your Ambari Admin credentials.
@jsensharma Getting error while running this query given by You.