Debian Codegraph @

contrib/kannel-monitor/index.php

raw
1 <?php
2 /*
3 * kannel-status.php -- display a summarized kannel status page
4 *
5 * This php script acts as client for the status.xml output of
6 * Kannel's bearerbox and aggregates information about smsc link
7 * status and message flow. It is the first step to provide an
8 * external Kannel Control Center interface via HTTP.
9 *
10 * Stipe Tolj <stolj at kannel dot org>
11 *
12 * Rewrite/Makeover to update the interface and add dlr support
13 * Alejandro Guerrieri <aguerrieri at kannel dot org>
14 *
15 * Copyright (c) 2003-2009 Kannel Group.
16 *
17 */
18
19 require_once("config.php");
20 require_once("xmlfunc.php");
21 require_once("xmltoarray.php");
22
23 $depth = array();
24 $status = array();
25
26 /* set php internal error reporting level */
27 error_reporting(0);
28
29 /* Refresh variables */
30 $timeout = get_timeout();
31 $t_down = ceil($timeout / 2);
32 $t_up = ceil($timeout * 2);
33 $purl = parse_url($_SERVER['REQUEST_URI']);
34 $base_uri = $purl[path];
35 ?>
36
37 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
38 <html>
39 <head>
40 <meta http-equiv="refresh" content="<?php echo $timeout ?>; URL=<?php echo $_SERVER[REQUEST_URI] ?>">
41 <title>Kannel Status</title>
42 <link href="kannel.css" rel="stylesheet" type="text/css">
43 <script src="kannel.js" type="text/javascript"></script>
44 </head>
45 <body>
46
47 <!-- the header block showing some basic information -->
48 <table width=100% cellspacing=0 cellpadding=0 border=0>
49 <tr><td valign=top>
50 <h3>Kannel Status Monitor</h3>
51 </td><td valign=top align=left class=text>
52 Current date and time: <br />
53 <b><?php echo date("Y-m-d H:i:s"); ?></b>
54 </td><td valign=top align=right class=text>
55 Refresh rate: <br />
56 <a class=href href="<?php echo $base_uri."?refresh=".$t_down; ?>"><?php echo $t_down; ?>s</a> |
57 <b><?php echo $timeout; ?>s</b> |
58 <a class=href href="<?php echo $base_uri."?refresh=".$t_up; ?>"><?php echo $t_up; ?>s</a>
59 </td></tr>
60 </table>
61
62 <table width="100%" cellspacing="0" cellpadding="5" border="0">
63 <tr>
64 <td class="text" valign="top" align="left">
65
66 <h4><?php echo sizeof($configs) ?> Configured instances</h4>
67
68 <table width="100%" cellspacing="0" class="text" id="overall" valign="top">
69 <tr>
70 <th>Name</th>
71 <th>Status</th>
72 <th>Started</th>
73 <th>Uptime</th>
74 <th colspan="3" align="center">SMS (MO)</th>
75 <th colspan="3" align="center">DLR (MO)</th>
76 <th colspan="3" align="center">SMS (MT)</th>
77 <th colspan="3" align="center">DLR (MT)</th>
78 <th style="border-right: 1px solid black">Commands</th>
79 </tr>
80 <?php
81 /* loop through all configured URLs */
82 foreach ($configs as $inst => $config) {
83 //echo "<tr><td class=text valign=top align=left>\n";
84
85 /* get the status.xml URL of one config */
86 $url = $config["base_url"]."/status.xml?password=".$config["status_passwd"];
87
88 $xml_data = "";
89
90 /* open the file description to the URL */
91 if (($fp = fopen($url, "r"))) {
92 $bgcolor = 'green';
93 /* read the XML input */
94 while (!feof($fp)) {
95 $xml_data .= fread($fp, 200000);
96 }
97 fclose($fp);
98 $xml_obj = new XmlToArray($xml_data);
99 $status[$inst] = cleanup_array($xml_obj->createArray());
100 for ($i=0;$i < sizeof($status[$inst]['smscs']); $i++) {
101 clean_branch($status[$inst]['smscs'][$i], '');
102 }
103 /* get the status of this bearerbox */
104 list ($st, $started, $uptime) = parse_uptime($status[$inst]['status']);
105 /* get the info of this bearerbox into a button, to save some screen real-estate*/
106 $ver = preg_replace("/\n+/", '\\n', $status[$inst]['version']);
107 $ver = preg_replace("/[\'\`]/", "\'", $ver);
108 $ver = 'Url: '.$config["base_url"].'\n\n'.$ver;
109 $boxstatus = array (
110 'name' => '<a class="href" style="color: green; font-weight: bold" href="#" onClick="alert(\''.$ver.'\'); return false;">'.$config['name'].'</a>',
111 'bgcolor' => 'green',
112 'status' => $st,
113 'started' => $started,
114 'uptime' => $uptime,
115 );
116 } else {
117 $boxstatus = array (
118 'name' => $config['name'],
119 'bgcolor' => 'red',
120 'status' => 'error',
121 'started' => '-',
122 'uptime' => '-',
123 );
124 }
125 ?>
126 <tr class="<?php echo $boxstatus['bgcolor'] ?>">
127 <td><?php echo $boxstatus['name'] ?></td>
128 <td><?php echo $boxstatus['status'] ?></td>
129 <td><?php echo $boxstatus['started'] ?></td>
130 <td><?php echo $boxstatus['uptime'] ?></td>
131 <?php echo split_load($status[$inst]['sms']['inbound']) ?>
132 <?php echo split_load($status[$inst]['dlr']['inbound']) ?>
133 <?php echo split_load($status[$inst]['sms']['outbound']) ?>
134 <?php echo split_load($status[$inst]['dlr']['outbound']) ?>
135 <td>
136 <?php echo admin_link('suspend')." | ".admin_link('isolate')." | ".admin_link('resume')." | ".admin_link('flush-dlr')."<br />"; ?>
137 <?php echo admin_link('shutdown')." | ".admin_link('restart')." | ".admin_link('graceful-restart') ?>
138 </td>
139 </tr>
140 <?php
141 }
142 ?>
143
144 </table>
145
146 <h4>Overall SMS traffic</h4>
147
148 <p id="bord">
149 <table width="100%" cellspacing="0" class="text" id="overall" valign="top">
150 <tr>
151 <th>Instance</th>
152 <th>Received (MO)</th>
153 <th>Received (DLR)</th>
154 <th>Inbound (MO)</th>
155 <th>Inbound (DLR)</th>
156 <th>Sent (MT)</th>
157 <th>Sent (DLR)</th>
158 <th>Outbound (MT)</th>
159 <th>Outbound (DLR)</th>
160 <th>Queued (MO)</th>
161 <th>Queued (MT)
162 </th>
163 </tr>
164 <?php
165 $sums = array(
166 0, 0, 0.0, 0.0, 0, 0, 0.0, 0.0, 0, 0
167 );
168 foreach ($configs as $inst => $config) {
169 $cols = array(
170 get_path($status[$inst], 'sms/received/total'),
171 get_path($status[$inst], 'dlr/received/total'),
172 get_path($status[$inst], 'sms/inbound'),
173 get_path($status[$inst], 'dlr/inbound'),
174 get_path($status[$inst], 'sms/sent/total'),
175 get_path($status[$inst], 'dlr/sent/total'),
176 get_path($status[$inst], 'sms/outbound'),
177 get_path($status[$inst], 'dlr/outbound'),
178 get_path($status[$inst], 'sms/received/queued'),
179 get_path($status[$inst], 'sms/sent/queued'),
180 );
181 for ($i=0;$i<10;$i++) {
182 $sums[$i] += $cols[$i];
183 }
184 ?>
185 <tr>
186 <td><?php echo $config['name'] ?></td>
187 <td><?php echo nf($cols[0]) ?></td>
188 <td><?php echo nf($cols[1]) ?></td>
189 <td><?php echo nfd($cols[2]) ?></td>
190 <td><?php echo nfd($cols[3]) ?></td>
191 <td><?php echo nf($cols[4]) ?></td>
192 <td><?php echo nf($cols[5]) ?></td>
193 <td><?php echo nfd($cols[6]) ?></td>
194 <td><?php echo nfd($cols[7]) ?></td>
195 <td><?php echo nf($cols[8]) ?></td>
196 <td><?php echo nf($cols[9]) ?></td>
197 </tr>
198 <?php
199 }
200 ?>
201 <tr class="sum">
202 <td>Total</td>
203 <td><?php echo nf($sums[0]) ?></td>
204 <td><?php echo nf($sums[1]) ?></td>
205 <td><?php echo nfd($sums[2]) ?></td>
206 <td><?php echo nfd($sums[3]) ?></td>
207 <td><?php echo nf($sums[4]) ?></td>
208 <td><?php echo nf($sums[5]) ?></td>
209 <td><?php echo nfd($sums[6]) ?></td>
210 <td><?php echo nfd($sums[7]) ?></td>
211 <td><?php echo nf($sums[8]) ?></td>
212 <td><?php echo nf($sums[9]) ?></td>
213 </tr>
214 </table>
215 </p>
216
217 <h4>Box connections</h4>
218
219 <p id=bord>
220 <table width="100%" cellspacing="0" class="text" id="overall" valign="top">
221 <tr>
222 <th>Instance</th>
223 <th>Type</th>
224 <th>ID</th>
225 <th>IP</th>
226 <th>Queued (MO)</th>
227 <th>Started</th>
228 <th>Uptime</th>
229 <th style="border-right: 1px solid black">SSL</th>
230 </tr>
231 <?php
232 foreach ($configs as $inst => $config) {
233 /* drop an error in case we have no boxes connected */
234 if (!is_array($status[$inst]['boxes']) || sizeof($status[$inst]['boxes']) < 0) {
235 ?>
236 <tr>
237 <td><?php echo $config['name'] ?></td>
238 <td colspan="8" class="red">
239 No boxes connected to this bearerbox!
240 </td>
241 </tr>
242 <?php
243 } else {
244 $sep = ($inst > 0) ? " class=\"sep\"":'';
245 /* loop the boxes */
246 foreach ($status[$inst]['boxes'] as $box) {
247 list ($st, $started, $uptime) = parse_uptime($box['status']);
248
249 ?>
250 <tr<?php echo $sep ?>>
251 <td><?php echo $config['name'] ?></td>
252 <td><?php echo $box['type'] ?></td>
253 <td><?php echo $box['id'] ?></td>
254 <td><?php echo $box['IP'] ?></td>
255 <td><?php echo nf($box['queued']) ?> msgs</td>
256 <td><?php echo $started ?></td>
257 <td><?php echo $uptime ?></td>
258 <td><?php echo $box['ssl'] ?></td>
259 </tr>
260 <?php
261 $sep = '';
262 }
263 }
264 }
265 ?>
266 </table>
267 </p>
268
269 <h4>SMSC connections</h4>
270
271 <p id=bord>
272 <table width="100%" cellspacing="0" class="text" id="overall" valign="top">
273 <tr>
274 <th>Instance</th>
275 <th>Links</th>
276 <th>Online</th>
277 <th>Disconnected</th>
278 <th>Connecting</th>
279 <th>Re-Connecting</th>
280 <th>Dead</th>
281 <th style="border-right: 1px solid black">Unknown</th>
282 </tr>
283 <?php
284 $sums = array(
285 0, 0, 0, 0, 0, 0, 0
286 );
287 foreach ($configs as $inst => $config) {
288 $smsc_status = count_smsc_status($status[$inst]['smscs']);
289 $cols = array(
290 array_sum($smsc_status),
291 $smsc_status['online'],
292 $smsc_status['disconnected'],
293 $smsc_status['connecting'],
294 $smsc_status['re-connecting'],
295 $smsc_status['dead'],
296 $smsc_status['unknown'],
297 );
298 for ($i=0;$i<7;$i++) {
299 $sums[$i] += $cols[$i];
300 }
301 ?>
302 <tr>
303 <td><?php echo $config['name'] ?></td>
304 <td><?php echo make_link($cols[0], 'total') ?></td>
305 <td><?php echo make_link($smsc_status, 'online', 'green') ?></td>
306 <td><?php echo make_link($smsc_status, 'disconnected') ?></td>
307 <td><?php echo make_link($smsc_status, 'connecting') ?></td>
308 <td><?php echo make_link($smsc_status, 're-connecting') ?></td>
309 <td><?php echo make_link($smsc_status, 'dead') ?></td>
310 <td><?php echo make_link($smsc_status, 'unknown') ?></td>
311 </tr>
312 <?php
313 }
314 ?>
315 <tr class="sum">
316 <td>Total</td>
317 <td><?php echo make_link($sums[0], 'total') ?></td>
318 <td><?php echo make_link($sums[1], 'total') ?></td>
319 <td><?php echo make_link($sums[2], 'total') ?></td>
320 <td><?php echo make_link($sums[3], 'total') ?></td>
321 <td><?php echo make_link($sums[4], 'total') ?></td>
322 <td><?php echo make_link($sums[5], 'total') ?></td>
323 <td><?php echo make_link($sums[6], 'total') ?></td>
324 </tr>
325 </table>
326 </p>
327 <?php
328 if (!empty($_REQUEST['details'])) {
329 ?>
330
331 <h4>SMSC connection details</h4>
332
333 <p id=bord>
334 <table width="100%" cellspacing="0" class="text" id="overall" valign="top">
335 <tr>
336 <th>Instance</th>
337 <th>SMSC-ID</th>
338 <th>Status</th>
339 <th>Uptime</th>
340 <th>Received (MO)</th>
341 <th>Received (DLR)</th>
342 <th>Sent (MT)</th>
343 <th>Sent (DLR)</th>
344 <th>Failed (MT)</th>
345 <th>Queued (MT)</th>
346 <th style="border-right: 1px solid black">Admins</th>
347 </tr>
348 <?php
349 foreach ($configs as $inst => $config) {
350 $sep = ($inst > 0) ? " class=\"sep\"":'';
351 foreach ($status[$inst]['smscs'] as $smsc) {
352 list ($st, $uptime) = explode(" ", $smsc['status']);
353 $uptime = ($uptime) ? get_uptime($uptime):'-';
354 ?>
355 <tr<?php echo $sep ?>>
356 <td><?php echo $config['name'] ?></td>
357 <td>
358 <?php echo $smsc['id'] ?> [<?php echo $smsc['admin-id'] ?>]<br />
359 <?php echo $smsc['name'] ?>
360 </td>
361 <td><?php echo format_status($st) ?></td>
362 <td><?php echo $uptime ?></td>
363 <td><?php echo nf($smsc['sms'][0]['received']) ?></td>
364 <td><?php echo nf($smsc['dlr'][0]['received']) ?></td>
365 <td><?php echo nf($smsc['sms'][0]['sent']) ?></td>
366 <td><?php echo nf($smsc['dlr'][0]['sent']) ?></td>
367 <td><?php echo nf($smsc['failed']) ?></td>
368 <td><?php echo nf($smsc['queued']) ?></td>
369 <td>
370 <a class="href" href="#" onClick="admin_smsc_url('stop-smsc',
371 '<?php echo $config["base_url"] ?>/stop-smsc?smsc=<?php echo $smsc['admin-id'] ?>',
372 '<?php echo $smsc['admin-id'] ?>',
373 '<?php echo $config["admin_passwd"] ?>'); return false;">stop</a>
374 |
375 <a class="href" href="#" onClick="admin_smsc_url('start-smsc',
376 '<?php echo $config["base_url"] ?>/start-smsc?smsc=<?php echo $smsc['admin-id'] ?>',
377 '<?php echo $smsc['admin-id'] ?>',
378 '<?php echo $config["admin_passwd"] ?>'); return false;">start</a>
379 <br />
380 <a class="href" href="#" onClick="admin_smsc_url('remove-smsc',
381 '<?php echo $config["base_url"] ?>/remove-smsc?smsc=<?php echo $smsc['admin-id'] ?>',
382 '<?php echo $smsc['admin-id'] ?>',
383 '<?php echo $config["admin_passwd"] ?>'); return false;">remove</a>
384 |
385 <a class="href" href="#" onClick="admin_smsc_url('add-smsc',
386 '<?php echo $config["base_url"] ?>/add-smsc?smsc=<?php echo $smsc['admin-id'] ?>',
387 '<?php echo $smsc['admin-id'] ?>',
388 '<?php echo $config["admin_passwd"] ?>'); return false;">add</a>
389 </td>
390 </tr>
391 <?php
392 $sep = '';
393 }
394 }
395 ?>
396 </table>
397 <?php
398 } else {
399 echo "<a class=href href=\"".$_SERVER['REQUEST_URI'];
400 if (strpos($_SERVER['REQUEST_URI'], "?") > 0) {
401 echo "&details=1";
402 } else {
403 echo "?details=1";
404 }
405 echo "\">SMSC connection details</a>\n";
406 }
407 ?>
408 </body>
409 </html>