1

我正在尝试实现slapd_用 perl 编写的 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;

我尝试通过输出所有变量/对象进行调试,如下所示:

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.

由于似乎设置了所有变量,我真的不明白我收到的错误消息

问:有人可以建议如何调试这个脚本吗?

4

1 回答 1

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);

注意你在后半部分如何更清楚地看到结构:

无参考:
$VAR1 = '巴兹';
$VAR2 = {
          'quux' => 3
        };
$VAR3 = 'foo';
$VAR4 = {
          '酒吧' => 1
        };

参考:
$VAR1 = {
          '巴兹' => {
                     'quux' => 3
                   },
          '富' => {
                     '酒吧' => 1
                   }
        };

你删掉了输出的关键部分。的价值是$VAR15多少?是它"localhost"还是别的什么?

当您打印$searchdn时,它的价值是什么?

于 2011-11-18T11:55:23.593 回答