Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checking server status via ASP.net

0 views
Skip to first unread message

darrel

unread,
Apr 29, 2008, 4:02:31 PM4/29/08
to
I swear I've read you can do this somewhere before, but don't recall where
or what it'd even be called to do the correct googling.

What I've been asked to do is make a 'dashboard' app that checks the status
of various servers. If they are down, show an error.

I found/modified this snippet:

---

Try
Dim req As Net.HttpWebRequest = Net.WebRequest.Create("your url")
Dim res As Net.HttpWebResponse = req.GetResponse()
Dim str As IO.Stream = res.GetResponseStream()
Return New IO.StreamReader(str).ReadToEnd()
Catch ex As Exception
Return ex.Message
End Try
End Function

---

2 issues:

1) When I try to call the function ala:
<%=checkURL("http://google.com")%>

I get this error: "Invalid URI: The format of the URI could not be
determined."

Unfortunately, that appears to be a common SharePoint error, so Google
results are a bit cluttered.

2) Even if this does work, will it return anything if the server times out
(the main thing we're looking to check for?

-Darrel


George Ter-Saakov

unread,
Apr 29, 2008, 4:47:15 PM4/29/08
to
I hope you changed this line

Dim req As Net.HttpWebRequest = Net.WebRequest.Create("your url")
"your url" suppose to be whatever you passing to checkURL

George.


"darrel" <not...@nowhere.com> wrote in message
news:eL3w2Pjq...@TK2MSFTNGP03.phx.gbl...

Juan T. Llibre

unread,
Apr 29, 2008, 4:54:40 PM4/29/08
to
re:
!> What I've been asked to do is make a 'dashboard' app that checks
!> the status of various servers. If they are down, show an error.

I think you're basically looking for this :

http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx

This solution doesn't use WebParts, but might give you a few ideas.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================


"darrel" <not...@nowhere.com> wrote in message news:eL3w2Pjq...@TK2MSFTNGP03.phx.gbl...

darrel

unread,
Apr 29, 2008, 4:55:36 PM4/29/08
to
>I hope you changed this line
> Dim req As Net.HttpWebRequest = Net.WebRequest.Create("your url")
> "your url" suppose to be whatever you passing to checkURL

You have my permission to walk over here and smack me upside the head for
such a stupid mistake! ;o)

I am completely embarrassed by that one. ;o)

OK, so, that works! Now, to followup...

That returns the actual page. What I need to do is check for specific
errors. For instance, if it can't access the page at all, I get a "Unable to
connect to the remote server".

Is there a master list of these types of errors out there to reference
against?

Or, in general, is this even a good way to go about testing for the status
of a server?

-Darrel


George Ter-Saakov

unread,
Apr 29, 2008, 5:53:32 PM4/29/08
to
the way I do it is to make custom page.
That connects to database, checks hard-drive space,.....
Basically does everything that needs to be checked. And outputs it as HTML.
Something like
Empty Space:1Gb<br>
Database: OK

Then your code simply displays it.

So you have for example
<%=checkURL("http://google.com/test.aspx")%>

And your checkURL will do folowing (pseducode, do not know VB well)

Function CheckUrl(sUrl) as String
Dim req As Net.HttpWebRequest
Dim res As Net.HttpWebResponse
Dim str As IO.Stream
Try
req = Net.WebRequest.Create("sUrl")
res = req.GetResponse()
str = res.GetResponseStream()
Return New IO.StreamReader(str).ReadToEnd()
Catch ex As WebException
ex.Response.Dispose()
Return "Connected to server but got an error: " & ex.Message
Catch e As Exception

Return "Could not connect to server: " & e.Message
Finally
if( str Not Is Nothing) Then str.Dispose()
if( res Not Is Nothing) Then res.Dispose()
End Try
End Function


PS: Do not forget to properly close Dispose objectes. You will run out of
resources soon otherwise.


But it only works if you can create your custom test.aspx page on the
server.
If not, you are limmited to was able to connect to server/was not able
to.....

George.


"darrel" <not...@nowhere.com> wrote in message

news:ue$MhtjqI...@TK2MSFTNGP04.phx.gbl...

John Timney (MVP)

unread,
Apr 29, 2008, 7:04:49 PM4/29/08
to
You've not said if they are all webservers, if not then an httprequest wont
help you much, and you'll need a tcp type ping request. The code is fairly
straightforward and you'll find httpget request example in the asp.net
quickstart.

Also, to run this kind of request in your sharepoint server, whther in a
webpart or not is almost certainly going to need a full trust level setting
in web.config.

Why don't you start by getting the code to work from a simple asp.net page,
and then migrate it into either a sharepoint page or a webpart if you can
get it to work.

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog

"darrel" <not...@nowhere.com> wrote in message

news:eL3w2Pjq...@TK2MSFTNGP03.phx.gbl...

darrel

unread,
Apr 30, 2008, 9:19:49 AM4/30/08
to
> Also, to run this kind of request in your sharepoint server

I'm avoiding putting anything in SharePoint these days. ;0)

-Darrel


darrel

unread,
Apr 30, 2008, 9:18:41 AM4/30/08
to
> But it only works if you can create your custom test.aspx page on the
> server.
> If not, you are limmited to was able to connect to server/was not able
> to.....

Good idea, though we really don't need anything that robust.

I found some suggestions one being to load the page, regex out the TITLE
tag, and compare it to what you think it should be. If it's different, then
either an error page loaded, or an error was returned.

The one unknown is what if the server just doesn't respond? I assume you'd
get some sort of time-out error. I'm just not quite sure how to test that
particular aspect yet. I'll have to wait for one of our servers to go down
;)

-Darrel


0 new messages