-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_by_http_regexp_string.pl
65 lines (53 loc) · 1.14 KB
/
check_by_http_regexp_string.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
#!/usr/bin/perl -w
# icinga: -epn
# 0 url
# 1 match string
# 2 replace string
# 3 label
# 4 warning
# 5 critical
use strict;
use lib "/monitor/icinga/libexec";
use LWP::UserAgent;
use HTTP::Request;
use Time::HiRes qw(gettimeofday);
use range;
my $start;
my $time;
my $ret;
my $lwp = LWP::UserAgent->new(timeout => 30);
my $request = HTTP::Request->new(GET => $ARGV[0]);
$start = gettimeofday;
my $response = $lwp->request($request);
$time = gettimeofday-$start;
if ($response->is_success)
{
$ret = $response->content;
if ($ret =~ /$ARGV[1]/)
{
$ret =~ s/.*$ARGV[1].*/$ARGV[2]/seeg;
}
else
{
print "UNKNOWN: String <" . $ARGV[1] . "> not found\n";
exit(3);
}
}
else
{
print "UNKNOWN: " . $response->status_line . "\n";
exit(3);
}
if (range->check_range($ARGV[5],$time)) {
print "CRITICAL: $ARGV[3]=$ret/$ARGV[4]/$ARGV[5]|$ARGV[3]=$ret/$ARGV[4]/$ARGV[5]\n";
exit(2);
}
if (range->check_range($ARGV[4],$time)) {
print "WARNING: $ARGV[3]=$ret/$ARGV[4]/$ARGV[5]|$ARGV[3]=$ret/$ARGV[4]/$ARGV[5]\n";
exit(1);
}
$time=sprintf("%.3f",$time);
print "OK: $ARGV[3]=$time/$ARGV[4]/$ARGV[5]|$ret\n";
#print $end-$start;
#print "\n";
exit(0);