Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / voip / murmur_ice_users @ 189c81ee

Historique | Voir | Annoter | Télécharger (5,44 ko)

1
#!/usr/bin/php
2
<?php
3
  /**
4
**   =head1 NAME
5
** 
6
**   murmur_ice_users
7
** 
8
**   =head1 DESCRIPTION
9
** 
10
**   This plugin monitors users on a Mumble server (a.k.a. murmur).
11
**   It uses PHP and ICE to to query murmur. On debian, you can install mumble-server-web
12
**   to get the dependencies installed and set up.
13
** 
14
** 
15
**   =head1 CONFIGURATION
16
** 
17
**   You can specify a different ip:port in the munin-node config file as follow:
18
** 
19
**   [murmur_ice_users]
20
**   env.host 127.0.0.1
21
**   env.port 6502
22
**   env.IceProfile xxxxx
23
**   env.IceSecret xxxxx
24
** 
25
**   =head1 AUTHOR
26
** 
27
**   Original Author Thomas L�veil
28
**   Modification by DisasteR - 2011/04/19
29
** 
30
**   =head1 LICENSE
31
** 
32
**   Permission to use, copy, and modify this software with or without fee
33
**   is hereby granted, provided that this entire notice is included in
34
**   all source code copies of any software which is or includes a copy or
35
**   modification of this software.
36
** 
37
**   THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
38
**   IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
39
**   REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
40
**   MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
41
**   PURPOSE.
42
** 
43
**
44
**   =head1 MAGIC MARKERS
45
**
46
**   #%# family=contrib 
47
**   #%# capabilities=autoconf
48
**
49
**
50
**   =head1 VERSION
51
**   
52
**       1.2
53
**   
54
**   =head1 CHANGELOG
55
**   
56
**   =head2 1.0 - 2009/05/04
57
**   
58
**   initial release
59
**   
60
**   =head2 1.1 - 2011/01/13
61
**   
62
**   fix to make it work with murmur v1.2.2
63
**   
64
**   =head3 1.2 - 2011/04/19
65
**
66
**   Code cleaning and refactoring
67
**   Stats for root server and Virtual Servers
68
**       
69
**   =cut
70
*/
71
    
72
    
73
$host = "127.0.0.1";
74
$port = "6502";
75
$IceProfile = 'Murmur123';
76
$IceSecret = array( 'secret' => 'mumble42' );
77

    
78
if (isset($_ENV['host'])) $host = $_ENV['host'];
79
if (isset($_ENV['port'])) $port = $_ENV['port'];
80
if (isset($_ENV['IceProfile'])) $IceProfile = $_ENV['IceProfile'];
81
if (isset($_ENV['IceScret'])) $IceSecret = array( 'secret' => $_ENV['IceScret'] );
82

    
83
if (count($argv)==1) {
84
  do_count();
85
 } 
86

    
87
switch ($argv[1]) 
88
  {
89
  case 'autoconf':
90
    do_autoconf();
91
    break;
92
	
93
  case 'config':
94
    do_config();
95
    break;
96
	
97
  default:
98
    do_count();
99
    break;
100
  }
