blob: ac585852cf6798bed9a4891f3c81dca9062806b4 (
plain) (
blame)
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
|
#!/usr/bin/perl -w
#
# Copyright (c) 2004 IMG SRC, Inc. All rights reserved.
#
# $Id: check_pgcluster.pl,v 1.2 2004/02/25 06:09:25 kuriyama Exp $
#
# Plugin for nagios.
#
# Prepare pgr_current_replicator() function before using.
#
# % psql -U pgsql -d template1
# template1=# create function pgr_current_replicator () returns text as 'pgr_current_replicator' language internal with (isStrict);
# CREATE FUNCTION
# template1=#
#
# define command{
# command_name check_pgcluster
# command_line $USER1$/check_pgcluster -H $HOSTADDRESS$ -p $ARG1$ -w $ARG2$
# }
#
# define service{
# use generic-service
# host_name cluster1.example.org
# service_description PGCLUSTER
# check_command check_pgcluster!5432!replicator.example.org:8777
# }
use strict;
use Getopt::Std;
use DBI;
my %O;
getopts('H:p:U:P:w:', \%O);
$O{p} ||= 5432;
$O{U} ||= "";
$O{P} ||= "";
usage() if (not $O{H} or not $O{w});
my $dbh = DBI->connect("dbi:Pg:dbname=template1;host=$O{H};port=$O{p}", $O{U}, $O{P});
die if (not $dbh);
my $sth = $dbh->prepare("select pgr_current_replicator()") or die;
$sth->execute or die;
my @r = $sth->fetchrow_array;
$sth->finish;
$dbh->disconnect;
my $ret = 0;
if ($r[0] ne $O{w}) {
$ret = 1;
$ret = 2 if (length($r[0]) < 1);
}
my %STATUS = (2 => "CRITICAL", 1 => "WARNING", 0 => "OK");
printf "PGCLUSTER %s: %s\n", $STATUS{$ret}, $r[0];
exit $ret;
# ============================================================
sub usage {
print "Usage: check_pgcluster -H host [-p dbport] [-U dbuser] [-P dbpass] -w <primary replication server:port>\n";
exit(3);
}
|