summaryrefslogtreecommitdiffstats
path: root/web/attachments/170107-check_pgsql.patch
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/170107-check_pgsql.patch')
-rw-r--r--web/attachments/170107-check_pgsql.patch138
1 files changed, 138 insertions, 0 deletions
diff --git a/web/attachments/170107-check_pgsql.patch b/web/attachments/170107-check_pgsql.patch
new file mode 100644
index 0000000..b880f8c
--- /dev/null
+++ b/web/attachments/170107-check_pgsql.patch
@@ -0,0 +1,138 @@
1--- check_pgsql.original 2006-03-07 12:40:11.000000000 -0700
2+++ check_pgsql.c 2006-03-07 12:47:48.000000000 -0700
3@@ -21,5 +21,5 @@
4 const char *progname = "check_pgsql";
5 const char *revision = "$Revision: 1.31 $";
6-const char *copyright = "1999-2004";
7+const char *copyright = "1999-2006";
8 const char *email = "nagiosplug-devel@lists.sourceforge.net";
9
10@@ -36,5 +36,7 @@
11 DEFAULT_PORT = 5432,
12 DEFAULT_WARN = 2,
13- DEFAULT_CRIT = 8
14+ DEFAULT_CRIT = 8,
15+ DEFAULT_WARNING_XID_AGE = 500000000, /* 500M */
16+ DEFAULT_CRITICAL_XID_AGE = 1000000000 /* 1B */
17 };
18
19@@ -58,4 +60,6 @@
20 double twarn = (double)DEFAULT_WARN;
21 double tcrit = (double)DEFAULT_CRIT;
22+int warning_xid_age = DEFAULT_WARNING_XID_AGE;
23+int critical_xid_age = DEFAULT_CRITICAL_XID_AGE;
24
25 PGconn *conn;
26@@ -124,4 +128,9 @@
27 int elapsed_time;
28 int status = STATE_UNKNOWN;
29+ int i,j;
30+ int nFields;
31+ const char *paramValues[1];
32+ char param[100];
33+ PGresult *res;
34
35 /* begin, by setting the parameters for a backend connection if the
36@@ -167,8 +176,43 @@
37 }
38 else {
39+ snprintf(param, 100, "%d", warning_xid_age);
40+ paramValues[0] = param;
41+ res = PQexecParams(conn,
42+ "SELECT datname,age(datvacuumxid) FROM pg_database WHERE age(datvacuumxid) > $1 ORDER BY age(datvacuumxid) DESC",
43+ 1, NULL, paramValues, NULL, NULL, 0);
44+ if (PQresultStatus(res) != PGRES_TUPLES_OK)
45+ {
46+ printf (_("CRITICAL - error '%s' running query on '%s' (%s).\n"),
47+ PQerrorMessage(conn), dbName, PQerrorMessage (conn));
48+ PQclear (res);
49+ PQfinish (conn);
50+ return STATE_CRITICAL;
51+ }
52+
53+ if (PQntuples(res) > 0)
54+ {
55+ j = atoi(PQgetvalue(res, 0, 1));
56+
57+ printf (_("%s: Databases in danger of XID wraparound: "),
58+ ((j > critical_xid_age) ? "CRITICAL" : "WARNING"));
59+
60+ for (i = 0; i < PQntuples(res); i++)
61+ {
62+ printf (_("%s age %s"), PQgetvalue(res, i, 0), PQgetvalue(res, i, 1));
63+ if (i < PQntuples(res) - 1)
64+ printf (_(","));
65+ else
66+ printf (_("\n\n"));
67+ }
68+ PQclear (res);
69+ PQfinish (conn);
70+ return (j > critical_xid_age) ? STATE_CRITICAL : STATE_WARNING;
71+ }
72+
73+ PQclear(res);
74 status = STATE_OK;
75 }
76 PQfinish (conn);
77- printf (_(" %s - database %s (%d sec.)|%s\n"),
78+ printf (_(" %s - database %s (%ds, XIDs OK)|%s\n"),
79 state_text(status), dbName, elapsed_time,
80 fperfdata("time", elapsed_time, "s",
81@@ -198,9 +242,11 @@
82 {"port", required_argument, 0, 'P'},
83 {"database", required_argument, 0, 'd'},
84+ {"warnxid", required_argument, 0, 'x'},
85+ {"critxid", required_argument, 0, 'y'},
86 {0, 0, 0, 0}
87 };
88
89 while (1) {
90- c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:",
91+ c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:x:y:",
92 longopts, &option);
93
94@@ -259,4 +305,16 @@
95 pguser = optarg;
96 break;
97+ case 'x':
98+ if (!is_intpos(optarg))
99+ usage2 (_("Warning XID age must be a positive integer"), optarg);
100+ else
101+ warning_xid_age = atoi(optarg);
102+ break;
103+ case 'y':
104+ if (!is_intpos(optarg))
105+ usage2 (_("Critical XID age must be a positive integer"), optarg);
106+ else
107+ critical_xid_age = atoi(optarg);
108+ break;
109 case 'p': /* authentication password */
110 case 'a':
111@@ -403,11 +461,17 @@
112
113 printf (_("\
114- -d, --database=STRING\n\
115+ -d, --database=STRING\n\
116 Database to check (default: %s)\n\
117- -l, --logname = STRING\n\
118+ -l, --logname = STRING\n\
119 Login name of user\n\
120- -p, --password = STRING\n\
121+ -p, --password = STRING\n\
122 Password (BIG SECURITY ISSUE)\n"), DEFAULT_DB);
123
124+ printf (_("\
125+ -x, --warnxid=INTEGER\n\
126+ Minimum XID age to generate a warning (default: %d)\n\
127+ -y, --critxid=INTEGER\n\
128+ Minimum XID age to generate a critical (default: %d)\n"), DEFAULT_WARNING_XID_AGE, DEFAULT_CRITICAL_XID_AGE);
129+
130 printf (_(UT_WARN_CRIT));
131
132@@ -442,4 +506,5 @@
133 printf ("\
134 Usage: %s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n\
135- [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n", progname);
136+ [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n\
137+ [-x <warning_xid_age>] [-y <critical_xid_age>]\n", progname);
138 }