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

asterisk: command replies are now embedded in server responses

Asterisk now replies to "Action: command" with the response embedded,
e.g. with "Response: Success" instead of "Response: Follows".

We need to adjust how we parse the server response otherwise we can't
grab any data at all from the AMI.

Closes: #887
This commit is contained in:
Gabriel Filion 2019-08-09 16:52:20 -04:00
parent 4cec0c099e
commit d66fef2dc6

View file

@ -77,30 +77,32 @@ use strict;
use Munin::Plugin; use Munin::Plugin;
use IO::Socket; 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 { sub asterisk_command {
my ($socket, $command) = @_; my ($socket, $command) = @_;
my $line, my $reply; my $line, my $reply;
$socket->print("Action: command\nCommand: $command\n\n"); $socket->print("Action: command\nCommand: $command\n\n");
# Response: (Error|Follows|???) # Response: (Error|Follows|Success)
$line = $socket->getline; $line = $socket->getline;
if ($line !~ /^Response: Follows\r?\n$/) { if ($line !~ /^Response: Success\r?\n$/) {
while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {} while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
return undef; return undef;
} }
# Privilege: Command # Message: Command output follows
$line = $socket->getline; $line = $socket->getline;
print STDERR "Command: got response: $line\n";
# Until we get the --END COMMAND-- marker, it's the command's output. # 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; $reply .= $line;
} }
# And then wait for the empty line that says we're done
while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
return $reply; return $reply;
} }
@ -237,13 +239,13 @@ my $meetme_response = asterisk_command($socket, "meetme list");
#* Total number of MeetMe users: 1 #* Total number of MeetMe users: 1
my $sipchannels_response = asterisk_command($socket, "sip show channels"); my $sipchannels_response = asterisk_command($socket, "sip show channels");
#Peer User/ANR Call ID Seq (Tx/Rx) Format #Peer User/ANR Call ID Format Hold Last Message Expiry Peer
#192.168.1.135 yann 6902112b3e0 00101/00002 g729 #192.168.1.135 yann 1341929961-161 00101/00002 No Rx: INVITE g729
#1 active SIP channel(s) #1 active SIP channel(s)
my $iaxchannels_response = asterisk_command($socket, "iax2 show channels"); my $iaxchannels_response = asterisk_command($socket, "iax2 show channels");
#Channel Peer Username ID (Lo/Rem) Seq (Tx/Rx) Lag Jitter JitBuf Format #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 #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) #1 active IAX channel(s)
# After all the data is fetched we can proceed to process it, the # After all the data is fetched we can proceed to process it, the