Monitoring a specific website

edited October 2012 in General
So I have a couple of IIS servers that I want to monitor for website uptimes. I can't do a heartbeat to them for a couple of reasons so instead I'd like to check the IIS sites. I've looked at the embedded scripts and although the iis_list_stopped_w3svc_sites.vbs script does work, it checks for all sites on the server. Some of the sites are stopped for testing and I only have a few that I need to monitor. I've also grabbed the checkurl tool and tested that but it seems that knowing if the site is up or down would be better.

My VB scripting is rusty, so I went a slightly different way to create a new script. The rough draft of the batch file is
this ($site is a variable for whatever site I want to look at. Removed for privacy.)

------Begin Code--------
del c:\iis_log.txt
iisweb /query $site>IIS_log.txt

set string=STOPPED
type "IIS_log.txt" | find "%string%" > nul
if ErrorLevel 1 (
echo. FALSE
) else (
echo. TRUE
eventcreate /ID 400 /L APPLICATION /T ERROR /SO IIS_UPTIME /D "$site is stopped"
------End Code---------

What I'd like to know is if there might be a better way to monitor a specific website from the inside of the network?



  • Hello Todd,

    Sorry for the late response but I updated our script for this situation. You can launch it with a list of sites. For example:

    cscript iis_list_stopped_w3svc_sites.vbs "Default Web Site" "TestSite"
    Default Web Site: Started
    TestSite: Started


    ------Begin Code--------
    ' Lists the state of IIS web sites provided from the command line
    ' and returns an %ERRORLEVEL% of:
    ' 1 - if at least one web site is not in the "Started" state.
    ' 2 - if no sites are provided from the arguments
    ' 3 - if none of the provided sites exist on the system
    ' When scheduling this script with EventSentry's application scheduler,
    ' make sure that the interpreter is set to "cscript.exe"

    Option Explicit

    Dim strServer, strServerType, strServerMetaType, strArg
    Dim objService
    Dim returnCode
    Dim siteDictionary
    Dim counter
    Dim siteMatched

    If WScript.Arguments.Count < 1 Then
    WScript.StdOut.Write "Please enter a site name to get the status of."
    WScript.Quit 2
    End If

    Set siteDictionary = CreateObject("scripting.dictionary")

    For Each strArg in WScript.Arguments
    siteDictionary.Add strArg, 1

    returnCode = 0
    strServer = "localhost"
    strServerType = "Web"
    strServerMetaType = "W3SVC"
    siteMatched = False

    Sub EnumServersites( objService )
    Dim objServer

    For Each objServer In objService
    If objServer.Class = "IIs" & strServerType & "Server" Then
    If siteDictionary.Exists(objServer.ServerComment) Then
    siteMatched = True
    If SiteIsNotRunning(objServer.ServerState) Then
    WScript.StdOut.Write "*"
    End If

    WScript.StdOut.Write _
    objServer.ServerComment & ": " & State2Desc( objServer.ServerState )

    If SiteIsNotRunning(objServer.ServerState) Then
    WScript.StdOut.Write "*"
    returnCode = 1
    End If

    WScript.StdOut.Write vbCRLF
    End If
    End If
    If siteMatched = False Then
    WScript.StdOut.WriteLine "No sites matched"
    WScript.Quit 3
    End If
    End Sub

    Function SiteIsNotRunning( nState )

    If nState <> 2 Then
    SiteIsNotRunning = 1
    SiteIsNotRunning = 0
    End If

    End Function

    Function State2Desc( nState )

    Select Case nState
    Case 1
    State2Desc = "Starting"
    Case 2
    State2Desc = "Started"
    Case 3
    State2Desc = "Stopping"
    Case 4
    State2Desc = "Stopped"
    Case 5
    State2Desc = "Pausing"
    Case 6
    State2Desc = "Paused"
    Case 7
    State2Desc = "Continuing"
    Case Else
    State2Desc = "Unknown state"
    End Select

    End Function

    SET objService = GetObject( "IIS://" & strServer & "/" & strServerMetaType )
    EnumServersites objService

    If returnCode <> 0 Then
    WScript.Echo vbCRLF & "WARNING: One or more IIS sites are not running" & vbCRLF
    End If

    WScript.Quit returnCode

    ------End Code---------
  • Oh fantastic. I haven't had a chance to get back to this (more projects getting in the way) and this saves me some re-writing time. I'll give it a go. Thanks again.

  • Downloaded NTToolkit tried using Urlchecker to a secured site Https and I get this certificate error.
    The following problems have been determined for this cert [0x800b0109] A certification chain processed correctly but terminated in a root certificate not trusted by the trust provider
  • Let me make my self a little clearer even secure sites work even through it gives the exception but what i need it to do is log into the secure site then find some string and output to the evt log
  • Hi,

    Are you using the utility from the v2.0 installer, or the nightly build?

    I would recommend using the nightly build, some of the utilities have updates available in that zip file.
  • Using nightly build
    trying to login into URL like https://mysite:8443 pass uid and psw using checkurl /u /p which will bring up another page once authenticated like https://mysite:8443/ and check for string
    Not able to check 2nd page for string
  • Hi,

    I'm a little unsure as to what is working, and what is not. Can you tell us exactly which command you are running (of course you can obfuscate the URL) and the output you are seeing?

    Also, could you tell us which type of web server you are using?

  • Connecting to the Https URL and checking for a string works fine on the main page but the issue I'm facing is logging into the main page and checking on the next page if there is a string.

    Cmd being used
    Checkurl /u uid /p psw /t "string" /ie /evt "txt_found=information, txt_notfound=warning" https://URL:8434

    IIS webserver

    This is the MSG returned within cli.

    Server provided the following certificate:
    Issuer: C=Xx, S=xxxx, L=xxxx, O=xxxxxxx., OU=xxxx CN=xxxxxx
    Subject: C=xxx, S=xxxx, L=xxxxx., OU=xxxxx, CN=xxxxxxxxx
    The following problems have been determined for this certificate: [0x800b0101] A required cert
    ificate is not within its validity period.

    Even though the error above is returned if I'm checking for something on the main pg it still verifies and logs to evt log which is good I thought this tool would be able to into the URL provided and verify a string on the next page after logging into the main page
  • Sorry for the delay, thanks for the additional information.

    checkurl.exe will at this point not automatically redirect to a different site, even when the site requests it. checkurl.exe doesn't analyze the page and run javascript for example (I'm assuming that's how the client is being redirected).

    Can you just make two calls in sequence - first authenticate against the first page, and then request the 2nd page?
Sign In or Register to comment.