1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-23 06:35:42 +00:00

Code cleanning/refactoring // Stats for root server and virtual servers

This commit is contained in:
DisasteR 2011-04-19 09:52:09 +02:00 committed by Steve Schnepp
parent d025504545
commit a8819e1993

View file

@ -1,185 +1,230 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/* /**
: << =cut ** =head1 NAME
**
=head1 NAME ** murmur_ice_users
**
murmur_ice_users ** =head1 DESCRIPTION
**
=head1 DESCRIPTION ** This plugin monitors users on a Mumble server (a.k.a. murmur).
** It uses PHP and ICE to to query murmur. On debian, you can install mumble-server-web
This plugin monitors users on a Mumble server (a.k.a. murmur). ** to get the dependencies installed and set up.
It uses PHP and ICE to to query murmur. On debian, you can install mumble-server-web **
to get the dependencies installed and set up. **
** =head1 CONFIGURATION
**
=head1 CONFIGURATION ** You can specify a different ip:port in the munin-node config file as follow:
**
You can specify a different ip:port in the munin-node config file as follow: ** [murmur_ice_users]
** env.host 127.0.0.1
[murmur_ice_users] ** env.port 6502
env.host 127.0.0.1 ** env.IceProfile xxxxx
env.port 6502 ** env.IceSecret xxxxx
**
** =head1 AUTHOR
=head1 AUTHOR **
** Original Author Thomas L<>veil
Thomas Léveil ** Modification by DisasteR - 2011/04/19
**
=head1 LICENSE ** =head1 LICENSE
**
Permission to use, copy, and modify this software with or without fee ** Permission to use, copy, and modify this software with or without fee
is hereby granted, provided that this entire notice is included in ** is hereby granted, provided that this entire notice is included in
all source code copies of any software which is or includes a copy or ** all source code copies of any software which is or includes a copy or
modification of this software. ** modification of this software.
**
THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR ** THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY ** IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE ** REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR ** MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
PURPOSE. ** PURPOSE.
**
=head1 CONTRIBUTE **
** =head1 MAGIC MARKERS
find this plugin on github at http://github.com/VolatileMesh/munin-plugins **
** #%# family=contrib
=head1 MAGIC MARKERS ** #%# capabilities=autoconf
**
#%# family=contrib **
#%# capabilities=autoconf ** =head1 VERSION
**
=head1 VERSION ** 1.2
**
1.1 ** =head1 CHANGELOG
**
=head1 CHANGELOG ** =head2 1.0 - 2009/05/04
**
=head2 1.0 - 2009/05/04 ** initial release
**
initial release ** =head2 1.1 - 2011/01/13
**
=head2 1.1 - 2011/01/13 ** fix to make it work with murmur v1.2.2
**
fix to make it work with murmur v1.2.2 ** =head3 1.2 - 2011/04/19
**
** Code cleaning and refactoring
=cut ** Stats for root server and Virtual Servers
**
** =cut
*/ */
$host = "127.0.0.1"; $host = "127.0.0.1";
$port = "6502"; $port = "6502";
$IceProfile = 'Murmur123';
$IceSecret = array( 'secret' => 'mumble42' );
if (isset($_ENV['host'])) $host = $_ENV['host']; if (isset($_ENV['host'])) $host = $_ENV['host'];
if (isset($_ENV['port'])) $port = $_ENV['port']; if (isset($_ENV['port'])) $port = $_ENV['port'];
if (isset($_ENV['IceProfile'])) $IceProfile = $_ENV['IceProfile'];
if (isset($_ENV['IceScret'])) $IceSecret = array( 'secret' => $_ENV['IceScret'] );
if (count($argv)==1) { if (count($argv)==1) {
do_count(); do_count();
} }
switch ($argv[1]) switch ($argv[1])
{ {
case 'autoconf': case 'autoconf':
do_autoconf(); do_autoconf();
break; break;
case 'config': case 'config':
do_config(); do_config();
break; break;
default: default:
do_count(); do_count();
break; break;
} }
exit(1); exit(1);
function IceConnect()
{
global $ICE, $host, $port, $IceProfile, $IceSecret;
try
{
Ice_loadProfile($IceProfile);
$iceproxy = $ICE->stringToProxy("Meta:tcp -h $host -p $port");
$metaServer = $iceproxy->ice_checkedCast("::Murmur::Meta")->ice_context($IceSecret);
}
catch (Exception $e)
{
fwrite(STDERR, $e."\n");
exit(1);
}
return $metaServer;
}
function do_autoconf() function do_autoconf()
{ {
global $ICE, $host, $port; $metaServer = null;
try
$metaServer = IceConnect();
if ($metaServer != null)
{
fwrite(STDOUT, "yes\n");
exit(0);
}
fwrite(STDOUT, "no\n");
exit(1);
}
function do_config_header()
{
fwrite(STDOUT, "graph_title Mumble Users\n");
fwrite(STDOUT, "graph_vlabel Connected Users\n");
fwrite(STDOUT, "graph_category VoIP\n");
fwrite(STDOUT, "graph_info This graph shows the number of connected users on a murmur server\n");
fwrite(STDOUT, "total_maxusers.label Maximum allowed users\n");
fwrite(STDOUT, "total_maxusers.type GAUGE\n");
fwrite(STDOUT, "total_online.label Connected users\n");
fwrite(STDOUT, "total_online.type GAUGE\n");
}
function do_config_data()
{
global $ICE, $IceSecret;
try
{
$metaServer = IceConnect();
$AdefaultConf = $metaServer->getDefaultConf();
$AvirtualServer = $metaServer->getAllServers();
foreach ($AvirtualServer as $numserver=>$s)
{ {
Ice_loadProfile(); $serverid = $s->ice_context($IceSecret)->id();
$iceproxy = $ICE->stringToProxy("Meta:tcp -h $host -p $port"); $servename = $s->ice_context($IceSecret)->getConf( 'registername');
$metaServer = $iceproxy->ice_checkedCast("::Murmur::Meta"); $servename = preg_replace('/[^a-zA-Z0-9-#\$%&@\.+=§\/\\\]/', ' ', $servename);
fwrite(STDOUT, "yes\n"); $servename = trim(preg_replace('/\s+/', ' ', $servename));
exit(0);
} fwrite(STDOUT, "vserver_".$serverid."_maxusers.label ".$servename." Max users\n");
catch (Exception $e) fwrite(STDOUT, "vserver_".$serverid."_maxusers.type GAUGE\n");
{ fwrite(STDOUT, "vserver_".$serverid."_online.label ".$servename." Connected users\n");
fwrite(STDOUT, "no\n"); fwrite(STDOUT, "vserver_".$serverid."_online.type GAUGE\n");
exit(1);
} }
exit(0);
}
catch (Exception $e)
{
fwrite(STDERR, $e."\n");
exit(1);
}
} }
function do_config() function do_config()
{ {
fwrite(STDOUT, "graph_title Mumble Users\n"); do_config_header();
fwrite(STDOUT, "graph_vlabel Connected Users\n"); do_config_data();
fwrite(STDOUT, "graph_category VoIP\n"); exit(0);
fwrite(STDOUT, "graph_info This graph shows the number of connected users on a murmur server\n");
fwrite(STDOUT, "maxusers.label Maximum number of users allowed\n");
fwrite(STDOUT, "maxusers.type GAUGE\n");
fwrite(STDOUT, "online.label connected users\n");
fwrite(STDOUT, "online.type GAUGE\n");
exit(0);
} }
function do_count() function do_count()
{ {
global $ICE, $host, $port; global $ICE, $IceSecret;
$totalMaxUsers="U";
$totalConnectedUsers="U";
try $totalMaxUsers="0";
{ $totalConnectedUsers="0";
Ice_loadProfile();
$iceproxy = $ICE->stringToProxy("Meta:tcp -h $host -p $port");
$metaServer = $iceproxy->ice_checkedCast("::Murmur::Meta");
$AdefaultConf = $metaServer->getDefaultConf();
$AvirtualServer = $metaServer->getBootedServers();
$totalMaxUsers = 0;
foreach ($AvirtualServer as $numserver=>$s)
{
$maxusers = $s->getConf('users');
if (!$maxusers) $maxusers = $AdefaultConf['users'];
$totalMaxUsers += intval($maxusers);
$tree = $s->getTree();
//print_r($tree);
$connectedUsers = countConnectedUsers($s->getTree());
$totalConnectedUsers += $connectedUsers;
}
fwrite(STDOUT, "maxusers.value ".$totalMaxUsers."\n"); try
fwrite(STDOUT, "online.value ".$totalConnectedUsers."\n"); {
exit(0); $metaServer = IceConnect();
} $AdefaultConf = $metaServer->getDefaultConf();
catch (Exception $e)
{ $AvirtualServer = $metaServer->getAllServers();
fwrite(STDERR, $e."\n");
exit(1);
}
}
function countConnectedUsers($channelTree) foreach ($AvirtualServer as $numserver=>$s)
{
$count = intval(count($channelTree->users));
if (isset($channelTree->children))
{ {
foreach ($channelTree->children as $c) $maxusers = $s->ice_context($IceSecret)->getConf( 'users' );
{ if (!$maxusers) $maxusers = $AdefaultConf['users'];
$count += countConnectedUsers($c); $totalMaxUsers += intval($maxusers);
}
if ($s->ice_context( $IceSecret )->isRunning())
{
$connectedUsers = count($s->ice_context($IceSecret)->getUsers());
$totalConnectedUsers += intval($connectedUsers);
}
else
$connectedUsers = 0;
$serverid = $s->ice_context($IceSecret)->id();
fwrite(STDOUT, "vserver_".$serverid."_maxusers.value ".$maxusers."\n");
fwrite(STDOUT, "vserver_".$serverid."_online.value ".$connectedUsers."\n");
} }
return $count; fwrite(STDOUT, "total_maxusers.value ".$totalMaxUsers."\n");
fwrite(STDOUT, "total_online.value ".$totalConnectedUsers."\n");
exit(0);
}
catch (Exception $e)
{
fwrite(STDERR, $e."\n");
exit(1);
}
} }
?> ?>