2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/forums/punbb_users
2014-09-06 22:28:53 +02:00

92 lines
1.8 KiB
Perl
Executable File

#!/usr/bin/perl
#
# Plugin to monitor the number of users on a punbb forum
#
# Requirements:
# - Needs access to the forum
#
# Parameters supported:
#
# config
# autoconf
#
# Configurable variables
#
# url to extern.php
#
#
# $Log$
#
#
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
my $ret = undef;
if (! eval "require LWP::UserAgent;")
{
$ret = "LWP::UserAgent not found";
}
# CHANGE ME
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://www.url.to/forums/extern.php?action=online";
# Should not be longer...
my $timeout = 5;
my $type = undef;
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
{
if ($ret)
{
print "no ($ret)\n";
exit 1;
}
}
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
{
print "graph_title Users\n";
print "graph_args --base 1000\n";
print "graph_vlabel current users\n";
print "graph_category Forum\n";
print "graph_total Total\n";
print "members.label Members\n";
print "members.draw AREA\n";
print "guests.draw STACK\n";
print "guests.label Guests\n";
exit 0;
}
my $ua = LWP::UserAgent->new(timeout => $timeout);
my $url = sprintf $URL;
my $response = $ua->request(HTTP::Request->new('GET', $url));
# Example output : Guests online: 92<br />Registered users online: 2<br />
if ($response->content =~ /Guests online: (\d+)<br \/>Registered users online: (\d+)<br \/>/im)
{
print "members.value $2\n";
print "guests.value $1\n";
} else
{
print $response->content."\n";
print "members.value U\n";
print "guests.value U\n";
}
# vim:syntax=perl