aerris Posted December 23, 2010 Share Posted December 23, 2010 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!! Quote Link to comment Share on other sites More sharing options...
the182guy Posted December 23, 2010 Share Posted December 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
aerris Posted December 23, 2010 Author Share Posted December 23, 2010 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>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.