【问题标题】:Unable to fetch port count on nagios无法获取 nagios 上的端口数
【发布时间】:2018-03-21 11:57:59
【问题描述】:

我已经形成了一个使用 nagios check_by_ssh 模块获取已建立端口连接的命令。
当我运行命令时,我能够获得输出,但是在将命令放入 commands.cfg 文件后,我在 GUI 中看到“check_by_ssh:skip-stderr 参数必须是整数”。
对此的任何建议都会有很大帮助。

Command:
/usr/local/nagios/libexec/check_by_ssh -l fuseadmin -H <hostname> -C "netstat -punta | grep -i ESTABLISHED | wc -l | awk '{if (\$0>2500) {print \"CRITICAL: Established Socket Count: \"\$0} else {print \"OK: Established Socket Count: \"\$0}}'" -i ~/.ssh/id_dsa -E

OK: Established Socket Count: 67

Commands.cfg:
define command {
      command_name    netstat_cnt_estanblished_gt_2500_fuse01
      command_line   /usr/local/nagios/libexec/check_by_ssh -l fuseadmin -H a0110pcsgesb01 -C "netstat -punta | grep -i ESTABLISHED | wc -l 2>&1 | awk '{if (\$0>2500) {print \"CRITICAL: Established Socket Count: \"\$0} else {print \"OK: Established Socket Count: \"\$0}}'" -i ~/.ssh/id_dsa -E
}

Service Definition
#netstat_cnt_estanblished_gt_2500_csg2.0

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       <hostname>
        service_description             Netstat Established Count
                event_handler                   send-service-trap-fms
        event_handler_enabled           1
        check_command                   netstat_cnt_estanblished_gt_2500_fuse01
        max_check_attempts              1
        notifications_enabled           1                      ; Service notifications are enabled
        check_period                    24x7                    ; The service can be checked at any time of the day
        max_check_attempts              3                       ; Re-check the service up to 3 times in order to determine its final (hard) state
        check_interval           2                     ; Check the service every 10 minutes under normal conditions
        retry_interval            2                     ; Re-check the service every two minutes until a hard state can be determined
        contact_groups                  fuse_users                  ; Notifications get sent out to everyone in the 'admins' group
        notification_options            w,u,c,r                 ; Send notifications about warning, unknown, critical, and recovery events
        notification_interval           30                      ; Re-notify about service problems every hour
        notification_period             24x7

       }

**由于合规性,我已将实际主机名更改为

【问题讨论】:

  • 更好的方法是编写自己的 shell/bash 脚本并将其放在远程主机上。然后你应该在 Nagios 服务器上通过 check_by_ssh 命令运行它。

标签: nagios


【解决方案1】:

here 它说:

 check_by_ssh: print command output in verbose mode

right now it is not possible to print the command output of ssh. check_by_ssh
only prints the command itself. This patchs adds printing the output too. This
makes it possible to use ssh with verbose logging which helps debuging any
connection, key or other ssh problems.
Note: you must use -E,--skip-stderr=<high number>, otherwise check_by_ssh would
always exit with unknown state.

Example:

  ./check_by_ssh -H localhost -o LogLevel=DEBUG3 -C "sleep 1" -E 999 -v

含义:你应该只需要在“-E”之后指定一个数字,比如-E 999,在你的定义中(就像上面代码块中的例子一样)

...尽管如此,这令人困惑(也许是一个错误?),因为check_by_ssh 的命令帮助说:

-E, --skip-stderr[=n]
    Ignore all or (if specified) first n lines on STDERR [optional]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2018-02-05
    • 1970-01-01
    相关资源
    最近更新 更多