Add --reverse option for custom_query actions.
authorGreg Sabino Mullane <greg@endpoint.com>
Tue, 3 Jun 2008 23:59:11 +0000 (19:59 -0400)
committerGreg Sabino Mullane <greg@endpoint.com>
Tue, 3 Jun 2008 23:59:11 +0000 (19:59 -0400)
Clean up the docs a bit.

check_postgres.pl
check_postgres.pl.asc
check_postgres.pl.html

index 17cc74bff0bc9a05394c8a9111d8cc9aacd232ed..36bb1c4a31b37092e18d83e4327975af1f2a1455 100755 (executable)
@@ -28,7 +28,7 @@ $Data::Dumper::Varname = 'POSTGRES';
 $Data::Dumper::Indent = 2;
 $Data::Dumper::Useqq = 1;
 
-our $VERSION = '1.7.1';
+our $VERSION = '1.8.0';
 
 use vars qw/ %opt $PSQL $res $COM $SQL $db /;
 
@@ -116,6 +116,7 @@ die $USAGE unless
                           'queryname=s', ## used by query_runtime only
                           'query=s',     ## used by custom_query only
                           'checktype=s', ## used by custom_query only
+                          'reverse',     ## used by custom_query only
                           'repinfo=s',   ## used by replicate_row only
                           )
        and keys %opt
