[Nagiosplug-help] mysqllag plugin
Jonathan Angliss
jon at netdork.net
Wed May 11 07:46:21 CEST 2011
On 05/01/11 20:20, Tim Dunphy wrote:
> Hello list!! I am attempting to implement a plugin that alerts when it detects lag in mysql repliction. It seems really useful and I would like to get this going, but I am running into an issue in doing so.
>
> I am receiving this error in the nagios ineterface:
>
>
> ## nagios script error
>
> MySQL Lag
>
> Notifications for this service have been disabled
> CRITICAL 05-01-2011 16:19:58 0d 4h 55m 58s 3/3 (Return code of 127 is out of bounds - plugin may be missing)
====8<-------
snipping host info
====8<-------
> ## locally mysqllag check script works! :)
What does "locally" mean? On the Mysql server? Or is this check_mysqllag
command on the nagios box?
> [root at virtcent10:/usr/local/nagios/libexec] #./check_mysqllag
> + STATE_OK=0
=====8<-----
snip plugin output
=====8<-----
> ## ls -l of script on nagios client
>
>
> [root at virtcent10:/usr/local/nagios/libexec] #ls -l check_mysqllag*
> lrwxrwxrwx 1 nagios nagios 17 May 1 11:12 check_mysqllag -> check_mysqllag.sh
> -rwx------ 1 nagios nagios 1908 May 1 13:20 check_mysqllag.sh
virtcent10 is the client machine, while virtcent11 is the nagios server
right?
> ## this is the mysqllag service definition
>
> define service{
> use generic-service ; Name of service template to use
> host_name db2
> service_description MySQL Lag
> check_command check_mysqllag
> notifications_enabled 0
> }
>
>
> ## this is the mysqllag command definition
>
> define command{
> command_name check_mysqllag
> command_line $USER1$/check_mysqllag -H $HOSTADDRESS$ -p 3306 -v $ARG1$ $ARG2$
> }
>
How does Nagios execute this command on the remote host? From the output
above, it looks like you put the plugin on the remote host, but Nagios
is trying to run it locally. This kind of execution requires the use of
an intermediary agent, such as nrpe, or the check_by_ssh plugin.
Otherwise, Nagios is actually trying to execute the script in the LOCAL
(to nagios) path, which according to your output, may not be where your
script has it.
> ## this is the mysqllag script
>
>
> #! /bin/sh -x
>
> STATE_OK=0
> STATE_WARNING=1
> STATE_CRITICAL=2
> STATE_UNKNOWN=3
> STATE_DEPENDENT=4
> mysqlpath='/usr/bin/'
> user='root'
> pass='secret'
> warn=30
> crit=60
> null="NULL"
> usage1="Usage: $0 -u$user -p$pass [-w<warn>] [-c<crit>]"
> usage2="<warn> is lag time, in seconds, to warn at. Default is 30."
> usage3="<crit> is lag time, in seconds, to be critical at. Default is 60."
>
> exitstatus=$STATE_WARNING #default
> while test -n "$1"; do
> case "$1" in
> -c)
> crit=$2
> shift
> ;;
> -w)
> warn=$2
> shift
> ;;
> -u)
> user=$2
> shift
> ;;
> -p)
> pass=$2
> shift
> ;;
> -h)
> echo $usage1;
> echo
> echo $usage2;
> echo $usage3;
> exit $STATE_UNKNOWN
> ;;
> -H)
> host=$2
> shift
> ;;
> *)
> echo "Unknown argument: $1"
> echo $usage1;
> echo
> echo $usage2;
> echo $usage3;
> exit $STATE_UNKNOWN
> ;;
> esac
> shift
> done
Your command_line definition is passing in a -v, but you have no handle
for it, which means it'll fall to the *), and as such may always return
an error that you have an unknown argument. Any reason that's there?
> thank you in advance for any suggestions you might have to get this working!!
My recommendation would be to copy the check_mysqllag script onto the
Nagios host. Change your command definition to look like this:
define command {
command_name check_mysqllag
command_line $USER1$/check_mysqllag -H $HOSTADDRESS$ -u $ARG1$ \
-p $ARG2$ -w $ARG3$ -c $ARG4$
}
I've wrapped the command_line for easy readability, it should be on one
line.
Your service definition would then look like this:
define service {
.... usual other svc stuff .....
check_command check_mysqllag!username!password!30!60
}
The alternative to above is leaving the plugin where it is, and using
NRPE, and defining a remote command. Nagios would use the following:
define command {
command_name check_mysqllag
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ \
-c check_mysqllag
}
Then on the mysql side, you'd have an nrpe configuration:
command[check_mysqllag]=/usr/local/nagios/libexec/check_mysqllag -w 30 -c 60
Hope that gives you some ideas.
--
Jon Angliss
More information about the Help
mailing list