Skip to main content

 

URLMonitor 1.3

14 months ago
OfflineBrittany Ross
Brittany Ross
Description:

[Originally posted by Robert Strandberg]

Main function:
For use with Whatsup Gold to monitor web sites.
The script can be used in four diffrent ways
#1-As an Active monitor controling a webpage or a web service
#2-As an Performance Monitor reporting responsetime of a webpage or a web service
#3-As an Performance Monitor extracting values from a webpage or a web service
#4-As an Active script action

The differens between a webpage and web service (SOAP) are the "content-type" when making a HTTP POST.

The script have a log file function that can be used to logg entrys to specific file.
If the folders (PATH) to the log file does not exist the script creates it.
If you have same name on a scripts running as Active Monitor and Performance monitor
on the same object they will use the same log file.

It is possible to make several HTTP GET and POST to simulate a user that
runs a webapplication.
Note that it have to be a "true" web application in that sense that it have to be
pure HTTP, no support for webpages that requires JavaScript,VBscript,Java applets,
Active X,Flash or any other plug-in.
The script uses WinHTTP 5.1

Version history
V1.0 First public release
V1.1 Added SOAP11 and SOAP12 as URLMethods to be able to make POST to webservices.
You can use the same MonitorURL parameters as in V1.0 but you have to replace the script.
V1.2
-Change the timeout to calculated connectiontime.
V1.3 New feature
-Added support to configure WinHttp 5.1 timeouts in the script or calculate connectiontime, Now there are two diffrent timeout modes.
-Added support to use a status file so that the script can run outside whatsup and not be affected of whatsup timeout of max 60 seconds on active script.The status file can only be used on active monitors.
This also includes possibility to logg status to windows eventlog (works only in windows prompt mode).
-Addes exitcode in windows prompt mode.0 = OK, 1 = Fail.
-Moved scriptname config to global parameter for windows prompt
-Updated the LogToFile() function

You can use the same MonitorURL parameters (function call) as in V1.0 and 1.1 but you have to replace the script.

