版本情况
- Nagios Server 10.0.8.252
[root@network-minitor libexec]# ./check_nrpe -V NRPE Plugin for Nagios Version: 4.0.3
- Client 10.0.8.253
PS C:Program FilesNSClient++> . scp.exe --version NSClient++, Version: 0.5.2.35 2018-01-28, Platform: x64
Powershell脚本
C:Program FilesNSClient++scriptswebsite_check_maic.ps1
#Author Bionw@Jul.30.2020 # First we create the request. $HTTP_Request = [System.Net.WebRequest]::Create('http://10.96.4.187:19190/') try{ # We then get a response from the site. $time = (Measure-Command {$HTTP_Response = $HTTP_Request.GetResponse()}).TotalSeconds # We then get the HTTP code as an integer. $HTTP_Status = [int]$HTTP_Response.StatusCode } catch{ $HTTP_Status = 404 } $HTTP_Response.Close() If ($HTTP_Status -eq 200) { Write-Host "OK! Responding time is" $time 'ms' exit 0 #Returns OK STATUS } Else { Write-Host "CRITICAL:The Site may be down, please check!" exit 2 #Returns CRITICAL STATUS }
nsclient.ini配置
# If you want to fill this file with all available options run the following command: # nscp settings --generate --add-defaults --load-all # If you want to activate a module and bring in all its options use: # nscp settings --activate-module <MODULE NAME> --add-defaults # For details run: nscp settings --help ; in flight - TODO [/settings/default] ; Undocumented key password = 1 ; Undocumented key allowed hosts = 127.0.0.1,10.0.8.252,10.0.8.4 ; in flight - TODO [/settings/NRPE/server] ; Undocumented key verify mode = none ; Undocumented key insecure = true ; ENABLE SSL ENCRYPTION - This option controls if SSL should be enabled. use ssl = 0 ; COMMAND ARGUMENT PROCESSING - This option determines whether or not the we will allow clients to specify arguments to commands that are executed. allow arguments = 1 ; in flight - TODO [/modules] ; Undocumented key CheckExternalScripts = enabled ; Undocumented key CheckHelpers = disabled ; Undocumented key CheckNSCP = disabled ; Undocumented key CheckDisk = enabled ; Undocumented key WEBServer = enabled ; Undocumented key CheckSystem = disabled ; Undocumented key NSClientServer = enabled ; Undocumented key CheckEventLog = disabled ; Undocumented key NSCAClient = enabled ; Undocumented key NRPEServer = enabled ; Script wrappings - A list of templates for defining script commands. Enter any command line here and they will be expanded by scripts placed under the wrapped scripts section. %SCRIPT% will be replaced by the actual script an %ARGS% will be replaced by any given arguments. [/settings/external scripts/wrappings] ; Batch file - Command used for executing wrapped batch files bat = scripts\%SCRIPT% %ARGS% ; Visual basic script - Command line used for wrapped vbs scripts vbs = cscript.exe //T:30 //NoLogo scripts\lib\wrapper.vbs %SCRIPT% %ARGS% ; POWERSHELL WRAPPING - Command line used for executing wrapped ps1 (powershell) scripts ps1 = cmd /c echo If (-Not (Test-Path "scripts\%SCRIPT%") ) { Write-Host "UNKNOWN: Script `"%SCRIPT%`" not found."; exit(3) }; scripts\%SCRIPT% $ARGS$; exit($lastexitcode) | powershell.exe /noprofile -command - ; Command aliases - A list of aliases for already defined commands (with arguments). An alias is an internal command that has been predefined to provide a single command without arguments. Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop) [/settings/external scripts/alias] ; check_dummy_ps1 - To configure this create a section under: /settings/external scripts/alias/check_dummy_ps1 ; External scripts - A list of scripts available to run from the CheckExternalScripts module. Syntax is: `command=script arguments` [/settings/external scripts/scripts] ; Undocumented key check_dummy_ps1 = cmd /c echo scripts\check_dummy.ps1 $ARG1$ "$ARG2$"; exit($lastexitcode) | powershell.exe -command - ; Undocumented key check_MAIC_connection_ps1 = cmd /c echo scripts\website_check_maic.ps1 ; exit($lastexitcode) | powershell.exe -command - ; External script settings - General settings for the external scripts module (CheckExternalScripts). [/settings/external scripts] ; Allow arguments when executing external scripts - This option determines whether or not the we will allow clients to specify arguments to commands that are executed. allow arguments = true
check_nrpe运行测试
正常状态
[root@network-minitor libexec]# ./check_nrpe -2 -H 10.0.8.253 -c check_MAIC_connection_ps1 OK! Responding time is 2.5769203 ms
异常状态
[root@network-minitor libexec]# ./check_nrpe -2 -H 10.0.8.253 -c check_MAIC_connection_ps1 CHECK_NRPE STATE CRITICAL: Socket timeout after 10 seconds.
Nagios配置调整
nagios.cfg
# Definitions for monitoring a Windows machine cfg_file=/usr/local/nagios/etc/objects/MAIC_Connector_windows.cfg
MAIC_Connector_windows.cfg
define host{ use windows-server ; Inherit default values from a template host_name maic_con_winserver ; The name we're giving to this host alias Maic Communication Server ; A longer name associated with the host address 10.0.8.253 ; IP address of the host } define hostgroup{ hostgroup_name windows-servers ; The name of the hostgroup alias Windows Servers ; Long name of the group } define service{ use generic-service host_name maic_con_winserver service_description NSClient++ Version check_command check_nt!CLIENTVERSION -t 600 -s 1 } define service{ use generic-service host_name maic_con_winserver service_description MAIC_Webservice_check check_command check_nrpe!check_MAIC_connection_ps1 } define service{ use generic-service host_name maic_con_winserver service_description CPU Load check_command check_nt!CPULOAD!-l 5,80,90 -t 600 -s 1 } define service{ use generic-service host_name maic_con_winserver service_description C: Drive Space check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90 -t 600 -s 1 }
command.cfg
# Check_nrpe command definition define command { command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
REF: