Help needed in reporting in script for website monitoring

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 7 months ago.

  • Author
    Posts
  • #5842

    by Sravan at 2013-04-24 03:45:22

    I m trying to prepare a script for website monitoring, which takes a list of URLs from a text file and displays the status in a HTML output, however one of the output items, "timeTaken" is displaying the result but it is including all the previous results, attached is the screenshot (Error.jpg).

    I tried several things couldn't fix it.. Can anyone help me how do i fix this, below is my code..

    ##############################################################################
    ## Test-Url
    ##############################################################################

    ## The URI to test
    $URLListFile = "D:\URLList.txt"
    $URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue
    $Result = @()

    Foreach($Uri in $URLList) {
    $time = @()
    $time += try{
    clear-variable -name time
    $request = $null
    $result += $null
    ## Request the URI, and measure how long the response took.
    $result += Measure-Command { $request = Invoke-WebRequest -Uri $uri }
    $result.TotalMilliseconds
    }
    catch
    {
    ## If the request generated an exception (i.e.: 500 server
    ## error or 404 not found), we can pull the status code from the
    ## Exception.Response property
    $request = $_.Exception.Response
    $time = -1
    }
    $result += [PSCustomObject] @{

    Time = Get-Date;
    Uri = $uri;
    StatusCode = [int] $request.StatusCode;
    StatusDescription = $request.StatusDescription;
    ResponseLength = $request.RawContentLength;
    TimeTaken = $time;
    }

    #$result
    }

    #Prepare email body in HTML format
    if($result -ne $null)
    {
    $EmailBody = "Ericsson Website Availability Report

    Website Availability Report

    "
    Foreach($Entry in $Result)
    {
    if($Entry.StatusCode -ne "200")
    {
    $EmailBody += "

    "
    }
    else
    {
    $EmailBody += ""
    }
    $EmailBody += "

    "
    }
    $EmailBody += "

    URL StatusCode StatusDescription ResponseLength TimeTaken
    $($Entry.uri) $($Entry.StatusCode) $($Entry.StatusDescription) $($Entry.ResponseLength) $($Entry.timetaken)

    "
    }

    $EmailBody | out-file C:\Scripts\Test.htm
    Invoke-Expression C]

    by Sravan at 2013-04-24 04:31:25

    I got this problem fixed, thanks anyway 🙂

    by happysysadm at 2013-04-24 06:01:41

    Hi, just out of curiosity, how did you solve this? By adding 'clear-variable -name time' maybe?

You must be logged in to reply to this topic.