prev. article next article
shinken

shinken 1.2.4 on ubuntu desktop 12.10 iii

15 Mar 2013

copied from shinken-monitoring.org

motivation

in this posting i want to enhance the shinken usage with a few new ideas

adding check_ping to hosts

there are two ways:

looks like:

how to write a custom test which generates a RRD graph -> perfdata

see [2] and [3]

specification

the right structure is :

what_you_want_to | variable1=value;warning_threshold;critical_threshold;min;max, variable2=value;;warning_threshold;critical_threshold;min;max

here is the modified example from the last blog posting about shinken:

#! /bin/bash
#
# js@lastlog.de
# 05/03/2013
#
#  This Nagios test plugin was created to demonstrate how it is integrated into shinken
#  now with perfdata creation
#

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="0.0.1"

. $PROGPATH/utils.sh

print_usage() {
  echo "Usage:"
  echo "  $PROGNAME --help"
  echo "  $PROGNAME --test"
  echo "  $PROGNAME --version"
}

print_help() {
  print_revision $PROGNAME $REVISION
  echo ""
  print_usage
  echo ""
  echo "Nagios test plugin"
  echo ""
  echo "--test"
  echo "   Perform a test; in this implementation it either returns: STATE_OK STATE_CRITICAL STATE_UNKNOWN "
  echo "--help"
  echo "   Print this help screen"
  echo "--version"
  echo "   Print version and license information"
  echo ""
  support
}

# Information options
case "$1" in
--help)
                print_help
    exit $STATE_OK
    ;;
-h)
                print_help
    exit $STATE_OK
    ;;
--version)
                print_revision $PROGNAME $REVISION
    exit $STATE_OK
    ;;
-V)
                print_revision $PROGNAME $REVISION
    exit $STATE_OK
    ;;
--test)
    # STATE_OK
    # STATE_WARNING
    # STATE_CRITICAL
    # STATE_UNKNOWN
    # STATE_DEPENDENT
    # $(($RANDOM%3))
    f=$(($RANDOM%9))
    l=$(($RANDOM%9))

    case $(($RANDOM%5)) in
      0)
# ping=2;50;100;; lost=0;5;10;;"

          echo "STATE_OK - $(date) | ping=$f;50;100;; lost=$l;5;10;;"
          exit $STATE_OK
      ;;
      1)
          echo "STATE_WARNING - $(date) | ping=$f;50;100;; lost=$l;5;10;;"
          exit $STATE_WARNING
      ;;
      2)
          echo "STATE_CRITICAL - $(date) | ping=$f;50;100;; lost=$l;5;10;;"
          exit $STATE_CRITICAL
      ;;
      3)
          echo "STATE_DEPENDENT - $(date) | ping=$f;50;100;; lost=$l;5;10;;"
          exit $STATE_DEPENDENT
      ;;
      *)
          echo "STATE_UNKNOWN - $(date) | ping=$f;50;100;; lost=$l;5;10;;"
          exit $STATE_UNKNOWN
      ;;
    esac
    ;;
*)
    print_usage
    exit $STATE_UNKNOWN
esac

example 1

echo "STATE_OK - PING = 2ms & LOST = 0 packets | ping=2;50;100;; lost=0;5;10;;"

the output looks like this:

example 2

echo "STATE_OK - $(date) | z=0.$f"

the output looks like this:

thanks

thanks to Issif and hufman from shinken#irc.freenode.org for explaining me the concept behind custom perfdata generation as shown in the examples!

links