#!/usr/bin/perl # SCM: @(#): $Id$ # # DESCRIPTION: # Nagios plugin to return perf data based on the startup time of Nagios # Requires Nagios 2.X and Altinity's patch for the MONITORINGSTARTTIME environment variable # # AUTHORS: # Copyright (C) 2007 Altinity Limited # # This file is part of Opsview # # Opsview 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. # # Opsview 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 Opsview; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # use warnings; use strict; sub nagios_exit { my ($val, $text) = @_; print $text,"\n"; exit $val; }; if (@ARGV && $ARGV[0] eq "-h") { print <<'EOF'; check_nagios_startup Returns the time taken between Nagios starting up and starting to monitor EOF exit 0; } my $monitoringstarttime = $ENV{NAGIOS_MONITORINGSTARTTIME} || nagios_exit( 2, "No NAGIOS_MONITORINGSTARTTIME environment variable found"); my $processstarttime = $ENV{NAGIOS_PROCESSSTARTTIME} || nagios_exit( 2, "No NAGIOS_PROCESSSTARTTIME environment variable found"); my $delay = $monitoringstarttime - $processstarttime; my $text; if ($delay == 1) { $text = "Nagios started up in 1 second"; } else { $text = "Nagios started up in $delay seconds"; } nagios_exit(0, "$text | delay=$delay");