diff --git a/plugins/asterisk/asterisk b/plugins/asterisk/asterisk index 7994617d..5c28a6df 100755 --- a/plugins/asterisk/asterisk +++ b/plugins/asterisk/asterisk @@ -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 <