![](/img/trans.png)
[英]nagios - nrpe - check_http - works from command prompt but fails on nrpe
[英]nagios check_http HTTP CRITICAL - Unable to open TCP socket, works fine from command line
我有以下服務定義:
define service{
use my-service ; Name of service template to use
host_name dra
service_description https://www.example.com
check_command check_http!-I my.ip.address --ssl -H www.example.com
notifications_enabled 1
retry_check_interval 2
normal_check_interval 5
contact_groups myadmins
}
服務檢查不斷失敗
Name or service not known
HTTP CRITICAL - Unable to open TCP socket
但是,如果我從命令行運行 http_check,則會得到 200 OK 結果:
/usr/lib/nagios/plugins/check_http -I my.ip.address --ssl -H www.example.com -v
.....
HTTP OK: HTTP/1.1 200 OK - 9176 bytes in 0.074 second response time |time=0.073543s;;;0.000000 size=9176B;;;0
另請注意,有問題的 URL 在瀏覽器中運行良好,證書有效等。我還對許多其他站點使用了完全相同的服務定義,並且它們都運行良好。 我唯一能想到的就是這個遠程主機在 DigitalOcean 上運行,並為其分配了一個“浮動 IP”。 我嘗試用分配給主機的浮動 IP 或“標准”IP 替換上面的my.ip.address
(以及在 nagios 配置文件的主機定義中),這沒有區別。
nagios 運行相同的命令怎么可能會失敗,但手動運行時會成功?
我的問題的答案是:不要使用check_http
,使用
check_https_hostname
,和host_name
節是實際的主機名service
和host
定義中匹配host_name
節。所以:
define service{
use my-service ; Name of service template to use
host_name www.example.com
service_description https://www.example.com
check_command check_https_hostname
notifications_enabled 1
retry_check_interval 2
normal_check_interval 5
contact_groups myadmins
}
原因如下:通過查看我安裝中的/etc/nagios-plugins/config/http.cfg
文件中的check_http
和check_https_hostname
的定義,它變得清晰。
# 'check_http' command definition
define command{
command_name check_http
command_line /usr/lib/nagios/plugins/check_http -H '$HOSTADDRESS$' -I '$HOSTADDRESS$' '$ARG1$'
}
# 'check_https_hostname' command definition
define command{
command_name check_https_hostname
command_line /usr/lib/nagios/plugins/check_http --ssl -H '$HOSTNAME$' -I '$HOSTADDRESS$' '$ARG1$'
}
您會注意到check_http
中的-H
和-I
參數獲得相同的值$HOSTADDRESS$
,而在check_https_hostname
它們分別獲得$HOSTNAME$
和$HOSTADDRESS$
。
我將原始命令構建為check_http!-I my.ip.address --ssl -H www.example.com
事實並不重要。 最后, /usr/lib/nagios/plugins/check_http
命令為-I
獲得了兩個值,為-H
獲得了兩個值,第二對被忽略了。
這確實打破了 Cloudflare 的“感謝”,因為 Cloudflare 動態分配給我的 www.example.com 的 IP 地址與我在主機定義中指定的實際主機 IP 地址不同。
最后,我想提一下,幫助我解決這個問題的是設置
debug_level=-1
debug_verbosity=1
在我的/etc/nagios3/nagios.cfg
文件中,然后查看/var/log/nagios3/nagios.debug
。
此外,在/etc/nagios-plugins/config/http.cfg
中/etc/nagios-plugins/config/http.cfg
check_http
命令的所有不同變體。 有一些非常有用的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.