-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_dshield_infocon.pl
executable file
·88 lines (72 loc) · 1.99 KB
/
check_dshield_infocon.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
#!/usr/bin/perl -w
#-----------------------------------------------------------------------------
#Author: John Lowry <[email protected]>
#Date: August 4, 2011
#Version: 0.01
#Description: This is a nagios command for checking the status of the DSheild
#Infocon.
#License: GPLv3
#-----------------------------------------------------------------------------
use strict;
use Getopt::Long;
use REST::Client;
use lib "/usr/lib/nagios/plugins";
use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
use vars qw($opt_V $opt_h $PROGNAME $VERSION);
$PROGNAME = 'check_dshield_infoconf.pl';
$VERSION = '0.01';
sub print_help ();
sub print_usage ();
$ENV{'PATH'}='';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';
Getopt::Long::Configure('bundling');
GetOptions
("V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h);
if ($opt_V){
print_revision($PROGNAME, $VERSION);
exit $ERRORS{'OK'};
}
if ($opt_h){
print_help();
exit $ERRORS{'OK'};
}
my $client = REST::Client->new({
host => 'http://isc.sans.edu',
timeout => $TIMEOUT,
});
$client->GET('/api/infocon');
my $xpc=$client->responseXpath();
my $status=$xpc->find('/infocon/status');
#Remove a possible empty line
$status=~s/^\n//;
if ($status =~ m/green/i){
print "Infocon is: $status";
exit $ERRORS{'OK'};
}
elsif ($status =~ m/yellow|orange/i){
print "Infocon is: $status";
exit $ERRORS{'WARNING'};
}
elsif ($status =~ m/red/i){
print "Infocon is: $status";
exit $ERRORS{'CRITICAL'};
}
else{
print "Unkown error! Response: $status";
exit $ERRORS{'UNKNOWN'};
}
sub print_usage() {
print "Usage: $PROGNAME\n";
}
sub print_help() {
print_revision($PROGNAME, $VERSION);
print "Copyright (c) 2011 John Lowry.
This plugin reports the status of the DSheild Infocon.
Green will return \'OK\'
Yellow and Orange will return \'Warning\'
Red will return \'Critical\'\n\n";
print_usage();
support();
};