#! /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'}; }