101
exit(1);
102

    
103
function IceConnect()
104
{
105
  global $ICE, $host, $port, $IceProfile, $IceSecret;
106
  try 
107
    {
108
      Ice_loadProfile($IceProfile);
109
      $iceproxy = $ICE->stringToProxy("Meta:tcp -h $host -p $port");
110
      $metaServer = $iceproxy->ice_checkedCast("::Murmur::Meta")->ice_context($IceSecret);
111
    }
112
  catch (Exception $e)
113
    {
114
      fwrite(STDERR, $e."\n");
115
      exit(1);
116
    }
117
  return $metaServer;
118
}
119

    
120
function do_autoconf()
121
{
122
  $metaServer = null;
123

    
124
  $metaServer = IceConnect();
125
  if ($metaServer != null)
126
    {
127
      fwrite(STDOUT, "yes\n");
128
      exit(0);
129
    }
130
  fwrite(STDOUT, "no\n");
131
  exit(1);
132
}
133

    
134
function do_config_header()
135
{
136
  fwrite(STDOUT, "graph_title Mumble Users\n");
137
  fwrite(STDOUT, "graph_vlabel Connected Users\n");
138
  fwrite(STDOUT, "graph_category VoIP\n");
139
  fwrite(STDOUT, "graph_info This graph shows the number of connected users on a murmur server\n");
140
  fwrite(STDOUT, "total_maxusers.label Maximum allowed users\n");
141
  fwrite(STDOUT, "total_maxusers.type GAUGE\n");
142
  fwrite(STDOUT, "total_online.label Connected users\n");
143
  fwrite(STDOUT, "total_online.type GAUGE\n");
144
}
145

    
146
function do_config_data()
147
{
148
  global $ICE, $IceSecret;
149
  
150
  try 
151
    {
152
      $metaServer = IceConnect();
153
      $AdefaultConf = $metaServer->getDefaultConf();
154
		
155
      $AvirtualServer = $metaServer->getAllServers();
156

    
157
      foreach ($AvirtualServer as $numserver=>$s) 
158
	{
159
	  $serverid = $s->ice_context($IceSecret)->id();
160
	  $servename = $s->ice_context($IceSecret)->getConf( 'registername');
161
	  $servename = preg_replace('/[^a-zA-Z0-9-#\$%&@\.+=§\/\\\]/', ' ', $servename);
162
	  $servename = trim(preg_replace('/\s+/', ' ', $servename));
163

    
164
	  fwrite(STDOUT,  "vserver_".$serverid."_maxusers.label ".$servename." Max users\n");
165
	  fwrite(STDOUT,  "vserver_".$serverid."_maxusers.type GAUGE\n");
166
	  fwrite(STDOUT,  "vserver_".$serverid."_online.label ".$servename." Connected users\n");
167
	  fwrite(STDOUT,  "vserver_".$serverid."_online.type GAUGE\n");
168
	}
169
      exit(0);
170
    }
171
  catch (Exception $e)
172
    {
173
      fwrite(STDERR, $e."\n");
174
      exit(1);
175
    }
176
}
177

    
178
function do_config()
179
{
180
  do_config_header();
181
  do_config_data();
182
  exit(0);
183
}
184

    
185
function do_count()
186
{
187
  global $ICE, $IceSecret;
188

    
189
  $totalMaxUsers="0";
190
  $totalConnectedUsers="0";
191

    
192
  try 
193
    {
194
      $metaServer = IceConnect();
195
      $AdefaultConf = $metaServer->getDefaultConf();
196
		
197
      $AvirtualServer = $metaServer->getAllServers();
198

    
199
      foreach ($AvirtualServer as $numserver=>$s) 
200
	{
201
	  $maxusers = $s->ice_context($IceSecret)->getConf( 'users' );
202
	  if (!$maxusers) $maxusers = $AdefaultConf['users'];
203
	  $totalMaxUsers += intval($maxusers);
204

    
205
	  if ($s->ice_context( $IceSecret )->isRunning())
206
	    {
207
	      $connectedUsers = count($s->ice_context($IceSecret)->getUsers());
208
	      $totalConnectedUsers += intval($connectedUsers);
209
	    }
210
	  else
211
	      $connectedUsers = 0;
212

    
213
	  $serverid = $s->ice_context($IceSecret)->id();
214

    
215
	  fwrite(STDOUT,  "vserver_".$serverid."_maxusers.value ".$maxusers."\n");
216
	  fwrite(STDOUT,  "vserver_".$serverid."_online.value ".$connectedUsers."\n");
217
	}
218
		
219
      fwrite(STDOUT,  "total_maxusers.value ".$totalMaxUsers."\n");
220
      fwrite(STDOUT,  "total_online.value ".$totalConnectedUsers."\n");
221
      exit(0);
222
    }
223
  catch (Exception $e)
224
    {
225
      fwrite(STDERR, $e."\n");
226
      exit(1);
227
    }
228
}
229

    
230
?>