A script to monitor servers, Ping Test, with email notification

The Script runs against a list of Servers and notifies the user if the servers are down.

 
 
 
 
 
4.3 Star
(16)
10,310 times
Add to favorites
Servers
7/16/2014
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Hey Ben, this is fantastic! Thank you!
    1 Posts | Last post 6:54 PM
    • I've got this working just fine now after tweaking a few antivirus settings (until then I was getting an 'unable to connect to the remote server' error.)
      
      It's almost perfect, but I'm wondering if you can advise how to tweak it to do the following:
      
      1) I only want to send the email after the ping cycle has completed three times and is still unsuccessful.  So for example, if I want the sleep period to be 24 hours (resulting in the script effectively running once a day), I only want it to send an email if it fails to ping for 3 continuous days.
      
      2) Is there an easy way to prevent it from sending an email every day until connectivity has been restored?  For our purposes, it's unnecessary to notify an individual more than once.
      
      I'd appreciate any ideas you have.  I have a little experience with other coding languages but PowerShell is still pretty foreign to me.
      
      Thanks again for this wonderful tool!
  • Not able to get ping status even if the system is up for some of the servers
    2 Posts | Last post April 05, 2017
    • Hi Ben, Thanks for a wonderful script. I have noticed even if my servers are up and able to do a lookup. script is not able to ping many of the computers in the list. I need your help in make the ping for some more pings and need a html output file so as to setup a status monitor which shows green is server up and red in server down.
      
      Thanks and regards,
       Sathish.K
      
      
    • by default ICMP is not enabled on servers due to the firewall.
      
      You may want to use Test-NetConnection or Test-WsMan instead, since they will respond by default.
      
      As far as the html report goes, one step at a time try to get a functional solution first with the responses.
  • Failed Host Back Online notification?
    2 Posts | Last post March 21, 2017
    • Hi Ben! GREAT script! thanks so much! I got it to work perfectly on my environment except one thing.
      
      I've tried few things but all I can get it to work is to email me every min once a host goes down. 
      
      Could you please help with the code to email me when a failed host is back up?
    • There is a parameter for that
      $EmailTimeOut = 30 
      
      Basically after this amount of time the host will be removed from the known hosts that are down, if the host is still down, then it will cause a new notification to be sent.
      
      So basically change that to 5 and you will get emailed every 5 minutes until the host is back online.
  • Same Computername issue
    4 Posts | Last post February 23, 2016
    • I get the same issue as several folks below. I've downloaded the file directly from the link (not copy/paste). Here's how I'm calling it:
      
      Import-Module Start-MonitorOnline.ps1
      Start-Monitor -ComputerName hostname.company.bz -NotifyAll
      
      Alternatively, tried your suggestion of running it like this:
      
      Import-Module Start-MonitorOnline.ps1
      'hostname.company.bz' | Start-Monitor -NotifyAll
      
      ERROR
      =========
      1/20/2016 10:24:03 AM
      Test-Connection : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argume
      nt that is not null or empty and then try the command again.
      At C:\PingMonitor\Start-Monitor.ps1:74 char:51
      +                   if(Test-Connection -ComputerName <<<<  $_ -Count 1 -ea silentlycontinue)
          + CategoryInfo          : InvalidData: (:) [Test-Connection], ParameterBindingValidationException
          + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestConnectionCommand
      
      Available count: 0
      Not available count: 0
      
      Sleeping 5 seconds
      
      
      Same error. The error stops being reported if you put multiple names in there - but it's still not really reading the hostnames.
      
      Import-Module Start-MonitorOnline.ps1
      'localhost,'hostname.company.bz' | Start-Monitor -NotifyAll
      
      This just repeatedly returns this dialogue without actually pinging anything:
      
      1/20/2016 10:28:13 AM
      Available count: 0
      Not available count: 0
      
      Sleeping 5 seconds
      1/20/2016 10:28:18 AM
      Available count: 0
      Not available count: 0
      
      Sleeping 5 seconds
      1/20/2016 10:28:23 AM
      Available count: 0
      Not available count: 0
      
      Sleeping 5 seconds
      1/20/2016 10:28:28 AM
      Available count: 0
      Not available count: 0
      
      Sleeping 5 seconds
      
      
      
      Any ideas?
    • This script does not have a -ComputerName parameter.
      
      If you take a look at the code it reads in the names of the computers in the following line of code:
      get-content \\server\share\hosts.txt
      
      So put your computers in that hosts file one computername on each new line.
      
      If you want the script that uses the computername, use the link in the notes to the newer script.
    • POsted under the wrong script - this was related to V3.
    • okay no worries, I think I saw your question over there.
  • Script getting stuck
    2 Posts | Last post August 15, 2015
    • I ran the script with 1 in network host and 2 out of network hosts to test. But the script is getting stuck on the below code:
      
      # First time down create the list and send email 
                      Write-Host "Adding $_ to OutageHosts." 
                      $OutageHosts = @{$_=(get-date)} 
                      $Now = Get-date
                      $Body = "$_ has not responded for 5 pings at $Now"  
                      Send-MailMessage -Body "$body" -to $notificationto -from $notificationfrom -Subject "Host $_ is down" -SmtpServer $smtpserv
    • did you test sending the mail message from your machine?
  • SMTP settings??
    2 Posts | Last post August 15, 2015
    • I'd like to use this script on a client server to monitor the VPN status, but how are the emails supposed to be sent??  They don't have a local server to relay off of so I'll need to add an outside mail server (gmail) and user/pass in somewhere.  Where does that info need configured.  This script looks pretty sleek but you seem to be leaving out a significant chunk of info about how to actually send the emails.
    • send-mailmessage does accept a credential.
      
      https://technet.microsoft.com/library/796227f5-c9ff-402d-8a04-cde9e0c180ee(v=wps.630).aspx
  • How would I schedule this
    2 Posts | Last post April 03, 2015
    • I added as a task but I couldn't get it to work. I have the powershell window open on one of my servers and that works. Whats the best way sql agent job run in intervals. I'm new to this Thanks 
    • I'll have to play around with the SQL agent, what version of SQL are you running?
      
      I normally schedule it with a standard scheduled task.
  • Linux Hosts
    2 Posts | Last post March 11, 2015
    • How could this be tweaked to test both Windows and Linux servers?
    • This just uses ICMP to make the connection with test connection. So as long as a machine will respond to ICMP this should work fine.
      
      You could also consider Test-WSMAN, however that uses a WSMAN query so you have to have wsman running in order to get the response from that. That is available on Linux if you install and configure OMI.
  • great...
    1 Posts | Last post October 19, 2014
  • Problem with New script, MaxOutageCount Hosts down ?
    2 Posts | Last post July 16, 2014
    • HI Ben,
      
      Being new to Power shell scripting,i believe second mail will trigger with all unavailable host file from $MaxOutageCount with all details, is it getting done for any one ? and any way to add CC list ? m using   
      
                          $ol = New-Object -comObject Outlook.Application 
                          $mail = $ol.CreateItem(0) 
                          $Mail.Recipients.Add($notificationto) 
                          $Mail.Subject = "More than ($MaxOutageCount Hosts down,monitoring aborted" 
                          $Mail.Body = $Body 
                          $Mail.Send()
    • I updated the newer script to add this functionality for you:
      
      Now you can choose by using a switch for when you get notifications for:
      1) when a server goes down
      2) when a server comes back online
      3) when the max threshold was hit for the script to stop sending emails.
      
      http://gallery.technet.microsoft.com/scriptcenter/d0670079-6158-4dc5-a9da-b261c70e4b7d/
1 - 10 of 14 Items