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)
11,636 times
Add to favorites
Servers
7/16/2014
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Loop Timeout - Can it be set?
    1 Posts | Last post Tue 10:00 AM
    • Hi Ben,
      
      Thank you so much for the script. It has helped a lot.
      
      Question: 
      Can you change the timeout for the loop?
      I want the Loop to run for only 5 minutes.
      
      I created a Scheduled Task on my Server to Run every hour, to execute the script.
      
      
      Regards,
      Matthew (Cape Town)
      
      
      
  • Hello Benn
    1 Posts | Last post July 31, 2017
    • Hello Ben,
      
      Thank you so much for the script.
      
      Can we make it get even working servers count via email. If so could you please help me in updating the script.
      
      Thank you again for a wonderful script 
  • Default settings runtime
    3 Posts | Last post June 14, 2017
    • Hello Ben,
      
      THanks for this very useful script.
      I was wondering, given the default values SleepTimeout=45, MaxOutageCount=10 and EmailTimeOut=30
      
      Does this mean the running it as such, it would run/loop for 45*10 Seconds before stopping and then send an email out 30seconds after last 10th run/loop is done?
      
      My ideal schedule would be to run every 6hrs and then email only if theres an unavailable host during a loop and then continue with its next scheduled run. 
      So, would this work as such? thanks
      $OutageHosts = $Null
      # specify the time you want email notifications resent for hosts that are down
      $EmailTimeOut = 14400
      # specify the time you want to cycle through your host lists.
      $SleepTimeOut = 21600
      # specify the maximum hosts that can be down before the script is aborted
      $MaxOutageCount = 1
      
    • Hello again,
      
      I think i worded the question wrongly. I meant to ask what values would make this run for an hour and then just stop. Then run again when the scheduler starts it again and so on and so forth?
      Currently, it seems it just keeps running and pauses and runs again. I'd like it to stop completely and pickup again later.
      thanks.
    • Hello The SOlution that works for me is to set the values as such:
      # specify the time you want email notifications resent for hosts that are down
      $EmailTimeOut = 10
      # specify the time you want to cycle through your host lists.
      $SleepTimeOut = 10
      # specify the maximum hosts that can be down before the script is aborted
      $MaxOutageCount = 0
      
      Task Scheduler then runs every 6hrs to activate a batch script that initiates the powershell.
      
      Thanks Ben.
  • Hey Ben, this is fantastic! Thank you!
    4 Posts | Last post May 05, 2017
    • 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!
    • The settings are there, it already pings 4 time over two cycles before it sends an email
      
      # specify the time you want email notifications resent for hosts that are down 
      $EmailTimeOut = (60 * 24)
      
    • Thanks, Ben!
      
      So for example if I want it to send an email every three days and cycle through the host list once a day, I'd modify the parameters to:
      
      $EmailTimeOut = (60 * 24 * 3)
      # specify the time you want to cycle through your host lists.
      $SleepTimeOut = (60 * 24)
      
      Right?
    • The script is on a loop and it checks to send an email based on the $EmailTimeOut value, which is in seconds.
      
      So if you want to send an email every minute (60 seconds) $EmailTimeOut = 60
      If you want to send an email every hour $EmailTimeOut = (60 * 60)
      If you want to send an email every day $EmailTimeOut = (60 * 60 * 24)
      
      There is not much point in not doing a continuous loop, you may as well see the continuous update, then just decide when you want alerts sent if machines go down.
  • 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.
1 - 10 of 17 Items