Jump to content
danialbulloch

Simple Website Content Checking Monitor

Recommended Posts

As an MSP, some clients want us to make sure various websites and web based tools are working. LabTech can check to see if a website is up, but it can't tell if it's the actual website, or an error page. The TCP check may be able to pull the page content and check it, but I couldn't get it to work.

 

I've wrote this little bit of VBS(with help from Google) that checks websites for input text and returns a response time or a 0 depending on if it is found. Drop the below code into a .VBS on L:\Transfer\Monitors. After a reload system cache you can choose at as a program for a monitor. Labtech will automatically download the script and execute it on the target machine. For the arguments put "http://websiteurl.com" "text to check for here" and give it a test. It should return >0 for found, 0 for not found. Set the result to "not equal" 0. That's it. Simple and to the point.

 

If this is helpful, or if there is some painfully obvious way to make LabTech do it internally, please let me know, I'll be the first to admit I overlook exactly what I want all the time.

 

dim URI, searchText, startTime, endTime, responseTime
URI = WScript.Arguments(0)
searchText = WScript.Arguments(1)
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")

xmlhttp.open "get", URI, false
startTime = Timer()
xmlhttp.send
endTime = Timer()
strOutput = xmlhttp.responseText
If InStr(strOutput,searchText) Then
  responseTime = FormatNumber(endTime - startTime, 2) * 1000
  WScript.Echo responseTime
Else
  WScript.Echo 0
End If

 

[edit]I added the feature to check request time. The script now returns the response time for a pass, and 0 for fail. This gives better info in the monitor logging.[/edit]

Edited by Guest

Share this post


Link to post
Share on other sites

I'm constantly overlooking things, but I didn't see that feature. I saw an uptime check and a TCP check, but I couldn't find one that checked the page for certain text.

 

The TCP check could check some text if you made it reply the right thing(by choosing port 80 from the dropdown box), but it seemed to have a cutoff point. Modern webpages are pretty big and jammed with text, and I just couldn't get it to work. If I missed something though, please point it out to me.

 

At the very least this might serve as a an example of a custom VBS monitor, and how labtech handles it largely automatically. Handy anywhere a VBS needs to be run for a monitor.

Share this post


Link to post
Share on other sites
I'm constantly overlooking things, but I didn't see that feature. I saw an uptime check and a TCP check, but I couldn't find one that checked the page for certain text.

 

The TCP check could check some text if you made it reply the right thing(by choosing port 80 from the dropdown box), but it seemed to have a cutoff point. Modern webpages are pretty big and jammed with text, and I just couldn't get it to work. If I missed something though, please point it out to me.

 

At the very least this might serve as a an example of a custom VBS monitor, and how labtech handles it largely automatically. Handy anywhere a VBS needs to be run for a monitor.

 

I don't believe you overlooked it. I even checked with Labtech after I read your post and they said that this isn't a built in feature. I was just sitting here thinking of the best way to write a plugin to do this. Still not 100% on how I want to do it, but it's coming to me bit by bit.

Share this post


Link to post
Share on other sites
I don't believe you overlooked it. I even checked with Labtech after I read your post and they said that this isn't a built in feature. I was just sitting here thinking of the best way to write a plugin to do this. Still not 100% on how I want to do it, but it's coming to me bit by bit.

 

So I did a bit of googling, and poking around in the functions in vb.net, and found it was pretty easy to create a vb.net app to do this. I even took it 1 step further to allow for checking SSL certificate expiration dates. I'm going to dump it into a class and turn it into a plugin with some tabs under client or something, to allow for easy configuration. Once I figure out how to setup the monitors for these, I'll be golden.

Share this post


Link to post
Share on other sites

A plugin could be cool, for sure, but my little VBScript up top has been working well for my job. It doesn't have many exceptions. I don't know what it would do on bad SSL certs or other issues of that sort.

Share this post


Link to post
Share on other sites

