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:

[pastacode lang=”sql” manual=”yum%20install%20httpd%0Ayum%20install%20gcc%0Ayum%20install%20glibc*%0Ayum%20install%20gd*%0A” message=”SQL CODE” highlight=”” provider=”manual”/]

Create Nagios user account and group:

[pastacode lang=”sql” manual=”useradd%20nagios%0Apasswd%20nagios%0Agroupadd%20nagcmd%0Ausermod%20-G%20nagcmd%20nagios%0Ausermod%20-G%20nagcmd%20apache%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/] [ad type=”banner”] Downloads:

Create directory:

[pastacode lang=”sql” manual=”mkdir%20NagiosSetup%0Acd%20NagiosSetup%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

Download nagios:

[pastacode lang=”sql” manual=”wget%20-X%20Get%20%22http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnagios%2Ffiles%2Fnagios-3.x%2Fnagios-3.2.1%2Fnagios-3.2.1.tar.gz%2Fdownload%22%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

Download Nagios Plugins:

[pastacode lang=”sql” manual=”wget%20-X%20Get%20%22http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnagiosplug%2Ffiles%2Fnagiosplug%2F1.4.15%2Fnagios-plugins-1.4.15.tar.gz%2Fdownload%22″ message=”MYSQL CODE” highlight=”” provider=”manual”/] [ad type=”banner”]

Install Nagios

[pastacode lang=”sql” manual=”tar%20-xzvf%20nagios-3.2.1.tar.gz%0Acd%20nagios-3.2.1%0A.%2Fconfigure%20–with-command-group%3Dnagcmd%0Amake%20all%0Amake%20install%0Amake%20install-config%0Amake%20install-commandmode%0Amake%20install-init%0Achkconfig%20–add%20nagios%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

Configure Nagios Web Interface:

[pastacode lang=”sql” manual=”make%20install-webconf%0Ahtpasswd%20-c%20%2Fusr%2Flocal%2Fnagios%2Fetc%2Fhtpasswd.users%20nagiosadmin%0A%5Bspecify%20password%20for%20nagios%20admin%5D%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

Install plugins

[pastacode lang=”sql” manual=”tar%20xvf%20nagios-plugins-1.4.11.tar.gz%0Acd%20nagios-plugins-1.4.11%0A.%2Fconfigure%20–with-nagios-user%3Dnagios%20–with-nagios-group%3Dnagios%0Amake%0Amake%20install%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/] [ad type=”banner”]

Verify Installation, Starting nagios for the first time

[pastacode lang=”sql” manual=”service%20nagios%20start%0ABrowse%3A%20http%3A%2F%2Flocalhost%2Fnagios%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

 Here if you get Error:

[pastacode lang=”sql” manual=”%E2%80%9CYou%20don%E2%80%99t%20have%20permission%20to%20access%20%2Fnagios%2F%20on%20this%20server.%E2%80%9D%0A%0ACheck%20%2Fetc%2Fhttpd%2Fconf%2Fhttpd.conf%20for%20DirectoryIndex.%0AIf%20it%E2%80%99s%20not%20having%20index.php%20add%20it%20as%20follows%3A%0A%0Avi%20%2Fetc%2Fhttpd%2Fconf%2Fhttpd.conf%0ADirectoryIndex%20index.php%20index.html%20index.html.var%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]
  • 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:

[pastacode lang=”sql” manual=”wget%20http%3A%2F%2Flabs.consol.de%2Fwp-content%2Fuploads%2F2010%2F10%2Fcheck_mysql_health-2.1.3.tar.gz%0A%0Atar%20-zxvf%20check_mysql_health-2.1.3.tar.gz%0Acd%20check_mysql_health-2.1.3%0A.%2Fconfigure%20–prefix%3D%2Fusr%2Flocal%2Fnagios%20–with-nagios-user%3Dnagios%20–with-nagios-group%3Dnagios%20–with-perl%3D%2Fusr%2Fbin%2Fperl%0Amake%0Amake%20install%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

Create database user:

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

Provide email address for nagiosadmin:

[pastacode lang=”sql” manual=”%5BChange%20contacts.cfg%20file%20accordingly.%5D%0Avi%20%2Fusr%2Flocal%2Fnagios%2Fetc%2Fobjects%2Fcontacts.cfg%0A%0Adefine%20contact%0A%7B%0Acontact_name%20nagiosadmin%20%3B%20Short%20name%20of%20user%0Ause%20generic-contact%20%3B%20Inherit%20default%20values%20from%20generic-contact%20template%20(defined%20above)%0Aalias%20Kedar%20%3B%20Full%20name%20of%20user%0Aemail%20kedar%40nitty-witty.com%20%3B%20%3C%3C*****%20CHANGE%20THIS%20TO%20YOUR%20EMAIL%20ADDRESS%20******%0A%7D%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/] [ad type=”banner”]

Configuring Nagios to Monitor MySQL Server

[pastacode lang=”sql” manual=”vi%20%2Fusr%2Flocal%2Fnagios%2Fetc%2Fnagios.cfg%20%0Aadd%20following%20line%3A%0Acfg_file%3D%2Fusr%2Flocal%2Fnagios%2Fetc%2Fobjects%2Fmysqlmonitoring.cfg%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

Define check_mysql_health command as follows:

[pastacode lang=”sql” manual=”vi%20%2Fusr%2Flocal%2Fnagios%2Fetc%2Fobjects%2Fcommands.cfg%0A%0Adefine%20command%0A%7B%0Acommand_name%20check_mysql_health%0Acommand_line%20%24USER1%24%2Fcheck_mysql_health%20-H%20%24ARG4%24%20–username%20%24ARG1%24%20–password%20%24ARG2%24%20–port%20%24ARG5%24%20–mode%20%24ARG3%24%0A%7D%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

Enter services to be monitored in mysqlmonitoring.cfg:

[pastacode lang=”sql” manual=”vi%20%2Fusr%2Flocal%2Fnagios%2Fetc%2Fobjects%2Fmysqlmonitoring.cfg%0AAdd%3A%0A%0Adefine%20service%0A%7B%0Ause%20local-service%0Ahost_name%20localhost%0Aservice_description%20MySQL%20connection-time%0Acheck_command%20check_mysql_health!nagios!nagios!connection-time!127.0.0.1!3306!%0A%7D%0Adefine%20service%7B%0Ause%20local-service%0Ahost_name%20localhost%0Aservice_description%20MySQL%20slave-io-running%0Acheck_command%20check_mysql_health!nagios!nagios!slave-io-running!127.0.0.1!3306!%0A%7D%0A%0Adefine%20service%7B%0Ause%20local-service%0Ahost_name%20localhost%0Aservice_description%20MySQL%20slave-sql-running%0Acheck_command%20check_mysql_health!nagios!nagios!slave-sql-running!127.0.0.1!3306!%0A%7D%0A” message=”MYSQL CODE” highlight=”” provider=”manual”/]

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: