Support Questions
Find answers, ask questions, and share your expertise

custom bash script to configure ambari alerts from UI

custom bash script to configure ambari alerts from UI

Hello,


Is there any way to create a custom script in bash to retrieve or get the custom alerts(Critical etc) from Ambari UI?

3 REPLIES 3

Re: custom bash script to configure ambari alerts from UI

Super Mentor

@Nani Bigdata

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.

.

Re: custom bash script to configure ambari alerts from UI

Super Mentor

@Nani Bigdata

Does it answers your query? Or do you have any additional query in this regard?
If not then please mark this HCC thread as resolved by clicking on the "Accept" Button.

Re: custom bash script to configure ambari alerts from UI

New Contributor

@jsensharma  Getting error while running this query given by You.

Error
_____________
Error:
<!DOCTYPE html>
<html>
<head>
<title>Runtime Error</title>
<meta name="viewport" content="width=device-width" />
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
@media screen and (max-width: 639px) {
pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
}
@media screen and (max-width: 479px) {
pre { width: 280px; }
}
</style>
</head>