Imported Upstream version 1.4.16_pre1

This commit is contained in:
Jan Wagner 2013-11-26 23:58:53 +01:00
parent 047baae1ca
commit 212b4b8677
69 changed files with 10803 additions and 2698 deletions

View file

@ -1,8 +1,8 @@
# Makefile.in generated by automake 1.10 from Makefile.am.
# Makefile.in generated by automake 1.10.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

View file

@ -67,7 +67,7 @@ my $host = $1 if ($opt_H =~ /^([-_.A-Za-z0-9 ]+\$?)$/);
($host) || usage("Invalid host: $opt_H\n");
($opt_s) || ($opt_s = shift @ARGV) || usage("Share volume not specified\n");
my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9]+\$?)$/);
my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9 ]+\$?)$/);
($share) || usage("Invalid share: $opt_s\n");
defined($opt_u) || ($opt_u = shift @ARGV) || ($opt_u = "guest");
@ -239,7 +239,7 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
$answer = "Result from smbclient not suitable\n";
$state = "UNKNOWN";
foreach (@lines) {
if (/(Access denied|NT_STATUS_LOGON_FAILURE)/) {
if (/(Access denied|NT_STATUS_LOGON_FAILURE|NT_STATUS_ACCESS_DENIED)/) {
$answer = "Access Denied\n";
$state = "CRITICAL";
last;

View file

@ -10,7 +10,7 @@ REVISION="@NP_VERSION@"
print_usage() {
echo "Usage: $PROGNAME"
echo "Usage: $PROGNAME" [--ignore-fault]
}
print_help() {
@ -21,25 +21,25 @@ print_help() {
echo "This plugin checks hardware status using the lm_sensors package."
echo ""
support
exit 0
exit $STATE_OK
}
case "$1" in
--help)
print_help
exit 0
exit $STATE_OK
;;
-h)
print_help
exit 0
exit $STATE_OK
;;
--version)
print_revision $PROGNAME $REVISION
exit 0
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-V)
print_revision $PROGNAME $REVISION
exit 0
exit $STATE_OK
;;
*)
sensordata=`sensors 2>&1`
@ -49,17 +49,20 @@ case "$1" in
fi
if test ${status} -eq 127; then
echo "SENSORS UNKNOWN - command not found (did you install lmsensors?)"
exit -1
elif test ${status} -ne 0 ; then
exit $STATE_UNKNOWN
elif test ${status} -ne 0; then
echo "WARNING - sensors returned state $status"
exit 1
exit $STATE_WARNING
fi
if echo ${sensordata} | egrep ALARM > /dev/null; then
echo SENSOR CRITICAL - Sensor alarm detected!
exit 2
else
echo sensor ok
exit 0
exit $STATE_CRITICAL
elif echo ${sensordata} | egrep FAULT > /dev/null \
&& test "$1" != "-i" -a "$1" != "--ignore-fault"; then
echo SENSOR UNKNOWN - Sensor reported fault
exit $STATE_UNKNOWN
fi
echo sensor ok
exit $STATE_OK
;;
esac

View file

