1 /*****************************************************************
2 *
3 * Program: check_mysql.c
4 * License: GPL
5 *
6 * Written by Tim Weippert
7 * (based on plugins by Ethan Galstad and MySQL example code)
8 *
9 * Command line: check_mysql <host> [user] [passwd]
10 * <host> can be the FQDN or the IP-Adress
11 * [user] and [passwd] are optional
12 *
13 * Description:
14 *
15 * This plugin attempts to connect to an MySQL Server
16 * with the optional specified parameters user and passwd.
17 * Normaly the host and a user HAVE to assigned.
18 *
19 * The plugin returns
20 * STATE_OK and the Version Number of the Server when all is fine
21 * STATE_CRITICAL if the Connection can't be esablished
22 * STATE_WARNING if the connection was established but the
23 * program can't get the Versoin Number
24 * STATE_UNKNOWN if to many parameters are given
25 *
26 * Copyright (c) 1999 by Tim Weippert
27 *
28 * Changes:
29 * 16.12.1999: Changed the return codes from numbers to statements
30 *
31 *******************************************************************/
33 #include "config.h"
34 #include "common.h"
35 #include "mysql.h"
37 MYSQL mysql;
39 int main(int argc, char **argv)
40 {
41 uint i = 0;
42 char *host;
43 char *user;
44 char *passwd;
46 char *status;
47 char *version;
49 if ( argc > 4 ) {
50 printf("Too many Arguments supplied - %i .\n", argc);
51 printf("Usage: %s <host> [user] [passwd]\n", argv[0]);
52 return STATE_UNKNOWN;
53 }
55 (host = argv[1]) || (host = NULL);
56 (user = argv[2]) || (user = NULL);
57 (passwd = argv[3]) || (passwd = NULL);
59 if (!(mysql_connect(&mysql,host,user,passwd))) {
60 printf("Can't connect to Mysql on Host: %s\n", host);
61 return STATE_CRITICAL;
62 }
64 if ( !(version = mysql_get_server_info(&mysql)) ) {
65 printf("Connect OK, but can't get Serverinfo ... something wrong !\n");
66 return STATE_WARNING;
67 }
69 printf("Mysql ok - Running Version: %s\n", version);
71 mysql_close(&mysql);
72 return STATE_OK;
73 }