Community Articles

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

This article talks about two things:

1. How to develop a simple python script which returns the result_code like 'CRITICAL', 'WARN', 'OK', 'UNKNOWN' based on certain conditions matching our requirement.

2. How to write an alert definition in json format so that we can install those alerts to the Ambari Server in order to get the alerts.

The scripts/files attached to this article are "" and "alerts.json" that we are going to use as part of the following steps:

Step-1). Create a python script as attached ""

that finds the list of mount points and the it returns the disk usage status of those mount points. The based on the percentages specified it returns the return code as


Step-2). Place the file "" in the following Path on the ambari-server : "/var/lib/ambari-server/resources/host_scripts/"


cp -f   /var/lib/ambari-server/resources/host_scripts

Step-3). Now restart the Ambari-Server.

Also we will need to restart the ambari-agents on each hosts so that it (agents) can pull the script from the ambari server. In this case when we restart ambari agents then the file "" will be fetched by agents and will be stored inside the ambari-agent cache dir: "/var/lib/ambari-agent/cache/host_scripts" on agent hosts.

Step-4). Run the following command to list all the existing alerts:

curl -u admin:admin -i -H 'X-Requested-By:ambari' -X GET

Here Ambari Server Host & port is : "" and Cluster name is : "ClusterDemo"

Step-5). Install the custom alert using Curl command as following:

curl -u admin:admin -i -H 'X-Requested-By:ambari' -X POST -d @alerts.json

The output of the above command execution should have the response code as 201 (created). If the response code is 500 (Internal Server Error) or 404 ( Resource not fount) then please double check the command URL/json file.

Check the ambari console to find if the alerts are getting triggered fine or not. Alternatively run the command mentioned in Step-4 to verify of the custom alert is registered fine or not. If needed please do "ambari-server restart".

In the "" script users can change the values of "PERCENT_USED_WARNING_KEY" and "PERCENT_USED_CRITICAL_KEY" as per their requirement.

# script parameter keys


Any changes if we make in this file then the ambari-server restart is needed so that ambari-server can push those changes to the agent hosts.

We should be able to see the following kind of alerts based on the the should we have set:


List of every mount point and it's disk usage percentage.



Manually Running Alert

If we want to manually run the alert then do the following (Notice the "?run_now=true" part in the url)

curl -u admin:admin -i -H 'X-Requested-By:ambari' -X PUT

Notice here the "151 is the "alert id" which we can get from the ambari console alert definitions page. or using the curl GET command from Step-4.

Deleting the Alerts

figured out: jar xvf


Can we use file at place of ?

Rising Star

Hi All!

After done steps describe above have strange errors : [Errno 2] No such file or directory: 'net_prio'

Please healp custom-host-mount-point-usage.png..

Ambari Version (HDP-


The script presented here doesn't work on CentOS 7 + Python 7 + Ambari

See for additional discussion.


So, I have added web type alerts to check some URLs. I have uploaded them into Ambari, assigned them to a group and manually run them with a PUT like http://localhost:8080/api/v1/clusters/Magellan/alert_definitions/313?run_now=true. They respond correctly.

But for the life of me I cannot see how to automate them (aside from a cron job that keeps applying the curl command to manually execute each one.)

I've tried intervals of 1 & 2 without any luck. Is there some sort of heartbeat or trigger that I am supposed to assign to them?

Thanks for any ideas.


Referring to the PUT command used for triggering the alert manually, Is it possible to pass some parameters/custom information to the script which gets trigged by the alert ? If yes, is it via headers OR body of the PUT request ?