#!/bin/sh
# 
# Plugin to monitor the number of users in an IRC channel.
# By Jean-Marc Liotier based on the example provided by other Munin scripts
# Latest version always available from http://www.ruwenzori.net/code/munin_irc_channel_users_plugin/
#
# Usage: Link or copy into /etc/munin/node.d/
#
# $Log$
#
# Revision 0.1  2007/08/01 00:00:00 liotier
# Initial revision
#
#
#
# Magic markers (optional - only used by munin-config and some
# installation scripts):
#
#%# family=auto
#%# capabilities=autoconf


# If run with the "autoconf"-parameter, give our opinion on wether we
# should be run on this system or not. This is optinal, and only used by
# munin-config. In the case of this plugin, we should most probably
# always be included.

if [ "$1" = "autoconf" ]; then
	echo yes
	exit 0
fi

# If run with the "config"-parameter, give out information on how the
# graphs should look. 
 
if [ "$1" = "config" ]; then
	# The host name this plugin is for. (Can be overridden to have
	# one machine answer for several)

	# The title of the graph
	echo 'graph_title #b^2 IRC channel users'
	# Arguments to "rrdtool graph". In this case, tell it that the
	# lower limit of the graph is '0', and that 1k=1000 (not 1024)
	echo 'graph_args --base 1000 -l 0'
	# The Y-axis label
	echo 'graph_vlabel population'
	# We want Cur/Min/Avg/Max unscaled (i.e. 0.42 load instead of
	# 420 milliload)
	echo 'graph_scale no'
	# Graph category. Defaults to 'other'
	#echo 'graph_category other'
	# The fields. "label" is used in the legend. "label" is the only
	# required subfield. 
	echo 'population.label users'

	# Last, if run with the "config"-parameter, quit here (don't
	# display any data)
	exit 0
fi


# If not run with any parameters at all (or only unknown ones), do the
# real work - i.e. display the data. Almost always this will be
# "value" subfield for every data field.

work_directory=/home/user/work/directory/plugindir
php_interpreter=`which php`

user_population=`$php_interpreter $work_directory/irc_channel_users.php | awk -F"#" '{print($1)}' | grep -e '^[0-9]\+$'`

echo -n "population.value "
echo $user_population