check_opsgenie_whoIsOnCall

This is a bash script to check who is listed as the on call person in Ops Genie ( https://www.opsgenie.com ). If you don't know what OpsGenie is, this check is probably useless to you.

The OpsGenie API returns a json formatted output, this check uses jq to decode the json to text which can be processed.

This is the check code, the command def is below:-

#!/bin/bash
# check_opsgenie_whoIsOnCall.sh
# Written Andrew Stringer 12/10/2016 onwards
# Purpose is to check who is the on-call bod as assigned through Ops Genie (https://www.opsgenie.com/)
# It also gets the next schedule (Just in case required)

# This relies on 'jq' to do the decoding of the json string returned by the API
# You will need an API key from OpsGenie to pass to this check as $1

APIKEY=$1

OPSGENIEURL='https://api.opsgenie.com/v1.1/json/schedule/whoIsOnCall'

ONCALL0=`curl -s "${OPSGENIEURL}?apiKey=${APIKEY}" | jq -r '.oncalls[0] .name + ":" + .oncalls[0] .participants[0] .name'`
#ONCALLRET0=$?

ONCALL1=`curl -s "${OPSGENIEURL}?apiKey=${APIKEY}" | jq -r '.oncalls[1] .name + ":" + .oncalls[1] .participants[0] .name'`
ONCALLRET1=$?
#daily_schedule:idavies@friendmts.com


SCHEDULE0=`echo ${ONCALL0} | cut -d: -f1`
BOD0=`echo ${ONCALL0} | cut -d: -f2`
SCHEDULE1=`echo ${ONCALL1} | cut -d: -f1`
BOD1=`echo ${ONCALL1} | cut -d: -f2`

#just in case the second schedule is mot in use....
if [ -z "$SCHEDULE1" ]; then
        SCHEDULE1='Schedule not defined'
        BOD1='On Call is N/A'
fi

#This may be true if the API key is wrong, or maybe we haven't paid the bill??
if [ -z "$SCHEDULE0" ] && [ -z "$SCHEDULE1" ]; then
        echo "Somethings gone wrong."
        exit 3
fi

#Start writing out status info

echo "${SCHEDULE0}:- ${BOD0}, ${SCHEDULE1}:- ${BOD1}"
exit 0

Command Def:-

#Check who is on call from OpsGenie API
define command {
        command_name    WhoIsOnCall
        command_line    /usr/lib/nagios/plugins/check_opsgenie_whoIsOnCall.sh '$ARG1$'
        }

Example usage:-

define service{
        use                             generic-service
        host_name                       OpsGenie
        service_description             OpsGenie WhoIsOnCall
        check_command                   WhoIsOnCall!YourAPIkeyGoesHere
        notification_options            c
        }
 
nagios/check_opsgenie_whoisoncall.txt · Last modified: 18/02/2021 10:44 by andrew