@@ -2535,6 +2536,8 @@ sub check_custom_query {
 
        my $query = $opt{query} or ndie q{Must provide a query string};
 
+       my $reverse = $opt{reverse} || 0;
+
        my $info = run_command($query);
 
        for $db (@{$info->{db}}) {
@@ -2554,7 +2557,7 @@ sub check_custom_query {
                        if (length $critical) {
                                if (($valtype eq 'string' and $data eq $critical)
                                        or
-                                       ($data >= $critical)) { ## covers integer, time, size
+                                       ($reverse ? $data <= $critical : $data >= $critical)) { ## covers integer, time, size
                                        add_critical "$data";
                                        $gotmatch = 1;
                                }
@@ -2563,7 +2566,7 @@ sub check_custom_query {
                        if (length $warning and ! $gotmatch) {
                                if (($valtype eq 'string' and $data eq $warning)
                                        or
-                                       ($data >= $warning)) {
+                                       ($reverse ? $data <= $warning : $data >= $warning)) {
                                        add_warning "$data";
                                        $gotmatch = 1;
                                }
@@ -2702,7 +2705,7 @@ check_postgres.pl - Postgres monitoring script for Nagios
 
 =head1 VERSION
 
-This documents describes B<check_postgres.pl> version 1.7.1
+This documents describes B<check_postgres.pl> version 1.8.0
 
 =head1 SYNOPSIS
 
@@ -2747,7 +2750,7 @@ as a short description of the results. The exit codes are:
 
 =head1 DATABASE CONNECTION OPTIONS
 
-Almost all actions accept a common set of options, most dealing with connecting to the databases.
+All actions accept a common set of database options. At least one is required.
 
 =over 4
 
@@ -2759,18 +2762,18 @@ are allowed. If no host is given, defaults to a local Unix socket.
 =item B<-p PORT> or B<--port=PORT>
 
 Connects using the specified PORT number. Can be a comma-separated list of port numbers, and multiple 
-port arguments are allowed. If no port number is given, we default to port 5432.
+port arguments are allowed. If no port number is given, the default is 5432.
 
 =item B<-db NAME> or B<--dbname=NAME>
 
 Specifies which database to connect to. Can be a comma-separated list of names, and multiple dbname 
-arguments are allowed. If no dbname option is provided, defaults to 'postgres' if the psql 
-version is version 8 or greater, and 'template1' otherwise.
+arguments are allowed. If no dbname option is provided, defaults to 'postgres' if psql 
+is version 8 or greater, and 'template1' otherwise.
 
 =item B<-u USERNAME> or B<--dbuser=USERNAME>
 
 The name of the database user to connect as. Can be a comma-separated list of usernames, and multiple 
-dbuser arguments are allowed. If this is not provided, defaults to 'postgres'.
+dbuser arguments are allowed. If this is not provided, the default is 'postgres'.
 
 =item B<--dbpass=PASSWORD>
 
@@ -2779,15 +2782,14 @@ Instead, one should use a .pgpass file.
 
 =back
 
-Connection options can be grouped: --host=a,b --host=c --port=1234 --port=3344
+The database connection options can be grouped: --host=a,b --host=c --port=1234 --port=3344
 would connect to a-1234, b-1234, and c-3344. Note that once set, an option 
 carries over until it is changed again.
 
 Examples:
 
   --host=a,b --port=5433 --db=c
-  Connects twice to port 5433, using database c, to hosts a and b
-  a-5433-c b-5433-c
+  Connects twice to port 5433, using database c, to hosts a and b: a-5433-c b-5433-c
 
   --host=a,b --port=5433 --db=c,d
   Connects four times: a-5433-c a-5433-d b-5433-c b-5433-d
@@ -2800,23 +2802,24 @@ Examples:
 
 =head1 OTHER OPTIONS
 
-Other common options include:
+Other options include:
 
 =over 4
 
-=item B<--output=VAL>
+=item B<--action=NAME>
 
-Determines the format of the output, for use in various programs. The default is 'nagios'. No 
-other systems are supported yet.
+States what action we are running. Required unless using a symlinked file, 
+in which case the name of the file is used to figure out the action.
 
-=item B<PSQL=PATH>
+=item B<--warning=VAL or -w VAL>
 
-Tells the script where to find the psql program. Useful if you have more than 
-one version of the psql executable on your system, or if there is no psql program 
-in your path. Note that this option is in all uppercase. By default, this option 
-is I<not allowed>. To enable it, you must change the C<$NO_PSQL_OPTION> near the 
-top of the script to 0. Avoid using this option if you can, and instead hard-code 
-your psql location into the C<$PSQL> variable, also near the top of the script.
+Sets the threshold at which a warning alert is fired. The valid options for this 
+option depends on the action used.
+
+=item B<--critical=VAL or -c VAL>
+
+Sets the threshold at which a critical alert is fired. The valid options for this 
+option depends on the action used.
 
 =item B<-t VAL> or B<--timeout=VAL>
 
@@ -2838,19 +2841,15 @@ Set the verbosity level. Can call more than once to boost the level. Setting it
 or higher (in other words, issuing C<-v -v -v>) turns on debugging information for this 
 program which is sent to stderr.
 
-=item B<--test>
-
-Enables test mode. See the L</"TEST MODE"> section below.
-
 =item B<--showperf=VAL>
 
-Determines if we output performance data in standard Nagios format 
+Determines if we output additional performance data in standard Nagios format 
 (at end of string, after a pipe symbol, using name=value). 
 VAL should be 0 or 1. The default is 1.
 
 =item B<--perflimit=i>
 
-Sets a limit s to how many items of interest are reported back when using the 
+Sets a limit as to how many items of interest are reported back when using the 
 B<showperf> option. This only has an effect for actions that return a large 
 number of items, such as B<table_size>. The default is 0, or no limit. Be 
 careful when using this with the B<--include> or B<--exclude> options, as 
@@ -2862,10 +2861,27 @@ limit may not include the items you want.
 Determines if the time taken to run each query is shown in the output. VAL 
 should be 0 or 1. The default is 1. No effect unless B<showperf> is on.
 
-=item B<--action=NAME>
+=item B<--test>
 
-States what action we are running. Required unless using a symlinked file, 
-in which case the name of the file is used to figure out the action.
+Enables test mode. See the L</"TEST MODE"> section below.
+
+=item B<--PSQL=PATH>
+
+Tells the script where to find the psql program. Useful if you have more than 
+one version of the psql executable on your system, or if there is no psql program 
+in your path. Note that this option is in all uppercase. By default, this option 
+is I<not allowed>. To enable it, you must change the C<$NO_PSQL_OPTION> near the 
+top of the script to 0. Avoid using this option if you can, and instead hard-code 
+your psql location into the C<$PSQL> variable, also near the top of the script.
+
+=item B<--symlinks>
+
+Creates symlinks to the main program for each action.
+
+=item B<--output=VAL>
+
+Determines the format of the output, for use in various programs. The default is 'nagios'. No 
+other systems are supported yet.
 
 =back
 
@@ -3002,6 +3018,10 @@ The warning and the critical are sizes, and can have units of bytes, kilobytes,
 terabytes, or exabytes. Each may be abbreviated to the first letter. If no units are given, 
 bytes are assumed. The first column should be an integer representing the number of bytes to check.
 
+Normally, an alert is triggered if the values returned are B<greater than> or equal to the critical or warning 
+value. However, an option of B<--reverse> will trigger the alert if the returned value is 
+B<lower than> or equal to the critical or warning value.
+
 Example 1: Warn if any relation over 100 pages is named "rad":
 
   check_postgres_custom_query --checktype=string -w "rad" --query="SELECT relname FROM pg_class WHERE relpages > 100" --port=5432
@@ -3010,6 +3030,10 @@ Example 2: Give a critical if the "foobar" function returns over 5GB of bytes:
 
   check_postgres_custom_query --port=5432 --critical='5MB'--checktype=size --query="SELECT foobar()"
 
+Example 2: Warn if the function "snazzo" returns less than 42:
+
+  check_postgres_custom_query --port=5432 --critical=42 --query="SELECT snazzo()" --reverse
+
 If you come up with a useful custom_query, consider sending in a patch to this program 
 to make it into a standard action that other people can use.
 
@@ -3336,7 +3360,7 @@ Example 1: Give a warning if any connection has been idle in transaction for mor
 This action requires no other arguments, and does not connect to any databases, 
 but simply creates symlinks in the current directory for each action, in the form 
 B<check_postgres_E<lt>action_nameE<gt>>.
- If the file already exists, it will not be overwritten. If the action is rebuild_symlinks_force, 
+If the file already exists, it will not be overwritten. If the action is rebuild_symlinks_force, 
 then symlinks will be overwritten. The option --symlinks is a shorter way of saying 
 --action=rebuild_symlinks
 
@@ -3529,9 +3553,8 @@ Check all items except for those belonging to the user scott:
 To help in setting things up, this program can be run in a "test mode" by 
 specifying the B<--test> option. This will perform some basic tests to 
 make sure that the databases can be contacted, and that certain per-action 
-prerequisites are met. Currently, we check that the user is a superuser 
-if required by that action, and that the version of Postgres is new enough 
-for those actions that depend on a specific version.
+prerequisites are met, such as whether the user is a superuser, if the version 
+of Postgres is new enough, and if stats_row_level is on.
 
 =head1 DEPENDENCIES
 
@@ -3569,6 +3592,10 @@ Items not specifically attributed are by Greg Sabino Mullane.
 
 =over 4
 
+=item B<Version 1.8.0> (June 3, 2008)
+
+Add the --reverse option to the custom_query action.
+
 =item B<Version 1.7.1> (June 2, 2008)
 
 Fix query_time action: account for race condition in which zero rows appear in pg_stat_activity.
index d7c3579674a93d7d06aa67b07ef53237fc197339..97015144c218541e27209127cf3823f49dac943a 100644 (file)
@@ -1,6 +1,6 @@
 -----BEGIN PGP SIGNATURE-----
 
-iEYEABEDAAYFAkhEILoACgkQvJuQZxSWSsgewACfbEZ4sL+RqC10h4PNWfS7Ozjv
-XgMAn0pSqw1kO/CkIxouURof3Kbfqker
-=5aGH
+iEYEABEDAAYFAkhF2lMACgkQvJuQZxSWSsg3agCdEGFl7OfdMJ5Dpx7bIQ4fpbcM
+amkAnRT4rvQ3bqMsc5zozEG/CE8rMGQ6
+=3jdI
 -----END PGP SIGNATURE-----
index 0e5bb9cc3167d60a75884638d3f99b8a20625eed..82f4b0382f9a1118626b2d8528649824b3392642 100644 (file)
@@ -49,7 +49,7 @@
 </p>
 <hr />
 <h1><a name="version">VERSION</a></h1>
-<p>This documents describes <strong>check_postgres.pl</strong> version 1.7.1</p>
+<p>This documents describes <strong>check_postgres.pl</strong> version 1.8.0</p>
 <p>
 </p>
 <hr />
@@ -96,7 +96,7 @@ as a short description of the results. The exit codes are:</p>
 </p>
 <hr />
 <h1><a name="database_connection_options">DATABASE CONNECTION OPTIONS</a></h1>
-<p>Almost all actions accept a common set of options, most dealing with connecting to the databases.</p>
+<p>All actions accept a common set of database options. At least one is required.</p>
 <dl>
 <dt><strong><a name="h_name_or_host_name" class="item"><strong>-H NAME</strong> or <strong>--host=NAME</strong></a></strong>
 
@@ -109,22 +109,22 @@ are allowed. If no host is given, defaults to a local Unix socket.</p>
 
 <dd>
 <p>Connects using the specified PORT number. Can be a comma-separated list of port numbers, and multiple 
-port arguments are allowed. If no port number is given, we default to port 5432.</p>
+port arguments are allowed. If no port number is given, the default is 5432.</p>
 </dd>
 </li>
 <dt><strong><a name="db_name_or_dbname_name" class="item"><strong>-db NAME</strong> or <strong>--dbname=NAME</strong></a></strong>
 
 <dd>
 <p>Specifies which database to connect to. Can be a comma-separated list of names, and multiple dbname 
-arguments are allowed. If no dbname option is provided, defaults to 'postgres' if the psql 
-version is version 8 or greater, and 'template1' otherwise.</p>
+arguments are allowed. If no dbname option is provided, defaults to 'postgres' if psql 
+is version 8 or greater, and 'template1' otherwise.</p>
 </dd>
 </li>
 <dt><strong><a name="u_username_or_dbuser_username" class="item"><strong>-u USERNAME</strong> or <strong>--dbuser=USERNAME</strong></a></strong>
 
 <dd>
 <p>The name of the database user to connect as. Can be a comma-separated list of usernames, and multiple 
-dbuser arguments are allowed. If this is not provided, defaults to 'postgres'.</p>
+dbuser arguments are allowed. If this is not provided, the default is 'postgres'.</p>
 </dd>
 </li>
 <dt><strong><a name="dbpass_password" class="item"><strong>--dbpass=PASSWORD</strong></a></strong>
@@ -135,14 +135,13 @@ Instead, one should use a .pgpass file.</p>
 </dd>
 </li>
 </dl>
-<p>Connection options can be grouped: --host=a,b --host=c --port=1234 --port=3344
+<p>The database connection options can be grouped: --host=a,b --host=c --port=1234 --port=3344
 would connect to a-1234, b-1234, and c-3344. Note that once set, an option 
 carries over until it is changed again.</p>
 <p>Examples:</p>
 <pre>
   --host=a,b --port=5433 --db=c
-  Connects twice to port 5433, using database c, to hosts a and b
-  a-5433-c b-5433-c</pre>
+  Connects twice to port 5433, using database c, to hosts a and b: a-5433-c b-5433-c</pre>
 <pre>
   --host=a,b --port=5433 --db=c,d
   Connects four times: a-5433-c a-5433-d b-5433-c b-5433-d</pre>
@@ -156,24 +155,27 @@ carries over until it is changed again.</p>
 </p>
 <hr />
 <h1><a name="other_options">OTHER OPTIONS</a></h1>
-<p>Other common options include:</p>
+<p>Other options include:</p>
 <dl>
-<dt><strong><a name="output_val" class="item"><strong>--output=VAL</strong></a></strong>
+<dt><strong><a name="action_name" class="item"><strong>--action=NAME</strong></a></strong>
 
 <dd>
-<p>Determines the format of the output, for use in various programs. The default is 'nagios'. No 
-other systems are supported yet.</p>
+<p>States what action we are running. Required unless using a symlinked file, 
+in which case the name of the file is used to figure out the action.</p>
 </dd>
 </li>
-<dt><strong><a name="psql_path" class="item"><strong>PSQL=PATH</strong></a></strong>
+<dt><strong><a name="warning_val_or_w_val" class="item"><strong>--warning=VAL or -w VAL</strong></a></strong>
 
 <dd>
-<p>Tells the script where to find the psql program. Useful if you have more than 
-one version of the psql executable on your system, or if there is no psql program 
-in your path. Note that this option is in all uppercase. By default, this option 
-is <em>not allowed</em>. To enable it, you must change the <code>$NO_PSQL_OPTION</code> near the 
-top of the script to 0. Avoid using this option if you can, and instead hard-code 
-your psql location into the <code>$PSQL</code> variable, also near the top of the script.</p>
+<p>Sets the threshold at which a warning alert is fired. The valid options for this 
+option depends on the action used.</p>
+</dd>
+</li>
+<dt><strong><a name="critical_val_or_c_val" class="item"><strong>--critical=VAL or -c VAL</strong></a></strong>
+
+<dd>
+<p>Sets the threshold at which a critical alert is fired. The valid options for this 
+option depends on the action used.</p>
 </dd>
 </li>
 <dt><strong><a name="t_val_or_timeout_val" class="item"><strong>-t VAL</strong> or <strong>--timeout=VAL</strong></a></strong>
@@ -204,16 +206,10 @@ or higher (in other words, issuing <code>-v -v -v</code>) turns on debugging inf
 program which is sent to stderr.</p>
 </dd>
 </li>
-<dt><strong><a name="test" class="item"><strong>--test</strong></a></strong>
-
-<dd>
-<p>Enables test mode. See the <a href="#test_mode">TEST MODE</a> section below.</p>
-</dd>
-</li>
 <dt><strong><a name="showperf_val" class="item"><strong>--showperf=VAL</strong></a></strong>
 
 <dd>
-<p>Determines if we output performance data in standard Nagios format 
+<p>Determines if we output additional performance data in standard Nagios format 
 (at end of string, after a pipe symbol, using name=value). 
 VAL should be 0 or 1. The default is 1.</p>
 </dd>
@@ -221,7 +217,7 @@ VAL should be 0 or 1. The default is 1.</p>
 <dt><strong><a name="perflimit_i" class="item"><strong>--perflimit=i</strong></a></strong>
 
 <dd>
-<p>Sets a limit s to how many items of interest are reported back when using the 
+<p>Sets a limit as to how many items of interest are reported back when using the 
 <strong>showperf</strong> option. This only has an effect for actions that return a large 
 number of items, such as <strong>table_size</strong>. The default is 0, or no limit. Be 
 careful when using this with the <strong>--include</strong> or <strong>--exclude</strong> options, as 
@@ -236,11 +232,34 @@ limit may not include the items you want.</p>
 should be 0 or 1. The default is 1. No effect unless <strong>showperf</strong> is on.</p>
 </dd>
 </li>
-<dt><strong><a name="action_name" class="item"><strong>--action=NAME</strong></a></strong>
+<dt><strong><a name="test" class="item"><strong>--test</strong></a></strong>
 
 <dd>
-<p>States what action we are running. Required unless using a symlinked file, 
-in which case the name of the file is used to figure out the action.</p>
+<p>Enables test mode. See the <a href="#test_mode">TEST MODE</a> section below.</p>
+</dd>
+</li>
+<dt><strong><a name="psql_path" class="item"><strong>--PSQL=PATH</strong></a></strong>
+
+<dd>
+<p>Tells the script where to find the psql program. Useful if you have more than 
+one version of the psql executable on your system, or if there is no psql program 
+in your path. Note that this option is in all uppercase. By default, this option 
+is <em>not allowed</em>. To enable it, you must change the <code>$NO_PSQL_OPTION</code> near the 
+top of the script to 0. Avoid using this option if you can, and instead hard-code 
+your psql location into the <code>$PSQL</code> variable, also near the top of the script.</p>
+</dd>
+</li>
+<dt><strong><a name="symlinks" class="item"><strong>--symlinks</strong></a></strong>
+
+<dd>
+<p>Creates symlinks to the main program for each action.</p>
+</dd>
+</li>
+<dt><strong><a name="output_val" class="item"><strong>--output=VAL</strong></a></strong>
+
+<dd>
+<p>Determines the format of the output, for use in various programs. The default is 'nagios'. No 
+other systems are supported yet.</p>
 </dd>
 </li>
 </dl>
@@ -405,6 +424,11 @@ terabytes, or exabytes. Each may be abbreviated to the first letter. If no units
 bytes are assumed. The first column should be an integer representing the number of bytes to check.</p>
 </dd>
 <dd>
+<p>Normally, an alert is triggered if the values returned are <strong>greater than</strong> or equal to the critical or warning 
+value. However, an option of <strong>--reverse</strong> will trigger the alert if the returned value is 
+<strong>lower than</strong> or equal to the critical or warning value.</p>
+</dd>
+<dd>
 <p>Example 1: Warn if any relation over 100 pages is named &quot;rad&quot;:</p>
 </dd>
 <dd>
@@ -419,6 +443,13 @@ bytes are assumed. The first column should be an integer representing the number
   check_postgres_custom_query --port=5432 --critical='5MB'--checktype=size --query=&quot;SELECT foobar()&quot;</pre>
 </dd>
 <dd>
+<p>Example 2: Warn if the function &quot;snazzo&quot; returns less than 42:</p>
+</dd>
+<dd>
+<pre>
+  check_postgres_custom_query --port=5432 --critical=42 --query=&quot;SELECT snazzo()&quot; --reverse</pre>
+</dd>
+<dd>
 <p>If you come up with a useful custom_query, consider sending in a patch to this program 
 to make it into a standard action that other people can use.</p>
 </dd>
@@ -863,7 +894,7 @@ If no units are given, the unit are assumed to be seconds.</p>
 <p>This action requires no other arguments, and does not connect to any databases, 
 but simply creates symlinks in the current directory for each action, in the form 
 <strong>check_postgres_&lt;action_name&gt;</strong>.
- If the file already exists, it will not be overwritten. If the action is rebuild_symlinks_force, 
+If the file already exists, it will not be overwritten. If the action is rebuild_symlinks_force, 
 then symlinks will be overwritten. The option --symlinks is a shorter way of saying 
 --action=rebuild_symlinks</p>
 </dd>
@@ -1082,9 +1113,8 @@ comma-separated list. The actions that currently use these options are:</p>
 <p>To help in setting things up, this program can be run in a &quot;test mode&quot; by 
 specifying the <strong>--test</strong> option. This will perform some basic tests to 
 make sure that the databases can be contacted, and that certain per-action 
-prerequisites are met. Currently, we check that the user is a superuser 
-if required by that action, and that the version of Postgres is new enough 
-for those actions that depend on a specific version.</p>
+prerequisites are met, such as whether the user is a superuser, if the version 
+of Postgres is new enough, and if stats_row_level is on.</p>
 <p>
 </p>
 <hr />
@@ -1119,6 +1149,12 @@ is needed by the <strong>check_disk_space</strong> action.</p>
 <h1><a name="history">HISTORY</a></h1>
 <p>Items not specifically attributed are by Greg Sabino Mullane.</p>
 <dl>
+<dt><strong><a name="0" class="item"><strong>Version 1.8.0</strong> (June 3, 2008)</a></strong>
+
+<dd>
+<p>Add the --reverse option to the custom_query action.</p>
+</dd>
+</li>
 <dt><strong><a name="1" class="item"><strong>Version 1.7.1</strong> (June 2, 2008)</a></strong>
 
 <dd>
@@ -1126,7 +1162,7 @@ is needed by the <strong>check_disk_space</strong> action.</p>
 Thanks to Dustin Black for the bug report.</p>
 </dd>
 </li>
-<dt><strong><a name="0" class="item"><strong>Version 1.7.0</strong> (May 11, 2008)</a></strong>
+<dt><strong><strong>Version 1.7.0</strong> (May 11, 2008)</strong>
 
 <dd>
 <p>Add --replicate_row action</p>