blog

Nagios Plugin for ClusterControl

Ashraf Sharif

Published:

Nagios is a very popular open source IT infrastructure monitoring tool, used by sysadmins to watch out for problems in their systems. If you use Nagios and would like to utilize it to monitor your database cluster, we have built a simple Nagios plugin for ClusterControl which can report on the status of your database cluster. The plugin is Nagios Plugin API v3.0 compatible.

 

The Nagios state will be as below:

Return Code

Service Status

Database Cluster Status

0

OK

STARTED: Cluster is started and running.

1

Warning

DEGRADED: Cluster is operational, but one or more of the database nodes are down or unreachable.

RECOVERING: One or more nodes are recovering, but cluster is operational.

2

Critical

FAILURE: Cluster has failed.

STOPPED: Cluster is stopped (gracefully).


SHUTTING_DOWN: Cluster is shutting down.

3

Unknown

UNKNOWN: Nagios could not connect to ClusterControl host to query the status. It could be wrong MySQL password/port, MySQL service is down or ClusterControl host is unreachable.

 

 

 

 

 

The plugin is available under our GitHub s9s-admin repository at https://github.com/severalnines/s9s-admin.git. This plugin can takes 3 arguments:

 

  • -H, –host: ClusterControl host IP address or host that hold cmon database
  • -p, –password: MySQL password for user cmon
  • -P, –port: MySQL port (optional with default value 3306)
  • -t, –type: Query type whether to get cluster status or alarms (optional with default value “cluster”)

 

Basically, you can trigger the plugin directly to check your database cluster status by using following command:

 

$ ./s9s_cluster_status -H <ClusterControl IP address> -p <cmon password>

 

**Updated 17th May 2013

We have added some functionality to include ClusterControl alarms. To get the alarms status of your database cluster, you can use following command:

$ ./s9s_cluster_status -H <ClusterControl IP address> -p <cmon password> -t alarm

Alarm’s command will returned all reported alarms gather by ClusterControl until dismissed.

The most important part when configuring Nagios plugin is the command, host and service definition. The following steps show an example on how to setup the plugin in a Nagios host (192.168.0.20) with a ClusterControl host, namely clustercontrol.mydomain.org (192.168.0.40):

1. Login in ClusterControl host’s MySQL console to allow cmon user from Nagios host:

mysql> GRANT SELECT ON cmon.* TO ‘cmon’@’192.168.0.20’ IDENTIFIED BY ‘cmonpassword123’
mysql> FLUSH PRIVILEGES

2. Login to Nagios host and clone the s9s-admin git repository:

$ git clone https://github.com/severalnines/s9s-admin.git

3. Copy the plugin into Nagios libexec directory:

$ cp s9s-admin/plugins/nagios/s9s_cluster_status /usr/local/nagios/libexec

4. Open commands.cfg and define the command for this plugin, by adding following line:

define command{
        command_name    s9s_cluster_status
        command_line    $USER1$/s9s_cluster_status -H $HOSTADDRESS$ -p $ARG1$
  }

5. Create a new file individual object config file called clustercontrol.cfg under etc/objects, to define the host and service:

$ vim /usr/local/nagios/etc/objects/clustercontrol.cfg

 

 

And add following line:

 

define host{
        use                     linux-server
        host_name               clustercontrol.mydomain.org
        alias                   clustercontrol.mydomain.org
        address                 192.168.0.40
        }
 
define service{
        use                             generic-service
        host_name                       clustercontrol.mydomain.org
        service_description             Database Cluster
        check_command                   s9s_cluster_status!cmonpassword123
        notifications_enabled           1
        }
 
define service{
        use                             generic-service
        host_name                       clustercontrol.mydomain.org
        service_description             Alarms
        check_command                   s9s_cluster_status!cmonpassword123!alarm
        notifications_enabled           1
        }

 

6. Add above object configuration file into Nagios main configuration:

$ echocfg_file=/usr/local/nagios/etc/objects/clustercontrol.cfg” >> /usr/local/nagios/etc/nagios.cfg

7. Restart Nagios service:

$ service nagios restart

After a while, you can see your database cluster status with alarms in Nagios, similar to screenshot below:

Moreover, you can use this plugin as a template for writing your own plugins for ClusterControl, for example to report on status of individual nodes.

If you have suggestions for improvements, please contact us!

Subscribe below to be notified of fresh posts