From 44a321cb8a42d6c0ea2d96a1086a17f2134c89cc Mon Sep 17 00:00:00 2001 From: Ethan Galstad Date: Thu, 28 Feb 2002 06:42:51 +0000 Subject: Initial revision git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c --- contrib/check_mysql.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 contrib/check_mysql.c (limited to 'contrib/check_mysql.c') diff --git a/contrib/check_mysql.c b/contrib/check_mysql.c new file mode 100644 index 00000000..9abacf87 --- /dev/null +++ b/contrib/check_mysql.c @@ -0,0 +1,75 @@ +/***************************************************************** + * + * Program: check_mysql.c + * License: GPL + * + * Written by Tim Weippert + * (based on plugins by Ethan Galstad and MySQL example code) + * + * Command line: check_mysql [user] [passwd] + * can be the FQDN or the IP-Adress + * [user] and [passwd] are optional + * + * Description: + * + * This plugin attempts to connect to an MySQL Server + * with the optional specified parameters user and passwd. + * 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 + * + *******************************************************************/ + +#include "../common/config.h" +#include "../common/common.h" +#include "mysql.h" + +MYSQL mysql; + +int main(int argc, char **argv) +{ + uint i = 0; + char *host; + char *user; + char *passwd; + + char *status; + char *version; + + if ( argc > 4 ) { + printf("Too many Arguments supplied - %i .\n", argc); + printf("Usage: %s [user] [passwd]\n", argv[0]); + return STATE_UNKNOWN; + } + + (host = argv[1]) || (host = NULL); + (user = argv[2]) || (user = NULL); + (passwd = argv[3]) || (passwd = NULL); + + if (!(mysql_connect(&mysql,host,user,passwd))) { + printf("Can't connect to Mysql on Host: %s\n", host); + 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