Help wanted: script to check service availability/uptime

All other technical assistance queries (General technical issues, IPv6. P2P, News groups, etc)
Post Reply
User avatar
Mort
Posts: 383
Joined: Sun Jan 23, 2005 3:04 pm
Location: Sydney
Contact:

Help wanted: script to check service availability/uptime

Post by Mort » Sun Mar 11, 2012 1:42 pm

Greetings all,

I've had an idea and I'm not quite sure how (or if) to do it.

I'd like to setup a webpage or script that I can put on my exetel webspace that will do a poll or check to see if the servers I host on my own ADSL are properly visible to the big wide world.

I'm thinking something that would be able to do a ping of the server, and maybe poll a couple of different ports to check they are responding (e.g. 25, 80, and some others like teamspeak). It doesn't need to do constant monitoring, just do the poll at the time I open the page to check, although if there was something that was allowed to run on the Exetel webspace (as a cron job?) every 15 minutes and log "uptime" that would be awesome as well.

I know there are some free uptime type services around, but they don't really do what I want and tend to be unreliable unless you buy the fully managed service which is more than I need.

Any suggestions or comments gratefully accepted.

Scott.
As we know, there are known knowns. There are things we know we know. We also know there are known unknowns. That is to say we know there are some things we do not know. But there are also unknown unknowns, the ones we don't know we don't know.

User avatar
Dazzled
Volunteer Site Admin
Posts: 5997
Joined: Mon Nov 13, 2006 1:16 pm
Location: Sydney

Re: Help wanted: script to check service availability/uptime

Post by Dazzled » Sun Mar 11, 2012 6:22 pm

I'm still thinking about running a scheduler on the free web space, but the gist of your problem can be handled by PHP on the server. Eg, function fsockopen - http://php.net/manual/en/function.fsockopen.php I suggest you turn off error_reporting - eg, http://php.net/manual/en/function.error-reporting.php because you need to do something on error.

You might put a button on the site to activate something in your html similar to:
<?php
error_reporting (0);
$address = "127.0.0.1";
$port = 80;
if (fsockopen ($address, $port))
{
echo "$address:$port was found";
}
else
{
echo "Curses - The site does not respond"';
}
?>

To run executables from php, refer to exec - http://php.net/manual/en/function.exec.php

User avatar
Mort
Posts: 383
Joined: Sun Jan 23, 2005 3:04 pm
Location: Sydney
Contact:

Re: Help wanted: script to check service availability/uptime

Post by Mort » Sun Mar 11, 2012 6:30 pm

Thanks Dazzled,

Yes, I think something along those lines would suit, however I'm not really a php programmer (I can read code, but not write it, if you know what I mean). I was trying to find an existing script or project that might already be doing this rather than writing it from scratch, but other I can't seem to think of what it would be called when searching.

Using the term "uptime" as a keyword just keeps finding the more real-time monitoring programs, or ones that try to read that actual "uptime" values from the servers themselves.

Scott.
As we know, there are known knowns. There are things we know we know. We also know there are known unknowns. That is to say we know there are some things we do not know. But there are also unknown unknowns, the ones we don't know we don't know.

User avatar
Dazzled
Volunteer Site Admin
Posts: 5997
Joined: Mon Nov 13, 2006 1:16 pm
Location: Sydney

Re: Help wanted: script to check service availability/uptime

Post by Dazzled » Sun Mar 11, 2012 7:29 pm

Mort, in the first post, you weren't directly seeking uptime, only whether the service was visible or not. The snippet I dashed off can do that, and the echo message would be placed on the web page in the current html paragraph or other text element. You could also echo "<h3>Message</h3>\n"; or the like to add some formatting. If you don't want it cluttering the home page, just put it in a .php file and go there directly, or provide a link to the file, or provide links to a suite of such files for each site to be checked.

For similar and more complex solutions Google php fsockopen server status. Uptime would require this test to be repeated at intervals. I haven't thought about getting cron function on the free server.

User avatar
Mort
Posts: 383
Joined: Sun Jan 23, 2005 3:04 pm
Location: Sydney
Contact:

Re: Help wanted: script to check service availability/uptime

Post by Mort » Sun Mar 11, 2012 10:04 pm

Yes, you are correct, I'm not after uptime, I have internal systems monitoring that.

I'll muck around with the php code sample you gave me (thanks) and see how it goes. I guess if there was something "pretty" that had already been created to do this, with a web page template or something, then that kind of what I was hoping someone might know of.

I found a couple of really old sourceforge projects that sort of do what I'm talking about, but I'll try looking around for some more "fsockopen" examples and see if that leads me in a better direction.

Another quick question... is that fsockopen command going to run client-side or server-side? If it's client side then it won't help me to run the test from a machine already inside my network. If it's server-side then that's what I'd really like, but then would I need to be concerned about causing issues on the Exetel servers if my script is having timeout issues connecting to several different services if they aren't responding?

Thanks again.
As we know, there are known knowns. There are things we know we know. We also know there are known unknowns. That is to say we know there are some things we do not know. But there are also unknown unknowns, the ones we don't know we don't know.

User avatar
Dazzled
Volunteer Site Admin
Posts: 5997
Joined: Mon Nov 13, 2006 1:16 pm
Location: Sydney

