#!/bin/sh

export RET=`/usr/lib/nagios/plugins/check_mysql "$@"`
STATUS=$?
echo "$RET" \
  | sed -e 's/  /\n/g' -e 's/: /=/g' -e 's/ /_/g' \
  | tr 'A-Z' 'a-z' \
  | grep '^[a-z_]\+=[0-9.]\+$' \
  | gawk -F= '
function fmt_long(key, warn, crit) {
  printf "%s=%d ", key, a[key]
}
{
  a[$1]=$2
}
END {
  printf "%s|", ENVIRON["RET"]
  fmt_long("questions", 10000, 100000)
  fmt_long("slow_queries", 10000, 100000)
  fmt_long("opens", 100, 1000)
  fmt_long("flush_tables", 100, 1000)
  fmt_long("open_tables", 100, 1000)
  fmt_long("threads", 300, 1000)
  printf "\n"
}
'

exit $STATUS
