|
How to send email message when a ping fails using the PingInfoView tool
|
One of the common feature request for the PingInfoView tool is to send an email message when a ping fails.
although the PingInfoView tool doesn't have an option to send an email message, you can still do it by using the combination of
PowerShell script and the 'Execute the following command on failed ping' option.
First, you have to create a PowerShell script that accepts as parameters the information about the failed ping and then sends it as email message.
If you are not a programmer, don't worry, here's a ready-to-use script that will do this job:
$Username = "YourMailUser";
$Password = "YourMailPassword";
$SendTo = "sendto@yourdomain.com";
$MailServer = "mail.yourdomain.com";
$HostName = $args[0];
$IPAddress = $args[1];
$PingStatus = $args[2];
$FailedOn = $args[3];
$message = new-object Net.Mail.MailMessage;
$message.From = $Username;
$message.To.Add($SendTo);
$message.Subject = "Failed Ping On $HostName" ;
$message.Body = "Information about the failed ping: `r`nHost Name: $HostName`r`nIP Address: $IPAddress`r`nPing Status: $PingStatus`r`nPing Time: $FailedOn";
$smtp = new-object Net.Mail.SmtpClient($MailServer, "587");
$smtp.EnableSSL = $true;
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message);
Before you use this script, you still have to update the first 4 lines with your email information:
First Line - The user name on your SMTP server for sending the message.
Second Line - The password on your SMTP server for sending the message.
Third Line - The email that will receive the failed ping message.
Fourh Line - The address of your SMTP server for sending the message
After updating the email information, save the script to .ps1 file, for example: send_message_failed_ping.ps1
You can use Notepad or any other text editor.
Now you have to update PingInfoView to run the PowerShell script when a ping fails.
In PingInfoView, press F9 ('Advanced Options' window), select the 'Execute the following command on failed ping' option and then type the command
to run the PowerShell script:
Powershell.exe -executionpolicy remotesigned -File F:\Scripts\send_message_failed_ping.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%"
In the above command example, the script is saved on F:\Scripts\send_message_failed_ping.ps1, and obviously you have to put the correct script filename on your system.
Assuming that you did everyting correctly - when a ping fails on PingInfoView, you'll receive an email message that looks like this:
|
|