Jump to content

Web Interface for displaying various service states


aerris

Recommended Posts

Hello,

I use loads of different servers at work and they all run seperate services that I need to keep my stuff running.

I want to build a simple webpage that will poll the services and display the current state by colour.  EG have table that lists the services in green and have them turn red if the service stops unexpectedly.

 

I can build the tables and stuff, I just don't know how to retrieve the state of a service.  I've been messing about with some ideas but nothing is working.

 

eg lets say I have two servers each with one service:

 

service one |IP Address of server |RUNNING

service two |IP Address of server |STOPPED

 

Has anyone got any ideas?

 

Thanks!!

Link to comment
Share on other sites

The simplest way to do it is to use php sockets to try and connect to the various services ports eg try port 21 to check FTP. If the socket connects then you can assume the service is running, if the connection fails then assume it is stopped. Have a search for php sockets for an example connection script, you can then just loop the connection code for each port and ip you want to test.

Link to comment
Share on other sites

Thanks!!

I did a search and have knocked this together after making a db of services to monitor.  It's doing the job nicely!!

<?php

// Connect to the database server
include("../../protect/dbconnect.php");
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the service database
if (!@mysql_select_db('service_check')) {
exit('<p>Unable to locate the service' .
'database at this time.</p>');
}

$result = @mysql_query('SELECT * FROM service');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
echo'<table border="1"><tr align="center"><td>Host</td><td>Service</td><td>State</td></tr>';

// Display the results
while ($row = mysql_fetch_array($result)) {
echo '<tr align="center"><td>' . $row['host'] . '</td><td>' . $row['servicename'] . '</td>';

error_reporting(0);

$fp = fsockopen($row['host'],$row['port'],$errno,$errstr,10);
if(!$fp)
{
echo "<TD BGCOLOR=red>DOWN</td></tr>";
}else{
echo "<TD BGCOLOR=lightgreen>UP</td></tr>";
fclose($fp);
}
}
echo"</table>";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.