避免Nagios commands.cfg

我想直接从Nagios服务文件中调用一个命令,而不是将参数笨拙地传递给commands.cfg。 比如我想要这样做:

define service { service_description footest check_command $USER1$/check_http example.com -u http://example.com/index.html use generic-service host_name example } 

但是我得到一个:

 Error: Service check command '/usr/share/nagios/libexec/check_http example.com -u http://example.com/index.html' specified in service 'footest' for host 'example' not defined anywhere! 

如果你坚持这样做,这是一个非常可怕的想法,这个片段应该工作:

 define command { command_name check_by_arbitrary_path check_command /bin/sh -c "$ARG1$" } define service { use remote-service host_name example service_description This is a bad idea, seriously check_command check_by_arbitrary_path!$USER1$/check_http example.com -u http://example.com/index.html } 

说真的,请不要。

我已经在commands.cfg中用check_any命令定义成功了

 define command { command_name check_any command_line $USER1$/check_$ARG1$ } 

我使用的定义如下所示:

 define service { service_description Forest is not on fire check_command check_any!forest --on-fire=false use generic-service host_name example } 

你需要把它分成两部分,第一个是check_command,第二个是检查本身。

创build模板来检查URL:

 define command { command_name check_http_url command_line $USER1$/check_http -I'$HOSTADDRESS$' -u '$ARG1$' } 

使用该模板来检查特定的URL(在这种情况下www.example.com):

 define service { host_name example service_description Check www.example.com URL check_command check_http_url!www.example.com use generic-service } 

Nagios的最佳做法是把你的支票分成一个命令并检查,check_command被定义为一个类似的命令

 define command { command_name footest command_line $USER1$/footest -a some-fixed-option -b $ARG1$ -c $ARG2$ } 

之前它应该用于服务检查。