讓我想要研究 在執行監控模組的時候 $HOSTADDRESS$ 這個 IP 到底是如何設定?
首先回到當我們進行 Nagios 監控的時候應該會看到以下設定
這邊以 /etc/nagios/objects/localhost.cfg 內的設定為範例
以 SSH 服務來說
define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
他會去呼叫 check_ssh 的指令
所以當我們去檢查 /etc/nagios/objects/commands.cfg 這個相關指令設定檔的時候
會看到
# 'check_ssh' command definition
define command{
command_name check_ssh
command_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$
}
這邊首先了解 $USER1$ 巨集的由來
這個可以參考, 也可以自己定義 /etc/nagios/resource.cfg
裡面有 $USER1$ 也就是 plugin 路徑的定義
# Sets $USER1$ to be the path to the plugins
$USER1$=/usr/lib/nagios/plugins
也就是說 上面的指令事實上是執行 (將 $USER!$的路徑帶進來)
/usr/lib/nagios/plugins/check_ssh $ARG1$ $HOSTADDRESS$
$ARG1$ 是如果在上面進行指令就有帶進引數就直接帶進來, 這個很好理解
但是 $HOSTADDRESS$ 這個巨集的值就沒有設定檔或是明講
所以我找了一下 Internet 上面的文章
有關於 Marco 的說明
http://nagios.sourceforge.net/docs/3_0/macros.html
Example 1: Host Address Macro
When you use host and service macros in command definitions, they refer to values for the host or service for which the command is being run. Let's try an example. Assuming we are using a host definition and a check_ping command defined like this:
define host{ host_name linuxbox address 192.168.1.2 check_command check_ping ... } define command{ command_name check_ping command_line /usr/local/nagios/libexec/check_ping -H $HOSTADDRESS$ -w 100.0,90% -c 200.0,60% }
the expanded/final command line to be executed for the host's check command would look like this:
/usr/local/nagios/libexec/check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60%
Pretty simple, right? The beauty in this is that you can use a single command definition to check an unlimited number of hosts. Each host can be checked with the same command definition because each host's address is automatically substituted in the command line before execution.
趕快把他記起來
以免自己忘記
^___^
沒有留言:
張貼留言