From c3631f0a253e2ef082bbebae4ede3eb94baa2e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3mas=20Edwardsson?= Date: Thu, 8 Apr 2010 15:29:41 +0000 Subject: [PATCH] Sett inn windows dfs --- check_squid/trunk/check_squid.pl | 4 +- .../trunk/check_windows_dfs.pl | 122 ++++++++++++++++++ 2 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 check_windows_dfs.pl/trunk/check_windows_dfs.pl diff --git a/check_squid/trunk/check_squid.pl b/check_squid/trunk/check_squid.pl index 79ea5a8..81d7d8a 100644 --- a/check_squid/trunk/check_squid.pl +++ b/check_squid/trunk/check_squid.pl @@ -22,7 +22,7 @@ use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); use LWP::UserAgent; use HTTP::Request::Common qw(POST GET); use HTTP::Headers; -use Time::HiRes; +use Time::HiRes qw(gettimeofday tv_interval); my ($url, $urluser, $urlpass, $proxy, $proxyport, $proxyuser, $proxypass, $expectstatus, $res, $req); @@ -99,7 +99,7 @@ my $elapsed = tv_interval ( $t0 ); if ($res->status_line =~ /^$expectstatus/) { - print "OK - Status: ".$res->status_line. " | 'response'=$elapsed\n"; + printf( "OK - Status: %s | 'response_time'=%ss\n", $res->status_line, $elapsed); exit $ERRORS{"OK"}; } else diff --git a/check_windows_dfs.pl/trunk/check_windows_dfs.pl b/check_windows_dfs.pl/trunk/check_windows_dfs.pl new file mode 100644 index 0000000..42ca4be --- /dev/null +++ b/check_windows_dfs.pl/trunk/check_windows_dfs.pl @@ -0,0 +1,122 @@ +#!/usr/bin/perl -w +# +# Copyright 2010, Tomas Edwardsson +# +# check_windows_dfs.pl 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 3 of the License, or +# (at your option) any later version. +# +# windows_dfs.pl 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, see . + +use Nagios::Plugin; +use strict; + + +# PATH to check_nrpe +my $nrpepath = '/nagios/libexec/check_nrpe'; + + +# Create the Nagios plugin object +my $np = Nagios::Plugin->new( + usage => "Usage: %s -H -c ", + version => "0.01", +); + + +# Add valid arguments +$np->add_arg( + spec => 'hostname|H=s', + help => '-H, --hostname=', + required => 1, +); + +$np->add_arg( + spec => 'longserviceoutput|l', + help => '-l, --longserviceoutput', + default => undef, + required => 0, +); + +# Parse Arguments +$np->getopts(); + + + +open NRPE, $nrpepath . " -H " . $np->opts->hostname . " -c get_dfsdiag_testdcs|" or + nagios_exit(UNKNOWN, "Unable to execute NRPE: $!"); + + + +# Result +my @results = (); + +# First line, for NRPE run problems +my $first_line = ''; + +# Loop through each installed sensor +while (my $line = ) { + print "NRPE Output: $line" if ($np->opts->verbose); +#NRPE Output: DFSDIAG_INFO - APPL - DFS Service on SMSADL5 is OK. + + $line =~ s/[\n\r]//g; + $line =~ s/[\.,]$//g; + $first_line = $line if (!$first_line); + if ($line =~ /^\s*DFSDIAG_(\S+) - (.*) - (.*)$/) { + next if ($1 eq 'ERROR' and $3 eq 'Access is denied'); + push @results, { "state" => $1, "source" => $2, "message" => $3 }; + } +} + +close NRPE; +my $err = $!; +my $exit_code = $? >> 8; + +if ($exit_code) { + $np->nagios_exit(UNKNOWN, "Unable to run nrpe: $first_line"); +} + +# ANY Problems ? +my $ok = 1; +foreach my $m (@results) { + $ok = 0 if ($m->{state} ne "INFO"); +} + +if ($ok) { + $np->add_message("OK", "DFS tests successfull"); +} elsif ($np->opts->longserviceoutput) { + $np->add_message("OK", "DFS some tests unsuccessfull"); +} + +# Hack for multiline status output +#$np->add_message( "OK", "" ) if ($np->opts->longserviceoutput); + +foreach my $m (@results) { + if ($m->{state} eq 'INFO') { + if ($np->opts->longserviceoutput) { + $np->add_message( "OK", "$m->{state} - $m->{source} - $m->{message}" ); + } + } elsif ($m->{state} eq 'WARNING') { + $np->add_message( "WARNING", "$m->{state} - $m->{source} - $m->{message}" ); + } elsif ($m->{state} eq 'ERROR') { + $np->add_message( "CRITICAL", "$m->{state} - $m->{source} - $m->{message}" ); + } else { + $np->add_message( "UNKNOWN", "state " . $m->{state} . " is unkown ? " . $m->{message} ); + } +} + + + +# Process messages and get return code +my ($code, $message) = $np->check_messages("join" => ($np->opts->longserviceoutput ? "\n" : " - "), "join_all" => $np->opts->longserviceoutput); + +# We're done, return exit code, message and perfdata +$np->nagios_exit( $code, $message ); + +