0

We have an internal IIS server that hosts several websites that redirects to external hosted web applications. Occasionally people will do nutty things like restart servers, stop services, unplug cables, you name it it happens.... I want to verify that our internal IIS webserver is up and running every 15 minutes, and if not try to restart the service and send me an email.

I wrote this powershell script, but am not sure if this is the best way to accomplish this?

###################################################################
# Summary: Verify W3SVC service is running, send email if it's down
###################################################################
##############################
# Get service status
##############################
$serviceName = "W3SVC"
$serverName = hostname

$status = (Get-Service $serviceName).Status

if ($status -ne "Running"){
    sendMail "$serviceName" "$serverName"  #sendmail is a function (not shown)
    Restart-Service $ServiceName
}else{
        # Service is running, do nothing;
}

However Im not sure if W3SVC is the best service to check that IIS7 is up? Do I need to check WAS and IISADMIN as well? Is there one that will accomplish everything?

I also thought about checking the HTTP status code for these hosts, but even if the site is down and IIS is up, my return code comes back 200. This was more of a brain storming idea, are there better "best practices" to accomplish something like this?

$url = "http://intranet_site"
$xHTTP = new-object -com msxml2.xmlhttp;
$xHTTP.open("GET",$url,$false);
$xHTTP.send();
$xHTTP.status # returns the status code 
    if ($xHTTP.status -ne "200"){
        sendMail "$serviceName" "$serverName"
        Restart-Service $ServiceName
    }

This was more of a brain storming idea, are there better "best practices" to accomplish something like this? I want to verify that the site is up and the redirects are working.

1
  • 2
    It sounds like you're trying to write a network monitoring system. It might be more effective in the long run to install an off-the-shelf NMS package and configure it to suit your needs. Most of them are either open source or at least highly extensible so even if you have unusual requirements it usually isn't necessary to create one from scratch. Sep 25, 2012 at 23:04

1 Answer 1

1

If you want to check if a site is available, the best way is to request a page and check its content. Check $xHTTP.responseText or $xHTTP.responseXML in addition to the status code in your second script. You may want to run this check from another host, though, otherwise things like packet filters or connectivity issues might prevent access despite the website being available on the host itself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .