The result will be send one email and write one event.
For this task I have created this script:
=========================================
$pingCount = 3
#Server Nagios
$server = '10.10.10.10'
# La siguiente linea solo hay que ejecutarla la primera vez
# New-EventLog –LogName Application –Source “MyMonitoringSystem”
$pingStatus = Test-Connection $server -Count $pingCount -ErrorAction SilentlyContinue
$pingsLost = $pingCount - ($pingStatus).Count
if ($pingsLost -eq $pingCount)
{
#Write one event to eventviwer
Write-EventLog -LogName Application -Source "MyMonitoringSystem" -EntryType Error -EventId 001 -Message "El servidor Nagios no responde"
#Send one email to inform
$PSEmailServer = "10.10.10.99"
Send-MailMessage -From "MyServer@MyDom.com" -To "infrastructure@mycompany.es" -Subject " !!NAGIOS DOWN!!! ** Moritorizacion parada ** --ALERTA--" -Body "Se ha perdido el ping contra el servidor XXXXXXXX"
}
=========================================
I have been scheduler this task to execute each minute
To check the event:
Check at Windows 2012
by GoN | Published: February 27, 2018 | Last Updated: