forked from HariSekhon/Templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-old-plugin.pl
executable file
·122 lines (102 loc) · 3.38 KB
/
template-old-plugin.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2008-10-19 14:18:51 +0100 (Sun, 19 Oct 2008)
#
# vim:ts=4:sts=4:sw=4:et
$main::VERSION = 0.1;
use strict;
use warnings;
use Benchmark::Timer;
use File::Basename;
use File::Temp "tempfile";
use FindBin;
use Getopt::Long qw(:config bundling);
use MIME::Lite;
use Pod::Usage;
use SMS::AQL;
use Sys::Hostname;
#use Time::Local;
use WWW::Shorten::TinyURL;
use lib "$FindBin::Bin";
use lib "/etc/nagios/plugins";
use lib "/usr/lib64/nagios/plugins";
use lib "/usr/lib/nagios/plugins";
use lib ".";
use utils qw(%ERRORS $TIMEOUT);
# go flock ur $self ;)
use Fcntl ':flock'; # import LOCK_* constants
INIT {
open *{0} or die "What!? $0:$!";
flock *{0}, LOCK_EX|LOCK_NB or die "$0 is already running somewhere!\n";
}
# Make %ENV safer (taken from PerlSec)
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
$ENV{'PATH'} = '/bin:/usr/bin';
my $progname = basename $0;
my $default_timeout = 10;
my $help;
my $timeout = $default_timeout;
my $verbose = 0;
my $version;
sub vlog{
print "@_\n" if $verbose;
}
sub quit{
print "$_[0]: $_[1]\n";
exit $ERRORS{$_[0]};
}
my $critical;
my $default_port = 80;
my $host;
my $port;
my $warning;
sub usage {
print "@_\n\n" if defined(@_);
print "usage: $progname [ options ]
-H --host Host to connect to
-p --port Port to connect to
-w --warning Warning threshold
-c --critical Critical threshold
-t --timeout Timeout in secs (default $default_timeout)
-v --verbose Verbose mode
-V --version Print version and exit
-h --help --usage Print this help
\n";
exit $ERRORS{"UNKNOWN"};
}
GetOptions (
"h|help|usage" => \$help,
"H|host=s" => \$host,
"p|port=s" => \$port,
"w|warning=i" => \$warning,
"c|critical=i" => \$critical,
"t|timeout=i" => \$timeout,
"v|verbose+" => \$verbose,
"V|version" => \$version,
# cannot use this while bundling though
# 't|tables=s{,}' => \@tables,
) or usage;
defined($help) and usage;
defined($version) and die "$progname version $main::VERSION\n";
vlog "verbose mode on";
defined($host) || usage "hostname not specified";
$host =~ /^([\w\.-]+)$/ || die "invalid hostname given\n";
$host = $1;
#defined($port) || usage "port not specified";
$port =~ /^(\d+)$/ || die "invalid port number given, must be a positive integer\n";
$port = $1;
($port >= 1 && $port <= 65535) || die "invalid port number given, must be between 1-65535)\n";
defined($warning) || usage "warning threshold not defined";
defined($critical) || usage "critical threshold not defined";
$warning =~ /^\d+$/ || usage "invalid warning threshold given, must be a positive numeric integer";
$critical =~ /^\d+$/ || usage "invalid critical threshold given, must be a positive numeric integer";
($critical >= $warning) || usage "critical threshold must be greater than or equal to the warning threshold";
$timeout =~ /^\d+$/ || die "timeout value must be a positive integer\n";
($timeout >= 1 && $timeout <= 60) || die "timeout value must be between 1 - 60 secs\n";
$SIG{ALRM} = sub {
quit "UNKNOWN", "check timed out after $timeout seconds";
};
vlog "setting plugin timeout to $timeout secs\n";
alarm($timeout);