Skip to content

Instantly share code, notes, and snippets.

@subutux
Created Jun 6, 2014
Embed
What would you like to do?
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