Skip to content

Commit

Permalink
Re-insterted the -f option
Browse files Browse the repository at this point in the history
  • Loading branch information
matteocorti committed Feb 9, 2016
1 parent ef36697 commit c487f80
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 91 deletions.
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Matteo Corti <matteo.corti@id.ethz.ch>
Matteo Corti <matteo@corti.li>

* Thanks to cmies (?) who published a simple version of this script on
Nagios Exchange
Expand Down
6 changes: 5 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
2016-02-09 Matteo Corti <matteo@corti.li>

* Testing

2010-12-29 Matteo Corti <matteo.corti@id.ethz.ch>

* check_nagios_latency: added the -f option
* check_nagios_latency: cleanup

2007-11-28 Matteo Corti <matteo.corti@id.ethz.ch>

* check_nagios_latency: cleaned up using bashcritic
Expand Down
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ version_check:
clean:
rm -f *~

.PHONY: install clean
test:
( cd test && ./unit_tests.sh )

# File version information:
# $Id: AUTHORS 1103 2009-12-07 07:49:19Z corti $
# $Revision: 1103 $
# $HeadURL: https://svn.id.ethz.ch/nagios_plugins/check_updates/AUTHORS $
# $Date: 2009-12-07 08:49:19 +0100 (Mon, 07 Dec 2009) $
.PHONY: install clean test
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2016-02-09 1.0.1: code cleanup
2010-12-29 1.0.0: added the -f command line option
2007-11-28 0.9.3: added -n path (see README)
2007-09-20 0.9.2: initial beta release
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
153 changes: 77 additions & 76 deletions check_nagios_latency
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@
# Checks the Nagios latency
#
# Copyright (c) 2007-2010 ETH Zurich.
# Copyright (c) 2007-2016 Matteo Corti
#
# This module is free software; you can redistribute it and/or modify it
# under the terms of GNU general public license (gpl) version 3.
# See the LICENSE file for details.
#
# RCS information
# enable substitution with:
# $ svn propset svn:keywords "Id Revision HeadURL Source Date"
#
# $Id: check_ssl_cert 1212 2010-12-16 06:08:19Z corti $
# $Revision: 1212 $
# $HeadURL: https://svn.id.ethz.ch/nagios_plugins/check_ssl_cert/check_ssl_cert $
# $Date: 2010-12-16 07:08:19 +0100 (Thu, 16 Dec 2010) $

################################################################################
# Constants

VERSION=1.0.0
VERSION=1.0.1
SHORTNAME="LATENCY"

################################################################################
Expand All @@ -49,7 +42,7 @@ usage() {
echo " -w warning threshold"
echo " -V version"
echo
echo "Report bugs to: Matteo Corti <matteo.corti@id.ethz.ch>"
echo "Report bugs to: Matteo Corti <matteo@corti.li> or on https://github.com/matteocorti/check_nagios_latency/issues"
echo

exit 3
Expand All @@ -63,7 +56,7 @@ usage() {
check_prog() {

if [ -z "$PROG" ] ; then
PROG=$(command -v $1)
PROG=$(command -v "$1")
fi

if [ -z "$PROG" ] ; then
Expand All @@ -78,85 +71,93 @@ check_prog() {

}

################################################################################
# Main
################################################################################
main() {

# initialize local variable (ovverride external definitions)
CONFIG=
CRITICAL=
PROG=
VERBOSE=
WARNING=

# process command line options
while getopts "vh?Vc:w:n:f:" opt; do
case $opt in
c ) CRITICAL=$OPTARG; ;;
f ) CONFIG=$OPTARG; ;;
h | \? ) usage ; exit 3; ;;
n ) PROG=$OPTARG ;;
V ) echo "check_nagios_latency version ${VERSION}"; exit 3; ;;
v ) VERBOSE=1; ;;
w ) WARNING=$OPTARG; ;;
esac
done
shift $(($OPTIND - 1))
################################################################################
# Main
################################################################################

# initialize local variable (ovverride external definitions)
CRITICAL=
PROG=
VERBOSE=
WARNING=

# process command line options
while getopts "vh?Vc:w:n:f:" opt; do
case $opt in
c ) CRITICAL=$OPTARG; ;;
f ) CFG=$OPTARG; ;;
h | \? ) usage ; exit 3; ;;
n ) PROG=$OPTARG ;;
V ) echo "check_nagios_latency version ${VERSION}"; exit 3; ;;
v ) VERBOSE=1; ;;
w ) WARNING=$OPTARG; ;;
esac
done
shift $((OPTIND - 1))

################################################################################
# sanity checks

###############
# Check options
if [ -z "${CRITICAL}" ] ; then
usage "No critical threshold specified"
fi
if [ -z "${WARNING}" ] ; then
usage "No warning threshold specified"
fi

################################################################################
# sanity checks
######################
# Check number formats

