summaryrefslogtreecommitdiffstats
path: root/web/attachments/182402-check_mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/182402-check_mysql.c')
-rw-r--r--web/attachments/182402-check_mysql.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/web/attachments/182402-check_mysql.c b/web/attachments/182402-check_mysql.c
new file mode 100644
index 0000000..5ef37d1
--- /dev/null
+++ b/web/attachments/182402-check_mysql.c
@@ -0,0 +1,100 @@
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 * Adapted by J. Javier Sianes - skyo@rotxa.org
10 *
11 *
12 * Command line: check_mysql <host> [user] [passwd] [db] [port]
13 * <host> can be the FQDN or the IP-Adress
14 * [user], [passwd], [db] and [port] are optional
15 *
16 * Description:
17 *
18 * This plugin attempts to connect to an MySQL Server
19 * with the optional specified parameters user, passwd and db.
20 * Normaly the host and a user HAVE to assigned.
21 *
22 * The plugin returns
23 * STATE_OK and the Version Number of the Server when all is fine
24 * STATE_CRITICAL if the Connection can't be esablished
25 * STATE_WARNING if the connection was established but the
26 * program can't get the Versoin Number
27 * STATE_UNKNOWN if to many parameters are given
28 *
29 * Copyright (c) 1999 by Tim Weippert
30 *
31 * Changes:
32 * 16.12.1999: Changed the return codes from numbers to statements
33 * 20.06.2006: Included new db and port parameters
34 * 20.06.2006: Adapted for using new MySQL5 API
35 *
36 *******************************************************************/
37
38/*****************************************************************
39 *
40 * Note that all includes are related to Nagios and MySQL default installation.
41 * If you have installed them on a different location, you may change
42 * the following include lines in order to make it works.
43 *
44 * To compile the agent, in a shell use the following command, for example:
45 *
46 * gcc -lmysqlclient -o check_mysql check_mysql.c
47 *
48 *******************************************************************/
49
50#include <stdio.h>
51#include <stdlib.h>
52#include "/usr/include/nagios/config.h"
53#include "/usr/include/nagios/common.h"
54#include "/usr/include/nagios/nagios.h"
55#include "/usr/include/mysql/mysql.h"
56
57MYSQL mysql;
58
59int main(int argc, char **argv)
60{
61 uint i = 0;
62 int mport;
63 char *host;
64 char *user;
65 char *passwd;
66 char *db;
67
68 char *status;
69 char *version;
70
71 if ( ( argc > 6 ) || ( argc < 2 ) ) {
72 printf("Incorrect number of arguments supplied - %i .\n", argc);
73 printf("Usage: %s <host> [user] [passwd] [db] [port]\n", argv[0]);
74 return STATE_UNKNOWN;
75 }
76
77 (host = argv[1]) || (host = NULL);
78 (user = argv[2]) || (user = NULL);
79 (passwd = argv[3]) || (passwd = NULL);
80 (db = argv[4]) || (db = "mysql");
81 if (argc==6) { mport = atoi(argv[5]); } else { mport = 3306; }
82
83 mysql_init(&mysql);
84 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"check_mysql");
85
86 if (!mysql_real_connect(&mysql,host,user,passwd,db,(unsigned int)mport,NULL,0)) {
87 printf("Connect ERROR, Failed to connect to database '%s': %s\n",db,mysql_error(&mysql));
88 return STATE_CRITICAL;
89 }
90
91 if ( !(version = mysql_get_server_info(&mysql)) ) {
92 printf("Connect OK, but can't get Serverinfo ... something wrong !\n");
93 return STATE_WARNING;
94 }
95
96 printf("MYSQL OK - Running Version: %s\n", version);
97
98 mysql_close(&mysql);
99 return STATE_OK;
100}