Language: VB Script/JScript
Code:
'------------------------------ Function of Script
'URLMonitor script
'Note:This script is provided "as is" with no warranty or support.
'As with many other public script this script is a combination of other scripts out there.
'With reservation for spelling and grammar.
'Version V1.3 2010-02-03/Robert Strandberg Sundsvall Sweden
'
'Main function:
'For use with Whatsup Gold to monitor web sites.
'The script can be used in four diffrent ways
'#1-As an Active monitor controling a webpage or a web service
'#2-As an Performance Monitor reporting responsetime of a webpage or a web service
'#3-As an Performance Monitor extracting values from a webpage or a web service
'#4-As an Active script action
'
'The differens between a webpage and web service (SOAP) are the "content-type" when making a HTTP POST.
'
'The script have a log file function that can be used to logg entrys to specific file.
'If the folders (PATH) to the log file does not exist the script creates it.
'If you have same name on a scripts running as Active Monitor and Performance monitor
'on the same object they will use the same log file.
'
'It is possible to make several HTTP GET and POST to simulate a user that
'runs a webapplication.
'Note that it have to be a "true" web application in that sense that it have to be
'pure HTTP, no support for webpages that requires JavaScript,VBscript,Java applets,
'Active X,Flash or any other plug-in.
'The script uses WinHTTP 5.1
'For more info on WinHTTP 5.1 see
'http://msdn.microsoft.com/en-us/library/aa382925(VS.85).aspx
'
'**** Fundamental understanding when configure the script *****
'Its important to understand the difference between the WinHTTP 5.1 (this script) and a web-browser.
'WinHTTP 5.1 only request the configured URL from the web-server and takes no more action.
'This script makes a very simple analyze of the received content.
'All modern web-pages today consist of several files.
'A web-browser analyze the web-pages and fetch all URL:s (files) that builds the "web-page".
'You can (in theory) build a web browser with WinHTTP 5.1 but this script is not a browser.
'
'Below is a short summary of WinHTTP 5.1
'************ Start Microsoft text
'WinHTTP 5.1 Features
'
'The following features have been added in version 5.1 of WinHTTP:
'
'IPv6 support.
'AutoProxy capabilities.
'HTTP/1.0 protocol, including support for keep-alive (persistent) connections and session cookies.
'HTTP/1.1 chunked transfer support for HTTP responses.
'Keep-alive pooling of anonymous connections across sessions.
'Secure Sockets Layer (SSL) functionality, including client certificates. Supported SSL protocols include the following:
'SSL 2.0, SSL 3.0, and Transport Layer Security (TLS) 1.0.
'Support for server and proxy authentication, including integrated support for Microsoft Passport 1.4 and the
'Negotiate/ Kerberos package.
'Automatic handling of redirects unless suppressed.
'Scriptable interface in addition to the API.
'Trace utility to help troubleshoot problems.
'A number of WinINet features are not supported in WinHTTP, including URL caching and persistent cookies, autoproxy,
'autodialing, offline support, File Transfer Protocol (FTP), and the Gopher protocol.
'************ End Microsoft text
'
'Script function in detail:
'#1-Active Monitor
'A URL is monitored if it responds with a configurable textstring.
'When a URL is monitored its configurable if the HTTP method should be GET or POST,
' when POST the posted data is also added.
'The script supports HTTP login.
'Its also possible to extract a dynamic textstring from the reveived webpage, this text
' string can be used as a a dynamic part of the next URL to be monitored (or as a
'variable in performance monitor).
'If the dynamic textstring couldt be found the script reports the URLMonitor to have
'failed the same way as if the received webpage dosent have the expected textstring.
'This means that with the textstring extraction the script actually makes three
'textstring controls of ths received webpage,the first is the actual control, the
'two following are the text before and after the dynamic textstring.
'All search of text in the received webpage is done from the beginning of the page.
'To simplify the URLs in the script and to handle diffrent charactersets the received
' webpage are "cleaned".
'The cleaning process makes the following changes of the received webpagestring:
'-NewLine,Carrige Return,Quotation,Horizontal and Vertical TAB are removed.
'-Characters with ASCII 128 to 255 are replaced with character "x".
'
'#2-Performance Monitor responsetime
'When used in performance monitor the same controls as when the script are used as a
'#1-active monitor are done plus that the script reports the resonsetime in
'milliseconds (1000 = 1 Second) of receiving the webpage.
'If the URLMonitor fails then the script reports to whatsup that the value
'reported is invalid.
'Its possible to use the same script as in active monitor, just change the global
'parameter "sintTypOfMonitor" from "sintTypOfMonitor=0" to "sintTypOfMonitor=1".
'
'#3-Performance Monitor extract value
'The script makes the same control as in #2 but instead of reporting the responstime
'it converts the extracted textstring to a value and reports it to whatsup.
'If the extracted textstring is not numeric then the script reports the value
'invalid as if the URLMonitor fails.
'When handeling values its possible to change the value separators like
'100.000 , 100,000 or 100 000.
'
'#4-Action
'Run the script as an active monitor, see #1 for details.
'
'Statement:
'I have tried to keep the code to VBScript Coding Conventions
' http://msdn.microsoft.com/en-us/library/ektke1b0(VS.85).aspx
'Since it is a script I have made extensive use of global variables to simplify
'configuration and reduce processor time.
'
'Global variabels
'The script makes extensive use of global parameter in a effort to simplify the
'configuration of the script.
'The variabel "sstrFromHost" contains the extracted textstring from the received
'webpage, sstrFromHost holds the latest URLMonitor that have extracted a
'textstring (with strPreStringsstrFromHost and strPostStringsstrFromHost configured).
'To speed up the "character" cleaing process of the monitored URL the
'sintMaxPageLengthKB variable is set, if a received webpage are longer then the
'script only control the received webpage up to the sintMaxPageLengthKB value.
'The script receives all the webpage but only clean and controll the page up
'to sintMaxPageLengthKB.
'The parameters strTextToFind,strPreStringsstrFromHost and strPostStringsstrFromHost
'in the MonitorURL function call MUST be within the sintMaxPageLengthKB range
'
'Use the Context.GetProperty("Address") if you have a monitor that can be used on
'several objects.
'Note that the Context.GetProperty("Address") only works in Whatsup mode.
'
'Global parameters
'sintScriptMode = Controls how the script report, to windows commandprompt or to whatsup
'sintScriptMode = 0 = Whatsup
'sintScriptMode <> 0 = Windows commandprompt
'
'sintTypOfMonitor = Controls if the script should run as Active Monitor or Performance Monitor
'sintTypOfMonitor = 0 = Active Monitor
'sintTypOfMonitor = 1 = Performance Monitor responsetime
'sintTypOfMonitor = 2 = Performance Monitor extract value
'
'When used to extract value from webpage set number handeling
'Example 100000 kan be express as 100.000 or 100 000 or 100.000
'For example
'strNumberSeparatorToReplace = ","
'strNewNumberSeparator = ""
'
'Two different timeouts modes
'In whatsup there a limitation that a script only can have a timeout at 60 seconds.
'1-Standard as URLMonitor 1.0 and 1.1
'2-Calculated connetion time
'
'Statusfile
'URLMonitor can run as a standalone script and update a status file that whatsup can read.(started in windows schedule)
'The script will bee run in windows prompt mode.(sintScriptMode = 1)
'This means that the script can run longer than 60 seconds.
'The script updates a status file that Whatsup reads and triggers alarms.
'You can use any type of timeout mode.
'Logg script reasult to windows eventlog (only in windows prompt mode)
'
'Details of the diffrent timeouts modes
'-Standard
'In this mode Whatsup will close the script if its longer then the script timeout.
'When Whatsup terminates the script then no entry in the URLMonitor log file will be made.
'This mode is the simpliest and is the standard setting.
'
'-Calculated connection time
'In this mode the script calculates the remaining script time and calculates (and sets) the connection time.
'The script will terminate and log to the log file before whatsup terminates the script.
'You have to configure serveral timeout values and sometimes finetune the settings.
'
'This gives the script a possibility to report resault to whatsup and end in a normal way.
'When whatsup terminates the script you never really know if it whas the script that failed or the monitored URL:s.
'Note that ALL timeouts are in milliseconds
'A value of 0 sets a time-out to wait infinitely. A value greater than 0
'sets the time-out value in milliseconds. For example, 30,000 would set the time-out to 30 seconds.
'
'slngResolveTimeout = Timeout set for every MonitorURL() function call
'Time-out value applied when resolving a host name (such as www.microsoft.com) to an IP address (such as 192.168.131.199), in milliseconds. The default value is zero, meaning no time-out (infinite). If DNS timeout is specified using NAME_RESOLUTION_TIMEOUT, there is an overhead of one thread per request.
'This value can normaly be fixed
'
'slngConnectTimeout = Timeout set for every MonitorURL() function call
'Time-out value applied when establishing a communication socket with the target server.
'This value is calculated as slngConnectTimeout = sScriptTimeOut - (slngSendTimeout + slngResolveTimeout + (slngReceiveTimeout * sintNumberOfReceivedpackets) + ScriptRunTime)
'This mean that the total time of every MonitorURL call never should exceed the sScriptTimeOut.
'
'slngSendTimeout = Timeout set for every MonitorURL() function call
'Time-out value applied when sending an individual packet of request data on the communication socket to the target server. A large request sent to an HTTP server are normally be broken up into multiple packets; the send time-out applies to sending each packet individually.
'This value can normaly be fixed
'
'slngReceiveTimeout = Timeout for every received packet
'Time-out value applied when receiving a packet of response data from the target server. Large responses are be broken up into multiple packets; the receive time-out applies to fetching each packet of data off the socket.
'This value can normaly be fixed, however it will be multiplyed with sintNumberOfReceivedpackets when timeout is calculated.
'50 packets and 100 milliseconds receivetimeout givew a total timeout calculation of 5000 milliseconds
'
'sintNumberOfReceivedpackets = The number of received packets in the longest MonitorURL being monitored.
'The MonitorURL only receives one URL, so even if our web aplication consist of several pages the MonitorURL only fetch the one
'you configured.
'This means that if you take the size of the largest URL that you monitor within a script and divide it with 1400 you get
'an estimate of the number of packets the URL will consist of.
'A URL of 28.000 bytes will need 28.000/1400=20 pakets to receive.
'
'sScriptTimeOut = timeout for the total of the script, should be lower than the active script timeout in whatsup.
'
'Character compability
'To handle different character sets only ASCII 1 to 127 is used in string.
'Ascii > 127 numbers are change to "x"
'
'Tips on how to configure the script using simple tools
'
'******** Working in Windows commandprompt
'
'Tool #1-FireFox with plug-in "Live HTTP Headers"
'This shows the HTTP GET and POST including POST-data (on HTTP and HTTPS).
'From this information you find the following:
'-Which URL to check
'-Which GET or POST method and POST data.
'-When to use HTTP login
'A more advanced tool is "FireBug"
'
'Tool #2-Microsoft script editor
'This tool have three main advantage compared to notepad.
'-It shows code,command and comments in different colors.
'-It have row,column and characther counter
'-It is aware of the MonitorURL functions parameters.
'The Microsoft script editor comes with office11/Office 2003
'You can start it from any office program, for example Excel choose Tools->Macro or you can start it direct
'with the command "PATH_TO_OFFICE11"\mse7.exe.
'
'Example on workflow to configure a script
'To start the script in windowsprompt type "cscript URLMonitor_1_0.vbs"
'
'#1 Configure the script for windowsprompt with parameter "sintScriptMode=1" in the script editor and the parameter "sintTypOfMonitor" to
'0,1 or 2 depending on your need.
'#2 Use Firefox and LiveHTTP headers to find the URL and HTTP parameters.
'#3 Configure the script in the script editor.
'#4 Start the script in a commandprompt
'#5 Find the text to monitor and if extraction of textstring find the surrounding static text.
'An alternativ to #3-#5 is to use view source in IE (not Firefox for this,I have experience problems with HTTPS) to find the text,
'remember that the script "cleans" the webpage.
'#6 Configure the script with the parameters.
'#7 Start the script again in a commandprompt, if it succeeds you have finished with the first URLMonitor.
'#8 Add a new MonitorURL line in the script and repeat step #2 to #7 until you have simulated a user.
'#9 Copy the script to whatsup and change the parameter "sintScriptMode=0".
'#10 Configuiration finished.
'
'Use the Whatsup eventviewer in debug mode (right mouse click) to see the log message.
'
'Configuration example
'Please note that the www.whatsupgold.com websites is used in the examples so that you can test that the script works,
'however use your own sites when you start making changes.
'This script examples below worked against the URL when this script was released.
'
'Check page and extract value
'sintTypOfMonitor = 0 or 1  
'MonitorURL "http://www.whatsupgold.com","<title>Network Management with Network Monitoring | Know Your Network with WhatsUp Gold</title>" ,"GET","","","","","",0
'
'Version history
'V1.0 First public release
'V1.1 Added SOAP11 and SOAP12 as URLMethods to be able to make POST to webservices.
'You can use the same MonitorURL parameters as in V1.0 but you have to replace the script.
'V1.2
'-Change the timeout to calculated connectiontime.
'V1.3 New feature
'-Added support to configure WinHttp 5.1 timeouts in the script or calculate connectiontime, Now there are two diffrent timeout modes.
'-Added support to use a status file so that the script can run outside whatsup and not be affected of whatsup timeout of max 60
'seconds on active script.The status file can only be used on active monitors.
'This also includes possibility to logg status to windows eventlog (works only in windows prompt mode).
'-Addes exitcode in windows prompt mode.0 = OK, 1 = Fail.
'-Moved scriptname config to global parameter for windows prompt
'-Updated the LogToFile() function
'
'You can use the same MonitorURL parameters (function call) as in V1.0 and 1.1 but you have to replace the script.
'
'------------------------------- Init of script
Option Explicit
Public sobjWinHttp51 'WinHTTP 5.1 object
Public sintMonitorResault 'Overall URL resault
Public sintFirstErrorFlag 'Used to detect and log only the first error
Public sintTimeOutFlag 'Used to detect Timeout
Public sstrFromHost 'Extracted textstring from URL
Public sintMaxPageLengthKB 'Max length of received page in Kbyte
Dim tmResponseTimeURL
Dim tmStartTimeURLCheck
Public sintScriptMode 'Whatsup or Windows mode
Public sintTypOfMonitor 'Active or performance monitor
Dim strNumberSeparatorToReplace
Dim strNewNumberSeparator
Public sstrScriptName
Public sintLogMode
Public sintLogFileSizeKB
Public sstrLogFilePath
Public sintStatusFileMode
Public sstrStatusFilePath
Public sstrLogTextToFile
Public sintTimeoutMode
Public slngResolveTimeout
Public slngConnectTimeout
Public slngSendTimeout
Public slngReceiveTimeout
Public sScriptTimeOut
Public sintNumberOfReceivedpackets
Public sVersion
sVersion = "ver 1.3"
'URL Check correct
sintMonitorResault = 0
sintFirstErrorFlag = 0
sintTimeOutFlag = 0
sstrFromHost = ""
sstrLogTextToFile =""
'Create objects
Set sobjWinHttp51 = CreateObject("WinHttp.WinHttpRequest.5.1")