Re: Help wanted: script to check service availability/uptime

Post by Dazzled » Sun Mar 11, 2012 10:45 pm

Check the fsockopen reference page for timeout info. It is an optional final argument. If a page on the website contains a php script it is executed at that point by the web server. That's why we can put html formatting tags into the echo statement, or any other kind of html we please. Whatever the php script writes is added into the html code and is transmitted, and finally displayed by your browser. This is different from javascripts, which get copied over for your browser to execute within itself.

[Edit] This intro to php may be helpful: http://www.tizag.com/phpT/. It covers all the basic stuff fairly well.

User avatar
Mort
Posts: 383
Joined: Sun Jan 23, 2005 3:04 pm
Location: Sydney
Contact:

Re: Help wanted: script to check service availability/uptime

Post by Mort » Sun Mar 11, 2012 11:32 pm

Thanks for all that. I've put together a script that seems to be doing the job. Next I'll just make it look pretty. :)

Thanks for your assistance Dazzled, hopefully it won't go causing any issues or alerts if there are multiple failed attempts to open socket connections.
As we know, there are known knowns. There are things we know we know. We also know there are known unknowns. That is to say we know there are some things we do not know. But there are also unknown unknowns, the ones we don't know we don't know.

User avatar
Mort
Posts: 383
Joined: Sun Jan 23, 2005 3:04 pm
Location: Sydney
Contact:

Re: Help wanted: script to check service availability/uptime

Post by Mort » Mon Mar 12, 2012 12:25 am

As we know, there are known knowns. There are things we know we know. We also know there are known unknowns. That is to say we know there are some things we do not know. But there are also unknown unknowns, the ones we don't know we don't know.

User avatar
Mort
Posts: 383
Joined: Sun Jan 23, 2005 3:04 pm
Location: Sydney
Contact:

Re: Help wanted: script to check service availability/uptime

Post by Mort » Mon Mar 12, 2012 11:03 pm

Hey Dazzled,

I was trying to do a connection to a SSL port 443 service and not sure if it's my script not working or the service not responding or blocking the connection

I noticed this on the fsockopen docs and wondered if it might be because OpenSSL isn't on the Exetel web space server?
If OpenSSL support is installed, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host.
As we know, there are known knowns. There are things we know we know. We also know there are known unknowns. That is to say we know there are some things we do not know. But there are also unknown unknowns, the ones we don't know we don't know.

User avatar
Mort
Posts: 383
Joined: Sun Jan 23, 2005 3:04 pm
Location: Sydney
Contact:

Re: Help wanted: script to check service availability/uptime

Post by Mort » Sun Mar 18, 2012 1:16 pm

Hey Dazzled,

I'm having a problem with checking for a a server on a particular port and I'm wondering if there's something on the Exetel web servers blocking the request?

If I run the script from a server external to Exetel it works (ignore the server can't be identified message)
http://dedimania.net/deditest/?ip=220.2 ... t+test+%21

But from the Exetel websapce it fails
http://home.exetel.com.au/ip1/tm_srv_ts ... t+test+%21

The script itself is here if that helps at all
http://dedimania.net/deditest/tm_srv_tst.zip
As we know, there are known knowns. There are things we know we know. We also know there are known unknowns. That is to say we know there are some things we do not know. But there are also unknown unknowns, the ones we don't know we don't know.

User avatar
Dazzled
Volunteer Site Admin
Posts: 5997
Joined: Mon Nov 13, 2006 1:16 pm
Location: Sydney

Re: Help wanted: script to check service availability/uptime

Post by Dazzled » Sun Mar 18, 2012 5:49 pm

What was wrong with the cooking with gas approach?

Curl and OpenSSL are listed by phpinfo as available on the server. Unfortunately the Exetel server doesn't put up the full phpinfo page. A one-line .php file containing <?php phpinfo(); ?> gets the unfinished page.

I had a quick look at the target site and connected at that port ok, faking it with curl, so it's up for the world. A very cursory look at the little script shows it's timing out at fsockopen - try including $ip and $port in the error message and dropping the timeout argument from the call, and see if there are any clues.

PS Sysadmin doesn't permit inward connections on oddball ports on the free server; there may be a block on non-standard outward ones also.

User avatar
Mort
Posts: 383
Joined: Sun Jan 23, 2005 3:04 pm
Location: Sydney
Contact:

Re: Help wanted: script to check service availability/uptime

Post by Mort » Sun Mar 18, 2012 6:44 pm

"cooking with gas" was the stuff running on port 80. When I tried adding the Trackmania and SSL ports it doesn't work.

I'm not entirely sure what you are asking me to do (I'll have a shot at it though), but the thing I don't understand is the same script behaves differently when run from two different places. When run from the dedimania.net site (which is in Germany I believe) it's fine, but when run on Exetel webspace it fails (timeout?). I don't see why it would timeout when run on the same "local" web server. It also works if I run it on my own internal network local to the game server.

The script I am using for the "basic" check page is much simpler. The "tm_srv_tst" script is one given to me be another person which I was just using to try and identify if it could work at all.
As we know, there are known knowns. There are things we know we know. We also know there are known unknowns. That is to say we know there are some things we do not know. But there are also unknown unknowns, the ones we don't know we don't know.

Post Reply