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


  • Failed Host Back Online notification?
    2 Posts | Last post Tue 11:42 PM
    • 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/
  • Email when server is back up
    2 Posts | Last post July 16, 2014
    • Hi Ben- thanks for the script- it works very nicely!
      
      I was wondering if you could help with the code to email when a failed server is back online? Or point me in the right direction to try and amend the script myself?
      
      Many thanks
      Bevan
    • I updated the newer script to add this functionality for you:
      
      http://gallery.technet.microsoft.com/scriptcenter/d0670079-6158-4dc5-a9da-b261c70e4b7d/
  • Error
    5 Posts | Last post July 19, 2012
    • I am new to powershell. I get the following error during execution of the script.Can one of you guide me
      
      PS D:\scripts\Alert> .\alive.ps1
      Missing expression after unary operator '-'.
      At D:\scripts\Alert\alive.ps1:56 char:20
      +                   -S <<<< ubject "Host $_ is down" -SmtpServer $smtpserver
      
    • Problem was with the old version of powershell. Installed powershell ver 2.0 it works fine.
      Only one error now:
      Test-Connection : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the comman
      d again.
      At C:\scripts\Alert\alive.ps1:27 char:33
        if(Test-Connection -ComputerName <<<<  $_ -Count 1 -ea silentlycontinue) 
            CategoryInfo          : InvalidData: (:) [Test-Connection], ParameterBindingValidationException
            FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestConnectionCommand
       
      
      
      
    • One more issue in the mail I don't get the downtime.
      
       $OutageHosts.Add($_,(Get-date)) 
                       $Now = Get-date 
                       $Body = "$_ has not responded for 5 pings at $Now" 
      
      There is some problem with the script here..
    • Hi,
      1) I had the same error, it was due to the copy and paste of the code. There is a '`' character in the line
      Send-MailMessage -Body "$body" -to $notificationto -from $notificationfrom ` 
                        -Subject "Host $_ is down" -SmtpServer $smtpserver 
      If you remove it and write the two lines as one the error is gone.
      2) Add $Now = Get-date in front of the second $Body = ... statement, the variable is assigned in the if block but was forgotten in the Else block.
      Hope this helps...
    • Hi _muris_ & bharathnazareth
      
      Thanks for your question and reponse. Hopefully that will help.
      
      
1 - 10 of 12 Items