Solved

Monitor a web page from VB program at specified intervals, and then take action after specified period of elapsed time if page not found or contents not what I expected

Posted on 2006-11-17
9
413 Views
Last Modified: 2008-02-07
Hi, guys.  I inherited an application that is very error-prone, and it will never be fixed, because our company is moving in another direction for web servers.  We use Domino right now for all web-front-ended applications, but we'll be moving to something else down the line.  I have no resources to put on actually fixing the application.  It is for our internal use only, so I can restart/reboot/whatever the server if I need to.

Periodically, the HTTP task fails, and the system quits serving up the web page.  This server needs to run 24x7x365, because it hosts an application that is used to requisition repair parts from our parts department.  We cannot seem to stop that from happening, so I want to write a monitor program to attempt to open the web page every < interval I choose >.  If the page does not open for whatever reason, I increment a counter, wait < interval I choose > , then check the page again.  Once that counter reaches 10, I will reboot the server.

I am new to VB, so please don't tar and feather me over the newbie coding.  I'm still learning, but I am at least trying.  What I need some help on is the " right " way to do this, and an example of code.  It needs to run unattended with no forms or windows requiring interaction.  I have tried making a program with the webbrowser control on a form, and going like so:

frmMain.wbMyBrowser.Navigate2 "somewebsite.com"
Do While frmMain.wbMyBrowser.Busy
DoEvents
Loop

If Not frmMain.wbMyBrowser.Busy Then
    If Not IsEmpty(frmMain.wbMyBrowser.Document.frames(1).Document.documentElement.innertext) Then
        If Not IsNull(frmMain.wbMyBrowser.Document.frames(1).Document.documentElement.innertext) Then
           strText = frmMain.wbMyBrowser.Document.frames(1).Document.documentElement.innertext
            strTestText = Mid(strText, 1, 7)
        Else
        counter = counter + 1
        AppendLine "C:\TestWebPageOpen.txt", Format(Now, "mm/dd/yyyy Hh:Nn:Ss AM/PM") & "  :SR TestWebPageOpen..  The check @ strText = frmMain.wbMyBrowser.Document.frames(1).Document.documentElement.innertext is null... failed.  Counter is incrementing.  Counter value is " & CStr(counter)
        GoTo Exit1
        End If
    Else
        counter = counter + 1
        AppendLine "C:\TestWebPageOpen.txt", Format(Now, "mm/dd/yyyy Hh:Nn:Ss AM/PM") & "  :SR TestWebPageOpen..  The check @ strText = frmMain.wbMyBrowser.Document.frames(1).Document.documentElement.innertext is empty... failed.  Counter is incrementing.  Counter value is " & CStr(counter)
        GoTo Exit1
    End If      
Else
End If

If frmMain.wbMyBrowser.Document.nameProp = "The page cannot be displayed" Or _
   frmMain.wbMyBrowser.Document.nameProp = "Cannot find server" _
     Then
     counter = counter + 1
End If

     If strTestText <> "Welcome" And strTestText <> "Locatio" Then ' Did not find it...
        counter = counter + 1
        AppendLine "C:\TestWebPageOpen.txt", Format(Now, "mm/dd/yyyy Hh:Nn:Ss AM/PM") & "  :SubRoutine TestWebPageOpen..  strTestText <> Welcome And strTestText <> Locatio...   Counter is incrementing.  Counter value is " & CStr(counter)
        GoTo Exit1
    Else
        If counter > 0 Then ' Write a line to the log file that you reset the counter, but only if it actually had a value....
            AppendLine "C:\TestWebPageOpen.txt", Format(Now, "mm/dd/yyyy Hh:Nn:Ss AM/PM") & "  :SubRoutine TestWebPageOpen..  strText = frmMain.wbMyBrowser.Document.frames(1).Document.documentElement.innertext value was found... Resetting counter to zero.  Counter value is " & CStr(counter)
        Else
        End If
        counter = 0
        GoTo Exit1
    End If


Exit1:
    If counter = 5 Then ' I put this in so that if I manually stop the server to do something, I don't get rudely kicked out...
        MsgBox "If you do not want automatic reboot, kill process called TestWebPageOpen within 5 minutes.  Please restart it afterwards...", vbInformation
    Else
    End If
   
    If counter > 10 Then ' We have looped through 10 times without being able to read the web page.  Reboot!
        AppendLine "C:\TestWebPageOpen.txt", Format(Now, "mm/dd/yyyy Hh:Nn:Ss AM/PM") & "  :SubRoutine TestWebPageOpen @
             Exit1:..  The system is rebooting.  Counter value is " & CStr(counter)
        SendPageCounter = SendPageCounter + 1
        If SendPageCounter = 1 Then
            mAlarmText = "Web server rebooting" & vbCrLf
            Call SendPages
        End If
         ShutdownSystem EWX_FORCE
    Else
        Exit Sub
    End If

It's here where I keep getting problems.   That may run fine in Debug mode, but it'll blow up when I run it for real with run-time errors.  Another thing that keeps happeninhg is that it'll run fine for awhile, but then it'll hit RTE's.  I tried logging what was happening and got stuff like:

11/16/2006 09:55:00 PM  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is 0 Error #-2147024726: Automation error
The requested resource is in use.
11/16/2006 09:56:00 PM  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is 1 Error #-2147024726: Automation error
The requested resource is in use.

What the heck is that all about?  I cannot find anything even moderately helpful by looking for that error on the web.  Am I even approaching this right?  Should I use something other than a WebBrowser control, like a socket-based approach?  If I use that, do I have to disconnect and reconnect every loop?  I had tried a socket=-based approach in another program, but gave up and made it a UDP because the socket would not get past " Connecting ".