'Start timer
tmStartTimeURLCheck =Timer()
'//////////////////////// G l o b a l - C o n f i g u r a t i o n
'sstrScriptName string below are only used in windows prompt mode.
'In whatsup mode the sstrScriptName will be calculated from monitorname and object IP configured in whatsup.
sstrScriptName = "URL Monitor 1.3 example"
'sintScriptMode = 0 = Whatsup
'sintScriptMode <> 0 = Windows commandprompt
sintScriptMode = 1
'sintTypOfMonitor = 0 = Active Monitor
'sintTypOfMonitor = 1 = Performance Monitor responsetime
'sintTypOfMonitor = 2 = Performance Monitor extract value
sintTypOfMonitor = 1
'When used to extract value from webpage set number handeling
'Example 100000 kan be express as 100.000 or 100 000 or 100.000
strNumberSeparatorToReplace = ","
strNewNumberSeparator = ""
'sintLogMode sets the logging mode
'sintLogMode = 0 = No logging to file (Normal Setting)
'sintLogMode = 1 = Logging overall failures to log file
'sintLogMode = 2 = Logging everything to log file
sintLogMode = 1
'Logfile path where the script stores logfiles when sintLogMode <> 0
'The logfile will have the name "sstrScriptName" + "HostName" in whatsup, when testing in windows pormpt it will be sstrScriptName string below
'The script create the log folders
sstrLogFilePath ="C:\URLMonitor\Log"
'sintLogFileSizeKB max size of logfile, if logfile reach that size loggning to file stops until
'logfile are renamed,moved or deleted
sintLogFileSizeKB = 1000
'sintMaxPageLengthKB max length of the received webpage in every MonitorURL function call.
'The script will receive all the webpage but to speed up the cleaning process a max size is recommended.
'This max size is for every separate MonitorURL function call, If you make 10 calls of MonitorURL simulating a user
'the script will only check every webpage to sintMaxPageLengthKB.
'The strTextToFind and variable sstrFromHost must be within the sintMaxPageLengthKB range
sintMaxPageLengthKB = 10
'sintStatusFileMode = 0 = No status file in use
'sintStatusFileMode = 1 = Status file in sstrStatusFilePath.
'The statusfile will have the name "Status-" + "sstrScriptName" + "HostName".txt in whatsup, when testing in windows pormpt it will be sstrScriptName.
'The script create the status folders
'The text in the status file will be OK or ERROR.
'In you can use whatsup File monitor monitor that the sice of the file is less then 5 byte.
'use this settning when you run the script outside whatsup.
'sintStatusFileMode = 2 = Same as "1" but now an entry in the event log will be created.(works only in windows prompt mode, not in whatsup)
'The event entry will have the name "Failure:" or "Success:" + "sstrScriptName" + "HostName".txt in whatsup, when testing in windows pormpt it will be sstrScriptName string below
sintStatusFileMode = 0
'sstrStatusFilePath only valid when sintStatusFileMode <> 0
sstrStatusFilePath = "C:\URLMonitor\Status"
'sintTimeoutMode = 0 = standard, the script uses the values below.
'sintTimeoutMode <> 0 = Calculated connectiontime, the script calculates the connectiontime and timeout values below have to be
'configured
sintTimeoutMode = 0
'slngResolveTimeout = Timeout set for every MonitorURL() function call
'A value of 0 sets a time-out to wait infinitely.
'URLMonitor default value 59000 milliseconds
'In sintTimeoutMode <> 0 use 5000 as start value
slngResolveTimeout = 59000
'slngSendTimeout = Timeout set for every MonitorURL() function call
'Only one packet is sent on every MonitorURL() call
'A value of 0 sets a time-out to wait infinitely.
'URLMonitor default value 59000 milliseconds
'In sintTimeoutMode <> 0 use 2500 as start value
slngSendTimeout = 59000
'slngConnectTimeout = Timeout set for every MonitorURL() function call
'Only one packet is sent on every MonitorURL() call
'A value of 0 sets a time-out to wait infinitely.
'URLMonitor default value 59000 milliseconds
'In sintTimeoutMode <> 0 this values is calculated by the script.
slngConnectTimeout = 59000
'slngReceiveTimeout = Timeout for every received packet
'Time-out value applied when receiving a packet of response data from the target server. Large responses are be broken up into multiple packets; the receive time-out applies to fetching each packet of data off the socket.
'URLMonitor default value 59000 milliseconds
'In sintTimeoutMode <> 0 this values is calculated together with sintNumberOfReceivedpackets as the total receivetimeout.
'50 packets and 100 milliseconds receivetimeout givew a total timeout calculation of 5000 milliseconds
'A value of 0 sets a time-out to wait infinitely.
slngReceiveTimeout = 59000
'sintNumberOfReceivedpackets are only valid when In sintTimeoutMode <> 0
'This means that if you take the size of the largest URL that you monitor within a script and divide it with 1400 you get
'an estimate of the number of packets the URL will consist of.
'A URL of 28.000 bytes will need 28.000/1400=20 pakets to receive.
sintNumberOfReceivedpackets = 10
'sScriptTimeOut are only valid when In sintTimeoutMode <> 0
'sScriptTimeOut = timeout for the total of the script, should be equal to active script timeout in whatsup.
sScriptTimeOut = 59000
'//////////////////////// E n d - o f - G l o b a l - C o n f i g u r a t i o n
'Scriptname
'This name is used to find the specific script and host combination in the whatsup eventviewer
If sintScriptMode = 0 Then
        If sintTypOfMonitor = 1 or sintTypOfMonitor = 2 then
            sstrScriptName = Context.GetProperty("PerformanceMonitorTypeName") & "-" & Context.GetProperty("Address")
        else
            sstrScriptName = Context.GetProperty("ActiveMonitorTypeName") & "-" & Context.GetProperty("Address")
        end if
end if
'////////////////////// Start the URL monitor configuration
'One row with MonitorURL for every URL to monitor
MonitorURL "http://www.whatsupgold.com","<title>Network Management with Network Monitoring | Know Your Network with WhatsUp Gold</title>" ,"GET","","","","","",0
'
'////////////// End of URL monitor configuration - No changes below are needed
'Count responetime
tmResponseTimeURL = CLng(TrueTimer(tmStartTimeURLCheck)*1000)
'Terminate object
Set sobjWinHttp51 = Nothing

If sintTypOfMonitor = 2 Then 'Performance monitor extract value
    If IsNumeric(sstrFromHost) = True Then
        sstrFromHost=Replace(sstrFromHost,strNumberSeparatorToReplace,strNewNumberSeparator)
        sstrFromHost=CLng(sstrFromHost)
    else
        sintMonitorResault = 1
        Log("Error, Value is not numeric for script=" & sstrScriptName & " value=" & sstrFromHost)
    end if
end if

'Check overall resault
if sintMonitorResault = 0 then
    'Set the result code of the check (0=Success, 1=Error)
    'Update Whatsup
    If sintScriptMode = 0 Then
        If sintTypOfMonitor = 1 Then
            Context.SetValue tmResponseTimeURL
        end if
        If sintTypOfMonitor = 2 Then
            Context.SetValue sstrFromHost
        end if
        Context.SetResult 0, "SetResult to success for script=" & sstrScriptName
    End if
    'Log message    
    If sintTypOfMonitor = 1 Then
        Log("URLCheck for script=" & sstrScriptName & " took " & tmResponseTimeURL & " ms to complete")
    end if
    If sintTypOfMonitor = 2 Then
        Log("Converted variable for script=" & sstrScriptName & " value= " & sstrFromHost)
    end if
    Log("Completed with success for script=" & sstrScriptName & ",All URL checks have responded correctly")
else
    If sintScriptMode = 0 Then
        Context.SetResult 1, "SetResult to failure for script=" & sstrScriptName
    end if    
    Log("Completed with error for script=" & sstrScriptName & ",the overall URL checks failed")
end if
'Update status file
StatusFile()
LogToFile()
If sintScriptMode = 1 Then 'windows prompt
    if sintMonitorResault = 0 then
        WScript.Quit(0)
    else
        WScript.Quit(1)
    end if
end if
'------------------------------ End Script -------------------------------------------

'************************************ Start of functions ************************************************

Function MonitorURL(strURLToCheck,strTextToFind,strURLMetod,strUserName,strUserPassword,strURLPostData,strPreStringsstrFromHost,strPostStringsstrFromHost,intDebugInfo)
'================== Parameters for every URL
'MonitorURL strURLToCheck,strTextToFind,strURLMetod,strUserName,strUserPassword,strURLPostData,strPreStringsstrFromHost,strPostStringsstrFromHost,intDebugInfo
'strURLToCheck = URL to check
'strTextToFind = Text string to seach for in received URL
'strURLMetod = GET,POST,SOAP11 or SOAP12, When POST then strURLPostData should contain the text to POST*
'When SOAP11 or SOAP12 the HTTP method is still POST but with diffrent content-types
'Content-type on POST,SOAP11(SOAP 1.1) and SOAP12(SOAP 1.2)
'POST = application/x-www-form-urlencoded
'SOAP11 = text/xml
'SOAP12 = application/soap+xml
'strUserName = Username when URL request login
'strUserPassword = Password when URL request login
'strURLPostData = String to POST,used togeter with strURLMetod=POST
'strPreStringsstrFromHost = String before extracted textstring (variable sstrFromHost) in the received HTML page
'strPostStringsstrFromHost = String after extracted textstring (variable sstrFromHost) in received HTML page
'intDebugInfo = 0 = No debug, 0 <> = echo webpage after characther cleaing
'If an error is received from the web server and intDebugInfo <> 0 the webpage are returned before cleaning
'
'The MonitorURL function checks and reports if error.
'The sstrFromHost contains the extract textstring from the receive webpage (when PreStringsstrFromHost and strPostStringsstrFromHost are defined)
'============================================
Dim strWebPage,intActionResault
Dim intPreVarStart,intPostVarEnd
'strURLToCheck = strURLMetod GET or POST

if sintTimeoutMode <> 0 then 'Check the timeout
    if sintTimeOutFlag = 1 then 'Timeout
        Log("Timeout reached for script=" & sstrScriptName &" ,no control made for MonitorURL=" & strURLToCheck & " with string=" & strTextToFind & " POSTdata: " & strURLPostData)    
        exit function
    end if
    if sScriptTimeOut > (slngSendTimeout + slngResolveTimeout + (slngReceiveTimeout * sintNumberOfReceivedpackets) + (TrueTimer(tmStartTimeURLCheck)*1000)) then
        'Still time to make a other MonitorURL() check
        'Calculate new timeout value
        slngConnectTimeout = sScriptTimeOut - (slngSendTimeout + slngResolveTimeout + (slngReceiveTimeout * sintNumberOfReceivedpackets) + (TrueTimer(tmStartTimeURLCheck)*1000))    
        else
        'Timeout reached
        'Set Error
        sintMonitorResault=1
        sintTimeOutFlag = 1
        Log("Not enough time to complete script=" & sstrScriptName & " ,MonitorURL=" & strURLToCheck & " with string=" & strTextToFind & " POSTdata: " & strURLPostData & ",timeout after " & (TrueTimer(tmStartTimeURLCheck)*1000) & " milliseconds")
        sintFirstErrorFlag = 1 ' set first error detected
        exit function
    end if
end if

'Sending log message to the WhatsUp Event Viewer
Log("Checking URL(" & sVersion & ")=" & strURLToCheck & " with string=" & strTextToFind & " POSTdata: " & strURLPostData)

strWebPage=GetDataFromURL(sobjWinHttp51,strURLToCheck,strURLMetod, strUserName,strUserPassword,strURLPostData,intActionResault)

if Len(strWebPage) > (sintMaxPageLengthKB * 1000) then 'receive Webpage > sintMaxPageLengthKB
    Log("Script=" & sstrScriptName & " strURLToCheck=" & strURLToCheck & " received a webpage that exceeds sintMaxPageLengthKB, the check will only be within the first " & sintMaxPageLengthKB & " Kbytes, actual received length was " & Len(strWebPage) & " bytes.")
    strWebpage = Left(strWebpage,sintMaxPageLengthKB * 1000)
End if

strWebPage = CleanString(strWebPage)

'If error from web server
If intActionResault = "ERROR" Then
    'Set Error
    sintMonitorResault=1
    'Set error detected
    Log(" URL Error from WinHTTP Requester 5.1")
    If sintFirstErrorFlag = 0 or intDebugInfo <> 0 Then
        Log("=== Start error message ===" & vbNewLine & strWebPage & vbNewLine & "=== End error message ===")
        Log("Calculated ConnectTimeout for script=" & sstrScriptName &" and MonitorURL=" & strURLToCheck & " with string=" & strTextToFind & " ,was " & slngConnectTimeout & " milliseconds")    
        sintFirstErrorFlag = 1 ' set first error detected
    end if    
    exit function
End If

If intDebugInfo <> 0 Then
    Log("========== Start of WebPage ============" & vbNewLine & strWebPage & vbNewLine & "========== End of WebPage ==============")
    End if

'Received String check
if Instr(strWebPage,strTextToFind) > 0 then
    Log("Success, "  & strURLToCheck & " returns the text=" & strTextToFind)
    else
    'Set Error
    sintMonitorResault=1
    Log("Error, "  & strURLToCheck & " failed to return the text=" & strTextToFind)
    If sintFirstErrorFlag = 0 Then 'log received string
        Log("=== Start received web page ===" & vbNewLine & strWebPage & vbNewLine & "=== End received web page ===")
        sintFirstErrorFlag = 1 ' set first error detected
    end if    
    exit function
end if
'Find variable in page
If strPreStringsstrFromHost <> "" and strPostStringsstrFromHost <> "" then
    intPreVarStart = Instr(strWebPage,strPreStringsstrFromHost)
    intPostVarEnd = Instr(strWebPage,strPostStringsstrFromHost)
    if intPreVarStart > 0 and intPostVarEnd > intPreVarStart then
        'Add the lenth of the string as starting point to fetch variable
        intPreVarStart = intPreVarStart + Len(strPreStringsstrFromHost)
        sstrFromHost = Mid(strWebPage,intPreVarStart,intPostVarEnd-intPreVarStart)
        Log("Success for script=" & sstrScriptName & ", found variable: "  & sstrFromHost)
        else
        'Set Error
        sintMonitorResault=1
        Log("Error for script=" & sstrScriptName & ", failed to find varible between strings: " & strPreStringsstrFromHost & " and " & strPostStringsstrFromHost)
        If sintFirstErrorFlag = 0 Then 'log received string
            Log("=== Start received web page ===" & vbNewLine & strWebPage & vbNewLine & "=== End received web page ===")
            sintFirstErrorFlag = 1 ' set first error detected
        end if    
        exit function
    End if
End if
End Function

'*****************************************************

Function CleanString(strSource)
strSource=Replace(strSource,Chr(9),"") 'Horizontal Tab
strSource=Replace(strSource,Chr(10),"") 'Line Feed
strSource=Replace(strSource,Chr(11),"") 'Vertical Tab
strSource=Replace(strSource,Chr(12),"") 'Form Feed
strSource=Replace(strSource,Chr(13),"") 'Carriage Return
strSource=Replace(strSource,Chr(34),"") 'Quotation
Dim i
For i = 128 to 255
strSource=Replace(strSource,Chr(i),"x") 'Replace all 8-bit characters
Next
CleanString=strSource
End Function

'******************************************************

Function GetDataFromURL(objWinHttp,strURL, strMethod, strLogin, strPassword, strPostData,ActionCode)
'strmethod have GET,POST,SOAP11 and SOAP12
'When SOAP11 or SOAP12 the HTTP method is still POST but with diffrent content-types
'Content-type on POST,SOAP11 and SOAP12
'POST = application/x-www-form-urlencoded
'SOAP11 = text/xml
'SOAP12 = application/soap+xml
'
'SOAP11 = SOAP 1.1 and SOAP12 = SOAP 1.2
'100120/Robert Strandberg
'Change timeouts value to global parameter

  Dim strUserAgentString
  Dim intSslErrorIgnoreFlags
  Dim blnEnableRedirects
  Dim blnEnableHttpsToHttpRedirects
  Dim strHostOverride
  Dim strResponseText
  Dim strContentType
    strUserAgentString = "http_requester_whatsup/1.2"
  intSslErrorIgnoreFlags = 13056 ' 13056: ignore all err, 0: accept no err
  blnEnableRedirects = True
  blnEnableHttpsToHttpRedirects = True
  strHostOverride = ""
  objWinHttp.SetTimeouts slngResolveTimeout, slngConnectTimeout, slngSendTimeout, slngReceiveTimeout
  'Set content-type
  'Rewriting strMethod to be compliant with previuos versions
  If strMethod = "POST" Then
    strContentType = "application/x-www-form-urlencoded"
  End If
  If strMethod = "SOAP11" Then
    strContentType = "text/xml"
     strMethod = "POST"
  End If
  If strMethod = "SOAP12" Then
     strContentType = "application/soap+xml"
     strMethod = "POST"
  End If
    objWinHttp.Open strMethod, strURL
  If strMethod = "POST" Then
    objWinHttp.setRequestHeader "Content-type", _
    strContentType
  End If  
  If strHostOverride <> "" Then
    objWinHttp.SetRequestHeader "Host", strHostOverride
  End If
  objWinHttp.Option(0) = strUserAgentString
  objWinHttp.Option(4) = intSslErrorIgnoreFlags
  objWinHttp.Option(6) = blnEnableRedirects
  objWinHttp.Option(12) = blnEnableHttpsToHttpRedirects
  If (strLogin <> "") And (strPassword <> "") Then
    objWinHttp.SetCredentials strLogin, strPassword, 0
  End If    
  On Error Resume Next
  objWinHttp.Send(strPostData)
  If Err.Number = 0 Then
    If objWinHttp.Status = "200" Then
      GetDataFromURL = objWinHttp.ResponseText
     ActionCode="OK"
    Else
      GetDataFromURL = "HTTP " & objWinHttp.Status & " " & _
        objWinHttp.StatusText & " " & objWinHttp.ResponseText
     ActionCode="ERROR"
    End If
  Else
    GetDataFromURL = "Error " & Err.Number & " " & Err.Source & " " & _
      Err.Description
     ActionCode="ERROR"
  End If
  On Error GoTo 0
End Function

'******************************************************

Function TrueTimer(StartTime)
'This function corrected the Timer() function "feature" of reporting time since midnight.
'Script that uses the Timer() function that runs over midnight will show wrong time.
'This script expect that the StartTime parameter contanins the Timer() values when the Time measure started.
'The script will return the corrected elapsed time over midnight.
Dim iTimer,ElapsedTime
iTimer = Timer()    'Timer() to variable for faster processing
if iTimer - StartTime < 0 then ' Measure have passed midnight.
ElapsedTime = 86400 - StartTime
TrueTimer = ElapsedTime + iTimer
    else
    TrueTimer = (iTimer - StartTime)
end if
End Function

'******************************************************

Function StatusFile()
'Updates the statusfile and create eventlog message is thats configured in global parameter sintStatusFileMode <> 0
'Uses the Log functions, reads the sstrScriptName,sstrStatusFilePath,sintStatusFileMode,sintMonitorResault global variable.
Dim strStatusFile 'Path and filename
Dim objStatusFile 'Fileobject (handle)
Dim strTempStatus 'previous status
Dim strTxtFile 'Working file object
Dim fsoStatusTxtFile 'Filesystem object
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
strTempStatus =""
strStatusFile = sstrStatusFilePath & "\" & sstrScriptName & ".txt"

if sintStatusFileMode <> 0 then ' use status file
    'Create folder in first run of the script and log the folder creation
    CreateFolder sstrStatusFilePath,1    'Create file in first run of the script
    Set fsoStatusTxtFile = CreateObject("Scripting.FileSystemObject")
    If fsoStatusTxtFile.FileExists(strStatusFile) = False then
        Set objStatusFile = fsoStatusTxtFile.CreateTextFile(strStatusFile, True)
        Log("Created status file:" & strStatusFile & " for script=" & sstrScriptName)
    end if
    
    Set objStatusFile = fsoStatusTxtFile.GetFile(strStatusFile)
    'Read previous status
    Set strTxtFile = objStatusFile.OpenAsTextStream(ForReading, TristateUseDefault)
    if strTxtFile.AtEndOfStream = False then
        strTempStatus = strTxtFile.readall
    end if
    strTxtFile.close
    'Update the statusfile
    Set strTxtFile = objStatusFile.OpenAsTextStream(ForWriting, TristateUseDefault)
        if sintMonitorResault = 0 then
        strTxtFile.write("OK")
        else
        strTxtFile.write("ERROR")
    end if
    Log("Updated the statusfile, " & strStatusFile)
    strTxtFile.close
    'Update eventlog
    if sintStatusFileMode = 2 then ' if eventlog should be updated control previus status
        if sintMonitorResault = 0 and strTempStatus <> "OK" then 'Log Status ok
        LogEvent 0,"Success:" & sstrScriptName & ",All URL checks have responded correctly"
        Log("Logged event normal " & chr(34)& "Success:" & sstrScriptName & ",All URL checks have responded correctly" & chr(34) & " in the windows eventlog")
        end if
        if sintMonitorResault = 1 and strTempStatus = "OK" then 'Log Status error
        LogEvent 1,"Faliure:" & sstrScriptName & ",the overall URL checks failed"
        Log("Logged event error " & chr(34)& "Faliure:" & sstrScriptName & ",the overall URL checks failed" & chr(34) & " in the windows eventlog")
        end if
    end if
end if
End Function

'*******************************************************

Function Log(strTextToLog)
'This Logs information to windows prompt or whatsup eventlog,it also logs to a file if logging are enable
'function reads global variable sintScriptMode and updates the sstrLogTextToFile.
If sintScriptMode = 0 Then
    Context.LogMessage strTextToLog
    else
    Wscript.Echo(strTextToLog)
end if
'Update the sstrLogTextToFile
sstrLogTextToFile = sstrLogTextToFile & date() & " " & time() & " " & strTextToLog & vbNewLine
End Function

'**********************************************************

