我的Powershell nagios脚本有问题,该脚本安装在带有NRPE_NT守护程序的MS Windows Server 2008 64位上。
我已经声明了这样的命令:
command[check_files]=cmd /c echo C:\nrpe\libexec\check_file.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command -
我已将ExecutionPolicy设置为不受限制
我已经重新启动NRPE_NT Services并在控制台上声明了命令,如下所示:
$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的其他参数。
在Debug模式下,在NRPE.log上我可以看到:
Running command: cmd /c echo C:\nrpe\libexec\check_file.ps1 C:\nrpe; exit($lastexitcode) | powershell.exe -command - $
Command completed with return code 0
为什么以这种方式,check_nrpe在结尾字符串处添加美元字符($),使整个控件脱轨?
提前致谢
最佳答案
我不确定这是否会帮助您解决问题,但是我只是发现环境中的某些原因导致了类似情况。这是我的NRPE命令配置:
command[foo]=grep file '^pattern$'
一切都很好,直到我想在
'^pattern$'
参数之后添加另一个参数...新参数(在命令行末尾)将在末尾附加一个额外的$
。似乎NRPE需要转义
$
,否则它认为这是一个变量引用,并且对此做了奇怪的事情。我原以为引用会成功,所以不需要转义,但是NRPE的配置文件不遵循shell样式的引用规则。因此,将我的NRPE配置更改为此解决了我的问题:command[foo]=grep file '^pattern$$'
注意修订后的NRPE命令定义中的双
$$
。
关于powershell - check_nrpe将$放在检查字符串的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21732760/