From: Joey Schulze Date: Sat, 3 May 2014 19:18:34 +0000 (+0200) Subject: Add ticker check X-Git-Url: https://git.infodrom.org/?p=infodrom%2Ficinga-plugins;a=commitdiff_plain;h=d230193dcee31a411627ee74eed6642374ad55e1 Add ticker check --- diff --git a/check_ticker b/check_ticker new file mode 100755 index 0000000..844bb1e --- /dev/null +++ b/check_ticker @@ -0,0 +1,103 @@ +#! /usr/bin/perl -w + +# Copyright (c) 2014 Joey Schulze +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA + +use strict; +use Getopt::Long; +use lib '/usr/lib/nagios/plugins'; +use utils qw(%ERRORS); +use POSIX qw(strftime); + +my $config = { + 'host' => undef, + 'warn' => 24, + 'crit' => 72, + +}; + +my $ticker; +Getopt::Long::Configure('no_ignore_case'); +GetOptions + 'ticker=s' => \$ticker, + 'warn=s' => \$config->{warn}, + 'crit=s' => \$config->{crit}, + 'help' => \&print_help; + +sub print_help +{ + print<{crit} * 60*60)) { + printf "TICKER CRITICAL - %s older than %d hours\n", $fname, $config->{crit}; + exit $ERRORS{'CRITICAL'}; + } elsif ($mtime < time - ($config->{warn} * 60*60)) { + printf "TICKER WARNING - %s older than %d hours\n", $fname, $config->{warn}; + exit $ERRORS{'WARNING'}; + } + + my $diff = (time - $mtime) / 60; + my $time = $diff % 60; + if ($diff > 60) { + $time = sprintf('%d:%02d hours', $diff / 60, $time); + } else { + $time .= ' minutes'; + } + + printf "TICKER OK - %s updated %s ago\n", $ticker, $time; + exit $ERRORS{'OK'}; +} else { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + my $monthstart = time - ($mday-1) * 60*60*24 - $hour*60*60 - $min*60 - $sec; + + if (time > $monthstart + ($config->{crit} * 60*60)) { + printf "TICKER CRITICAL - %s not updated for %d hours\n", $ticker, $config->{crit}; + exit $ERRORS{'CRITICAL'}; + } elsif (time > $monthstart + ($config->{warn} * 60*60)) { + printf "TICKER WARNING - %s not updated for %d hours\n", $ticker, $config->{warn}; + exit $ERRORS{'WARNING'}; + } + + my $diff = (time - $monthstart) / 60; + my $time = $diff % 60; + if ($diff > 60) { + $time = sprintf('%d:%02d', $diff / 60, $time); + } else { + $time .= ' minutes'; + } + + printf "TICKER OK - %s not updated for %s\n", $ticker, $time; + exit $ERRORS{'OK'}; +} +