通过NRPE处理Perl脚本时出错

时间:2015-08-28 14:03:25

标签: perl nagios nrpe

我正在尝试使用NRPE将Perl程序check_httpd_limits.pl from here添加为插件。以下部分似乎没有失败

# -----------------------------------------
# READ PROCESS INFORMATION FOR HTTPD BINARY
# -----------------------------------------
#
opendir ( my $proc_fh, "/proc" ) or die "ERROR: /proc - $!\n";
while ( my $pid = readdir( $proc_fh ) ) {
        my $exe = readlink( "/proc/$pid/exe" );
        next unless ( defined $exe );
        if ( $exe eq $httpd{'EXE'} ) {
#print "OK";
#exit 0;
                open ( my $stat_fh, "<", "/proc/$pid/stat" ) or die "ERROR: /proc/$pid/stat - $!\n";
                my @pid_stat = split (/ /, readline( $stat_fh )); close ( $stat_fh );

                open ( my $statm_fh, "<", "/proc/$pid/statm" ) or die "ERROR: /proc/$pid/statm - $!\n";
                my @pid_statm = split (/ /, readline( $statm_fh )); close ( $statm_fh );

                my %all_stats = (
                        'pid' => $pid_stat[0],
                        'name' => $pid_stat[1],
                        'ppid' => $pid_stat[3],
                        'rss' => $pid_stat[23] * $pagesize / 1024 / 1024,
                        'share' => $pid_statm[2] * $pagesize / 1024 / 1024,
                );
                push ( @stathrefs, \%all_stats );
        }
#print "WARN";
#exit 0;

}
close ( $proc_fh );
die "ERROR: No $httpd{'EXE'} processes found in /proc/*/exe! Are you root?\n"
        unless ( @stathrefs );

# -------------------------------------

脚本本身运行正常,直到上述点通过NRPE失败。

如果我运行./check_nrpe -H domain -c check_ram,我会

  

NRPE:无法读取输出

在我拥有的monitered服务器上

command[check_ram]=/usr/local/nagios/libexec/check_httpd_limits.pl

nrpe.cfg文件

我认为这可能是某人在/proc下提到的许可问题。

当我作为用户nagios运行时,我得到相同的错误NRPE: Unable to read output

ll  /proc
total 0
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 10
dr-xr-xr-x  8 rpc       rpc          0 Sep  4 08:12 1007
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1038
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1039
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1044
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 11
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 11221
dr-xr-xr-x  8 dbus      dbus         0 Sep  4 08:12 1155
dr-xr-xr-x  8 mysql     mysql        0 Sep  4 08:12 11644
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1187
dr-xr-xr-x  8 haldaemon haldaemon    0 Jun  4 21:55 1197
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1198
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 12
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1230
dr-xr-xr-x  8 haldaemon haldaemon    0 Sep  4 08:12 1254
dr-xr-xr-x  8 memcached memcached    0 Sep  4 08:12 1267
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1287
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 1296
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 13
dr-xr-xr-x  8 ntp       ntp          0 Sep  4 08:10 1319
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 14
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 15
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 16
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 17
dr-xr-xr-x  8 postfix   postfix      0 Sep  4 10:07 1735
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 18
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 18357
dr-xr-xr-x  8 mcmap     apache       0 Sep  4 08:12 18363
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 19
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 20
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2004
dr-xr-xr-x  8 postfix   postfix      0 Sep  4 08:12 2024
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2029
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2037
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2056
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2069
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 21
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2104
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2113
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2115
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2117
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2119
dr-xr-xr-x  8 root      root         0 Sep  4 08:09 2120
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2121
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2123
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2126
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2127
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 2128
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 21885
dr-xr-xr-x  8 mcmap     apache       0 Sep  4 08:12 21887
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 21903
dr-xr-xr-x  8 mcmap     apache       0 Sep  4 08:12 21907
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 21918
dr-xr-xr-x  8 mcmap     apache       0 Sep  4 08:12 21920
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 22
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 227
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 228
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 23
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 24
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 25
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 26
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 26388
dr-xr-xr-x  8 admin     admin        0 Sep  4 08:12 26390
dr-xr-xr-x  8 admin     admin        0 Sep  4 08:12 26391
dr-xr-xr-x  8 root      admin        0 Sep  4 08:12 26408
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 26411
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 27
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 272
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 28
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 283
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 284
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 29
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 293
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 3
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 30
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 31
dr-xr-xr-x  8 root      root         0 Sep  4 08:09 31243
dr-xr-xr-x  8 mcmap     apache       0 Sep  4 08:09 31247
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 32
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:42 3246
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 33
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:43 3321
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 34
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:47 3461
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:47 3474
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:47 3484
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 35
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:47 3534
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:48 3552
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 36
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:49 3633
dr-xr-xr-x  8 root      root         0 Sep  4 10:48 3639
dr-xr-xr-x  8 nagios    nagios       0 Sep  4 10:49 3640
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:49 3664
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3689
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 37
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 371
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3711
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3714
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3715
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3725
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3726
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3728
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3739
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3740
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3745
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3746
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3747
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:51 3748
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:52 3771
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:52 3774
dr-xr-xr-x  8 apache    apache       0 Sep  4 10:52 3775
dr-xr-xr-x  8 root      root         0 Sep  4 10:52 3779
dr-xr-xr-x  8 root      root         0 Sep  4 10:52 3780
dr-xr-xr-x  8 sshd      sshd         0 Sep  4 10:52 3781
dr-xr-xr-x  8 nagios    nagios       0 Sep  4 10:52 3782
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 38
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 39
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 4
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 40
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 406
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 408
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 41
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 42
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 43
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 44
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 45
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 5
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 53
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 54
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 56
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 57
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 58
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 6
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 6953
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 7
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 713
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 714
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 754
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 8
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 89
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 9
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 90
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 940
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 961
dr-xr-xr-x  8 root      root         0 Sep  4 08:12 991
dr-xr-xr-x 10 root      root         0 Jun  4 21:55 acpi
-r--r--r--  1 root      root         0 Sep  4 10:52 buddyinfo
dr-xr-xr-x  6 root      root         0 Jun  4 22:54 bus
-r--r--r--  1 root      root         0 Sep  4 10:52 cgroups
-r--r--r--  1 root      root         0 Sep  4 10:52 cmdline
-r--r--r--  1 root      root         0 Sep  4 10:52 cpuinfo
-r--r--r--  1 root      root         0 Sep  4 10:52 crypto
-r--r--r--  1 root      root         0 Sep  4 10:52 devices
-r--r--r--  1 root      root         0 Sep  4 10:52 diskstats
-r--r--r--  1 root      root         0 Sep  4 10:52 dma
dr-xr-xr-x  2 root      root         0 Sep  4 10:52 driver
-r--r--r--  1 root      root         0 Sep  4 10:52 execdomains
-r--r--r--  1 root      root         0 Sep  4 10:52 fb
-r--r--r--  1 root      root         0 Sep  4 10:52 filesystems
dr-xr-xr-x  5 root      root         0 Sep  4 10:52 fs
-r--r--r--  1 root      root         0 Sep  4 10:52 interrupts
-r--r--r--  1 root      root         0 Sep  4 10:52 iomem
-r--r--r--  1 root      root         0 Sep  4 10:52 ioports
dr-xr-xr-x 23 root      root         0 Sep  4 10:52 irq
-r--r--r--  1 root      root         0 Sep  4 10:52 kallsyms
-r--------  1 root      root      4096 Sep  4 10:52 kcore
-r--r--r--  1 root      root         0 Sep  4 10:52 keys
-r--r--r--  1 root      root         0 Sep  4 10:52 key-users
-r--------  1 root      root         0 Jun  4 21:55 kmsg
-r--------  1 root      root         0 Sep  4 10:52 kpagecount
-r--------  1 root      root         0 Sep  4 10:52 kpageflags
-r--r--r--  1 root      root         0 Sep  4 10:52 loadavg
-r--r--r--  1 root      root         0 Sep  4 10:52 locks
-r--r--r--  1 root      root         0 Jun  4 21:55 mdstat
-r--r--r--  1 root      root         0 Sep  4 10:52 meminfo
-r--r--r--  1 root      root         0 Sep  4 10:52 misc
-r--r--r--  1 root      root         0 Sep  4 10:52 modules
lrwxrwxrwx  1 root      root        11 Sep  4 10:52 mounts -> self/mounts
-r--r--r--  1 root      root         0 Sep  4 10:52 mtd
-rw-r--r--  1 root      root         0 Sep  4 10:52 mtrr
lrwxrwxrwx  1 root      root         8 Sep  4 10:52 net -> self/net
-r--r--r--  1 root      root         0 Sep  4 10:52 pagetypeinfo
-r--r--r--  1 root      root         0 Sep  4 10:52 partitions
-r--r--r--  1 root      root         0 Sep  4 10:52 sched_debug
-r--r--r--  1 root      root         0 Sep  4 10:52 schedstat
dr-xr-xr-x  2 root      root         0 Sep  4 10:52 scsi
lrwxrwxrwx  1 root      root        64 Sep  4 08:09 self -> 3782
-rw-r--r--  1 root      root         0 Sep  4 10:52 slabinfo
-r--r--r--  1 root      root         0 Sep  4 10:52 softirqs
-r--r--r--  1 root      root         0 Sep  4 10:52 stat
-r--r--r--  1 root      root         0 Sep  4 10:52 swaps
dr-xr-xr-x  1 root      root         0 Jun  4 22:54 sys
--w-------  1 root      root         0 Sep  4 10:52 sysrq-trigger
dr-xr-xr-x  2 root      root         0 Sep  4 10:52 sysvipc
-r--r--r--  1 root      root         0 Sep  4 10:52 timer_list
-rw-r--r--  1 root      root         0 Sep  4 10:52 timer_stats
dr-xr-xr-x  4 root      root         0 Sep  4 10:52 tty
-r--r--r--  1 root      root         0 Sep  4 10:52 uptime
-r--r--r--  1 root      root         0 Sep  4 10:52 version
-r--------  1 root      root         0 Sep  4 10:52 vmallocinfo
-r--r--r--  1 root      root         0 Sep  4 10:52 vmstat
-r--r--r--  1 root      root         0 Sep  4 10:52 zoneinfo

以root身份运行时的输出

/usr/local/nagios/libexec/check_httpd_limits.pl
OK: AllProcsTotalMem (1996.04 MB) fits within MemTotal (3830.75 MB)

调试打开

Sep 17 12:38:53 domani xinetd[1296]: START: nrpe pid=17206 from=::ffff:127.0.0.1
Sep 17 12:38:53 domain xinetd[1296]: EXIT: nrpe status=0 pid=17206 duration=0(sec)

0 个答案:

没有答案