windows上配置snmpd.conf出错substr outside of string

这两天在WindowsXP上搭建Cacti,安装Net-SNMP的snmpd.conf不太顺利,当提示输入community name时,我输入public后回车,便出现错误信息:
The community name to add read-only access for: public
substr outside of string at C:/perl/lib/Term/ReadLine/readline.pm line 1974.
Use of uninitialized value $s in length at C:/perl/lib/Term/ReadLine/readline.pm line 1783.
Use of uninitialized value $s in length at C:/perl/lib/Term/ReadLine/readline.pm line 1789.
Use of uninitialized value $s in substr at C:/perl/lib/Term/ReadLine/readline.pm line 1800.
The hostname or network address to accept this community name from [RETURN for all]: Use of uninitialized value $dline in length at C:/perl/lib/Term/ReadLine/readline.pm line 2046.
google了一把,也有人遇到同样的问题,但是没找到解决的办法。只好一头扎进snmconf以及报错的文件,一路跟踪,终于发现在C:/perl/lib/Term/ReadLine/readline.pm line文件中为了调整显示,截断了过长的字符串。windows cmd窗口的默认属性中,一行的默认长度是80,当字符串的长度超过80时,会被截取到80。其中问题“The community name to add read-only access for:”后面的问题“The hostname or network address to accept this community name from [RETURN for all]:”超过了80个字符,显示时被截取为80个字符,所以出错。解决办法有两种,建议采用第一种办法:
1. 调整windows cmd窗口的行宽
在cmd窗口头上点鼠标右键-〉属性-〉布局,设置“屏幕缓冲区大小”和“窗口大小”的宽度后点“确定”
2. 修改代码
下列代码就是C:/perl/lib/Term/ReadLine/readline.pm line中调整字符串显示的代码,其中第一行$thislen = &min(length($dline) – $si, $rl_screen_width);是获取长度的串,把$thislen = &min(length($dline) – $si, $rl_screen_width);改为$thislen = length($dline) – $si;后,显示就不会受windows cmd窗口的行宽的限制了。

$thislen = &min(length($dline) – $si, $rl_screen_width);
if ($si + $thislen < length($dline)) {
## need to place a ‘>’… make sure to place on first byte.
$thislen– if &OnSecondByte($si+$thislen-1);
substr($dline, $si+$thislen-1,1) = ‘>’;
$have_ket = 1;
}

##
## Now know what to display.
## Must get substr($dline, $si, $thislen) on the screen,
## with the cursor at $D-$si characters from the left edge.
##
$dline = substr($dline, $si, $thislen);
$delta = $D – $si; ## delta is cursor distance from beginning of $dline.
if (defined $bsel) {
$bsel -= $si;
$esel = $delta;
($bsel, $esel) = ($esel, $bsel) if $bsel > $esel;
$bsel = 0 if $bsel < 0;
if ($have_ket) {
$esel = $thislen – 1 if $esel > $thislen – 1;
} else {
$esel = $thislen if $esel > $thislen;
}
}
if ($si >= length($prompt)) { # Keep $dline for $lastredisplay…
$prompt = ($have_bra ? “<” : “”);
$dline = substr $dline, 1; # After prompt
$bsel = 1 if defined $bsel and $bsel == 0;
} else {
$dline = substr($dline, (length $prompt) – $si);
$prompt = substr($prompt,$si);
substr($prompt, 0, 1) = ‘<’ if $si > 0;
}

 

最多留言日志

此条目发表在 SNMP 分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已被标记为 *

*

*


您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>