在 slapd_ munin 插件中的串联 (.) 或字符串中使用未初始化的值

发布于 2024-12-16 18:09:12 字数 1475 浏览 1 评论 0原文

我正在尝试实现 slapd_ munin 插件,该插件是用 perl 编写的,但我对此一无所知。 完整的插件位于此处。我得到的错误是这个:

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.

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

问:任何人都可以建议如何调试此脚本吗?

I'm trying to implement the slapd_ munin plugin which is written in perl which I'm pretty much clueless about. The full plugin is available here. The error I'm getting is this one:

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

Line 232 is this one:

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

I tried debugging by outputing all the variables/objects as follows:

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

When I run it again here is what I obtain:

[...] # 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.

Since all the variables seem to be set, I really don't understand the error message I'm getting

Q: Can anybody advise on how debugging this script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几度春秋 2024-12-23 18:09:12

您应该将引用转储到%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 时,它的值是多少?

You should dump a reference to %ops, as in

print Dumper \%ops;

This will make the debug output clearer. To illustrate, consider the output of

#! /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);

Notice how you see the structure much more clearly in the latter half:

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

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

You cut out a critical bit of the output. What's the value of $VAR15? Is it "localhost" or something else?

When you print $searchdn, what is its value?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文