2009-05-04 04:29:41 +02:00
|
|
|
|
#!/usr/bin/php
|
|
|
|
|
<?php
|
2011-04-19 09:52:09 +02:00
|
|
|
|
/**
|
|
|
|
|
** =head1 NAME
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** murmur_ice_users
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =head1 DESCRIPTION
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** 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
|
|
|
|
|
** to get the dependencies installed and set up.
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =head1 CONFIGURATION
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** You can specify a different ip:port in the munin-node config file as follow:
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** [murmur_ice_users]
|
|
|
|
|
** env.host 127.0.0.1
|
|
|
|
|
** env.port 6502
|
|
|
|
|
** env.IceProfile xxxxx
|
|
|
|
|
** env.IceSecret xxxxx
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =head1 AUTHOR
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** Original Author Thomas L<>veil
|
|
|
|
|
** Modification by DisasteR - 2011/04/19
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =head1 LICENSE
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** Permission to use, copy, and modify this software with or without fee
|
|
|
|
|
** 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
|
|
|
|
|
** modification of this software.
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
|
|
|
|
|
** IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
|
|
|
|
|
** REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
|
|
|
|
|
** MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
|
|
|
|
|
** PURPOSE.
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
**
|
|
|
|
|
** =head1 MAGIC MARKERS
|
|
|
|
|
**
|
2018-08-02 02:03:42 +02:00
|
|
|
|
** #%# family=contrib
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** #%# capabilities=autoconf
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** =head1 VERSION
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** 1.2
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =head1 CHANGELOG
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =head2 1.0 - 2009/05/04
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** initial release
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =head2 1.1 - 2011/01/13
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** fix to make it work with murmur v1.2.2
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =head3 1.2 - 2011/04/19
|
|
|
|
|
**
|
|
|
|
|
** Code cleaning and refactoring
|
|
|
|
|
** Stats for root server and Virtual Servers
|
2018-08-02 02:03:42 +02:00
|
|
|
|
**
|
2011-04-19 09:52:09 +02:00
|
|
|
|
** =cut
|
2009-05-04 04:29:41 +02:00
|
|
|
|
*/
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
|
|
|
|
|
2009-05-04 04:29:41 +02:00
|
|
|
|
$host = "127.0.0.1";
|
|
|
|
|
$port = "6502";
|
2011-04-19 09:52:09 +02:00
|
|
|
|
$IceProfile = 'Murmur123';
|
|
|
|
|
$IceSecret = array( 'secret' => 'mumble42' );
|
2009-05-04 04:29:41 +02:00
|
|
|
|
|
|
|
|
|
if (isset($_ENV['host'])) $host = $_ENV['host'];
|
|
|
|
|
if (isset($_ENV['port'])) $port = $_ENV['port'];
|
2011-04-19 09:52:09 +02:00
|
|
|
|
if (isset($_ENV['IceProfile'])) $IceProfile = $_ENV['IceProfile'];
|
|
|
|
|
if (isset($_ENV['IceScret'])) $IceSecret = array( 'secret' => $_ENV['IceScret'] );
|
2009-05-04 04:29:41 +02:00
|
|
|
|
|
2011-01-13 20:08:31 +01:00
|
|
|
|
if (count($argv)==1) {
|
2011-04-19 09:52:09 +02:00
|
|
|
|
do_count();
|
2018-08-02 02:03:42 +02:00
|
|
|
|
}
|
2009-05-04 04:29:41 +02:00
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
|
switch ($argv[1])
|
2011-04-19 09:52:09 +02:00
|
|
|
|
{
|
|
|
|
|
case 'autoconf':
|
|
|
|
|
do_autoconf();
|
|
|
|
|
break;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
case 'config':
|
|
|
|
|
do_config();
|
|
|
|
|
break;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
default:
|
|
|
|
|
do_count();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-05-04 04:29:41 +02:00
|
|
|
|
exit(1);
|
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
function IceConnect()
|
|
|
|
|
{
|
|
|
|
|
global $ICE, $host, $port, $IceProfile, $IceSecret;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
try
|
2011-04-19 09:52:09 +02:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
2009-05-04 04:29:41 +02:00
|
|
|
|
|
|
|
|
|
function do_autoconf()
|
|
|
|
|
{
|
2011-04-19 09:52:09 +02:00
|
|
|
|
$metaServer = null;
|
|
|
|
|
|
|
|
|
|
$metaServer = IceConnect();
|
|
|
|
|
if ($metaServer != null)
|
|
|
|
|
{
|
|
|
|
|
fwrite(STDOUT, "yes\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
fwrite(STDOUT, "no\n");
|
|
|
|
|
exit(1);
|
2009-05-04 04:29:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
function do_config_header()
|
2009-05-04 04:29:41 +02:00
|
|
|
|
{
|
2011-04-19 09:52:09 +02:00
|
|
|
|
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");
|
2009-05-04 04:29:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
function do_config_data()
|
2009-05-04 04:29:41 +02:00
|
|
|
|
{
|
2011-04-19 09:52:09 +02:00
|
|
|
|
global $ICE, $IceSecret;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
|
|
|
|
try
|
2011-04-19 09:52:09 +02:00
|
|
|
|
{
|
|
|
|
|
$metaServer = IceConnect();
|
|
|
|
|
$AdefaultConf = $metaServer->getDefaultConf();
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
$AvirtualServer = $metaServer->getAllServers();
|
2009-05-04 04:29:41 +02:00
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
|
foreach ($AvirtualServer as $numserver=>$s)
|
2009-05-04 04:29:41 +02:00
|
|
|
|
{
|
2011-04-19 09:52:09 +02:00
|
|
|
|
$serverid = $s->ice_context($IceSecret)->id();
|
|
|
|
|
$servename = $s->ice_context($IceSecret)->getConf( 'registername');
|
|
|
|
|
$servename = preg_replace('/[^a-zA-Z0-9-#\$%&@\.+=§\/\\\]/', ' ', $servename);
|
|
|
|
|
$servename = trim(preg_replace('/\s+/', ' ', $servename));
|
|
|
|
|
|
|
|
|
|
fwrite(STDOUT, "vserver_".$serverid."_maxusers.label ".$servename." Max users\n");
|
|
|
|
|
fwrite(STDOUT, "vserver_".$serverid."_maxusers.type GAUGE\n");
|
|
|
|
|
fwrite(STDOUT, "vserver_".$serverid."_online.label ".$servename." Connected users\n");
|
|
|
|
|
fwrite(STDOUT, "vserver_".$serverid."_online.type GAUGE\n");
|
2009-05-04 04:29:41 +02:00
|
|
|
|
}
|
2011-04-19 09:52:09 +02:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e)
|
|
|
|
|
{
|
|
|
|
|
fwrite(STDERR, $e."\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2009-05-04 04:29:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
function do_config()
|
2009-05-04 04:29:41 +02:00
|
|
|
|
{
|
2011-04-19 09:52:09 +02:00
|
|
|
|
do_config_header();
|
|
|
|
|
do_config_data();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function do_count()
|
|
|
|
|
{
|
|
|
|
|
global $ICE, $IceSecret;
|
|
|
|
|
|
|
|
|
|
$totalMaxUsers="0";
|
|
|
|
|
$totalConnectedUsers="0";
|
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
|
try
|
2011-04-19 09:52:09 +02:00
|
|
|
|
{
|
|
|
|
|
$metaServer = IceConnect();
|
|
|
|
|
$AdefaultConf = $metaServer->getDefaultConf();
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
$AvirtualServer = $metaServer->getAllServers();
|
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
|
foreach ($AvirtualServer as $numserver=>$s)
|
2009-05-04 04:29:41 +02:00
|
|
|
|
{
|
2011-04-19 09:52:09 +02:00
|
|
|
|
$maxusers = $s->ice_context($IceSecret)->getConf( 'users' );
|
|
|
|
|
if (!$maxusers) $maxusers = $AdefaultConf['users'];
|
|
|
|
|
$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");
|
2009-05-04 04:29:41 +02:00
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
2011-04-19 09:52:09 +02:00
|
|
|
|
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);
|
|
|
|
|
}
|
2009-05-04 04:29:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
|
?>
|