I started the plugin. It works well for manual runs, but it's always tricky to make the plugin kick off in intervals. :) My method is quite similar to yours, but in vb.net. In fact, it was your vbscript that pushed me toward the plugin, so I am very appreciative. If I can get it to work of course. It isn't a high priority for me at the moment, but it's on my list.

 

   Private Function GetWebsiteData(ByVal url As String, ByVal searchText As String) As Boolean
       Try
           Dim request As WebRequest = WebRequest.Create(url)
           Dim response As WebResponse = request.GetResponse
           Dim inStream As StreamReader = New StreamReader(response.GetResponseStream())
           Dim finalRead As String = inStream.ReadToEnd()

           If finalRead.IndexOf(searchText, 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
               Return True
           Else
               Return False
           End If
       Catch
           Return Nothing
       End Try
   End Function

   Private Function GetSSLExpiration(ByVal url As String)
       Try
           Dim request As HttpWebRequest = WebRequest.Create(url)
           Dim response As WebResponse = request.GetResponse()
           Return request.ServicePoint.Certificate.GetExpirationDateString()
       Catch
           Return Nothing
       End Try
   End Function

Share this post


Link to post
Share on other sites
I believe you can create new types of monitors with plugins, so that would probably be the easiest way to handle it.

 

Yes, my problem is currently that I am not quite sure if I can make my monitor talk to my plugin's functions. I'd most likely have to convert them into Labtech scripts and create the monitor for them. I have some good experience writing my own plugins using both SDK methods.

 

I have a service plugin running on my LT server right now that utilizes the LT web reference. A Windows based service makes it easy to setup tasks and whatnot, but not the ability to provide an interface for the users to choose what to do. Is scripts the only way to go in this situation?

Share this post


Link to post
Share on other sites

I managed to have a working website response analyzer monitor using powershell, a batch file and some glue ;)

 

It checks the page and if it answers anything else than HTTP 200 OK the monitor triggers an alert, we use it mainly to monitor owa's since it's much better than just "is the site responding or not" it's "is it responding right?"

 

If people are interested i'll share the howto as it's a bit complex (have to create a group monitor,etc...)

Share this post


Link to post
Share on other sites
I managed to have a working website response analyzer monitor using powershell, a batch file and some glue ;)

 

It checks the page and if it answers anything else than HTTP 200 OK the monitor triggers an alert, we use it mainly to monitor owa's since it's much better than just "is the site responding or not" it's "is it responding right?"

 

If people are interested i'll share the howto as it's a bit complex (have to create a group monitor,etc...)

 

It may help to share. I specifically do it this way:

 

Service running on LT server that monitors a folder and has a lot of web reference functions (IE. Run local command on machine, update LT inventory). As it is monitoring a folder, I have Plugin running on the LT Control Center that has a web interface. The users can select the options that they want here, and it sends those options in code through LabTech Command Shell, and it will create certain text files with certain information to do specific tasks through functions in the Service that runs on the server. The Service checks every 5 minutes, and if it sees a file, it pull the info out, executes it according to whatever ComputerID created the text file (This information is noted in the text file that is created), deletes the file and runs whatever functions are noted inside the text file.

 

I basically had to write 2 completely different applications for this, as the Plugin and Web references are all different. In any case, it is very complicated to program, but it is SO user friendly and works very quickly. The queuing of the changes happens within a 5 minute window for anything that doesn't require the Control Center to be open. I setup the LT Control Center plugin to allow for instant changes so those specific changes that the users would want to change right away are able to be changed while they are there in the Control Center.

 

This, obviously, makes plenty of sense to me because I spent the time to create it. If any part is kind of confusing, I am happy to be more clear on it.

Share this post


Link to post
Share on other sites

Anyone willing to share their secret for this?

 

I just tried to create a tcp monitor on port 443 and it passes whether the website exists or not and is incapable of checking the actual content of the site.

 

I can probably write a powershell script to check the content, but if anyone has a working monitor configuration for 443 that checks the content I'd be happy to check it over for you ;-)

Share this post


Link to post
Share on other sites

My VBS script at the beginning of the post will do HTTPS, all you have to do is put in an HTTPS url. My monitor's arguments, for example, are "https://www.FireFold.com" "704-979-7100". This checks FireFold.com using 443 for the text "704-979-7100", the company phone number that will always be on the front page.

 

To review, take the VBS code at the begining, put it in a text file ending in .vbs. Place it in "L:\Transfer\Monitors". Then create a monitor and choose "External EXE Check". The VBS file should be in the "Executable" section.

Share this post


Link to post
Share on other sites

When I tried that, it seemed to fail on long pages. It may be better now or I may have been doing something wrong, but I was trying to get the tail of a very busy page and it would always fail for me. I haven't tried in Labtech 10 though, that might have been fixed. Using the built in monitor is of course the better way to go if it works.

