#!/usr/bin/perl -w # # Copyright (C) 2005 Rodolphe Quiedeville # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2 dated June, # 1991. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # If you improve this script please send your version to my email address # with the copyright notice upgrade with your name. # # Plugin to monitor number of active channels by codec used, use the # asterisk's manager API to fecth datas. # # $Log$ # Revision 1.1 2005/10/28 21:04:01 rodo # Created by Rodolphe Quiedeville # # Parameters mandatory: # # username # secret # #%# family=asterisk #%# capabilities=autoconf use strict; use Curses; use Term::ReadKey; my $ret = undef; if (! eval "require Net::Telnet;") { $ret = "Net::Telnet not found"; } my $host = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1"; my $port = exists $ENV{'port'} ? $ENV{'port'} : "5038"; my $username = 'munin'; my $secret = 'mysecret'; my $pop = new Net::Telnet (Telnetmode => 0); $pop->open(Host => $host, Port => $port); ## Read connection message. my $line = $pop->getline; die $line unless $line =~ /^Asterisk/; ## Send user name. $pop->print("Action: login"); $pop->print("Username: $username"); $pop->print("Secret: $secret"); $pop->print("Events: off"); $pop->print(""); #Response: Success #Message: Authentication accepted my ($key, $i) = (0,0); initscr(); my $b = subwin(10, 40, 0, 0); my $c = subwin(10, 39, 0, 41); my $d = subwin($LINES-10, 80, 10, 0); noecho(); cbreak(); eval { box($b, '|', '-') }; eval { box($c, '|', '-') }; eval { box($d, '|', '-') }; addstr(1, 18, 'SIP'); addstr(1, 28, 'IAX'); addstr(2, 2, 'Canaux : '); addstr(1, 54, 'SIP'); addstr(1, 64, 'IAX'); addstr(2, 44, 'Peers : '); $i = 0; my $pos = 0; while (not defined ($key = ReadKey(-1)) && $key eq 'q') { $pop->print("Action: command"); $pop->print("Command: iax2 show peers"); $pop->print(""); my ($iaxpeers, $start)=(0,0); while (($line = $pop->getline) and ($line !~ /END COMMAND/o)) { if ($start) { $iaxpeers = $iaxpeers + 1 if ((split ' ',$line)[4] > 0); } $start = 1 if ($line =~ /Name/o); } $pos = 56; $pos = 55 if $iaxpeers > 99; addstr(2, $pos, $iaxpeers); ## $pop->print("Action: command"); $pop->print("Command: sip show peers"); $pop->print(""); $start = 0; my $sippeers=0; while (($line = $pop->getline) and ($line !~ /END COMMAND/o)) { if ($start) { $sippeers = $sippeers + 1 if ((split ' ',$line)[4] > 0); } $start = 1 if ($line =~ /Name/o); } $pos = 66 - lenght($iaxpeers); ##$pos = 65 if $iaxpeers > 99; addstr(2, $pos, $sippeers); sleep 1; $i++; addstr($LINES-2, 1, "Itération : $i"); move($LINES - 1, 0); refresh; } move($LINES - 1, 0); refresh(); endwin(); $pop->print("Action: logoff"); $pop->print(""); print "Get key $key\n";