Script to monitor when Package Server URL goes down
search cancel

Script to monitor when Package Server URL goes down

book

Article ID: 281888

calendar_today

Updated On:

Products

IT Management Suite Client Management Suite

Issue/Introduction

The Package Server website may go down for various reasons. Is there a script that can send Admin's an email when our Package Server URL's go down?

Resolution

The following script will check for the Package Share to be 'live' and return a "200".  If anything other than a 200 is returned it will send an email to Admin User.

NOTE: This can be ran as a "Run Script on Server" and automated that way.  Choose Powershell as the script type.  For best results, install the latest version of Powershell on the SMP.

NOTE: change the items in Bold to match your environment

DISCLAIMER: This script is provided "AS IS" by a third-party and not supported by Broadcom.  Use at your own discretion.

$urls = @('http://Server1.Example.com/Altiris/PS/Share',
               'http://Server2.Example.com/Altiris/PS/Share' )
$downUrls = @()
foreach ($url in $urls) {
    try {
        $response = Invoke-WebRequest -Uri $url -Method Head
        if ($response.StatusCode -ne 200) {
            # Website is down, add to list of down URLs
            $downUrls += $url + " "
        }
    } catch {
        # Website is down, add to list of down URLs
       $downUrls += $url + " "
    }
}
if ($downUrls -ne "") {
    # Send email with list of down URLs
    $emailFrom = "[email protected]"
    $emailTo = "[email protected]"
    $subject = "Package Server Website Down"
    $body = "The following websites are currently down:"+"`n"+($downUrls -join "`n")
    $smtpServer = "SMTPServer.Example.com"
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($emailFrom, $emailTo, $subject, $body)
}

Additional Information

Script published with permission and courtesy of Brian Whitacre @ ITS Partners