From: Sebastian Harl Date: Thu, 7 Apr 2011 09:50:10 +0000 (+0200) Subject: check_pgsql: Added support for the -o command line option. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a02b463ff6c923d2432fe8ab6536262a250b330d;p=nagiosplug.git check_pgsql: Added support for the -o command line option. This option may be used to specify further connection parameters to be passed to PQconnectdb(). For example, this may be used to specify a service name in pg_service.conf to be used for additional connection parameters: -o 'service=' or to specify the SSL mode: -o 'sslmode=require'. See the chapter "libpq - C Library" in the PostgreSQL manual for details. --- diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 85e26fe..aa65fb2 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c @@ -80,6 +80,7 @@ char *pgtty = NULL; char dbName[NAMEDATALEN] = DEFAULT_DB; char *pguser = NULL; char *pgpasswd = NULL; +char *pgparams = NULL; double twarn = (double)DEFAULT_WARN; double tcrit = (double)DEFAULT_CRIT; char *pgquery = NULL; @@ -130,9 +131,6 @@ Please note that all tags must be lowercase to use the DocBook XML DTD. Future Enhancements ToDo List - -Add option to get password from a secured file rather than the command line - @@ -179,7 +177,10 @@ main (int argc, char **argv) } alarm (timeout_interval); - asprintf (&conninfo, "dbname = '%s'", dbName); + if (pgparams) + asprintf (&conninfo, "%s ", pgparams); + + asprintf (&conninfo, "%sdbname = '%s'", conninfo ? conninfo : "", dbName); if (pghost) asprintf (&conninfo, "%s host = '%s'", conninfo, pghost); if (pgport) @@ -273,6 +274,7 @@ process_arguments (int argc, char **argv) {"authorization", required_argument, 0, 'a'}, {"port", required_argument, 0, 'P'}, {"database", required_argument, 0, 'd'}, + {"option", required_argument, 0, 'o'}, {"query", required_argument, 0, 'q'}, {"query_critical", required_argument, 0, 'C'}, {"query_warning", required_argument, 0, 'W'}, @@ -281,7 +283,7 @@ process_arguments (int argc, char **argv) }; while (1) { - c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:q:C:W:v", + c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:o:q:C:W:v", longopts, &option); if (c == EOF) @@ -348,6 +350,12 @@ process_arguments (int argc, char **argv) case 'a': pgpasswd = optarg; break; + case 'o': + if (pgparams) + asprintf (&pgparams, "%s %s", pgparams, optarg); + else + asprintf (&pgparams, "%s", optarg); + break; case 'q': pgquery = optarg; break; @@ -503,6 +511,8 @@ print_help (void) printf (" %s\n", _("Login name of user")); printf (" %s\n", "-p, --password = STRING"); printf (" %s\n", _("Password (BIG SECURITY ISSUE)")); + printf (" %s\n", "-o, --option = STRING"); + printf (" %s\n", _("Connection parameters (keyword = value), see below")); printf (UT_WARN_CRIT); @@ -534,6 +544,13 @@ print_help (void) printf (" %s\n", _("See the chapter \"Monitoring Database Activity\" of the PostgreSQL manual")); printf (" %s\n\n", _("for details about how to access internal statistics of the database server.")); + printf (" %s\n", _("For a list of available connection parameters which may be used with the -o")); + printf (" %s\n", _("command line option, see the documentation for PQconnectdb() in the chapter")); + printf (" %s\n", _("\"libpq - C Library\" of the PostgreSQL manual. For example, this may be")); + printf (" %s\n", _("used to specify a service name in pg_service.conf to be used for additional")); + printf (" %s\n", _("connection parameters: -o 'service=' or to specify the SSL mode:")); + printf (" %s\n\n", _("-o 'sslmode=require'.")); + printf (" %s\n", _("The plugin will connect to a local postmaster if no host is specified. To")); printf (" %s\n", _("connect to a remote host, be sure that the remote postmaster accepts TCP/IP")); printf (" %s\n\n", _("connections (start the postmaster with the -i option)."));