diff --git a/plugins/nagios/README b/plugins/nagios/README index d02bc1fa6..9065796c4 100644 --- a/plugins/nagios/README +++ b/plugins/nagios/README @@ -1,5 +1,16 @@ MaxScale Nagios plugins, for Nagios 3.5.1 +MaxScale must be configured with 'maxscaled' protocol for the administration interface + +[AdminInterface] +type=service +router=cli + +[AdminListener] +type=listener +service=AdminInterface +protocol=maxscaled +port=6603 1) copy check_maxscale_*.pl under /usr/lib64/nagios/plugins 2) copy maxscale_commands.cfg, server1.cfg to /etc/nagios/objects/ @@ -11,10 +22,22 @@ cfg_file=/etc/nagios/objects/maxscale_commands.cfg cfg_file=/etc/nagios/objects/server1.cfg Please note: -- modify server IP address in server1.cfg +- modify server IP address in server1.cfg, pointing to MaxScale server - maxadmin executable must be in the nagios server +- default AdminInterface port is 6603 +- default maxadmin executable path is /usr/local/skysql/maxscale/bin/maxadmin + It can be changed by -m option +Example related to server1.cfg +# Check MaxScale sessions, on the remote machine. +define service{ + use local-service ; Name of service template to use + host_name server1 + service_description MaxScale_sessions + check_command check_maxscale_resource!6603!admin!skysql!sessions!/path_to/maxadmin + notifications_enabled 0 + } 4) Restart Nagios diff --git a/plugins/nagios/check_maxscale_monitors.pl b/plugins/nagios/check_maxscale_monitors.pl index 2cee92625..2850bd754 100755 --- a/plugins/nagios/check_maxscale_monitors.pl +++ b/plugins/nagios/check_maxscale_monitors.pl @@ -72,17 +72,21 @@ EOF 'P' => 6603, # port 'm' => '/usr/local/skysql/maxscale/bin/maxadmin', # maxadmin ); + +my $MAXADMIN_DEFAULT = $opts{'m'}; + getopts('r:hH:u:p:P:m:', \%opts) or usage( $ERRORS{"UNKNOWN"} ); usage( $ERRORS{'OK'} ) if $opts{'h'}; my $MAXADMIN_RESOURCE = $opts{'r'}; my $MAXADMIN = $opts{'m'}; +if (!defined $MAXADMIN || length($MAXADMIN) == 0) { + $MAXADMIN = $MAXADMIN_DEFAULT; +} -x $MAXADMIN or die "$curr_script: Failed to find required tool: $MAXADMIN. Please install it or use the -m option to point to another location."; -my ( $state, $status ) = ( "OK", 'maxadmin ' . $MAXADMIN_RESOURCE .' succeeds.' ); - # Just in case of problems, let's not hang Nagios $SIG{'ALRM'} = sub { print ("UNKNOWN: No response from MaxScale server (alarm)\n"); @@ -117,7 +121,7 @@ my %monitor_data; while ( ) { chomp; - if ( /Unable to connect to MaxScale/ ) { + if ( /(Failed|Unable) to connect to MaxScale/ ) { printf "CRITICAL: $_\n"; close(MAXSCALE); exit(2); diff --git a/plugins/nagios/check_maxscale_resources.pl b/plugins/nagios/check_maxscale_resources.pl index dcb43d772..2cb3944e0 100755 --- a/plugins/nagios/check_maxscale_resources.pl +++ b/plugins/nagios/check_maxscale_resources.pl @@ -72,17 +72,22 @@ EOF 'P' => 6603, # port 'm' => '/usr/local/skysql/maxscale/bin/maxadmin', # maxadmin ); + +my $MAXADMIN_DEFAULT = $opts{'m'}; + getopts('r:hH:u:p:P:m:', \%opts) or usage( $ERRORS{"UNKNOWN"} ); usage( $ERRORS{'OK'} ) if $opts{'h'}; my $MAXADMIN_RESOURCE = $opts{'r'}; my $MAXADMIN = $opts{'m'}; +if (!defined $MAXADMIN || length($MAXADMIN) == 0) { + $MAXADMIN = $MAXADMIN_DEFAULT; +} + -x $MAXADMIN or die "$curr_script: Failed to find required tool: $MAXADMIN. Please install it or use the -m option to point to another location."; -my ( $state, $status ) = ( "OK", 'maxadmin ' . $MAXADMIN_RESOURCE .' succeeds.' ); - # Just in case of problems, let's not hang Nagios $SIG{'ALRM'} = sub { print ("UNKNOWN: No response from MaxScale server (alarm)\n"); @@ -128,7 +133,7 @@ if ($resource_type eq "session") { while ( ) { chomp; - if ( /Unable to connect to MaxScale/ ) { + if ( /(Failed|Unable) to connect to MaxScale/ ) { printf "CRITICAL: $_\n"; close(MAXSCALE); exit(2); diff --git a/plugins/nagios/check_maxscale_threads.pl b/plugins/nagios/check_maxscale_threads.pl index b2813eb10..7486a6b24 100755 --- a/plugins/nagios/check_maxscale_threads.pl +++ b/plugins/nagios/check_maxscale_threads.pl @@ -72,17 +72,21 @@ EOF 'P' => 6603, # port 'm' => '/usr/local/skysql/maxscale/bin/maxadmin', # maxadmin ); + +my $MAXADMIN_DEFAULT = $opts{'m'}; + getopts('r:hH:u:p:P:m:', \%opts) or usage( $ERRORS{"UNKNOWN"} ); usage( $ERRORS{'OK'} ) if $opts{'h'}; my $MAXADMIN_RESOURCE = $opts{'r'}; my $MAXADMIN = $opts{'m'}; +if (!defined $MAXADMIN || length($MAXADMIN) == 0) { + $MAXADMIN = $MAXADMIN_DEFAULT; +} -x $MAXADMIN or die "$curr_script: Failed to find required tool: $MAXADMIN. Please install it or use the -m option to point to another location."; -my ( $state, $status ) = ( "OK", 'maxadmin ' . $MAXADMIN_RESOURCE .' succeeds.' ); - # Just in case of problems, let's not hang Nagios $SIG{'ALRM'} = sub { print ("UNKNOWN: No response from MaxScale server (alarm)\n"); @@ -122,7 +126,7 @@ my $start_queue_len = 0; while ( ) { chomp; - if ( /Unable to connect to MaxScale/ ) { + if ( /(Failed|Unable) to connect to MaxScale/ ) { printf "CRITICAL: $_\n"; close(MAXSCALE); exit(2); diff --git a/plugins/nagios/maxscale_commands.cfg b/plugins/nagios/maxscale_commands.cfg index d6dc6f47b..ca3446d4e 100644 --- a/plugins/nagios/maxscale_commands.cfg +++ b/plugins/nagios/maxscale_commands.cfg @@ -15,17 +15,17 @@ # check maxscale monitors define command{ command_name check_maxscale_monitors - command_line $USER1$/check_maxscale_monitors.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ + command_line $USER1$/check_maxscale_monitors.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ -m $ARG5$ } # check maxscale threads define command{ command_name check_maxscale_threads - command_line $USER1$/check_maxscale_threads.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ + command_line $USER1$/check_maxscale_threads.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ -m $ARG5$ } # check maxscale resource (listeners, services, etc) define command{ command_name check_maxscale_resource - command_line $USER1$/check_maxscale_resources.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ + command_line $USER1$/check_maxscale_resources.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ -m $ARG5$ } diff --git a/plugins/nagios/server1.cfg b/plugins/nagios/server1.cfg index ee7b2f8fd..d571fb1aa 100644 --- a/plugins/nagios/server1.cfg +++ b/plugins/nagios/server1.cfg @@ -101,7 +101,7 @@ define service{ notifications_enabled 0 } -# Define a service to check Script on the local machine. +# Define a service to check Script on the remote machine. define service{ use local-service ; Name of service template to use host_name server1