summaryrefslogtreecommitdiff
path: root/databases/pgcluster/files/check_pgreplicate.pl
diff options
context:
space:
mode:
authorJun Kuriyama <kuriyama@FreeBSD.org>2004-02-25 13:47:27 +0000
committerJun Kuriyama <kuriyama@FreeBSD.org>2004-02-25 13:47:27 +0000
commitf18b1ceaea3d1b56ad15395efce4064344557ae9 (patch)
tree9b55689b9e8cf1d39f88654efc4ccfcea1eb2e30 /databases/pgcluster/files/check_pgreplicate.pl
parentUpdate to 0.11 (diff)
o Fix some bugs reported on ML.
o Fix more style bugs in debug message. o Add internal function to postmaster which returns current replication server. o Add new packet handler to pgreplicate which returns cluster node status information. o Add check scripts for nagios. These scripts may be useful, but not intended to officially supported by me. I'll make them as another port when they become stable.
Notes
Notes: svn path=/head/; revision=102097
Diffstat (limited to 'databases/pgcluster/files/check_pgreplicate.pl')
-rw-r--r--databases/pgcluster/files/check_pgreplicate.pl84
1 files changed, 84 insertions, 0 deletions
diff --git a/databases/pgcluster/files/check_pgreplicate.pl b/databases/pgcluster/files/check_pgreplicate.pl
new file mode 100644
index 000000000000..7451c3c27c8d
--- /dev/null
+++ b/databases/pgcluster/files/check_pgreplicate.pl
@@ -0,0 +1,84 @@
+#!/usr/bin/perl -w
+#
+# Copyright (c) 2004 IMG SRC, Inc. All rights reserved.
+#
+# $Id: check_pgreplicate.pl,v 1.1 2004/02/23 06:06:13 kuriyama Exp $
+#
+# Plugin for nagios.
+#
+# define command{
+# command_name check_pgreplicate
+# command_line $USER1$/check_pgreplicate -H $HOSTADDRESS$ -p $ARG1$ -w $ARG2$ -c $ARG3$
+# }
+#
+# # Declare cluster which has 2 pgcluster instances.
+# # Send a warning if usable pgcluster is under 2.
+# # Send a critical if usable pgcluster is under 1.
+# define service{
+# use generic-service
+# host_name replicator.example.org
+# service_description PGREPLICATE
+# check_command check_pgreplicate!8777!2!1
+# }
+
+use strict;
+use Getopt::Std;
+use IO::Socket::INET;
+
+my %O;
+getopts('H:p:w:c:v', \%O);
+
+my $w = $O{w};
+my $c = $O{c};
+usage() if (not $w or not $c);
+
+my $host = sprintf("%s:%d", $O{H} || "localhost", $O{p} || 8777);
+my $sock = IO::Socket::INET->new($host) or die "$!";
+
+my $HOSTNAME_MAX_LENGTH = 128;
+my $DBNAME_MAX_LENGTH = 128;
+my $USERNAME_MAX_LENGTH = 128;
+
+my $query = "dummy";
+my $packet = pack "CCCCllla128a128a128a128ll", 0, 0, 0, ord("o"),
+ 0, 0, 5, "except host", "from host", "db name", "user name",
+ time, 0;
+
+print $sock $packet;
+print $sock $query;
+
+my ($use, @Host, %tmp) = (0);
+while (<$sock>) {
+ chomp;
+ if ($_ eq "") {
+ push @Host, { %tmp };
+ $use++ if ($tmp{useFlag} == 2);
+ %tmp = ();
+ } else {
+ my ($var, $val) = split(/=/, $_, 2);
+ $tmp{$var} = $val;
+ }
+}
+close($sock);
+
+my $ret = 0;
+if ($use < $O{c}) {
+ $ret = 2;
+} elsif ($use < $O{w}) {
+ $ret = 1;
+}
+my %STATUS = (2 => "CRITICAL", 1 => "WARNING", 0 => "OK");
+printf "PGREPLICATE %s: %d hosts active\n", $STATUS{$ret}, $use;
+if ($O{v}) {
+ foreach (@Host) {
+ printf "%s:%d, useFlag=%d, recoveryPort=%d\n",
+ $_->{hostName}, $_->{port}, $_->{useFlag}, $_->{recoveryPort};
+ }
+}
+exit $ret;
+
+# ============================================================
+sub usage {
+ print "Usage: check_pgreplicate -H host -p port -w <warn> -c <crit> [-v]\n";
+ exit(3);
+}