mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
[asterisk] cleanup linebreak handling and single/plurals (Closes: #698)
lelutin proposed some changes: * the total is 0 if there is only one channel active (due to "channel" vs. "channels") * linebreaks "\r\n" are expected See https://github.com/munin-monitoring/contrib/issues/698
This commit is contained in:
parent
66d48afbbb
commit
04def756bc
1 changed files with 13 additions and 13 deletions
|
@ -85,8 +85,8 @@ sub asterisk_command {
|
|||
|
||||
# Response: (Error|Follows|???)
|
||||
$line = $socket->getline;
|
||||
if ($line ne "Response: Follows\r\n") {
|
||||
while ( $line = $socket->getline and $line ne "\r\n" ) {}
|
||||
if ($line !~ /^Response: Follows\r?\n$/) {
|
||||
while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -94,12 +94,12 @@ sub asterisk_command {
|
|||
$line = $socket->getline;
|
||||
|
||||
# Until we get the --END COMMAND-- marker, it's the command's output.
|
||||
while ( $line = $socket->getline and $line ne "--END COMMAND--\r\n" ) {
|
||||
while ( $line = $socket->getline and $line !~ /^--END COMMAND--\r?\n$/ ) {
|
||||
$reply .= $line;
|
||||
}
|
||||
|
||||
# And then wait for the empty line that says we're done
|
||||
while ( $line = $socket->getline and $line ne "\r\n" ) {}
|
||||
while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
|
||||
|
||||
return $reply;
|
||||
}
|
||||
|
@ -130,13 +130,13 @@ if ( $socket ) {
|
|||
$socket->print("Action: login\nUsername: $username\nSecret: $secret\nEvents: off\n\n");
|
||||
my $response_status = $socket->getline;
|
||||
|
||||
if ( $response_status ne "Response: Success\r\n" ) {
|
||||
if ( $response_status !~ /^Response: Success\r?\n$/ ) {
|
||||
my $response_message = $socket->getline;
|
||||
$response_message =~ s/Message: (.*)\r\n/$1/;
|
||||
$response_message =~ s/Message: (.*)\r?\n/$1/;
|
||||
$error = "Asterisk authentication error: " . $response_message;
|
||||
}
|
||||
|
||||
while ( $line = $socket->getline and $line ne "\r\n" ) {}
|
||||
while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
|
||||
}
|
||||
|
||||
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
|
||||
|
@ -251,7 +251,7 @@ my $iaxchannels_response = asterisk_command($socket, "iax2 show channels");
|
|||
$socket->close();
|
||||
|
||||
my $active_channels = 'U';
|
||||
$active_channels = $1 if $channels_response =~ /\n([0-9]+) active channels/;
|
||||
$active_channels = $1 if $channels_response =~ /\n([0-9]+) active channels?/;
|
||||
|
||||
print <<END;
|
||||
|
||||
|
@ -259,7 +259,7 @@ multigraph asterisk_channels
|
|||
total.value $active_channels
|
||||
END
|
||||
|
||||
my @channels_list = split(/\r\n/, $channels_response) if $channels_response;
|
||||
my @channels_list = split(/\r?\n/, $channels_response) if $channels_response;
|
||||
foreach my $channel (@CHANNELS) {
|
||||
print "$channel.value ";
|
||||
print $channels_response ? scalar(grep(/^$channel\//, @channels_list)) : "U";
|
||||
|
@ -271,7 +271,7 @@ if ( !$voicemail_response or $voicemail_response =~ /no voicemail users/ ) {
|
|||
print "total.value U\n";
|
||||
} else {
|
||||
my $messages = 0;
|
||||
foreach my $line (split(/\r\n/, $voicemail_response)) {
|
||||
foreach my $line (split(/\r?\n/, $voicemail_response)) {
|
||||
next unless $line =~ / ([0-9]+)$/;
|
||||
$messages += $1;
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ users.value 0
|
|||
conferences.value 0
|
||||
END
|
||||
} else {
|
||||
my @meetme_list = split(/\r\n/, $meetme_response);
|
||||
my @meetme_list = split(/\r?\n/, $meetme_response);
|
||||
|
||||
my $users = pop(@meetme_list);
|
||||
$users =~ s/^Total number of MeetMe users: ([0-9]+)$/$1/;
|
||||
|
@ -320,9 +320,9 @@ END
|
|||
}
|
||||
|
||||
# split the channels' listing and drop header and footnotes
|
||||
my @sipchannels = $sipchannels_response ? split(/\r\n|\n/, $sipchannels_response) : ();
|
||||
my @sipchannels = $sipchannels_response ? split(/\r?\n/, $sipchannels_response) : ();
|
||||
pop(@sipchannels); shift(@sipchannels);
|
||||
my @iaxchannels = $iaxchannels_response ? split(/\r\n|\n/, $iaxchannels_response) : ();
|
||||
my @iaxchannels = $iaxchannels_response ? split(/\r?\n/, $iaxchannels_response) : ();
|
||||
pop(@iaxchannels); shift(@iaxchannels);
|
||||
|
||||
$i = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue