This post guides you to install check_mysql_health plugin in nagios. So, first we have to install and configure Nagios. Follow the steps as below:

Installing and configuring Nagios:

Install required stuff:

SQL CODE
yum install httpd
yum install gcc
yum install glibc*
yum install gd*

Create Nagios user account and group:

MYSQL CODE
useradd nagios
passwd nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
[ad type=”banner”] Downloads:

Create directory:

MYSQL CODE
mkdir NagiosSetup
cd NagiosSetup

Download nagios:

MYSQL CODE
wget -X Get "http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz/download"

Download Nagios Plugins:

MYSQL CODE
wget -X Get "http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz/download"
[ad type=”banner”]

Install Nagios

MYSQL CODE
tar -xzvf nagios-3.2.1.tar.gz
cd nagios-3.2.1
./configure --with-command-group=nagcmd
make all
make install
make install-config
make install-commandmode
make install-init
chkconfig --add nagios

Configure Nagios Web Interface:

MYSQL CODE
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
[specify password for nagios admin]

Install plugins

MYSQL CODE
tar xvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
[ad type=”banner”]

Verify Installation, Starting nagios for the first time

MYSQL CODE
service nagios start
Browse: http://localhost/nagios

 Here if you get Error:

MYSQL CODE
“You don’t have permission to access /nagios/ on this server.”

Check /etc/httpd/conf/httpd.conf for DirectoryIndex.
If it’s not having index.php add it as follows:

vi /etc/httpd/conf/httpd.conf
DirectoryIndex index.php index.html index.html.var
  • Make sure you do restart apache(httpd) and nagios every time you change the config file. You must have php installed

Monitoring MySQL:

Download, Extract and install the MySQL Plugin:

MYSQL CODE
wget http://labs.consol.de/wp-content/uploads/2010/10/check_mysql_health-2.1.3.tar.gz

tar -zxvf check_mysql_health-2.1.3.tar.gz
cd check_mysql_health-2.1.3
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-perl=/usr/bin/perl
make
make install

Create database user:

grant usage, replication client on *.* to ‘nagios’@’localhost’ identified by ‘nagios’;

Provide email address for nagiosadmin:

MYSQL CODE
[Change contacts.cfg file accordingly.]
vi /usr/local/nagios/etc/objects/contacts.cfg

define contact
{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Kedar ; Full name of user
email [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
[ad type=”banner”]

Configuring Nagios to Monitor MySQL Server

MYSQL CODE
vi /usr/local/nagios/etc/nagios.cfg 
add following line:
cfg_file=/usr/local/nagios/etc/objects/mysqlmonitoring.cfg

Define check_mysql_health command as follows:

MYSQL CODE
vi /usr/local/nagios/etc/objects/commands.cfg

define command
{
command_name check_mysql_health
command_line $USER1$/check_mysql_health -H $ARG4$ --username $ARG1$ --password $ARG2$ --port $ARG5$ --mode $ARG3$
}

Enter services to be monitored in mysqlmonitoring.cfg:

MYSQL CODE
vi /usr/local/nagios/etc/objects/mysqlmonitoring.cfg
Add:

define service
{
use local-service
host_name localhost
service_description MySQL connection-time
check_command check_mysql_health!nagios!nagios!connection-time!127.0.0.1!3306!
}
define service{
use local-service
host_name localhost
service_description MySQL slave-io-running
check_command check_mysql_health!nagios!nagios!slave-io-running!127.0.0.1!3306!
}

define service{
use local-service
host_name localhost
service_description MySQL slave-sql-running
check_command check_mysql_health!nagios!nagios!slave-sql-running!127.0.0.1!3306!
}

Note: Every time you change configuration file, verify before starting nagios using command:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Finally start nagios service and you’re done with nagios installation and configuration for monitoring MySQL.

How to “compile” the check_mysql_health script:

  • Run the configure script to initialize variables and create a Makefile, etc.
./configure --prefix=BASEDIRECTORY --with-nagios-user=SOMEUSER --with-nagios-group=SOMEGROUP
--with-perl=PATH_TO_PERL --with-statefiles-dir=STATE_PATH
  • Replace BASEDIRECTORY with the path of the directory under which Nagios

is installed (default is ‘/usr/local/nagios’)

  •  Replace SOMEUSER with the name of a user on your system that will be

assigned permissions to the installed plugins (default is ‘nagios’)

  •  Replace SOMEGRP with the name of a group on your system that will be

assigned permissions to the installed plugins (default is ‘nagios’)

  •  Replace PATH_TO_PERL with the path where a perl binary can be found.

Besides the system wide perl you might have installed a private perl

just for the nagios plugins (default is the perl in your path).

  •  Replace STATE_PATH with the directory where you want the script to

write state files which transport information from one run to the next.

(default is /tmp)

Simply running ./configure will be sufficient to create a check_mssql_health script which you can customize later.

[ad type=”banner”]

Compile the plugin with the following command:

make

  • This will produce a “check_mssql_health” script.
  • You will also find a “check_mssql_health.pl” which you better ignore.
  • It is the base for the compilation filled with placeholders.
  • These will be replaced during the make process.

Install the compiled plugin script with the following command:

make install

  • The installation procedure will attempt to place the plugin in a  ‘libexec/’ subdirectory in the base directory you specified with the –prefix argument to the configure script.
  • Verify that your configuration files for Nagios contains the correct paths to the new plugin.

 

Categorized in: