#!/bin/sh
#
# Copyright (C) 2010  Kouhei Sutou <kou@clear-code.com>
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library.  If not, see <http://www.gnu.org/licenses/>.
#
#%# family=auto
#%# capabilities=autoconf

case "$1" in
    config)
	cat <<EOF
graph_title Postfix Processes
graph_vlabel processes
graph_category postfix
graph_info Number of smtpd processes

processes.label Processes
processes.type GAUGE
EOF
	exit 0
	;;
    auto|autoconf|detect)
	master_process=$(ps ax | grep master | grep -i postfix | grep -v 'grep')
    	if [ -n "$master_process" ]; then
	    echo "yes"
	    exit 0
	else
	    echo "no (no Postifx master process is running)"
	    exit 1
	fi
	;;
    *)
	n_processes=$(ps ax | grep smtpd | grep -v 'grep' | wc -l)
	echo "processes.value ${n_processes}"
	exit 0
	;;
esac