Sometimes I log:

11/16/2006 10:06:36 PM  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is 1 Error #-2147352567: Exception occurred.

Occasionally I hit it on the sweet spot and get:


11/17/2006 10:35:31 AM  :SubRoutine TestWebPageOpen..  @ test for strText = frmMain.wbMyBrowser.Document.frames(1).Document.documentElement.innertext  --- A value was found.   Resetting counter to zero.  Counter value was 2.

I tried to do error handling like so:
On Error GoTo Err_TestWebPageOpen

Exit_TestWebPageOpen:
    If counter > 10 Then ' We have looped through 10 times without being able to read the web page.  Reboot!
        AppendLine "C:\TestWebPageOpen.txt", Format(Now, "mm/dd/yyyy Hh:Nn:Ss AM/PM") & "  :SubRoutine TestWebPageOpen @ Exit_TestWebPageOpen:..    The system is rebooting.  Counter value is " & CStr(counter)
        SendPageCounter = SendPageCounter + 1
        If SendPageCounter = 1 Then  '  Dispatch a page to my pager if the program reboots the server
            mAlarmText = "Web server rebooting" & vbCrLf
            Call SendPages
        End If
        ShutdownSystem EWX_FORCE
    Else
        Exit Sub
    End If


Err_TestWebPageOpen:
   
    If (Err.Number <> 0) Then
        AppendLine "C:\TestWebPageOpen.txt", Format(Now, "mm/dd/yyyy Hh:Nn:Ss AM/PM") & "  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is " & CStr(counter) & "Error #" & Err.Number & ": " & Err.Description
        counter = counter + 1
    Else
    End If
    Resume Exit_TestWebPageOpen

Is it safe to error trap like that?  Do I need to error trap in the exit routine as well?  I ask that because I also get entries like:

11/16/2006 10:04:00 PM  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is 9 Error #-2147024726: Automation error
The requested resource is in use.
11/16/2006 10:05:00 PM  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is 10 Error #-2147024726: Automation error
The requested resource is in use.
11/16/2006 10:05:00 PM  :SubRoutine TestWebPageOpen @ Exit_TestWebPageOpen:..  The system is rebooting.  Counter value is 11
11/16/2006 10:05:00 PM  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is 11 Error #20: Resume without error
11/16/2006 10:05:00 PM  :SubRoutine TestWebPageOpen @ Exit_TestWebPageOpen:..  The system is rebooting.  Counter value is 12
11/16/2006 10:05:00 PM  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is 12 Error #20: Resume without error
11/16/2006 10:05:00 PM  :SubRoutine TestWebPageOpen @ Exit_TestWebPageOpen:..  The system is rebooting.  Counter value is 13
11/16/2006 10:05:00 PM  :SubRoutine TestWebPageOpen  @ Exit_TestWebPageOpen:..  Error encountered.  Counter value is 13  Error #20: Resume without error
11/16/2006 10:05:00 PM  :SubRoutine TestWebPageOpen @ Exit_TestWebPageOpen:..  The system is rebooting.  Counter value is 14


OBVIOUSLY, that ain't working like I wanted.  Notice that there is not a one-minute gap between the entries above, and when it hit 11, the reboot did not happen.

Any help or advice would be appreciated.
0
Comment
Question by:frosteemjj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 4

Expert Comment

by:JRCSystems
ID: 17969581
Ignoring the code for a moment, Is this possible:

Right-Click My Computer, Left-click Manage.
Under Services + App, Left-Click Services.

Locate the Service that is giving you this problem. ( WWW Publishing service, inetinfo ).
Right Click on it, go to properties, recovery tab.
For failure 1 and 2, tell it to restart.
For failure #3, tell it to reboot.

Seems like it would save a lot of coding.


0
 

Author Comment

by:frosteemjj
ID: 17970086
Thanks for the thought, and I wish it were that simple.  Unfortunately, the Domino server application is not set up to run as a service, and it hosts the HTTP task.

It has to run interactively because of another one of the arcane ( and archaic ) components used by the primary application this server hosts.  The HTTP task which is a part of the Domino server application just fails randomly, so I need to find a way to monitor it from code.
0
 
LVL 29

Accepted Solution

by:
Nightman earned 300 total points
ID: 17970665
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:sakuya_su
ID: 17971026
so can we not just check to see if the process is still running, if not restart?

or.....

just have a web browser control on the form, have a timer that automatically directs the browser to that webpage you are checking, if its offline then restart the server?
0
 

Author Comment

by:frosteemjj
ID: 17975464
Nightman,
I had not thought of that approach before, and I'll look into it.  I am on vacation for the next week, so I won't be thinking about work much.  :-)

sakuya_su,
  The process is often still running, but the web page is not being served up to users.  The second suggestion you make is pretty much what I was doing.  There is a webbrowser control on the form, and I attempt to open it in the code every 60 seconds.  After 10 checks I wanted to reboot.  That program is being called at startup, so that's why I do a loop with a counter value.   It often takes a few minutes for the HTTP task to get started when the Domino server app opens, so I don't want to reboot unless I get several consecutive failures.

 
0
 
LVL 29

Expert Comment

by:Nightman
ID: 18197963
Hi frosteemjj

Have our commens assisted you? If not, please can you provide some feedback, otherwise have a look at http://www.experts-exchange.com/help.jsp#hs5 for information on closing questions.

Regards
Nightman
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question