避免 Nagios commands.cfg

hen*_*dry 2 nagios

我想直接从 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
}
Run Code Online (Sandbox Code Playgroud)

但我得到一个:

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!
Run Code Online (Sandbox Code Playgroud)

BMD*_*Dan 5

如果你绝对坚持这样做,这是一个非常非常糟糕的主意,这个片段应该有效:

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
}
Run Code Online (Sandbox Code Playgroud)

不过,说真的,请不要。