###############
# Check options
if [ -z "${CRITICAL}" ] ; then
usage "No critical threshold specified"
fi
if [ -z "${WARNING}" ] ; then
usage "No warning threshold specified"
fi
if ! echo "$WARNING" | grep -qE '^[0-9]+(\.[0-9]+)?$' ; then
echo "${SHORTNAME} UNKOWN - Wrong number: $WARNING"
exit 3
fi

if ! echo "$CRITICAL" | grep -qE '^[0-9]+(\.[0-9]+)?$' ; then
echo "${SHORTNAME} UNKOWN - Wrong number: $WARNING"
exit 3
fi

######################
# Check number formats
#######################
# Check needed programs

if ! echo $WARNING | grep -qE '^[0-9]+(\.[0-9]+)?$' ; then
echo "${SHORTNAME} UNKOWN - Wrong number: $WARNING"
exit 3
fi
check_prog nagiostats

if ! echo $CRITICAL | grep -qE '^[0-9]+(\.[0-9]+)?$' ; then
echo "${SHORTNAME} UNKOWN - Wrong number: $WARNING"
exit 3
fi
test -n "$CFG" && PROG="$PROG -c $CFG"

#######################
# Check needed programs
# Check the latency

check_prog nagiostats
LATENCY=$($PROG | grep "Active Service Latency" |cut -f3 -d'/' | awk '{print $1}' | tr -d '\n');

test -n "$CFG" && PROG="$PROG -c $CFG"
if [ -n "${VERBOSE}" ] ; then echo "latency: ${LATENCY}"; fi

# Check the latency
####################
# Perform the checks

LATENCY=$($PROG | grep "Active Service Latency" |cut -f3 -d'/' | awk '{print $1}' | tr -d '\n');
PERF="Latency=${LATENCY};${WARNING};${CRITICAL};;"

if [ -n "${VERBOSE}" ] ; then echo "latency: ${LATENCY}"; fi
COMPARISON=$(echo "if($LATENCY>$CRITICAL) 1 else 0;" | bc)
if [ "$COMPARISON" -eq 1 ] ; then
echo "${SHORTNAME} CRITICAL ${LATENCY}s | $PERF"
exit 2
fi

####################
# Perform the checks
COMPARISON=$(echo "if($LATENCY>$WARNING) 1 else 0;" | bc)
if [ "$COMPARISON" -eq 1 ] ; then
echo "${SHORTNAME} WARNING ${LATENCY}s | $PERF"
exit 1
fi

PERF="Latency=${LATENCY};${WARNING};${CRITICAL};;"
echo "${SHORTNAME} OK ${LATENCY}s| $PERF"

exit 0;

COMPARISON=$(echo "if($LATENCY>$CRITICAL) 1 else 0;" | bc)
if [ $COMPARISON -eq 1 ] ; then
echo "${SHORTNAME} CRITICAL ${LATENCY}s | $PERF"
exit 2
fi
}

COMPARISON=$(echo "if($LATENCY>$WARNING) 1 else 0;" | bc)
if [ $COMPARISON -eq 1 ] ; then
echo "${SHORTNAME} WARNING ${LATENCY}s | $PERF"
exit 1
if [ -z "${SOURCE_ONLY}" ]; then
main "${@}"
fi

echo "${SHORTNAME} OK ${LATENCY}s| $PERF"
exit 0;
7 changes: 2 additions & 5 deletions check_nagios_latency.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" Process this file with
.\" groff -man -Tascii foo.1
.\"
.TH "check_nagios_latency" 1 "October, 2010" "1.0.0" "USER COMMANDS"
.TH "check_nagios_latency" 9 "February, 2016" "1.0.1" "USER COMMANDS"
.SH NAME
check_nagios_latency \- checks the latency of the Nagios server
.SH SYNOPSIS
Expand All @@ -21,9 +21,6 @@ warning threshold
.BR "-h,-?"
help message
.TP
.BR "-f" " path"
Nagios config file path
.TP
.BR "-n" " path"
nagiostats path
.TP
Expand All @@ -38,6 +35,6 @@ check_nagios_latency returns a zero exist status if it finds no errors, 1 for wa
Please report bugs to: Matteo Corti (matteo.corti (at) id.ethz.ch)

.SH AUTHOR
Matteo Corti (matteo.corti (at) id.ethz.ch)
Matteo Corti (matteo (at) corti.li )
See the AUTHORS file for the complete list of contributors

5 changes: 4 additions & 1 deletion check_nagios_latency.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%define version 1.0.0
%define version 1.0.1
%define release 0
%define sourcename check_nagios_latency
%define packagename nagios-plugins-check_nagios_latency
Expand Down Expand Up @@ -42,6 +42,9 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/%{sourcename}.1*

%changelog
* Wed Dec 29 2010 Matteo Corti <matteo.corti@id.ethz.ch> - 1.0.1-0
- updated to 1.0.1

* Wed Dec 29 2010 Matteo Corti <matteo.corti@id.ethz.ch> - 1.0.0-0
- added the -f option

Expand Down

0 comments on commit c487f80

Please sign in to comment.