Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Wormly API - manipulate alert recipients
# 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 (
# 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 "$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 "$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:
# 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 "$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 "$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
You can’t perform that action at this time.