#!/bin/sh # Check Asterisk ODBC CDR row count plugin for Nagios. # Written by Chad Phillips (chad@apartmentlines.com) # Last Modified: 2009-03-01 ASTERISK=/usr/sbin/asterisk ISQL=/usr/bin/isql PROGPATH=`dirname $0` REVISION=`echo '$Revision: 1 $' | sed -e 's/[^0-9.]//g'` DATETIME=`date "+%Y-%m-%d %H:%M:%S"` TAB=" " . $PROGPATH/utils.sh print_usage() { echo " Usage: check_asterisk_odbc_cdr_row_count --dsn | -d --table | -t Usage: check_asterisk_odbc_cdr_row_count --help | -h Description: This plugin checks total Asterisk ODBC CDR records via isql. The number of CDR records is returned as performance data. Tested to work on Linux. The following arguments are accepted: --dsn | -d The ODBC DSN associated with the CDR database, as found in odbc.ini. --table | -t The CDR table name in the CDR database. --help | -h Print this help and exit. Examples: Check CDR connection with ODBC DSN asterisk_cdr, where the CDR table is named cdr. check_asterisk_cdr -d asterisk_cdr -t cdr " } print_help() { print_usage echo "Check Asterisk ODBC CDR row count plugin for Nagios." echo "" } # Defaults. dsn= table= # Grab the command line arguments. while test -n "$1"; do case "$1" in --help) print_help exit $STATE_OK ;; -h) print_help exit $STATE_OK ;; --dsn) dsn=$2 shift ;; -d) dsn=$2 shift ;; --table) table=$2 shift ;; -t) table=$2 shift ;; -x) exitstatus=$2 shift ;; --exitstatus) exitstatus=$2 shift ;; *) echo "Unknown argument: $1" print_usage exit $STATE_UNKNOWN ;; esac shift done # Sanity checking for arguments. if [ ! "$dsn" ]; then echo "You must provide a DSN." exit $STATE_UNKNOWN fi if [ ! "$table" ]; then echo "You must provide a table name." exit $STATE_UNKNOWN fi # Fetch the data from isql. command_output=`echo "SELECT COUNT(*) FROM $table" | isql -b -dX $dsn 2>&1` command_return=$? isql_error=`echo "$command_output" | grep "\[ISQL\]ERROR:"` if [ "$command_return" != "0" ] || [ "$isql_error" ]; then echo "CRITICAL: $command_output" exit $STATE_CRITICAL fi echo "OK: $command_output CDR records | ${DATETIME}${TAB}${command_output}"; exit $STATE_OK