Function LogToFile()
'This Logs information to windows prompt or whatsup eventlog,it also logs to a file if logging are enable
'function reads global variable sintLogMode,sstrLogFilePath,sintLogFileSizeKB,sstrScriptName and sstrLogTextToFile.
'When logging to file the logging stops when the logfile reach max limit, to continue with loggning to file the
'existing logfile have to be renamed,moved or deleted.
'uses the Log() and CreateFolder() Function.
If sintLogMode <> 0 then
    Dim strLogFileName
    Dim fso
    Dim strLogFile
    Const ForAppending = 8
    strLogFileName = sstrLogFilePath & "\" & sstrScriptName & ".log"
    Set fso = CreateObject("Scripting.FileSystemObject")
    'Check if file exist
    If fso.FileExists(strLogFileName) then
        'Control size
        Set strLogFile = fso.GetFile(strLogFileName)
        'Logfile size exceeds max size
        If strLogFile.size/1000 > sintLogFileSizeKB then
            Log("Failed to write to logfile for script " & sstrScriptName & " ,file exceeds sintLogFileSizeKB value=" & sintLogFileSizeKB & "KB for logfile " & strLogFileName)
            Exit function    
            else
            'File open
            set strLogFile = fso.OpenTextFile(strLogFileName,ForAppending)
        End if
    else
        'Control if folders exist
        CreateFolder sstrLogFilePath,1 'Log folder creation
            'create file
            Set strLogFile = fso.CreateTextFile(strLogFileName, True)
            Log("Created logfile " & strLogFileName)
        end if
        'File ready for use
        'Log level
        If sintLogMode  = 1  and sintMonitorResault = 1 or sintLogMode  >= 2 then
        strLogFile.Write(sstrLogTextToFile)
        Log("Added entry to logfile " & strLogFileName)
        end if
strLogFile.Close
End if
End Function

'*********************************************************

Function LogEvent(iEventType,strEventMessage)
'Valid event types:
'0=SUCCESS
'1=ERROR
'2=WARNING
'4=INFORMATION
'8=AUDIT_SUCCESS
'16=AUDIT_FAILURE
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
    Select case iEventType
        Case 0,1,2,4,8,16
            WshShell.LogEvent iEventType,strEventMessage
        end Select
End Function

'********************************************************

