1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

Merge pull request #1005 from lelutin/fix_asterisk_ami_parsing

Fix asterisk ami parsing
This commit is contained in:
Lars Kruse 2019-08-10 14:17:36 +02:00 committed by GitHub
commit 0ca0e78b9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,30 +77,32 @@ use strict;
use Munin::Plugin;
use IO::Socket;
# See the following and its subpages for change history in the AMI protocol:
# https://wiki.asterisk.org/wiki/display/AST/Asterisk+Manager+Interface+%28AMI%29+Changes
sub asterisk_command {
my ($socket, $command) = @_;
my $line, my $reply;
$socket->print("Action: command\nCommand: $command\n\n");
# Response: (Error|Follows|???)
# Response: (Error|Follows|Success)
$line = $socket->getline;
if ($line !~ /^Response: Follows\r?\n$/) {
if ($line !~ /^Response: Success\r?\n$/) {
while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
return undef;
}
# Privilege: Command
# Message: Command output follows
$line = $socket->getline;
print STDERR "Command: got response: $line\n";
# Until we get the --END COMMAND-- marker, it's the command's output.
while ( $line = $socket->getline and $line !~ /^--END COMMAND--\r?\n$/ ) {
while ( $line = $socket->getline and $line =~ /^Output:/ ) {
print STDERR "Command: got response: $line\n";
# Don't keep the "Output: " part of the response
substr($line, 0, 8, '');
$reply .= $line;
}
# And then wait for the empty line that says we're done
while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
return $reply;
}
@ -190,7 +192,7 @@ END
print <<END;
multigraph asterisk_codecs
graphs_title Asterisk channels per codec
graph_title Asterisk channels per codec
graph_args --base 1000 -l 0
graph_vlabel channels
graph_category voip
@ -237,13 +239,13 @@ my $meetme_response = asterisk_command($socket, "meetme list");
#* Total number of MeetMe users: 1
my $sipchannels_response = asterisk_command($socket, "sip show channels");
#Peer User/ANR Call ID Seq (Tx/Rx) Format
#192.168.1.135 yann 6902112b3e0 00101/00002 g729
#Peer User/ANR Call ID Format Hold Last Message Expiry Peer
#192.168.1.135 yann 1341929961-161 00101/00002 No Rx: INVITE g729
#1 active SIP channel(s)
my $iaxchannels_response = asterisk_command($socket, "iax2 show channels");
#Channel Peer Username ID (Lo/Rem) Seq (Tx/Rx) Lag Jitter JitBuf Format
#IAX2/rodolphe@rodolp 10.8.53.6 rodolphe 00003/01287 00006/00004 00000ms 0148ms 0000ms gsm
#Channel Peer Username ID (Lo/Rem) Seq (Tx/Rx) Lag Jitter JitBuf Format FirstMsg LastMsg
#IAX2/rodolphe@rodolp 10.8.53.6 rodolphe 00003/01287 00006/00004 00000ms 0148ms 0000ms gsm Rx:NEW Tx:ACK
#1 active IAX channel(s)
# After all the data is fetched we can proceed to process it, the