Wormly API: Setting host-specific alert recipients
In this example, we use the getAlertMatrix and setAlertMatrix API commands to copy the alert recipient matrix from one host to another.
These commands are intended for use on any UNIX-like system, and require cURL (version >= 7.18) and a command line PHP interpreter. Also be sure to grab a Wormly API key first.
Visit Github if you cannot see the code below.
# Choose a host which is configured to use host-specific alert recipients. | |
# You will find the Host ID in small gray text next to its' name on the | |
# Host Overview page (wormly.com/answers/sid/63/topicid/13). | |
# Now, prepare some environment variables: | |
export HOSTID=12345 | |
export WORMLY_API_KEY=<Insert your API key here> | |
# First, check to see if you can read the alert matrix | |
# for the host you chose: | |
curl --silent "https://api.wormly.com/?key=$WORMLY_API_KEY&response=xml&cmd=getAlertMatrix&mode=HOST&hostid=$HOSTID" | |
# You should see a small XML document with a <matrix> element | |
# Keep an eye out for errors - remember that the host you select | |
# must be configured with host-specific alert recipients | |
# Now we'll fetch the alert matrix from the API and store it | |
# in an environment variable: | |
export ALERTMATRIX=`curl --silent "https://api.wormly.com/?key=$WORMLY_API_KEY&response=php&cmd=getAlertMatrix&mode=HOST&hostid=$HOSTID" | \ | |
php -r 'echo unserialize(file_get_contents("php://stdin"))->matrix;'` | |
# Verify that the matrix was successfully retreived and stored: | |
echo $ALERTMATRIX | |
# Now, find the ID of the host to which we want to apply this alert matrix: | |
export HOSTID=98765 | |
# And make the setAlertMatrix API call: | |
curl -i --silent "https://api.wormly.com/?key=$WORMLY_API_KEY&response=xml&cmd=setAlertMatrix&mode=HOST&hostid=$HOSTID" \ | |
--data-urlencode matrix=$ALERTMATRIX | |
# Again, keep an eye out for a 200 OK response code, | |
# otherwise inspect the error message. | |
# Verify that the change was made: | |
curl --silent "https://api.wormly.com/?key=$WORMLY_API_KEY&response=xml&cmd=getAlertMatrix&mode=HOST&hostid=$HOSTID" | |
# You can also verify the change within the Wormly web interface. | |