diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 2acddc4..cf526a6 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
@@ -42,6 +42,20 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
42 | #define DEFAULT_DB "template1" | 42 | #define DEFAULT_DB "template1" |
43 | #define DEFAULT_HOST "127.0.0.1" | 43 | #define DEFAULT_HOST "127.0.0.1" |
44 | 44 | ||
45 | /* return the PSQL server version as a 3-tuple */ | ||
46 | #define PSQL_SERVER_VERSION3(server_version) \ | ||
47 | (server_version) / 10000, \ | ||
48 | (server_version) / 100 - (int)((server_version) / 10000) * 100, \ | ||
49 | (server_version) - (int)((server_version) / 100) * 100 | ||
50 | /* return true if the given host is a UNIX domain socket */ | ||
51 | #define PSQL_IS_UNIX_DOMAIN_SOCKET(host) \ | ||
52 | ((NULL == (host)) || ('\0' == *(host)) || ('/' == *(host))) | ||
53 | /* return a 3-tuple identifying a host/port independent of the socket type */ | ||
54 | #define PSQL_SOCKET3(host, port) \ | ||
55 | ((NULL == (host)) || ('\0' == *(host))) ? DEFAULT_PGSOCKET_DIR : host, \ | ||
56 | PSQL_IS_UNIX_DOMAIN_SOCKET (host) ? "/.s.PGSQL." : ":", \ | ||
57 | port | ||
58 | |||
45 | enum { | 59 | enum { |
46 | DEFAULT_PORT = 5432, | 60 | DEFAULT_PORT = 5432, |
47 | DEFAULT_WARN = 2, | 61 | DEFAULT_WARN = 2, |
@@ -133,6 +147,7 @@ int | |||
133 | main (int argc, char **argv) | 147 | main (int argc, char **argv) |
134 | { | 148 | { |
135 | PGconn *conn; | 149 | PGconn *conn; |
150 | char *conninfo = NULL; | ||
136 | 151 | ||
137 | int elapsed_time; | 152 | int elapsed_time; |
138 | int status = STATE_UNKNOWN; | 153 | int status = STATE_UNKNOWN; |
@@ -164,18 +179,30 @@ main (int argc, char **argv) | |||
164 | } | 179 | } |
165 | alarm (timeout_interval); | 180 | alarm (timeout_interval); |
166 | 181 | ||
167 | if (verbose) | 182 | asprintf (&conninfo, "dbname = '%s'", dbName); |
168 | printf("Connecting to database:\n DB: %s\n User: %s\n Host: %s\n Port: %d\n", dbName, | 183 | if (pghost) |
169 | (pguser != NULL) ? pguser : "unspecified", | 184 | asprintf (&conninfo, "%s host = '%s'", conninfo, pghost); |
170 | (pghost != NULL) ? pghost : "unspecified", | 185 | if (pgport) |
171 | (pgport != NULL) ? atoi(pgport) : DEFAULT_PORT); | 186 | asprintf (&conninfo, "%s port = '%s'", conninfo, pgport); |
187 | if (pgoptions) | ||
188 | asprintf (&conninfo, "%s options = '%s'", conninfo, pgoptions); | ||
189 | /* if (pgtty) -- ignored by PQconnectdb */ | ||
190 | if (pguser) | ||
191 | asprintf (&conninfo, "%s user = '%s'", conninfo, pguser); | ||
192 | |||
193 | if (verbose) /* do not include password (see right below) in output */ | ||
194 | printf ("Connecting to PostgreSQL using conninfo: %s%s\n", conninfo, | ||
195 | pgpasswd ? " password = <hidden>" : ""); | ||
196 | |||
197 | if (pgpasswd) | ||
198 | asprintf (&conninfo, "%s password = '%s'", conninfo, pgpasswd); | ||
172 | 199 | ||
173 | /* make a connection to the database */ | 200 | /* make a connection to the database */ |
174 | time (&start_time); | 201 | time (&start_time); |
175 | conn = | 202 | conn = PQconnectdb (conninfo); |
176 | PQsetdbLogin (pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpasswd); | ||
177 | time (&end_time); | 203 | time (&end_time); |
178 | elapsed_time = (int) (end_time - start_time); | 204 | elapsed_time = (int) (end_time - start_time); |
205 | |||
179 | if (verbose) | 206 | if (verbose) |
180 | printf("Time elapsed: %d\n", elapsed_time); | 207 | printf("Time elapsed: %d\n", elapsed_time); |
181 | 208 | ||
@@ -197,6 +224,20 @@ main (int argc, char **argv) | |||
197 | else { | 224 | else { |
198 | status = STATE_OK; | 225 | status = STATE_OK; |
199 | } | 226 | } |
227 | |||
228 | if (verbose) { | ||
229 | char *server_host = PQhost (conn); | ||
230 | int server_version = PQserverVersion (conn); | ||
231 | |||
232 | printf ("Successfully connected to database %s (user %s) " | ||
233 | "at server %s%s%s (server version: %d.%d.%d, " | ||
234 | "protocol version: %d, pid: %d)\n", | ||
235 | PQdb (conn), PQuser (conn), | ||
236 | PSQL_SOCKET3 (server_host, PQport (conn)), | ||
237 | PSQL_SERVER_VERSION3 (server_version), | ||
238 | PQprotocolVersion (conn), PQbackendPID (conn)); | ||
239 | } | ||
240 | |||
200 | printf (_(" %s - database %s (%d sec.)|%s\n"), | 241 | printf (_(" %s - database %s (%d sec.)|%s\n"), |
201 | state_text(status), dbName, elapsed_time, | 242 | state_text(status), dbName, elapsed_time, |
202 | fperfdata("time", elapsed_time, "s", | 243 | fperfdata("time", elapsed_time, "s", |