i wanted to use the check_mysql_health script in zabbix. wrote a little wrapper script which returns the data in zabbix usable format. it may work with other nagios checks too.
- Thomas
- Thomas
Code:
#!/bin/sh # # zabbix-nagios-wrapper <plugin> <args> (<state>|<value> <valuename>) # # Examples: # zabbix-nagios-wrapper check_mysql_health "--mode slave-lag" value slave_lag # <numeric return> # # zabbix-nagios-wrapper check_mysql_health "--mode slave-lag" state # <0=OK,1=WARNING,2=CRITICAL> # # Howto configure ZABBIX Agentd: # zabbix_agentd.conf: Add # UserParameter=zabbix-nagios-wrapper[*],<Path-to>/zabbix-nagios-wrapper "$1" "$2" "$3" "$4" # 1 = pluginname # 2 = args # 3 = state or value # 4 = name of value (only if 3 = value) # # Edit /etc/zabbix/nagios-wrapper.env to point env PLUGINDIR to the nagios plugins directory # Add any other env vars needed by checks to nagios-wrapper.env # # Limitation: # Don't know any way how to pass a , (comma) in the args field in zabbix webgui # # (c) Thomas Mueller <[email protected]> # License: GPL v3 (http://www.gnu.org/licenses/gpl-3.0.txt) test -f /etc/zabbix/nagios-wrapper.env && . /etc/zabbix/nagios-wrapper.env PLUGIN=$1 ARGS=$2 STATEORVALUE=$3 VALUENAME=$4 PLUGINDIR=${PLUGINDIR:=/usr/libexec} if [ -f "$PLUGINDIR/$PLUGIN" ] then if [ "$STATEORVALUE" = "state" ] then state=$($PLUGINDIR/$PLUGIN $ARGS | cut -d" " -f1) case "$state" in OK) echo 0;; WARNING) echo 1;; CRITICAL) echo 2;; *) echo "ERROR: not found OK, WARNING or CRITICAL";; esac elif [ "$STATEORVALUE" = "value" ] then values=$($PLUGINDIR/$PLUGIN $ARGS | cut -d\| -f2) for i in $values do if echo "$i" | grep $VALUENAME >/dev/null then value=$(echo $i | cut -f2 -d= | cut -f1 -d\; | egrep -o '[[:digit:]\.]+') echo $value; exit fi done fi else echo "ERROR: $PLUGINDIR/$PLUGIN not found" && exit 1 fi


Comment