/******************************************************************************
*
* Nagios check_mysql_query plugin
*
* License: GPL
* Copyright (c) 2006 nagios-plugins team, after Didi Rieder (check_mysql)
*
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
* This file contains the check_mysql_query plugin
*
* This plugin is for running arbitrary SQL and checking the results
*
* License Information:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* CHECK_MYSQL_QUERY.C
*
* $Id: check_mysql_query.c 1590 2007-01-28 21:46:41Z hweiss $
*
******************************************************************************/
const char *progname = "check_mysql_query";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
#include "utils.h"
#include "utils_base.h"
#include "netutils.h"
#include <mysql.h>
#include <errmsg.h>
char *db_user = NULL;
char *db_host = NULL;
char *db_pass = NULL;
char *db = NULL;
unsigned int db_port = MYSQL_PORT;
int process_arguments (int, char **);
int validate_arguments (void);
void print_help (void);
void print_usage (void);
char *sql_query = NULL;
int verbose = 0;
thresholds *my_thresholds = NULL;
int
main (int argc, char **argv)
{
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
double value;
char *error = NULL;
int status;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
if (process_arguments (argc, argv) == ERROR)
usage4 (_("Could not parse arguments"));
/* initialize mysql */
mysql_init (&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client");
/* establish a connection to the server and error checking */
if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,NULL,0)) {
if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
die (STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error (&mysql));
else if (mysql_errno (&mysql) == CR_VERSION_ERROR)
die (STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error (&mysql));
else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY)
die (STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error (&mysql));
else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR)
die (STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error (&mysql));
else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR)
=1= |