2

我的 powershell nagios 脚本有问题,该脚本安装在 MS Windows Server 2008 64 位上,带有 NRPE_NT 守护进程。

我已经声明了这样的命令:

command[check_files]=cmd /c echo C:\nrpe\libexec\check_file.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command - 

我已将 ExecutionPolicy 设置为不受限制

我已经重新启动 NRPE_NT 服务并在控制台上声明了命令,如下所示:

$USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c check_files -a $ARG1$

现在,为什么如果我在本地运行它,它工作得很好:

C:\>cmd /c echo C:\nrpe\libexec\_file.ps1 C:\nrpe; exit($lastexitcode)| powershell.exe -command -
No file/s present with this string

但是,如果我通过 check_nrpe 运行它,我会收到以下输出:

'-' 是用 -Command 参数指定的:不允许 -Command 的其他参数。

在调试模式下,在 NRPE.log 上我可以看到:

运行命令:cmd /c echo C:\nrpe\libexec\check_file.ps1 C:\nrpe; 退出($lastexitcode) | powershell.exe - 命令 - $

命令完成,返回码 0

为什么以这种方式,check_nrpe 在字符串末尾添加一个美元字符 ($),从而使整个控件脱轨?

提前致谢

4

1 回答 1

1

我不确定这是否会对您的情况有所帮助,但我只是在我的环境中发现了一些导致类似情况的东西。这是我的 NRPE 命令配置:

command[foo]=grep file '^pattern$'

一切都很好,直到我想在参数之后添加另一个参数'^pattern$'......那个新参数(在命令行的末尾)会$在末尾附加一个额外的参数。

似乎 NRPE 需要$转义,否则它认为它是一个变量引用并用它做奇怪的事情。我期望引用会使其不需要转义,但是 NRPE 的配置文件不遵循 shell 样式的引用规则。因此,将我的 NRPE 配置更改为此解决了我的问题:

command[foo]=grep file '^pattern$$'

$$请注意修订后的 NRPE 命令定义中的双精度。

于 2016-04-07T14:29:15.763 回答