-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_by_sql_with_range.pl
71 lines (54 loc) · 1.29 KB
/
check_by_sql_with_range.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
#!/usr/bin/perl -w
use strict;
use lib "/monitor/icinga/libexec/lib/perl";
use lib "/monitor/icinga/libexec";
use range;
use DBI;
# 0 - database
# 1 - username
# 2 - password
# 3 - sql file path
# 4 - description
open(INFILE,"<$ARGV[3]");
my @sql = <INFILE>;
close(INFILE);
my $dbh = DBI->connect("DBI:Oracle:" . $ARGV[0],$ARGV[1],$ARGV[2],{PrintError=>0});
if (!$dbh) {
print "Can't connect to database: " . DBI->errstr . "\n";
exit(3);
}
my ($d,$m,$y) = (localtime)[3,4,5];
$y = $y + 1900;
$m = $m + 1;
my $sqlstr = join('',@sql);
$sqlstr =~ s/\{DD\}/sprintf("%02d",$d)/ge;
$sqlstr =~ s/\{MM\}/sprintf("%02d",$m)/ge;
$sqlstr =~ s/\{YYYY\}/sprintf("%04d",$y)/ge;
my $dbs = $dbh->prepare($sqlstr);
if (!$dbs) {
print "Can't prepare statement: " . $dbh->errstr . "\n";
exit(3);
}
my $dbe = $dbs->execute();
if (!$dbe) {
print "Can't execute statement: " . $dbh->errstr . "\n";
exit(3);
}
my($ret, $w, $c);
$dbs->bind_columns(undef, \$w, \$c, \$ret);
if (!$dbs->fetch()) {
print "Fetch error\n";
exit(3);
}
$dbs->finish;
$dbh->disconnect;
if (range->check_range($c,$ret)) {
print "CRITICAL: $ret/$w/$c|$ARGV[4]=$ret/$w/$c\n";
exit(2);
}
if (range->check_range($w,$ret)) {
print "WARNING: $ret/$w/$c|$ARGV[4]=$ret/$w/$c\n";
exit(1);
}
print "OK: $ret/$w/$c|$ARGV[4]=$ret/$w/$c\n";
exit(0);