Share this post


Link to post
Share on other sites

When I tried on a tcp monitor for port 443 my monitor would never come back as success. I was actually monitoring for the head string in the page as that is obviously at the top and would therefore not worry about the rest of the page loading in the available time (which is another problem entirely!). However i could not get the monitor to work. I removed the data to search for and got a successful monitor. To simulate the website being down, I changed the url to a non-existent site and the monitor was still coming back successful for the site so I'm highly suspicious of the accuracy of the tcp monitor on port 443, hence my post on this board.

 

I will double check the script that was posted at the beginning of this thread and will report back....

Share this post


Link to post
Share on other sites

Glad to hear it. I don't blame you for using the built in system first. I'm guessing it doesn't work for 443 because it doesn't do the TLS negotiation like mine does(by nature of .net HTTPS connections). I've actually got a more advanced set of scripts in powershell to do things like check the certificate that I should probably post. I should probably also remake the above script in powershell, as you could put the entire thing into the monitor without needing an actual script. I have a few long powershell commands as monitors already for pulling certain information, so I'm certain it can be done.

Share this post


Link to post
Share on other sites

I've updated my script a little. It now returns the website latency instead of 1 on a success. If you update the script on your end, you will want to check for Not Equal 0 instead of Equal 1. Then, you can use the data collector to see the latency of your website as well as monitor uptime. I'm currently thinking about how to make it show up in a nice graph in a LabTech Hud. The existing graph option really sucks. I'm thinking maybe writing the latency results to a text file then reading the text file in an HTML file that graphs it. Code for latency check below:

 

dim URI, searchText, startTime, endTime, responseTime
URI = WScript.Arguments(0)
searchText = WScript.Arguments(1)
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")

xmlhttp.open "get", URI, false
startTime = Timer()
xmlhttp.send
endTime = Timer()
strOutput = xmlhttp.responseText
If InStr(strOutput,searchText) Then
responseTime = FormatNumber(endTime - startTime, 2) * 1000
WScript.Echo responseTime
Else
WScript.Echo 0
End If

Share this post


Link to post
Share on other sites

Sorry to resurrect an old thread but anyone know if this monitor should work with a website that is accessed on a custom port? I can get it working on a normal website but not one with a custom port, it just gives the error:

"C:\Windows\LTSvc\websiteCheck.vbs(8, 1) msxml6.dll: The server name or address could not be resolved"

Edited by szkoda

Share this post


Link to post
Share on other sites
4 hours ago, szkoda said:

Sorry to resurrect an old thread but anyone know if this monitor should work with a website that is accessed on a custom port? I can get it working on a normal website but not one with a custom port, it just gives the error:

"C:\Windows\LTSvc\websiteCheck.vbs(8, 1) msxml6.dll: The server name or address could not be resolved"

Ugh... I have no problem with you resurrecting an old thread but I do have a problem with my completely pointless post above.  I droned on and on about something with no details at all.  Plus, my solution sounds overly complicated!  Lol

In any case, what are you trying to do?  Perhaps we can be of assistance in various ways if you give us a description of exactly what you need to monitor.

Edited by slwtx1983

Share this post


Link to post
Share on other sites
57 minutes ago, szkoda said:

I'm using OP's script which works fine for regular URL's but doesn't seem to like http://www.example.com:1234 - I would like to be able to monitor a website with a custom port for specific text (to tell if it is up or down).

That is what I figured.  This functionality is built into Labtech.  I use it to monitor my Plex server at home.  I have a "Does not contain" text running, but you can use it as a "Contains" if you are looking for specific text.  I attached a screenshot.

EDIT: Sorry, I wanted to point out that I am monitoring on port 32400.  I didn't have much success putting it on the "Port:" text box, but I put it at the end of my URL like https://PLEXURL:32400/web/index.html instead of asking it to monitor a port.  using that ":32400" at the end of the URL and before the post script at the end of the URL, it tells it to go to that port.  For those who don't know, that is the same as typing in something like https://google.com:443 to go to port 443 (the default https port for URL's).

Capture.JPG

Edited by slwtx1983

Share this post


Link to post
Share on other sites

Got it working now, oversight on my part, the location where the server is that the monitor is running on was being blocked by the firewall as we only allow 80 and 443 outbound for that particular server.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...