summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_dbi.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c
index 468ded31..2e110ce3 100644
--- a/plugins/check_dbi.c
+++ b/plugins/check_dbi.c
@@ -76,21 +76,6 @@ static mp_state_enum do_query(dbi_conn /*conn*/, const char ** /*res_val_str*/,
76 mp_dbi_type /*type*/, char * /*np_dbi_query*/); 76 mp_dbi_type /*type*/, char * /*np_dbi_query*/);
77 77
78int main(int argc, char **argv) { 78int main(int argc, char **argv) {
79 int status = STATE_UNKNOWN;
80
81 dbi_driver driver;
82 dbi_conn conn;
83
84 unsigned int server_version;
85
86 struct timeval start_timeval;
87 struct timeval end_timeval;
88 double conn_time = 0.0;
89 double query_time = 0.0;
90
91 const char *query_val_str = NULL;
92 double query_val = 0.0;
93
94 setlocale(LC_ALL, ""); 79 setlocale(LC_ALL, "");
95 bindtextdomain(PACKAGE, LOCALEDIR); 80 bindtextdomain(PACKAGE, LOCALEDIR);
96 textdomain(PACKAGE); 81 textdomain(PACKAGE);
@@ -116,8 +101,7 @@ int main(int argc, char **argv) {
116 printf("Initializing DBI\n"); 101 printf("Initializing DBI\n");
117 } 102 }
118 103
119 dbi_inst *instance_p = {0}; 104 dbi_inst *instance_p = NULL;
120
121 if (dbi_initialize_r(NULL, instance_p) < 0) { 105 if (dbi_initialize_r(NULL, instance_p) < 0) {
122 printf( 106 printf(
123 "UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n"); 107 "UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n");
@@ -133,7 +117,7 @@ int main(int argc, char **argv) {
133 printf("Opening DBI driver '%s'\n", config.dbi_driver); 117 printf("Opening DBI driver '%s'\n", config.dbi_driver);
134 } 118 }
135 119
136 driver = dbi_driver_open_r(config.dbi_driver, instance_p); 120 dbi_driver driver = dbi_driver_open_r(config.dbi_driver, instance_p);
137 if (!driver) { 121 if (!driver) {
138 printf("UNKNOWN - failed to open DBI driver '%s'; possibly it's not installed.\n", 122 printf("UNKNOWN - failed to open DBI driver '%s'; possibly it's not installed.\n",
139 config.dbi_driver); 123 config.dbi_driver);
@@ -147,9 +131,10 @@ int main(int argc, char **argv) {
147 } 131 }
148 132
149 /* make a connection to the database */ 133 /* make a connection to the database */
134 struct timeval start_timeval;
150 gettimeofday(&start_timeval, NULL); 135 gettimeofday(&start_timeval, NULL);
151 136
152 conn = dbi_conn_open(driver); 137 dbi_conn conn = dbi_conn_open(driver);
153 if (!conn) { 138 if (!conn) {
154 printf("UNKNOWN - failed top open connection object.\n"); 139 printf("UNKNOWN - failed top open connection object.\n");
155 dbi_conn_close(conn); 140 dbi_conn_close(conn);
@@ -210,14 +195,16 @@ int main(int argc, char **argv) {
210 return STATE_UNKNOWN; 195 return STATE_UNKNOWN;
211 } 196 }
212 197
198 struct timeval end_timeval;
213 gettimeofday(&end_timeval, NULL); 199 gettimeofday(&end_timeval, NULL);
214 conn_time = timediff(start_timeval, end_timeval); 200 double conn_time = timediff(start_timeval, end_timeval);
215 201
216 server_version = dbi_conn_get_engine_version(conn); 202 unsigned int server_version = dbi_conn_get_engine_version(conn);
217 if (verbose) { 203 if (verbose) {
218 printf("Connected to server version %u\n", server_version); 204 printf("Connected to server version %u\n", server_version);
219 } 205 }
220 206
207 int status = STATE_UNKNOWN;
221 if (config.metric == METRIC_SERVER_VERSION) { 208 if (config.metric == METRIC_SERVER_VERSION) {
222 status = get_status(server_version, config.dbi_thresholds); 209 status = get_status(server_version, config.dbi_thresholds);
223 } 210 }
@@ -243,6 +230,10 @@ int main(int argc, char **argv) {
243 } 230 }
244 } 231 }
245 232
233
234 const char *query_val_str = NULL;
235 double query_val = 0.0;
236 double query_time = 0.0;
246 if (config.dbi_query) { 237 if (config.dbi_query) {
247 /* execute query */ 238 /* execute query */
248 status = do_query(conn, &query_val_str, &query_val, &query_time, config.metric, config.type, 239 status = do_query(conn, &query_val_str, &query_val, &query_time, config.metric, config.type,