Skip to content

Instantly share code, notes, and snippets.

@subutux
Created June 6, 2014 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subutux/a2b17e15ce2f695e7f79 to your computer and use it in GitHub Desktop.
Save subutux/a2b17e15ce2f695e7f79 to your computer and use it in GitHub Desktop.
Opsview boxcar notification method

Usage:

  • Place this file into /usr/local/nagios/libexec/notifications/

  • Create a new notification method in Opsview (Advanced > Notification methods > "+")

    command: send_boxcar_notitfication.sh

    contact variables: BOXCAR_API

  • Edit your contacts: fill the Boxcar api with your api key

  • set the notification method on some notification groups

  • done

#!/bin/bash
API_KEY=${NAGIOS__CONTACTBOXCAR_API};
if [ "${NAGIOS_SERVICEDESC}x" != "x" ]; then
if [ "${NAGIOS_SERVICEACKCOMMENT}x" != "x" ]; then
TITLE="${NAGIOS_SERVICEDESC}:${NAGIOS_SERVICEACKCOMMENT}";
MSG="${NAGIOS_SERVICEDESC} on ${NAGIOS_HOSTNAME}<br>${NAGIOS_SERVICEACKCOMMENT}<br>${NAGIOS_SERVICEACKAUTHOR}<br>${NAGIOS_SHORTDATETIME}";
else
TITLE="${NAGIOS_SERVICEDESC}:${NAGIOS_SERVICEOUTPUT}";
MSG="${NAGIOS_SERVICEDESC} on ${NAGIOS_HOSTNAME}<br>${NAGIOS_SERVICEOUTPUT}<br>${NAGIOS_SHORTDATETIME}";
fi
else
if [ "${NAGIOS_HOSTACKCOMMENT}x" != "x" ]; then
TITLE="${NAGIOS_HOSTNAME}:${NAGIOS_SERVICEACKCOMMENT}";
MSG="${NAGIOS_HOSTNAME} is ${NAGIOS_HOSTSTATE}<br>${NAGIOS_HOSTACKCOMMENT}<br>${NAGIOS_HOSTACKAUTHOR}<br>${NAGIOS_SHORTDATETIME}";
else
TITLE="${NAGIOS_HOSTNAME}:${NAGIOS_HOSTSTATE}";
MSG="${NAGIOS_HOSTNAME} is ${NAGIOS_HOSTSTATE}<br>${NAGIOS_HOSTOUTPUT}<br>${NAGIOS_SHORTDATETIME}";
fi
fi
curl -d "user_credentials=${API_KEY}" \
-d "notification[title]=opsview ${TITLE//%/%25}" \
-d "notification[long_message]=${MSG//%/%25}" \
-d "notification[sound]=bird-1" \
-d "notification[source_name]=Opsview" \
https://new.boxcar.io/api/notifications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment