Projet

Général

Profil

Révision 04def756

ID04def756bc906ebb22cb55f64fbf3ea31f943372
Parent 66d48afb
Enfant 9dcf5885

Ajouté par Lars Kruse il y a environ 9 ans

[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

Voir les différences:

plugins/asterisk/asterisk
85 85

  
86 86
  # Response: (Error|Follows|???)
87 87
  $line = $socket->getline;
88
  if ($line ne "Response: Follows\r\n") {
89
    while ( $line = $socket->getline and $line ne "\r\n" ) {}
88
  if ($line !~ /^Response: Follows\r?\n$/) {
89
    while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
90 90
    return undef;
91 91
  }
92 92

  
......
94 94
  $line = $socket->getline;
95 95

  
96 96
  # Until we get the --END COMMAND-- marker, it's the command's output.
97
  while ( $line = $socket->getline and $line ne "--END COMMAND--\r\n" ) {
97
  while ( $line = $socket->getline and $line !~ /^--END COMMAND--\r?\n$/ ) {
98 98
    $reply .= $line;
99 99
  }
100 100

  
101 101
  # And then wait for the empty line that says we're done
102
  while ( $line = $socket->getline and $line ne "\r\n" ) {}
102
  while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
103 103

  
104 104
  return $reply;
105 105
}
......
130 130
  $socket->print("Action: login\nUsername: $username\nSecret: $secret\nEvents: off\n\n");
131 131
  my $response_status = $socket->getline;
132 132

  
133
  if ( $response_status ne "Response: Success\r\n" ) {
133
  if ( $response_status !~ /^Response: Success\r?\n$/ ) {
134 134
    my $response_message = $socket->getline;
135
    $response_message =~ s/Message: (.*)\r\n/$1/;
135
    $response_message =~ s/Message: (.*)\r?\n/$1/;
136 136
    $error = "Asterisk authentication error: " . $response_message;
137 137
  }
138 138

  
139
  while ( $line = $socket->getline and $line ne "\r\n" ) {}
139
  while ( $line = $socket->getline and $line !~ /^\r?\n$/ ) {}
140 140
}
141 141

  
142 142
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
......
251 251
$socket->close();
252 252

  
253 253
my $active_channels = 'U';
254
$active_channels = $1 if $channels_response =~ /\n([0-9]+) active channels/;
254
$active_channels = $1 if $channels_response =~ /\n([0-9]+) active channels?/;
255 255

  
256 256
print <<END;
257 257

  
......
259 259
total.value $active_channels
260 260
END
261 261

  
262
my @channels_list = split(/\r\n/, $channels_response) if $channels_response;
262
my @channels_list = split(/\r?\n/, $channels_response) if $channels_response;
263 263
foreach my $channel (@CHANNELS) {
264 264
  print "$channel.value ";
265 265
  print $channels_response ? scalar(grep(/^$channel\//, @channels_list)) : "U";
......
271 271
  print "total.value U\n";
272 272
} else {
273 273
  my $messages = 0;
274
  foreach my $line (split(/\r\n/, $voicemail_response)) {
274
  foreach my $line (split(/\r?\n/, $voicemail_response)) {
275 275
    next unless $line =~ / ([0-9]+)$/;
276 276
    $messages += $1;
277 277
  }
......
292 292
conferences.value 0
293 293
END
294 294
  } else {
295
    my @meetme_list = split(/\r\n/, $meetme_response);
295
    my @meetme_list = split(/\r?\n/, $meetme_response);
296 296

  
297 297
    my $users = pop(@meetme_list);
298 298
    $users =~ s/^Total number of MeetMe users: ([0-9]+)$/$1/;
......
320 320
  }
321 321

  
322 322
  # split the channels' listing and drop header and footnotes
323
  my @sipchannels = $sipchannels_response ? split(/\r\n|\n/, $sipchannels_response) : ();
323
  my @sipchannels = $sipchannels_response ? split(/\r?\n/, $sipchannels_response) : ();
324 324
  pop(@sipchannels); shift(@sipchannels);
325
  my @iaxchannels = $iaxchannels_response ? split(/\r\n|\n/, $iaxchannels_response) : ();
325
  my @iaxchannels = $iaxchannels_response ? split(/\r?\n/, $iaxchannels_response) : ();
326 326
  pop(@iaxchannels); shift(@iaxchannels);
327 327

  
328 328
  $i = 0;

Formats disponibles : Unified diff