Created
August 17, 2011 06:47
-
-
Save JulesAU/1150962 to your computer and use it in GitHub Desktop.
Wormly API - manipulate alert recipients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment