-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_isitdownrightnow
executable file
·156 lines (111 loc) · 3.56 KB
/
check_isitdownrightnow
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/perl
# check_isitdownrightnow.pl Copyright (C) 2014-2024 Bernd Arnold
#
# ...
#
#
# This program 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.
#
# This program 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 (or with Nagios); if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA
use strict;
use warnings;
require LWP::UserAgent;
use Getopt::Long;
# Sub routines
sub print_help();
#my $opt_host;
my $opt_help;
my $opt_site;
#, $opt_V);
#my ($result, $message, $age, $size, $st, $site);
my $answer = "";
my $crit_count = 0;
my $warn_count = 0;
my $status = "Unknown";
my @perfdata = ();
my @additional = ();
#
# Process command line options
#
GetOptions(
"s|site=s" => \$opt_site,
"h|help" => \$opt_help,
)
or do { print STDERR "Error in command line argument processing. Try '$0 -help'.\n"; exit 4; };
if ( $opt_help ) {
print_help();
exit 4; # Outside of the official monitoring plugin's exit codes
}
if ( ! $opt_site ) {
print STDERR "Error: option -site missing.\n";
exit 4;
}
if ( $opt_site !~ /^[-_0-9.A-Za-z]+$/ ) {
print STDERR "Error: Illegal characters in '$opt_site'!\n";
exit 4;
}
#
# Get status
#
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->agent('Mozilla/5.0');
# Check manually:
# curl 'http://www.isitdownrightnow.com/check.php?domain=google.com'
my $url = "https://www.isitdownrightnow.com/check.php?domain=$opt_site";
#print "<<$url>>\n";
my $response = $ua->get( $url );
if ( ! $response->is_success ) {
print "UNKNOWN: Could not fetch info from isitdownrightnow.\n";
exit 3; # UNKNOWN
}
# Sample result OK:
# <div class="tabletr" style="height:40px;"><span class="upicon">UP</span><div class="statusup">Google.com is UP and reachable by us.</div>Please check and report on local outages below ...</div>
# Sample result DOWN:
# #TODO
my $output = $response->content;
#print "Output: >> $output\n";
if ( $output =~ m{<span class="upicon">UP</span><div class="statusup">\S+ is UP and reachable by us\.</div>} ) {
print "OK: Site '$opt_site' is up and reachable according to isitdownrightnow.com. ";
# Get performance data
# <div class="tabletr"><span class="tab">2.23 ms.</span><b>Response Time:</b></div>
if ( $output =~ m{<span class="tab">([\d.]+ ms)\.</span><b>Response Time:</b>} ) {
my $perfdata = $1;
# Remove blank
$perfdata =~ s/ //g;
print "| response_time=$perfdata ";
}
print "\n";
exit 0; # OK
}
# Seems the site is down...
my ( $msg ) = $output =~ m{<div class="status\S+">(.*?)</div>};
print "WARNING: Site '$opt_site' seems to be down according to isitdownrightnow.com. Message: $msg.\n";
exit 1; # WARNING
# Should be never reached
exit 3; # UNKNOWN
#
# Print help
#
sub print_help () {
print STDERR <<~"END"
Check a website's status on isitdownrightnow.com
Usage: $0 [--site SITE]
Example: $0 --site google.com
Warning when site is not reported as UP
Parameters:
-h, --help Show this help text
-s, --site SITE The site that should be checked
END
}