@ -0,0 +1,96 @@
#! /usr/bin/perl -w -I ..
#
# test cases for check_disk_smb
#
use strict;
use Test::More;
use NPTest;
my $tests = 14;
plan tests => $tests;
my $res;
my $plugin = "check_disk_smb";
SKIP: {
skip "$plugin is not created", $tests if ( ! -x $plugin );
my $auth = "";
my $host = getTestParameter("NP_HOST_SMB", "A host providing an SMB Service",
"localhost");
my $smb_share = getTestParameter("NP_SMB_SHARE",
"An SMB share name the host provides",
"public");
my $smb_share_spc = getTestParameter("NP_SMB_SHARE_SPC",
"An SMB share name containing one or more spaces the host provides",
"pub lic");
my $smb_share_deny = getTestParameter("NP_SMB_SHARE_DENY",
"An access denying SMB share name the host provides",
"private");
my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
"The hostname of system not responsive to network requests", "10.0.0.1" );
my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
"An invalid (not known to DNS) hostname",
"nosuchhost" );
my $user = getTestParameter( "NP_SMB_VALID_USER", "A valid smb user", "" );
my $pass = getTestParameter( "NP_SMB_VALID_USER_PASS", "A valid password for valid smb user", "" );
$auth .= "-u $user " if ($user);
$auth .= "-p $pass " if ($pass);
$res = NPTest->testCmd( "./$plugin" );
is( $res->return_code, 3, "No arguments" );
$res = NPTest->testCmd( "./$plugin -H fakehostname" );
is( $res->return_code, 3, "No share specified" );
$res = NPTest->testCmd( "./$plugin -H fakehostname -s share -w 100G -c 101G" );
is( $res->return_code, 3, "warn is less than critical" );
SKIP: {
skip "no smb host defined", 6 if ( ! $host );
SKIP: {
skip "no share name defined", 2 if ( ! $smb_share );
$res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 2k -c 1k" );
cmp_ok( $res->return_code, '==', 0, "Exit OK if $smb_share has > 1k free space");
like($res->output, '/free/i', "String contains the word 'free'");
$res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 10001G -c 10000G" );
cmp_ok( $res->return_code, '==', 2, "Exit CRIT if $smb_share has < 10000G free space");
like($res->output, '/free/i', "String contains the word 'free'");
$res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 10000G -c 1k" );
cmp_ok( $res->return_code, '==', 1, "Exit WARN if $smb_share has > 10000G and <1k free space");
like($res->output, '/free/i', "String contains the word 'free'");
}
SKIP: {
skip "no share name containing spaces defined", 2 if ( ! $smb_share_spc );
$res = NPTest->testCmd( "./$plugin -H $host $auth -s '$smb_share_spc' -w 2k -c 1k" );
cmp_ok( $res->return_code, '==', 0, "Exit OK if '$smb_share_spc' has > 1k free space");
like($res->output, '/free/i', "String contains the word 'free'");
}
SKIP: {
skip "no share name without permissions ", 2 if ( ! $smb_share_deny );
$res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share_deny -w 2k -c 1k" );
cmp_ok( $res->return_code, '==', 2, "Exit CRIT if $smb_share_deny has > 1k free space");
unlike($res->output, '/free/i', "String does not contain the word 'free'");
}
}
SKIP: {
skip "no non responsive host defined", 1 if ( ! $host_nonresponsive );
$res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -s np_foobar ");
cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
}
}

View file

@ -21,3 +21,88 @@ support() {
$ECHO "@SUPPORT@" | sed -e 's/\n/ /g'
}
#
# check_range takes a value and a range string, returning successfully if an
# alert should be raised based on the range.
#
check_range() {
local v range yes no err decimal start end cmp match
v="$1"
range="$2"
# whether to raise an alert or not
yes=0
no=1
err=2
# regex to match a decimal number
decimal="-?([0-9]+\.?[0-9]*|[0-9]*\.[0-9]+)"
# compare numbers (including decimals), returning true/false
cmp() { awk "BEGIN{ if ($1) exit(0); exit(1)}"; }
# returns successfully if the string in the first argument matches the
# regex in the second
match() { echo "$1" | grep -E -q -- "$2"; }
# make sure value is valid
if ! match "$v" "^$decimal$"; then
echo "${0##*/}: check_range: invalid value" >&2
unset -f cmp match
return "$err"
fi
# make sure range is valid
if ! match "$range" "^@?(~|$decimal)(:($decimal)?)?$"; then
echo "${0##*/}: check_range: invalid range" >&2
unset -f cmp match
return "$err"
fi
# check for leading @ char, which negates the range
if match $range '^@'; then
range=${range#@}
yes=1
no=0
fi
# parse the range string
if ! match "$range" ':'; then
start=0
end="$range"
else
start="${range%%:*}"
end="${range#*:}"
fi
# do the comparison, taking positive ("") and negative infinity ("~")
# into account
if [ "$start" != "~" ] && [ "$end" != "" ]; then
if cmp "$start <= $v" && cmp "$v <= $end"; then
unset -f cmp match
return "$no"
else
unset -f cmp match
return "$yes"
fi
elif [ "$start" != "~" ] && [ "$end" = "" ]; then
if cmp "$start <= $v"; then
unset -f cmp match
return "$no"
else
unset -f cmp match
return "$yes"
fi
elif [ "$start" = "~" ] && [ "$end" != "" ]; then
if cmp "$v <= $end"; then
unset -f cmp match
return "$no"
else
unset -f cmp match
return "$yes"
fi
else
unset -f cmp match
return "$no"
fi
}