windows 如何使用 NSClient 批量检查远程主机上一个端口的状态?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5823261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a batch to check status of one port on remote host using NSClient?
提问by Ozl
I saw that you can use netcat to scan for open ports but how can i scan a port in a batch file to send it to Nagios using NSclient? for example i'm trying to check if port 7003 is open on a remote unix server from inside Windows Server, so the batch should check for the remote port on unix and send the feedback to Nagios so i can see it on the monitoring site. The result of the current port search is:
我看到您可以使用 netcat 来扫描开放端口,但是如何使用 NSclient 扫描批处理文件中的端口以将其发送到 Nagios?例如,我正在尝试从 Windows Server 内部检查远程 unix 服务器上的端口 7003 是否打开,因此批处理应检查 unix 上的远程端口并将反馈发送给 Nagios,以便我可以在监控站点上看到它。当前端口搜索的结果是:
nagios# /usr/local/libexec/nagios/check_nrpe2 -H 192.168.55.10 -c run_script -t 20
(UNKNOWN) [192.168.10.10] 7003 (?) open
This is what i have working now:
这就是我现在的工作:
@echo off
nc -v -n -z -w 3 192.168.10.10 7003
IF %ERRORLEVEL% EQU 0 goto bueno
:malo
echo TCServer Connectivity: Bad
exit /b 2
:bueno
echo TCServer: Connectivity Good
exit /b 0
:end
Thanks so much, i just had to understand the output of %errorlevel% with an echo %errorlevel%
xD since i was thinking i get a 0 or 1 just by default...
非常感谢,我只需要通过echo %errorlevel%
xD了解 %errorlevel% 的输出,因为我认为默认情况下我会得到 0 或 1...
回答by Ozl
This is what i have working now:
这就是我现在的工作:
@echo off
nc -v -n -z -w 3 192.168.10.10 7003
IF %ERRORLEVEL% EQU 0 goto bueno
:malo
echo TCServer Connectivity: Bad
exit /b 2
:bueno
echo TCServer: Connectivity Good
exit /b 0
:end
i just had to understand the output of %errorlevel% with an echo %errorlevel%
xD since i was thinking i get a 0 or 1 just by default
我只需要用echo %errorlevel%
xD来理解 %errorlevel% 的输出,因为我认为我在默认情况下会得到 0 或 1