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.

 
 
 
 
 
(8)
2,572 times
Add to favorites
Servers
7/16/2014
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 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.
      
      
  • SMTP Configure
    3 Posts | Last post November 03, 2010
    • How i have to configure the smtp password and user to send mail???
      
      Thx a lot
    • The full help for Send-MailMessage is found by using:
      
      get-help Send-MailMessage -full
      
      The full SYNTAX from that page is:
      SYNTAX
          Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] 
          [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc 
          <string[]>] [-Credential <PSCredential>] [-DeliveryNotificationOption {None | OnSuccess 
          | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [
          -UseSsl] [<CommonParameters>]
      
      You can see that this cmdlet uses the -credential parameter for supplying the username. If you use that parameter then it will prompt for the password, which would be a manual process for sending the mail, which is fine unless you run this using a scheduled task or by some other automation method.
      
      Most Enterprise Email Servers will have a Relay server setup that will accept unauthenticated relay of mail from certain host or IP Ranges. If none of these options cover your needs, you would have to use one of the many other tools that allow you to send emails and also possibly store the credentials.
    • Hi guys, 
      great script by the way for the author, my thanks for all your help. 
      Just to let you know I am using the smtpclient.send function to send the emails. here is how it looks:
       # First time down add to the list and send email
                       Write-Host "$_ Is not in the OutageHosts list, first time down"
                       $OutageHosts.Add($_,(get-date))
                       $Now = get-date
                       $Body = "$_ has not responded for 5 pings at $Now" 
                       $Subject = "Host $_ is down"
                       $SMTPClient.Send($notificationfrom, $notificationto, $Subject, $Body)
                       $SMTPClient.Send($notificationfrom, $notificationto2, $Subject, $Body)
      this is the way i do it to send to 2 address because i dont know of the other way to do it, I am still learning as well. any help would be greatful 
      but thanks once again, 
      Scott the visit my site at 
      http://scottalvarino.com
      http://techjunkie.tv
      
  • A script to monitor servers, Ping Test, with email notification
    2 Posts | Last post August 25, 2010
    • I am new to scripting thus I will like you explian how if any way to customize this script to fit my need. I am of the opinion that is where you mention host, do I put my server name there or is it safe to say that all I need do is copy the script as is to a folder on the server to be monitored and run the scritp with task shedule?. 
      
      In the email to and from notification could you explain it. Can I put my exchange email address in the email to and in the email from should that be the my exchange server name?.
      
      Further nmore, the time specified in the scritpt fro email notification resend is it seconds or minutes?.
      
      Thanks.
    • Since I designed this script to be run with a Scheduled task I made the decision not to use parameters, however I have since wanted to use this script many times by supplying parameters to monitor a chosen group of servers from the command line. Because of this I am going to updates this script to a PowerShell version 2.0 Script and include Full parameters and help.
      
      Now back to your question. . . . In order to provide the script with a list of server names you need to put the list of computers in the .txt file \\server\share\hosts.txt (as listed in the script).
      
      Since the script gets the contents of that file to use the items listed as the computers to monitor.
      
      You can of course simply change that path to any path that matches your needs. 
      E.g C:\Scripts\computers.txt or something similar.
      
      I hope that helps.
      
      Actually I have already updated this script so please check back in a day or so and I will upload the new version.