【发布时间】:2014-02-05 12:00:28
【问题描述】:
我对 check_logfiles.exe 运行的包含 $prescript 参数的 *.cfg 文件的结果有疑问。 我的平台是 MS Windows Server 2008 R2 64 位。 如果有 *.err 文件,我必须检查目录。为了完成这项工作,我编写了这个 powershell 脚本:
$mypath="W:\nrpe\tmp\"
$logfile = $args
$logfile = Foreach-Object {$logfile -replace '\\', '_' -replace "__", "" -replace ":", ""}
$result = ls $args -Filter *.err|Measure-Object -Line | select -expand lines
echo "$result file/s present with .*err string"| out-file -filepath $mypath$logfile'.log' -append -encoding unicode
exit 0
我选择详细说明 $logfile 参数,因为我必须检查更多路径,并且我想使用相同的脚本。
这是cfg文件:
$scriptpath = 'C:\Windows\System32\WindowsPowerShell\v1.0';
$seekfilesdir = 'C:\nrpe\tmp';
$prescript = 'powershell.exe';
$prescriptparams = '-File C:\nrpe\libexec\check_err_file.ps1 \\\networkpath\FTP_Data\ExtraUE\Input';
$options = 'supersmartprescript';
$log='W:\nrpe\tmp\networkpath_FTP_Data_ExtraUE_Input';
@searches = (
{
tag => 'check_logfiles_test',
type => 'simple',
logfile => $log,
criticalpatterns => ['.*'],
criticalexceptions => ['0 file'],
options => 'count,noprotocol,noperfdata',
}
);
如果我运行 checklogfiles,$log 文件是空的:
C:\nrpe\libexec\check_logfiles -f C:\nrpe\cfg\check_logfiles_test.cfg
但如果我手动运行 powershell,它可以正常工作:
PS C:> C:\nrpe\libexec\check_err_file.ps1 \networkpath\FTP_Data\ExtraUE\Input
W 的内容:\nrpe\tmp\networkpath_FTP_Data_ExtraUE_Input:
1 个文件/s 存在 .*err 字符串
这是跟踪日志:
Fri Feb 7 16:55:08 2014: call (smart) prescript powershell.exe
Fri Feb 7 16:55:08 2014: found script in C:\Windows\System32\WindowsPowerShell\v1.0/powershell.exe
Fri Feb 7 16:55:08 2014: execute C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\nrpe\libexec\check_err_file.ps1 \\networkpath\FTP_Data\ExtraUE\Input
Fri Feb 7 16:57:50 2014: script said:
Fri Feb 7 16:57:50 2014: script powershell.exe exits with code 1
Fri Feb 7 16:57:50 2014: failed supersmart prescript. aborting...
在 Nagios 上,这个 istance 处于“CRITICAL : (Service Check Timed Out)”中
你知道可能是什么问题吗?
【问题讨论】:
-
如果你在日志文件中准确地调用它会发生什么:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\nrpe\libexec\check_err_file.ps1 \\networkpath\FTP_Data\ExtraUE\Input? -
进入警告状态,处方不正确。我已经试过了:(
标签: windows powershell nagios