2011-11-18 31 views
1

我正在嘗試使用perl編寫的slapd_ munin插件,我幾乎不知道該插件。 The full plugin is available here。我得到的錯誤是這一個:slapd_ munin插件中串聯(。)或字符串中未初始化值的使用

Use of uninitialized value in concatenation (.) or string at 
/etc/munin/plugins/slapd_localhost line 232, <DATA> line 275. 

232線路是這一個:

my $searchdn = $ops{$action}->{'search'} . "," . $basedn; 

我通過outputing所有變量試圖調試/對象如下:

use Data::Dumper; # top of script 
# [...] 
print Dumper(%ops); 
print "action = [$action]\n"; 
print "basedn = [$basedn]\n\n"; 
my $searchdn = $ops{$action}->{'search'} . "," . $basedn; 

當我再次運行它時,我得到:

[...] # 15 other variables belonging to $ops 
$VAR16 = { 
      'info' => 'The graph shows the number of Waiters', 
      'search' => 'cn=Waiters', 
      'desc' => 'The current number of Waiters', 
      'filter' => '(|(cn=Write)(cn=Read))', 
      'title' => 'Number of Waiters', 
      'label2' => { 
         'read' => 'Read', 
         'write' => 'Write' 
         }, 
      'vlabel' => 'Waiters' 
     }; 
action = [localhost] 
action = [cn=Monitor] 

Use of uninitialized value in concatenation (.) or string at /etc/munin/plugins/slapd_localhost line 237, <DATA> line 275. 

由於所有的變量似乎設置,我真的不明白我得到的錯誤信息

問:任何人都可以建議如何調試此腳本?

+0

您確定$ basedn已被賦值嗎?用參考打印 – canavanin

回答

3

您應該轉儲參考%ops,如

print Dumper \%ops; 

這將使調試輸出更清晰。爲了說明這一點,考慮

#! /usr/bin/perl 

use strict; 
use warnings; 

use Data::Dumper; 

my %h = (foo => { bar => 1 }, baz => { quux => 3 }); 

print "No reference:\n", 
     Dumper(%h), 
     "\n", 
     "Reference:\n", 
     Dumper(\%h); 

通知的輸出如何在下半年更清楚地看到結構:

No reference: 
$VAR1 = 'baz'; 
$VAR2 = { 
      'quux' => 3 
     }; 
$VAR3 = 'foo'; 
$VAR4 = { 
      'bar' => 1 
     }; 

Reference: 
$VAR1 = { 
      'baz' => { 
        'quux' => 3 
        }, 
      'foo' => { 
        'bar' => 1 
        } 
     };

你切出的輸出的關鍵位。 $VAR15的價值是多少?是"localhost"還是別的?

當您打印$searchdn時,它的價值是多少?

+0

確實有幫助。很明顯,$ ops數組實際上包含了插件配置,並且我錯誤地創建了插件符號鏈接(在munin世界中,您使用符號鏈接本身將參數傳遞給您的插件),因此它失敗了。 – Max

+0

我很高興它幫助! –