check_pgsql.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*****************************************************************************
  2. *
  3. * Nagios check_pgsql plugin
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999-2014 Nagios Plugins Development Team
  7. *
  8. * Description:
  9. *
  10. * This file contains the check_pgsql plugin
  11. *
  12. * Test whether a PostgreSQL Database is accepting connections.
  13. *
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation, either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. *
  29. *****************************************************************************/
  30. const char *progname = "check_pgsql";
  31. const char *copyright = "1999-2014";
  32. const char *email = "devel@nagios-plugins.org";
  33. #include "common.h"
  34. #include "utils.h"
  35. #include "netutils.h"
  36. #include <libpq-fe.h>
  37. #include <pg_config_manual.h>
  38. #define DEFAULT_DB "template1"
  39. #define DEFAULT_HOST "127.0.0.1"
  40. /* return the PSQL server version as a 3-tuple */
  41. #define PSQL_SERVER_VERSION3(server_version) \
  42. (server_version) / 10000, \
  43. (server_version) / 100 - (int)((server_version) / 10000) * 100, \
  44. (server_version) - (int)((server_version) / 100) * 100
  45. /* return true if the given host is a UNIX domain socket */
  46. #define PSQL_IS_UNIX_DOMAIN_SOCKET(host) \
  47. ((NULL == (host)) || ('\0' == *(host)) || ('/' == *(host)))
  48. /* return a 3-tuple identifying a host/port independent of the socket type */
  49. #define PSQL_SOCKET3(host, port) \
  50. ((NULL == (host)) || ('\0' == *(host))) ? DEFAULT_PGSOCKET_DIR : host, \
  51. PSQL_IS_UNIX_DOMAIN_SOCKET (host) ? "/.s.PGSQL." : ":", \
  52. port
  53. enum {
  54. DEFAULT_PORT = 5432,
  55. DEFAULT_WARN = 2,
  56. DEFAULT_CRIT = 8
  57. };
  58. int process_arguments (int, char **);
  59. int validate_arguments (void);
  60. void print_usage (void);
  61. void print_help (void);
  62. int is_pg_dbname (char *);
  63. int is_pg_logname (char *);
  64. int do_query (PGconn *, char *);
  65. char *pghost = NULL; /* host name of the backend server */
  66. char *pgport = NULL; /* port of the backend server */
  67. int default_port = DEFAULT_PORT;
  68. char *pgoptions = NULL;
  69. char *pgtty = NULL;
  70. char dbName[NAMEDATALEN] = DEFAULT_DB;
  71. char *pguser = NULL;
  72. char *pgpasswd = NULL;
  73. char *pgparams = NULL;
  74. double twarn = (double)DEFAULT_WARN;
  75. double tcrit = (double)DEFAULT_CRIT;
  76. char *pgquery = NULL;
  77. char *query_warning = NULL;
  78. char *query_critical = NULL;
  79. static int print_query = 0;
  80. thresholds *qthresholds = NULL;
  81. int verbose = 0;
  82. /******************************************************************************
  83. The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
  84. tags in the comments. With in the tags, the XML is assembled sequentially.
  85. You can define entities in tags. You also have all the #defines available as
  86. entities.
  87. Please note that all tags must be lowercase to use the DocBook XML DTD.
  88. @@-<article>
  89. <sect1>
  90. <title>Quick Reference</title>
  91. <!-- The refentry forms a manpage -->
  92. <refentry>
  93. <refmeta>
  94. <manvolnum>5<manvolnum>
  95. </refmeta>
  96. <refnamdiv>
  97. <refname>&progname;</refname>
  98. <refpurpose>&SUMMARY;</refpurpose>
  99. </refnamdiv>
  100. </refentry>
  101. </sect1>
  102. <sect1>
  103. <title>FAQ</title>
  104. </sect1>
  105. <sect1>
  106. <title>Theory, Installation, and Operation</title>
  107. <sect2>
  108. <title>General Description</title>
  109. <para>
  110. &DESCRIPTION;
  111. </para>
  112. </sect2>
  113. <sect2>
  114. <title>Future Enhancements</title>
  115. <para>ToDo List</para>
  116. </sect2>
  117. <sect2>
  118. <title>Functions</title>
  119. -@@
  120. ******************************************************************************/
  121. int
  122. main (int argc, char **argv)
  123. {
  124. PGconn *conn;
  125. char *conninfo = NULL;
  126. struct timeval start_timeval;
  127. struct timeval end_timeval;
  128. double elapsed_time;
  129. int status = STATE_UNKNOWN;
  130. int query_status = STATE_UNKNOWN;
  131. /* begin, by setting the parameters for a backend connection if the
  132. * parameters are null, then the system will try to use reasonable
  133. * defaults by looking up environment variables or, failing that,
  134. * using hardwired constants */
  135. pgoptions = NULL; /* special options to start up the backend server */
  136. pgtty = NULL; /* debugging tty for the backend server */
  137. setlocale (LC_ALL, "");
  138. bindtextdomain (PACKAGE, LOCALEDIR);
  139. textdomain (PACKAGE);
  140. /* Parse extra opts if any */
  141. argv=np_extra_opts (&argc, argv, progname);
  142. if (process_arguments (argc, argv) == ERROR)
  143. usage4 (_("Could not parse arguments"));
  144. if (verbose > 2)
  145. printf("Arguments initialized\n");
  146. /* Set signal handling and alarm */
  147. if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) {
  148. usage4 (_("Cannot catch SIGALRM"));
  149. }
  150. alarm (timeout_interval);
  151. if (pgparams)
  152. asprintf (&conninfo, "%s ", pgparams);
  153. asprintf (&conninfo, "%sdbname = '%s'", conninfo ? conninfo : "", dbName);
  154. if (pghost)
  155. asprintf (&conninfo, "%s host = '%s'", conninfo, pghost);
  156. if (pgport)
  157. asprintf (&conninfo, "%s port = '%s'", conninfo, pgport);
  158. if (pgoptions)
  159. asprintf (&conninfo, "%s options = '%s'", conninfo, pgoptions);
  160. /* if (pgtty) -- ignored by PQconnectdb */
  161. if (pguser)
  162. asprintf (&conninfo, "%s user = '%s'", conninfo, pguser);
  163. if (verbose) /* do not include password (see right below) in output */
  164. printf ("Connecting to PostgreSQL using conninfo: %s%s\n", conninfo,
  165. pgpasswd ? " password = <hidden>" : "");
  166. if (pgpasswd)
  167. asprintf (&conninfo, "%s password = '%s'", conninfo, pgpasswd);
  168. /* make a connection to the database */
  169. gettimeofday (&start_timeval, NULL);
  170. conn = PQconnectdb (conninfo);
  171. gettimeofday (&end_timeval, NULL);
  172. while (start_timeval.tv_usec > end_timeval.tv_usec) {
  173. --end_timeval.tv_sec;
  174. end_timeval.tv_usec += 1000000;
  175. }
  176. elapsed_time = (double)(end_timeval.tv_sec - start_timeval.tv_sec)
  177. + (double)(end_timeval.tv_usec - start_timeval.tv_usec) / 1000000.0;
  178. if (verbose)
  179. printf("Time elapsed: %f\n", elapsed_time);
  180. /* check to see that the backend connection was successfully made */
  181. if (verbose)
  182. printf("Verifying connection\n");
  183. if (PQstatus (conn) == CONNECTION_BAD) {
  184. printf (_("CRITICAL - no connection to '%s' (%s).\n"),
  185. dbName, PQerrorMessage (conn));
  186. PQfinish (conn);
  187. return STATE_CRITICAL;
  188. }
  189. else if (elapsed_time > tcrit) {
  190. status = STATE_CRITICAL;
  191. }
  192. else if (elapsed_time > twarn) {
  193. status = STATE_WARNING;
  194. }
  195. else {
  196. status = STATE_OK;
  197. }
  198. if (verbose) {
  199. char *server_host = PQhost (conn);
  200. int server_version = PQserverVersion (conn);
  201. printf ("Successfully connected to database %s (user %s) "
  202. "at server %s%s%s (server version: %d.%d.%d, "
  203. "protocol version: %d, pid: %d)\n",
  204. PQdb (conn), PQuser (conn),
  205. PSQL_SOCKET3 (server_host, PQport (conn)),
  206. PSQL_SERVER_VERSION3 (server_version),
  207. PQprotocolVersion (conn), PQbackendPID (conn));
  208. }
  209. printf (_(" %s - database %s (%f sec.)|%s\n"),
  210. state_text(status), dbName, elapsed_time,
  211. fperfdata("time", elapsed_time, "s",
  212. !!(twarn > 0.0), twarn, !!(tcrit > 0.0), tcrit, TRUE, 0, FALSE,0));
  213. if (pgquery)
  214. query_status = do_query (conn, pgquery);
  215. if (verbose)
  216. printf("Closing connection\n");
  217. PQfinish (conn);
  218. return (pgquery && query_status > status) ? query_status : status;
  219. }
  220. /* process command-line arguments */
  221. int
  222. process_arguments (int argc, char **argv)
  223. {
  224. int c;
  225. int option = 0;
  226. static struct option longopts[] = {
  227. {"help", no_argument, 0, 'h'},
  228. {"version", no_argument, 0, 'V'},
  229. {"timeout", required_argument, 0, 't'},
  230. {"critical", required_argument, 0, 'c'},
  231. {"warning", required_argument, 0, 'w'},
  232. {"hostname", required_argument, 0, 'H'},
  233. {"logname", required_argument, 0, 'l'},
  234. {"password", required_argument, 0, 'p'},
  235. {"authorization", required_argument, 0, 'a'},
  236. {"port", required_argument, 0, 'P'},
  237. {"database", required_argument, 0, 'd'},
  238. {"option", required_argument, 0, 'o'},
  239. {"query", required_argument, 0, 'q'},
  240. {"query_critical", required_argument, 0, 'C'},
  241. {"query_warning", required_argument, 0, 'W'},
  242. {"print-query", no_argument, 0, 'r'},
  243. {"verbose", no_argument, 0, 'v'},
  244. {0, 0, 0, 0}
  245. };
  246. while (1) {
  247. c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:o:q:C:W:v",
  248. longopts, &option);
  249. if (c == EOF)
  250. break;
  251. switch (c) {
  252. case '?': /* usage */
  253. usage5 ();
  254. case 'h': /* help */
  255. print_help ();
  256. exit (STATE_OK);
  257. case 'V': /* version */
  258. print_revision (progname, NP_VERSION);
  259. exit (STATE_OK);
  260. case 't': /* timeout period */
  261. timeout_interval = parse_timeout_string (optarg);
  262. break;
  263. case 'c': /* critical time threshold */
  264. if (!is_nonnegative (optarg))
  265. usage2 (_("Critical threshold must be a positive integer"), optarg);
  266. else
  267. tcrit = strtod (optarg, NULL);
  268. break;
  269. case 'w': /* warning time threshold */
  270. if (!is_nonnegative (optarg))
  271. usage2 (_("Warning threshold must be a positive integer"), optarg);
  272. else
  273. twarn = strtod (optarg, NULL);
  274. break;
  275. case 'C': /* critical query threshold */
  276. query_critical = optarg;
  277. break;
  278. case 'W': /* warning query threshold */
  279. query_warning = optarg;
  280. break;
  281. case 'r':
  282. print_query = 1;
  283. break;
  284. case 'H': /* host */
  285. if ((*optarg != '/') && (!is_host (optarg)))
  286. usage2 (_("Invalid hostname/address"), optarg);
  287. else
  288. pghost = optarg;
  289. break;
  290. case 'P': /* port */
  291. if (!is_integer (optarg))
  292. usage2 (_("Port must be a positive integer"), optarg);
  293. else
  294. pgport = optarg;
  295. break;
  296. case 'd': /* database name */
  297. if (!is_pg_dbname (optarg)) /* checks length and valid chars */
  298. usage2 (_("Database name is not valid"), optarg);
  299. else /* we know length, and know optarg is terminated, so us strcpy */
  300. strcpy (dbName, optarg);
  301. break;
  302. case 'l': /* login name */
  303. if (!is_pg_logname (optarg))
  304. usage2 (_("User name is not valid"), optarg);
  305. else
  306. pguser = optarg;
  307. break;
  308. case 'p': /* authentication password */
  309. case 'a':
  310. pgpasswd = optarg;
  311. break;
  312. case 'o':
  313. if (pgparams)
  314. asprintf (&pgparams, "%s %s", pgparams, optarg);
  315. else
  316. asprintf (&pgparams, "%s", optarg);
  317. break;
  318. case 'q':
  319. pgquery = optarg;
  320. break;
  321. case 'v':
  322. verbose++;
  323. break;
  324. }
  325. }
  326. set_thresholds (&qthresholds, query_warning, query_critical);
  327. return validate_arguments ();
  328. }
  329. /******************************************************************************
  330. @@-
  331. <sect3>
  332. <title>validate_arguments</title>
  333. <para>&PROTO_validate_arguments;</para>
  334. <para>Given a database name, this function returns TRUE if the string
  335. is a valid PostgreSQL database name, and returns false if it is
  336. not.</para>
  337. <para>Valid PostgreSQL database names are less than &NAMEDATALEN;
  338. characters long and consist of letters, numbers, and underscores. The
  339. first character cannot be a number, however.</para>
  340. </sect3>
  341. -@@
  342. ******************************************************************************/
  343. int
  344. validate_arguments ()
  345. {
  346. return OK;
  347. }
  348. /******************************************************************************
  349. @@-
  350. <sect3>
  351. <title>is_pg_dbname</title>
  352. <para>&PROTO_is_pg_dbname;</para>
  353. <para>Given a database name, this function returns TRUE if the string
  354. is a valid PostgreSQL database name, and returns false if it is
  355. not.</para>
  356. <para>Valid PostgreSQL database names are less than &NAMEDATALEN;
  357. characters long and consist of letters, numbers, and underscores. The
  358. first character cannot be a number, however.</para>
  359. </sect3>
  360. -@@
  361. ******************************************************************************/
  362. int
  363. is_pg_dbname (char *dbname)
  364. {
  365. char txt[NAMEDATALEN];
  366. char tmp[NAMEDATALEN];
  367. if (strlen (dbname) > NAMEDATALEN - 1)
  368. return (FALSE);
  369. strncpy (txt, dbname, NAMEDATALEN - 1);
  370. txt[NAMEDATALEN - 1] = 0;
  371. if (sscanf (txt, "%[_a-zA-Z]%[^_a-zA-Z0-9-]", tmp, tmp) == 1)
  372. return (TRUE);
  373. if (sscanf (txt, "%[_a-zA-Z]%[_a-zA-Z0-9-]%[^_a-zA-Z0-9-]", tmp, tmp, tmp) ==
  374. 2) return (TRUE);
  375. return (FALSE);
  376. }
  377. /**
  378. the tango program should eventually create an entity here based on the
  379. function prototype
  380. @@-
  381. <sect3>
  382. <title>is_pg_logname</title>
  383. <para>&PROTO_is_pg_logname;</para>
  384. <para>Given a username, this function returns TRUE if the string is a
  385. valid PostgreSQL username, and returns false if it is not. Valid PostgreSQL
  386. usernames are less than &NAMEDATALEN; characters long and consist of
  387. letters, numbers, dashes, and underscores, plus possibly some other
  388. characters.</para>
  389. <para>Currently this function only checks string length. Additional checks
  390. should be added.</para>
  391. </sect3>
  392. -@@
  393. ******************************************************************************/
  394. int
  395. is_pg_logname (char *username)
  396. {
  397. if (strlen (username) > NAMEDATALEN - 1)
  398. return (FALSE);
  399. return (TRUE);
  400. }
  401. /******************************************************************************
  402. @@-
  403. </sect2>
  404. </sect1>
  405. </article>
  406. -@@
  407. ******************************************************************************/
  408. void
  409. print_help (void)
  410. {
  411. char *myport;
  412. xasprintf (&myport, "%d", DEFAULT_PORT);
  413. print_revision (progname, NP_VERSION);
  414. printf (COPYRIGHT, copyright, email);
  415. printf (_("Test whether a PostgreSQL Database is accepting connections."));
  416. printf ("\n\n");
  417. print_usage ();
  418. printf (UT_HELP_VRSN);
  419. printf (UT_EXTRA_OPTS);
  420. printf (UT_HOST_PORT, 'P', myport);
  421. printf (" %s\n", "-d, --database=STRING");
  422. printf (" %s", _("Database to check "));
  423. printf (_("(default: %s)\n"), DEFAULT_DB);
  424. printf (" %s\n", "-l, --logname = STRING");
  425. printf (" %s\n", _("Login name of user"));
  426. printf (" %s\n", "-p, --password = STRING");
  427. printf (" %s\n", _("The user's password. To avoid security issues, define this option using"));
  428. printf (" %s\n", _("--extra-opts when possible."));
  429. printf (" %s\n", "-o, --option = STRING");
  430. printf (" %s\n", _("Connection parameters (keyword = value), see below"));
  431. printf (UT_WARN_CRIT);
  432. printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
  433. printf (" %s\n", "-q, --query=STRING");
  434. printf (" %s\n", _("SQL query to run. Only first column in first row will be read"));
  435. printf (" %s\n", "-W, --query-warning=RANGE");
  436. printf (" %s\n", _("SQL query value to result in warning status (double)"));
  437. printf (" %s\n", "-C, --query-critical=RANGE");
  438. printf (" %s\n", _("SQL query value to result in critical status (double)"));
  439. printf (" %s\n", "-r, --print-query");
  440. printf (" %s\n", _("Print the output of the entire query to extended plugin output."));
  441. printf (UT_VERBOSE);
  442. printf ("\n");
  443. printf (" %s\n", _("All parameters are optional."));
  444. printf (" %s\n", _("This plugin tests a PostgreSQL DBMS to determine whether it is active and"));
  445. printf (" %s\n", _("accepting queries. In its current operation, it simply connects to the"));
  446. printf (" %s\n", _("specified database, and then disconnects. If no database is specified, it"));
  447. printf (" %s\n", _("connects to the template1 database, which is present in every functioning"));
  448. printf (" %s\n\n", _("PostgreSQL DBMS."));
  449. printf (" %s\n", _("If a query is specified using the -q option, it will be executed after"));
  450. printf (" %s\n", _("connecting to the server. The result from the query has to be numeric."));
  451. printf (" %s\n", _("Multiple SQL commands, separated by semicolon, are allowed but the result "));
  452. printf (" %s\n", _("of the last command is taken into account only. The value of the first"));
  453. printf (" %s\n\n", _("column in the first row is used as the check result."));
  454. printf (" %s\n", _("See the chapter \"Monitoring Database Activity\" of the PostgreSQL manual"));
  455. printf (" %s\n\n", _("for details about how to access internal statistics of the database server."));
  456. printf (" %s\n", _("For a list of available connection parameters which may be used with the -o"));
  457. printf (" %s\n", _("command line option, see the documentation for PQconnectdb() in the chapter"));
  458. printf (" %s\n", _("\"libpq - C Library\" of the PostgreSQL manual. For example, this may be"));
  459. printf (" %s\n", _("used to specify a service name in pg_service.conf to be used for additional"));
  460. printf (" %s\n", _("connection parameters: -o 'service=<name>' or to specify the SSL mode:"));
  461. printf (" %s\n\n", _("-o 'sslmode=require'."));
  462. printf (" %s\n", _("The plugin will connect to a local postmaster if no host is specified. To"));
  463. printf (" %s\n", _("connect to a remote host, be sure that the remote postmaster accepts TCP/IP"));
  464. printf (" %s\n\n", _("connections (start the postmaster with the -i option)."));
  465. printf (" %s\n", _("Typically, the nagios user (unless the --logname option is used) should be"));
  466. printf (" %s\n", _("able to connect to the database without a password. The plugin can also send"));
  467. printf (" %s\n", _("a password, but no effort is made to obscure or encrypt the password."));
  468. printf (UT_SUPPORT);
  469. }
  470. void
  471. print_usage (void)
  472. {
  473. printf ("%s\n", _("Usage:"));
  474. printf ("%s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname);
  475. printf (" [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n"
  476. "[-q <query>] [-C <critical query range>] [-W <warning query range>] [-r]\n");
  477. }
  478. int
  479. do_query (PGconn *conn, char *query)
  480. {
  481. PGresult *res;
  482. char *val_str;
  483. double value;
  484. char *endptr = NULL;
  485. int my_status = STATE_UNKNOWN;
  486. // Only used for print_query block at the end of this function
  487. PQprintOpt po;
  488. if (verbose)
  489. printf ("Executing SQL query \"%s\".\n", query);
  490. res = PQexec (conn, query);
  491. if (PGRES_TUPLES_OK != PQresultStatus (res)) {
  492. printf (_("QUERY %s - %s: %s.\n"), _("CRITICAL"), _("Error with query"),
  493. PQerrorMessage (conn));
  494. return STATE_CRITICAL;
  495. }
  496. if (PQntuples (res) < 1) {
  497. printf ("QUERY %s - %s.\n", _("WARNING"), _("No rows returned"));
  498. return STATE_WARNING;
  499. }
  500. if (PQnfields (res) < 1) {
  501. printf ("QUERY %s - %s.\n", _("WARNING"), _("No columns returned"));
  502. return STATE_WARNING;
  503. }
  504. val_str = PQgetvalue (res, 0, 0);
  505. if (! val_str) {
  506. printf ("QUERY %s - %s.\n", _("CRITICAL"), _("No data returned"));
  507. return STATE_CRITICAL;
  508. }
  509. value = strtod (val_str, &endptr);
  510. if (verbose)
  511. printf ("Query result: %f\n", value);
  512. if (endptr == val_str) {
  513. printf ("QUERY %s - %s: %s\n", _("CRITICAL"), _("Is not a numeric"), val_str);
  514. return STATE_CRITICAL;
  515. }
  516. else if ((endptr != NULL) && (*endptr != '\0')) {
  517. if (verbose)
  518. printf ("Garbage after value: %s.\n", endptr);
  519. }
  520. my_status = get_status (value, qthresholds);
  521. printf ("QUERY %s - ",
  522. (my_status == STATE_OK)
  523. ? _("OK")
  524. : (my_status == STATE_WARNING)
  525. ? _("WARNING")
  526. : (my_status == STATE_CRITICAL)
  527. ? _("CRITICAL")
  528. : _("UNKNOWN"));
  529. printf (_("'%s' returned %f"), query, value);
  530. printf ("|query=%f;%s;%s;;\n", value,
  531. query_warning ? query_warning : "",
  532. query_critical ? query_critical : "");
  533. if (print_query) {
  534. printf("\n");
  535. po.header = 1;
  536. po.align = 1;
  537. po.standard = 1;
  538. po.html3 = 0;
  539. po.expanded = 0;
  540. po.pager = 0;
  541. po.fieldSep = "|";
  542. po.tableOpt = NULL;
  543. po.caption = NULL;
  544. po.fieldName = NULL;
  545. PQprint(stdout, res, &po);
  546. }
  547. return my_status;
  548. }