summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-08-10 06:53:22 +0000
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-08-10 06:53:22 +0000
commitf4f92be60c94fd4e0dd4b2b4b3101543eedb706a (patch)
tree28d25bd0ab624d82435823c940a186370947ad4d /plugins/check_mysql.c
parentcbf702f51f839af5a8e9c66bdae7d6a3dc363ace (diff)
downloadmonitoring-plugins-f4f92be60c94fd4e0dd4b2b4b3101543eedb706a.tar.gz
the last round of pedantic compiler warnings
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@676 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c196
1 files changed, 94 insertions, 102 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 16a1f133..a7afa52f 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -25,65 +25,23 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
25#include <mysql/mysql.h> 25#include <mysql/mysql.h>
26#include <mysql/errmsg.h> 26#include <mysql/errmsg.h>
27 27
28void 28char *db_user = NULL;
29print_usage (void) 29char *db_host = NULL;
30{ 30char *db_pass = NULL;
31 printf (_("\ 31char *db = NULL;
32Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"),
33 progname);
34 printf (_(UT_HLP_VRS), progname, progname);
35}
36
37void
38print_help (void)
39{
40 char *myport;
41 asprintf (&myport, "%d", MYSQL_PORT);
42
43 print_revision (progname, revision);
44
45 printf (_(COPYRIGHT), copyright, email);
46
47 printf (_("This program tests connections to a mysql server\n"));
48
49 print_usage ();
50
51 printf (_(UT_HELP_VRSN));
52
53 printf (_(UT_HOST_PORT), 'P', myport);
54
55 printf (_("\
56 -d, --database=STRING\n\
57 Check database with indicated name\n\
58 -u, --username=STRING\n\
59 Connect using the indicated username\n\
60 -p, --password=STRING\n\
61 Use the indicated password to authenticate the connection\n\
62 ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
63 Your clear-text password will be visible as a process table entry\n"));
64
65 printf (_("\n\
66There are no required arguments. By default, the local database with\n\
67a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT);
68
69 printf (_(UT_SUPPORT));
70}
71
72char *db_user = "";
73char *db_host = "";
74char *db_pass = "";
75char *db = "";
76unsigned int db_port = MYSQL_PORT; 32unsigned int db_port = MYSQL_PORT;
77 33
78int process_arguments (int, char **); 34int process_arguments (int, char **);
79int validate_arguments (void); 35int validate_arguments (void);
36void print_help (void);
37void print_usage (void);
80 38
81int 39int
82main (int argc, char **argv) 40main (int argc, char **argv)
83{ 41{
84 42
85 MYSQL mysql; 43 MYSQL mysql;
86 char result[1024]; 44 char *result = NULL;
87 45
88 if (process_arguments (argc, argv) != OK) 46 if (process_arguments (argc, argv) != OK)
89 usage (_("Invalid command arguments supplied\n")); 47 usage (_("Invalid command arguments supplied\n"));
@@ -92,62 +50,32 @@ main (int argc, char **argv)
92 mysql_init (&mysql); 50 mysql_init (&mysql);
93 51
94 /* establish a connection to the server and error checking */ 52 /* establish a connection to the server and error checking */
95 if (!mysql_real_connect 53 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,NULL,0)) {
96 (&mysql, db_host, db_user, db_pass, db, db_port, NULL, 0)) { 54 if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
97 55 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
98 if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) { 56 else if (mysql_errno (&mysql) == CR_VERSION_ERROR)
99 printf ("%s\n", mysql_error (&mysql)); 57 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
100 return STATE_WARNING; 58 else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY)
101 59 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
102 } 60 else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR)
103 else if (mysql_errno (&mysql) == CR_VERSION_ERROR) { 61 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
104 printf ("%s\n", mysql_error (&mysql)); 62 else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR)
105 return STATE_WARNING; 63 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
106 64 else
107 } 65 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
108 else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY) {
109 printf ("%s\n", mysql_error (&mysql));
110 return STATE_WARNING;
111
112 }
113 else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR) {
114 printf ("%s\n", mysql_error (&mysql));
115 return STATE_WARNING;
116
117 }
118 else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR) {
119 printf ("%s\n", mysql_error (&mysql));
120 return STATE_WARNING;
121
122 }
123 else {
124 printf ("%s\n", mysql_error (&mysql));
125 return STATE_CRITICAL;
126 }
127
128 } 66 }
129 67
130 /* get the server stats */ 68 /* get the server stats */
131 sprintf (result, mysql_stat (&mysql)); 69 result = strdup (mysql_stat (&mysql));
132 70
133 /* error checking once more */ 71 /* error checking once more */
134 if (mysql_error (&mysql)) { 72 if (mysql_error (&mysql)) {
135 73 if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR)
136 if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR) { 74 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
137 printf ("%s\n", mysql_error (&mysql)); 75 else if (mysql_errno (&mysql) == CR_SERVER_LOST)
138 return STATE_CRITICAL; 76 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
139 77 else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR)
140 } 78 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
141 else if (mysql_errno (&mysql) == CR_SERVER_LOST) {
142 printf ("%s\n", mysql_error (&mysql));
143 return STATE_CRITICAL;
144
145 }
146 else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR) {
147 printf ("%s\n", mysql_error (&mysql));
148 return STATE_UNKNOWN;
149 }
150
151 } 79 }
152 80
153 /* close the connection */ 81 /* close the connection */
@@ -169,8 +97,8 @@ process_arguments (int argc, char **argv)
169{ 97{
170 int c; 98 int c;
171 99
172 int option_index = 0; 100 int option = 0;
173 static struct option long_options[] = { 101 static struct option longopts[] = {
174 {"hostname", required_argument, 0, 'H'}, 102 {"hostname", required_argument, 0, 'H'},
175 {"database", required_argument, 0, 'd'}, 103 {"database", required_argument, 0, 'd'},
176 {"username", required_argument, 0, 'u'}, 104 {"username", required_argument, 0, 'u'},
@@ -186,7 +114,7 @@ process_arguments (int argc, char **argv)
186 return ERROR; 114 return ERROR;
187 115
188 while (1) { 116 while (1) {
189 c = getopt_long (argc, argv, "hVP:p:u:d:H:", long_options, &option_index); 117 c = getopt_long (argc, argv, "hVP:p:u:d:H:", longopts, &option);
190 118
191 if (c == -1 || c == EOF) 119 if (c == -1 || c == EOF)
192 break; 120 break;
@@ -256,5 +184,69 @@ process_arguments (int argc, char **argv)
256int 184int
257validate_arguments (void) 185validate_arguments (void)
258{ 186{
187 if (db_user == NULL)
188 db_user = strdup("");
189
190 if (db_host == NULL)
191 db_host = strdup("");
192
193 if (db_pass == NULL)
194 db_pass == strdup("");
195
196 if (db == NULL)
197 db = strdup("");
198
259 return OK; 199 return OK;
260} 200}
201
202
203
204
205
206
207void
208print_help (void)
209{
210 char *myport;
211 asprintf (&myport, "%d", MYSQL_PORT);
212
213 print_revision (progname, revision);
214
215 printf (_(COPYRIGHT), copyright, email);
216
217 printf (_("This program tests connections to a mysql server\n"));
218
219 print_usage ();
220
221 printf (_(UT_HELP_VRSN));
222
223 printf (_(UT_HOST_PORT), 'P', myport);
224
225 printf (_("\
226 -d, --database=STRING\n\
227 Check database with indicated name\n\
228 -u, --username=STRING\n\
229 Connect using the indicated username\n\
230 -p, --password=STRING\n\
231 Use the indicated password to authenticate the connection\n\
232 ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
233 Your clear-text password will be visible as a process table entry\n"));
234
235 printf (_("\n\
236There are no required arguments. By default, the local database with\n\
237a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT);
238
239 printf (_(UT_SUPPORT));
240}
241
242
243
244
245void
246print_usage (void)
247{
248 printf (_("\
249Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"),
250 progname);
251 printf (_(UT_HLP_VRS), progname, progname);
252}