From 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 30 Sep 2013 00:03:24 +0200 Subject: Import Nagios Plugins site Import the Nagios Plugins web site, Cronjobs, infrastructure scripts, and configuration files. --- web/attachments/182402-check_mysql.c | 100 +++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 web/attachments/182402-check_mysql.c (limited to 'web/attachments/182402-check_mysql.c') 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 @@ +/***************************************************************** + * + * Program: check_mysql.c + * License: GPL + * + * Written by Tim Weippert + * (based on plugins by Ethan Galstad and MySQL example code) + * + * Adapted by J. Javier Sianes - skyo@rotxa.org + * + * + * Command line: check_mysql [user] [passwd] [db] [port] + * can be the FQDN or the IP-Adress + * [user], [passwd], [db] and [port] are optional + * + * Description: + * + * This plugin attempts to connect to an MySQL Server + * with the optional specified parameters user, passwd and db. + * Normaly the host and a user HAVE to assigned. + * + * The plugin returns + * STATE_OK and the Version Number of the Server when all is fine + * STATE_CRITICAL if the Connection can't be esablished + * STATE_WARNING if the connection was established but the + * program can't get the Versoin Number + * STATE_UNKNOWN if to many parameters are given + * + * Copyright (c) 1999 by Tim Weippert + * + * Changes: + * 16.12.1999: Changed the return codes from numbers to statements + * 20.06.2006: Included new db and port parameters + * 20.06.2006: Adapted for using new MySQL5 API + * + *******************************************************************/ + +/***************************************************************** + * + * Note that all includes are related to Nagios and MySQL default installation. + * If you have installed them on a different location, you may change + * the following include lines in order to make it works. + * + * To compile the agent, in a shell use the following command, for example: + * + * gcc -lmysqlclient -o check_mysql check_mysql.c + * + *******************************************************************/ + +#include +#include +#include "/usr/include/nagios/config.h" +#include "/usr/include/nagios/common.h" +#include "/usr/include/nagios/nagios.h" +#include "/usr/include/mysql/mysql.h" + +MYSQL mysql; + +int main(int argc, char **argv) +{ + uint i = 0; + int mport; + char *host; + char *user; + char *passwd; + char *db; + + char *status; + char *version; + + if ( ( argc > 6 ) || ( argc < 2 ) ) { + printf("Incorrect number of arguments supplied - %i .\n", argc); + printf("Usage: %s [user] [passwd] [db] [port]\n", argv[0]); + return STATE_UNKNOWN; + } + + (host = argv[1]) || (host = NULL); + (user = argv[2]) || (user = NULL); + (passwd = argv[3]) || (passwd = NULL); + (db = argv[4]) || (db = "mysql"); + if (argc==6) { mport = atoi(argv[5]); } else { mport = 3306; } + + mysql_init(&mysql); + mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"check_mysql"); + + if (!mysql_real_connect(&mysql,host,user,passwd,db,(unsigned int)mport,NULL,0)) { + printf("Connect ERROR, Failed to connect to database '%s': %s\n",db,mysql_error(&mysql)); + return STATE_CRITICAL; + } + + if ( !(version = mysql_get_server_info(&mysql)) ) { + printf("Connect OK, but can't get Serverinfo ... something wrong !\n"); + return STATE_WARNING; + } + + printf("MYSQL OK - Running Version: %s\n", version); + + mysql_close(&mysql); + return STATE_OK; +} -- cgit v1.2.3-74-g34f1