[check_postgres] [commit] Basic i18n support.
check_postgres at bucardo.org
check_postgres at bucardo.org
Sun Feb 15 22:36:30 UTC 2009
Committed by Greg Sabino Mullane <greg at endpoint.com>
Basic i18n support.
---
check_postgres.pl | 104 +++++++++++++++++++++++++++++++++++------------
check_postgres.pl.html | 27 +++++++++++-
index.html | 8 ++--
3 files changed, 105 insertions(+), 34 deletions(-)
diff --git a/check_postgres.pl b/check_postgres.pl
index 0d5d431..378b335 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -65,7 +65,7 @@ our $YELLNAME = 1;
## Nothing below this line should need to be changed for normal usage.
## If you do find yourself needing to change something,
-## please email the author as it probably indicates something
+## please email the author as it probably indicates something
## that could be made into a command-line option or moved above.
## Messages are stored in these until the final output via finishup()
@@ -239,6 +239,43 @@ for (sort keys %$action_info) {
$action_usage .= sprintf " %-*s - %s\n", 2+$longname, $_, $action_info->{$_}[1];
}
+## Standard messages. Translations always welcome
+
+our %msg = (
+ 'en' => {
+ 'T-EXCLUDE-DB' => 'No matching databases found due to exclusion/inclusion options',
+ 'T-EXCLUDE-FS' => 'No matching file systems found due to exclusion/inclusion options',
+ 'T-EXCLUDE-REL' => 'No matching relations found due to exclusion/inclusion options',
+ 'T-EXCLUDE-SET' => 'No matching settings found due to exclusion/inclusion options',
+ 'T-EXCLUDE-TABLE' => 'No matching tables found due to exclusion/inclusion options',
+ 'T-EXCLUDE-USEROK' => 'No matching entries found due to user exclusion/inclusion options',
+ 'T-BAD-QUERY' => 'Invalid query returned:',
+ 'invalid-psql' => 'Invalid psql argument: must be full path to a file named psql',
+ 'no-find-psql' => 'Cannot find given psql executable: $1',
+ 'no-time-hires' => q{Cannot find Time::HiRes, needed if 'showtime' is true},
+ 'no-psql' => q{Could not find a suitable psql executable},
+ 'no-psql-executable' => q{The file "$1" does not appear to be executable},
+ 'no-psql-version' => q{Could not determine psql version},
+ 'create-symlink' => q{Created "$1"},
+ 'symlink-exists' => q{Not creating "$1": $2 file already exists},
+ 'symlink-done' => qq{Not creating "\$1": \$2 already linked to "\$3"\n},
+ 'symlink-fail' => qq{Could not symlink \$1 to \$2: \$3\n},
+ 'no-target-database' => q{No target databases could be found},
+ },
+ 'de' => {
+ 'T-BAD-QUERY' => 'Invalid query returned:',
+ },
+ 'es' => {
+ 'T-BAD-QUERY' => 'Invalid query returned:',
+ },
+ 'fr' => {
+ 'T-BAD-QUERY' => 'Invalid query returned:',
+ },
+ );
+
+my $lang = $ENV{LC_ALL} || $ENV{LC_MESSAGES} || $ENV{LANG} || 'en';
+$lang = substr($lang,0,2);
+
if ($opt{help}) {
print qq{Usage: $ME2 <options>
Run various tests against one or more Postgres databases.
@@ -304,7 +341,7 @@ if ($opt{showtime}) {
import Time::HiRes qw/gettimeofday tv_interval sleep/;
};
if ($@) {
- die qq{Cannot find Time::HiRes, needed if 'showtime' is true\n};
+ die msg('no-time-hires');
}
}
@@ -317,6 +354,32 @@ sub ndie {
exit 3;
}
+sub msg {
+
+ my $name = shift || '?';
+
+ my $msg = '';
+
+ if (exists $msg{$lang}{$name}) {
+ $msg = $msg{$lang}{$name};
+ }
+ elsif (exists $msg{'en'}{$name}) {
+ $msg = $msg{'en'}{$name};
+ }
+ else {
+ return "Invalid message: $name";
+ }
+
+ my $x=1;
+ {
+ last unless $msg =~ s/\$$x/$_[$x-1]/ge;
+ $x++;
+ redo;
+ }
+ return $msg;
+
+} ## end of msg
+
## Everything from here on out needs psql, so find and verify a working version:
if ($NO_PSQL_OPTION) {
delete $opt{PSQL};
@@ -325,37 +388,23 @@ if ($NO_PSQL_OPTION) {
if (! defined $PSQL or ! length $PSQL) {
if (exists $opt{PSQL}) {
$PSQL = $opt{PSQL};
- $PSQL =~ m{^/[\w\d\/]*psql$} or ndie qq{Invalid psql argument: must be full path to a file named psql\n};
- -e $PSQL or ndie qq{Cannot find given psql executable: $PSQL\n};
+ $PSQL =~ m{^/[\w\d\/]*psql$} or ndie msg('invalid-psql');
+ -e $PSQL or ndie msg('no-find-psql', $PSQL);
}
else {
chomp($PSQL = qx{which psql});
- $PSQL or ndie qq{Could not find a suitable psql executable\n};
+ $PSQL or ndie msg('no-psql');
}
}
--x $PSQL or ndie qq{The file "$PSQL" does not appear to be executable\n};
+-x $PSQL or ndie msg('no-psql-executable', $PSQL);
$res = qx{$PSQL --version};
-$res =~ /^psql \(PostgreSQL\) (\d+\.\d+)/ or ndie qq{Could not determine psql version\n};
+$res =~ /^psql \(PostgreSQL\) (\d+\.\d+)/ or ndie msg('no-psql-version');
our $psql_version = $1;
$VERBOSE >= 1 and warn qq{psql=$PSQL version=$psql_version\n};
$opt{defaultdb} = $psql_version >= 7.4 ? 'postgres' : 'template1';
-## Standard messages. Use these whenever possible when building actions.
-
-our %template =
- (
- 'T-EXCLUDE-DB' => 'No matching databases found due to exclusion/inclusion options',
- 'T-EXCLUDE-FS' => 'No matching file systems found due to exclusion/inclusion options',
- 'T-EXCLUDE-REL' => 'No matching relations found due to exclusion/inclusion options',
- 'T-EXCLUDE-SET' => 'No matching settings found due to exclusion/inclusion options',
- 'T-EXCLUDE-TABLE' => 'No matching tables found due to exclusion/inclusion options',
- 'T-EXCLUDE-USEROK' => 'No matching entries found due to user exclusion/inclusion options',
- 'T-BAD-QUERY' => 'Invalid query returned:',
- );
-
-
sub add_response {
my ($type,$msg) = @_;
@@ -369,7 +418,7 @@ sub add_response {
if ($db->{perf}) {
$perf .= " $db->{perf}";
}
- $msg =~ s/(T-[\w\-]+)/$template{$1}/g;
+ $msg =~ s/(T-[\w\-]+)/msg($1)/ge;
push @{$type->{$header}} => [$msg,$perf];
}
@@ -765,22 +814,22 @@ sub build_symlinks {
if (-l $file) {
if (!$force) {
my $source = readlink $file;
- print qq{Not creating "$file":$space already linked to "$source"\n};
+ print msg('symlink-done', $file, $space, $source);
next;
}
print qq{Unlinking "$file":$space };
unlink $file or die qq{Failed to unlink "$file": $!\n};
}
elsif (-e $file) {
- print qq{Not creating "$file":$space file already exists\n};
+ print msg('symlink-exists', $file, $space);
next;
}
if (symlink $0, $file) {
- print qq{Created "$file"\n};
+ print msg('create-symlink', $file);
}
else {
- print qq{Could not symlink $file to $ME: $!\n};
+ print msg('symlink-fail', $file, $ME, $!);
}
}
@@ -1011,7 +1060,7 @@ sub run_command {
} ## end GROUP
if (! @target) {
- ndie qq{No target databases found\n};
+ ndie msg('no-target-database');
}
## Create a temp file to store our results
@@ -5238,6 +5287,7 @@ Items not specifically attributed are by Greg Sabino Mullane.
=item B<Version 2.8.0> (February ??, 2009)
Add the 'disabled_triggers' check.
+ Added basic internationalization support.
=item B<Version 2.7.3> (February 10, 2009)
diff --git a/check_postgres.pl.html b/check_postgres.pl.html
index 0e4304f..145d91c 100644
--- a/check_postgres.pl.html
+++ b/check_postgres.pl.html
@@ -43,6 +43,7 @@
<li><a href="#custom_query"><strong>custom_query</strong></a></li>
<li><a href="#database_size"><strong>database_size</strong></a></li>
<li><a href="#dbstats"><strong>dbstats</strong></a></li>
+ <li><a href="#disabled_triggers"><strong>disabled_triggers</strong></a></li>
<li><a href="#disk_space"><strong>disk_space</strong></a></li>
<li><a href="#fsm_pages"><strong>fsm_pages</strong></a></li>
<li><a href="#fsm_relations"><strong>fsm_relations</strong></a></li>
@@ -92,7 +93,7 @@
<hr />
<h1><a name="name">NAME</a></h1>
<p><strong>check_postgres.pl</strong> - a Postgres monitoring script for Nagios, MRTG, Cacti, and others</p>
-<p>This documents describes check_postgres.pl version 2.7.3</p>
+<p>This documents describes check_postgres.pl version 2.8.0</p>
<p>
</p>
<hr />
@@ -228,7 +229,7 @@ it defaults to 'postgres'.</p>
<dt><strong><a name="item__2d_2ddbpass_3dpassword"><strong>--dbpass=PASSWORD</strong></a></strong></dt>
<dd>
-<p>Provides the password to connect to the database with. Use of this option is highly discouraged.
+<p>Provides the password to connect to the database with. Use of this option is highly discouraged.
Instead, one should use a .pgpass file.</p>
</dd>
<dt><strong><a name="item__2d_2ddbservice_3dname"><strong>--dbservice=NAME</strong></a></strong></dt>
@@ -644,6 +645,19 @@ not available in those versions.</p>
check_postgres_dbstats --dbhost willow --dbname products</pre>
<p>
</p>
+<h2><a name="disabled_triggers"><strong>disabled_triggers</strong></a></h2>
+<p>(<code>symlink: check_postgres_disabled_triggers</code>) Checks on the number of disabled triggers inside the database.
+The <em>--warning</em> and <em>--critical</em> options are the number of such triggers found, and both
+default to "1", as in normal usage having disabled triggers is a dangerous event. If the
+database being checked is 8.3 or higher, the check is for the number of triggers that are
+in a 'disabled' status (as opposed to being 'always' or 'replica'). The output will show
+the name of the table and the name of the trigger for each disabled trigger.</p>
+<p>Example 1: Make sure that there are no disabled triggers</p>
+<pre>
+ check_postgres_disabled_triggers</pre>
+<p>For MRTG output, returns the number of disabled triggers on the first line.</p>
+<p>
+</p>
<h2><a name="disk_space"><strong>disk_space</strong></a></h2>
<p>(<code>symlink: check_postgres_disk_space</code>) Checks on the available physical disk space used by Postgres. This action requires
that you have the executable "/bin/df" available to report on disk sizes, and it
@@ -1235,6 +1249,13 @@ feature requests, and commit notices, send email to <a href="mailto:check_postgr
<h1><a name="history">HISTORY</a></h1>
<p>Items not specifically attributed are by Greg Sabino Mullane.</p>
<dl>
+<dt><strong><a name="item_0"><strong>Version 2.8.0</strong> (February ??, 2009)</a></strong></dt>
+
+<dd>
+<pre>
+ Add the 'disabled_triggers' check.
+ Added basic internationalization support.</pre>
+</dd>
<dt><strong><a name="item_3"><strong>Version 2.7.3</strong> (February 10, 2009)</a></strong></dt>
<dd>
@@ -1254,7 +1275,7 @@ feature requests, and commit notices, send email to <a href="mailto:check_postgr
<pre>
Allow the -p argument for port to work again.</pre>
</dd>
-<dt><strong><a name="item_0"><strong>Version 2.7.0</strong> (February 4, 2009)</a></strong></dt>
+<dt><strong><strong>Version 2.7.0</strong> (February 4, 2009)</strong></dt>
<dd>
<pre>
diff --git a/index.html b/index.html
index d525be5..8b981c6 100644
--- a/index.html
+++ b/index.html
@@ -21,14 +21,14 @@ h1 {
<h1>check_postgres.pl</h1>
-<p><b>check_postgres.pl</b> is a script for checking the state of one or more Postgres databases and reporting back in a Nagios-friendly manner. It was developed by Greg Sabino Mullane of <a href="http://www.endpoint.com/">End Point Corporation</a> and is BSD-licensed. The latest version is <b>2.7.3</b>, and was released on February 10, 2009.</p>
+<p><b>check_postgres.pl</b> is a script for checking the state of one or more Postgres databases and reporting back in a Nagios-friendly manner. It was developed by Greg Sabino Mullane of <a href="http://www.endpoint.com/">End Point Corporation</a> and is BSD-licensed. The latest version is <b>2.8.0</b>, and was released on February 15, 2009.</p>
<ul>
- <li><a href="/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.7.3</a></li>
+ <li><a href="/check_postgres/check_postgres.pl.html">Documentation for check_postgres 2.8.0</a></li>
</ul>
<ul>
- <li><a href="/check_postgres/check_postgres.pl">Download check_postgres.pl 2.7.3</a></li>
- <li><a href="/check_postgres/check_postgres.pl.asc">PGP signature for check_postgres.pl 2.7.3</a></li>
+ <li><a href="/check_postgres/check_postgres.pl">Download check_postgres.pl 2.8.0</a></li>
+ <li><a href="/check_postgres/check_postgres.pl.asc">PGP signature for check_postgres.pl 2.8.0</a></li>
</ul>
<p>The latest development version can be downloaded via git:</p>
--
1.6.0.5
More information about the Check_postgres
mailing list