Function CreateFolder(strFolderPath,intLog)
'This Function Creates folders,it also logs to a file if logging are enable
'strFolder should end with a \
'uses the Log() Function and sstrScriptName global variable.
'intLog = 0 = No logging of folder creation and first line
'intLog <> 0 = Logging of folder creation and first line
    'Control if folders exist
    Dim i,strTempPath,intLoopEnd
    i = 3
    intLoopEnd = 0
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    'Loop until all folders in the path are created
    Do until intLoopEnd <> 0
    'No more "\" in the string
        If instr(i+1,strFolderPath,"\",0) = 0 then
            strTempPath = strFolderPath
            intLoopEnd = 1 'all folders are extracted from string and created if nessesary
            else
            strTempPath = Mid(strFolderPath,1,instr(i+1,strFolderPath,"\",0))
            i = instr(i,strFolderPath,"\",0)
        end if
        If fso.FolderExists(strTempPath) = False then
            Dim fsoFolder
            'Create folders
            Set fsoFolder = fso.CreateFolder(strTempPath)
            if intLog <> 0 then
                Log("Created folder path " & strTempPath & " script=" & sstrScriptName)
            end if
        end if
        i = instr(i+1,strFolderPath,"\",0)
    loop    
End Function

-----
You liked this too1 person likes this discussion.
 
Concluded

0 Conclusions:

12 Replies

OfflineBrittany Ross Brittany Ross said 14 months ago

[Originally posted by Chandru K]

Hi,

I am trying to understand this script and see how i can use this to monitor some of the external websites?

I am new to this and wanted to know if there is a inbuilt feature where we can monitor external website for RTT

We have the latest version of WUG 14.0 Build 511 remote side edition and Central site edition

 

Thanks

C


OfflineBrittany Ross Brittany Ross said 14 months ago

[Originally posted by Robert Strandberg]

Hi Chandru K.

There is a built-in feature in whatsup to monitor web sites (active monitor), the "old" way with TCP/IP active monitor using send and expext commands, I have used it for several years but you have to make your own HTTP syntax, It can be done and there are several examples in the forum, the other way is to use the new HTTP content active monitor that basicly makes the same thing as  when you run URLMonitor as an active monitor and makes one MonitorURL() function call.

But if you need to test a "web"-application doing serveral URL checks, measure resonsetime,extract values from a web page and log that in a performance monitor or log the actual error/receive text string from a URL check (in a simple way) then I do not know any other way then using a active script (as Active or performance monitor), that was the driver for me to develop the URLMonitor script.

This information is a abstract of the documentation in the script.

Copy the script to you local computer and name it .vbs, in the example below I named it example.vbs and placed it in C: and
started the script with cscript


C:\>cscript example.vbs
Microsoft (R) Windows Script Host version 5.7
Copyright (C) Microsoft Corporation 1996-2001.

Checking URL(ver 1.3)=http://www.whatsupgold.com with string=<title>Network Management with Network Monitoring | Know Your Network
 with WhatsUp Gold</title> POSTdata:
Script=URL Monitor 1.3 example strURLToCheck=http://www.whatsupgold.com received a webpage that exceeds sintMaxPageLengthKB, the check will only be within the first 10 Kbytes, actual received length was 28421 bytes.
Success, http://www.whatsupgold.com returns the text=<title>Network Management with Network Monitoring | Know Your Network with Wh
atsUp Gold</title>
URLCheck for script=URL Monitor 1.3 example took 688 ms to complete
Completed with success for script=URL Monitor 1.3 example,All URL checks have responded correctly

C:\>

The MonitorURL() function call have the following parameters

MonitorURL "http://www.whatsupgold.com","<title>Network Management with Network Monitoring | Know Your Network with WhatsUp Gold</title>" ,"GET","","","","","",0

This means:
Use HTTP GET to receive the URL www.whatsupgold.com
If the received textstring consist of "<title>Network Management with Network Monitoring | Know Your Network with WhatsUp Gold</title>" then the URL check have completed successfully.

Change the parameters to MonitorURL() according to your own needs, you can make several MonitorURL calls in one script.

The setup in the example.vbs script are:
Windows prompt mode (not whatsup mode), sintScriptMode = 1
Responsetime monitor (reports response time to a whatsup performance monitor), sintTypOfMonitor = 1
If the script received a text string that dosent consist of the expexted then logg to a logfile. sintLogMode = 1
The script uses default timeouts of 59 seconds for the timeouts in winHTTP 5.1, sintTimeoutMode = 0

If you change sintScriptMode = 0 you can use it in whatsup as a performance monitor showing the responsetime
If you change sintTypOfMonitor = 0 you can use it in whatsup as a Active monitor (or action)
If you change sintLogMode = 0 no log file will be created and you can ignore sstrLogFilePath.

Summary
Test the script in windows prompt mode sintScriptMode = 1.
Choose sintTypOfMonitor = 0 or 1 depending on your need

Configure the MonitorURL() function call with the URL and expected response.

When you are finish developing your script, in other words you have configure the MonitorURL() calls change the sintScriptMode = 0 and create it in whatsup as a active or performance monitor (sintTypOfMonitor).
Please note that if you want to monitor and measure the response time on the same URL you have to use the same script as both a active and a performance monitor.
Do this by simply change the sintTypOfMonitor.

Hope that helps.
/R


OfflineBrittany Ross Brittany Ross said 14 months ago

[Originally posted by Edward Smith]

Hi There,

I am currently trying to implement this script as a performance monitor, but having some issues.

I managed to get the script working with command prompt, but when I try to directly implement the script into WhatsUp Gold as a performance monitor I get the following error:

Checking URL(ver 1.3)=http://www.whatsupgold.com with string=<title>Network &amp; Server Management System with Network Monitoring | Know Your Network with WhatsUp Gold</title> POSTdata: 

Script=-156.21.1.169 strURLToCheck=http://www.whatsupgold.com received a webpage that exceeds sintMaxPageLengthKB, the check will only be within the first 10 Kbytes, actual received length was 56557 bytes.

Success, http://www.whatsupgold.com returns the text=<title>Network &amp; Server Management System with Network Monitoring | Know Your Network with WhatsUp Gold</title>

Error: Source:'Microsoft VBScript runtime error'Line:157  Char:12Error:0  'Object doesn't support this property or method: 'Context.SetValue''-----------v(null)

any ideas what causes this error and how to fix it? please?

Many Thanks

*text document with altered script attached



OfflineBrittany Ross Brittany Ross said 14 months ago

[Originally posted by Robert Strandberg]

Hi, I tested your script and it works as a Performance Monitor.

I get the same error when I test your script as an active monitor.

The sintTypOfMonitor controls when the script should use Context.SetValue or not (sintTypOfMonitor = 1 or 2).

The reason for the error is that Context.SetValue isnt supported in an Active monitor.

Unfortunately Whatsup only have a "test" function for active monitor and not  for performance monitor (and only in the console, not in web)

The only "tools" you have is the specific log file that the script create and the performance error log in whatsup.

Hope that helps!

/R


OfflineBrittany Ross Brittany Ross said 14 months ago

[Originally posted by Edward Smith]

Hi Robert,

Thanks for the Reply, was a great help.

I have now got the script working as a performance monitor...like you correctly pointed out I was adding it as an active monitor by mistake. 

As an extra note: is there a way I can alter the script to cover all my devices apposed to duplicating the performance monitor over and over editing the url and title as needed ?

Many Thanks


OfflineBrittany Ross Brittany Ross said 14 months ago

[Originally posted by Robert Strandberg]

Hi Edward.

Yes you can, by configure the MonitorURL function call .

As the comment in the script say (I know that the script is a bit "overdocumented" with maybe to much information.)

'Use the Context.GetProperty("Address") if you have a monitor that can be used on 'several objects.
'Note that the Context.GetProperty("Address") only works in Whatsup mode.

This mean that you can use the same monitor on several devices, this will change the adress part.

Here are a example (for port 8080)

MonitorURL "http://" & Context.GetProperty("Address") & ":8080/your-URL/","Your expected content" ,"GET","","","","","",0

/R


OfflineBrittany Ross Brittany Ross said 14 months ago

[Originally posted by Ken Savoy]

hi,

we use host headers so I cannot use the Context.GetProperty("Address") property. how can I use the url?  what does ":8080/your-URL/" do?  thanks for a great script!

Thanks


OfflineBrittany Ross Brittany Ross said 14 months ago

[Originally posted by Robert Strandberg]

Hi Ken,

Host headers,
I have attached a new version 1.3.1 that hopefolly supports host headers.
The script extracts the host part of the URL in the URLMonitor() function call and set the host header.

If you need to modify the script you can search for this code in the script to find the change in 1.3.1

strHostHeader = strURL
    'Clean https:// and http:// from hostheader
    strHostHeader = LCase(strHostHeader)
    strHostHeader = Replace(strHostHeader,"http:","")
    strHostHeader = Replace(strHostHeader,"https:","")
    strHostHeader = Replace(strHostHeader,"//","")
    If instr(1,strHostHeader,"/") > 0 Then
  'Fetch hostname
  strHostHeader = Mid(strHostHeader,1,instr(1,strHostHeader,"/")-1)
 End if
    objWinHttp.SetRequestHeader "Host", strHostHeader

But hopefully 1.3.1 works for you.

Unfourtunably I do not know of any "standard" way of reading the hostname or displayname in a activemonitor (it should be possible in a action) so you have to make one active monitor per site/application.
I seen examples of script thet uses the context.getdb and SQL but I have not used it.

Does 1.3.1 work for you?

The ":8080/your-URL/" is only a example, the example in 1.3.1 MonitorURL script

MonitorURL "http://www.whatsupgold.com","<title>Network Management Software | Server Monitoring | WhatsUp Gold</title>" ,"GET","","","","","",0

Can also be expressed as

MonitorURL "http://www.whatsupgold.com:80","<title>Network Management Software | Server Monitoring | WhatsUp Gold</title>" ,"GET","","","","","",0
or
MonitorURL "http://" & "www.whatsupgold.com" & ":80","<title>Network Management Software | Server Monitoring | WhatsUp Gold</title>" ,"GET","","","","","",0

They all resaults in a URL http://www.whatsup.com using port 80, the syntaxt is the same as you use in your browser (normaly)

The & is the VB way of adding strings togehter.

Does that answer your questing?
/R


OfflineKeith Levenson Keith Levenson said 3 months ago

Hi,

The link to the 1.3.1 version that supports host headers is no longer available.  Can  you please report it?

Thanks!


OfflineManfred Klingbeil Manfred Klingbeil said 3 months ago

Hi,

I love this script and can use it as is but would have to define it many times.  What I have are a number of web sites that I need to extract the same information from.  The only value that changes is the web site name.  Is there a way to pass the web site name to the script and have it insert that value into the MonitorURL function?  That would help me out a great deal.

 

Thanks,

Manfred


OfflineRobert strandberg Robert strandberg said 5 weeks ago

Hi, here are new link to the 1.3.1 version (until whatsugold community breaks it again)

 

Attachments

 

OfflineRobert strandberg Robert strandberg said 5 weeks ago

Hi Manfred, maybe Context.GetProperty("Address") will work for you?

Example: MonitorURL "http://" & Context.GetProperty("Address") & "/your-URL/","Your expected content" ,"GET","","","","","",0

Or if you can try to use the displayname "ActiveMonitorTypeName"

 /R


Would you like to comment?

You must be a member. Sign In if you are already a member.

  • 1,632 views
  • $obj.VersionIndex versions
  • 12 replies
  • 1 follower
     
Post Date:
February 23, 2011
Posted By:
Brittany Ross

About this forum

  • 52,475 views
  • 75 topics
  • 20 followers
     

Viewed 1,632 times