--- /dev/null
+#!/bin/sh
+# License: GPL v2
+# Author: Elan Ruusamäe <glen@delfi.ee>
+#
+# Usage: check_mysql-heartbeat
+#
+
+PROGRAM=${0##*/}
+REVISION=$(echo '$Revision$' | sed -e 's/[^0-9.]//g')
+PROGPATH=${0%/*}
+. $PROGPATH/utils.sh
+
+heartbeat=mk-heartbeat
+hostname=
+port=
+username=
+password=
+database=
+
+die() {
+ eval local rc=\$STATE_$1
+ [ "$rc" ] || rc=$STATE_UNKNOWN
+ echo "$2"
+ exit $rc
+}
+
+usage() {
+ cat >&2 <<EOF
+Usage: check_mysql-heartbeat
+
+ --mk | --maatkit
+ Uses maatkit: mk-heartbeat
+ --pt | --percona-toolkit
+ Uses percona-toolkit: pt-hearbeat
+EOF
+}
+
+## Start of main program ##
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ -V|--version)
+ echo $PROGRAM $REVISION
+ exit 0
+ ;;
+ --mk|--maatkit)
+ heartbeat=mk-heartbeat
+ ;;
+ --pt|--percona-toolkit)
+ heartbeat=mk-heartbeat
+ ;;
+ -H|--host)
+ shift
+ hostname=$1
+ ;;
+ -P|--port)
+ shift
+ port=$1
+ ;;
+ -u|--username)
+ shift
+ username=$1
+ ;;
+ -p|--password)
+ shift
+ password=$1
+ ;;
+ -D|--database)
+ shift
+ database=$1
+ ;;
+ esac
+ shift
+done
+
+if [ -z "$hostname" ]; then
+ die UNKNOWN "No hostname given"
+fi
+
+out=$($heartbeat ${database:+-D $database} --check -h $hostname ${username:+-u $username} ${password:+-p $password} 2>&1)
+rc=$?
+if [ "$rc" != 0 ]; then
+ die UNKNOWN "$out"
+fi
+die OK "OK $heartbeat on $hostname @$out"
--- /dev/null
+%define plugin check_mysql-heartbeat
+%define php_min_version 5.0.0
+%include /usr/lib/rpm/macros.php
+Summary: Nagios plugin to check MySQL heartbeat
+Name: nagios-plugin-%{plugin}
+Version: 1.0
+Release: 0.1
+License: GPL v2
+Group: Networking
+BuildRequires: rpm-php-pearprov >= 4.4.2-11
+Requires: nagios-common
+Requires: nagios-plugins-libs
+BuildArch: noarch
+BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+
+%define _sysconfdir /etc/nagios/plugins
+%define plugindir %{_prefix}/lib/nagios/plugins
+
+%define _cvsroot :ext:cvs.delfi.ee:/usr/local/cvs
+%define _cvsmodule nagios/plugins
+
+%description
+Nagios plugin to check MySQL heartbeat with maatkit or percona-toolkit.
+
+%prep
+# check early if build is ok to be performed
+%if %{!?debug:1}%{?debug:0} && %{!?_cvstag:1}%{?_cvstag:0} && %([[ %{release} = *.* ]] && echo 0 || echo 1)
+# break if spec is not commited
+cd %{_specdir}
+if [ "$(cvs status %{name}.spec | awk '/Status:/{print $NF}')" != "Up-to-date" ]; then
+ : "Integer build not allowed: %{name}.spec is not up-to-date with CVS"
+ exit 1
+fi
+cd -
+%endif
+%setup -qTc
+cd ..
+cvs -d %{_cvsroot} co -d %{name}-%{version} %{_cvsmodule}/%{plugin}
+cd -
+cvs up %{plugin}.cfg
+
+%build
+# skip tagging if we checkouted from tag or have debug enabled
+# also make make tag only if we have integer release
+%if %{!?debug:1}%{?debug:0} && %{!?_cvstag:1}%{?_cvstag:0} && %([[ %{release} = *.* ]] && echo 0 || echo 1)
+# do tagging by version
+tag=%{name}-%(echo %{version} | tr . _)-%(echo %{release} | tr . _)
+
+cd %{_specdir}
+if [ $(cvs status -v %{name}.spec | grep -Ec "$tag[[:space:]]") != 0 ]; then
+ : "Tag $tag already exists"
+ exit 1
+fi
+cvs tag $tag %{name}.spec
+cd -
+cvs tag $tag
+%endif
+
+%install
+rm -rf $RPM_BUILD_ROOT
+install -d $RPM_BUILD_ROOT{%{_sysconfdir},%{plugindir}}
+install -p %{plugin} $RPM_BUILD_ROOT%{plugindir}
+cp -p %{plugin}.cfg $RPM_BUILD_ROOT%{_sysconfdir}/%{plugin}.cfg
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(644,root,root,755)
+%attr(640,root,nagios) %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/%{plugin}.cfg
+%attr(755,root,root) %{plugindir}/%{plugin}