Rev 4219 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.erggroup.buildtool.daemon;import com.erggroup.buildtool.daemon.BuildDaemon;import org.apache.log4j.Logger;import java.net.ServerSocket;import java.net.Socket;import java.lang.Thread;import java.io.*;//----------------------------------------------------------------------------// CLASS : NagiosThread//// DESCRIPTION : A class to provide Nagios support////public class NagiosThread extends Thread {// Server socketprivate ServerSocket srv;// BuildDaemonprivate BuildDaemon mBuildDaemon;// Flag that indicates whether the poller is running or not.private volatile boolean isRunning = true;/**Logger* @attribute*/private static final Logger mLogger = Logger.getLogger(NagiosThread.class);// Constructor.public NagiosThread(ServerSocket srv, BuildDaemon bd) {this.isRunning = true;this.srv = srv;this.mBuildDaemon = bd;}// Method for terminating the listenerpublic void terminate() {mLogger.fatal("NagiosThread terminate");this.isRunning = false;}/*** This method start the thread and performs all the operations.*/public void run() {mLogger.fatal("NagiosThread Run");setName("Nagios");try {// Wait for connection from client.while (isRunning) {Socket socket = srv.accept();mLogger.warn("Nagios Socket Accepted");// Open a reader to receive (and ignore the input)BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));// try {// String request = rd.readLine();// BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));// wr.write("Build Daemon nagios inferface command:"+ request +" \n");// if ( request.equals( "quit") ) {// wr.write("Got a QUIT\n");// }// else if (request.equals("status")) {// wr.write("Got a STATUS\n");// }// else {// wr.write("Unknown command\n");// }// wr.flush();// } catch (IOException e) {// mLogger.fatal("NagiosThread caught Exception reading from port:" + e.getMessage() );// }// Write the status message to the outputstream// Currently this is too simple, but it is a start//try {BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));if ( mBuildDaemon == null ) {wr.write("Build Daemon status: NULL\n");} else if ( mBuildDaemon.checkThreads() ) {wr.write("Build Daemon status: OK\n");} else {wr.write("Build Daemon status: NOT HAPPY\n");mLogger.fatal("NagiosThread: NOT HAPPY");}wr.write("Version: "+ this.getClass().getPackage().getImplementationVersion() + "\n");wr.write("HostName: "+ BuildDaemon.mHostname + "\n");File cwd = new File(".");wr.write( "Usable space: " + cwd.getUsableSpace() + "\n");wr.flush();} catch (IOException e) {mLogger.fatal("NagiosThread caught Exception writing to port:" + e.getMessage() );}// Close the inputstream since we really don't care about itrd.close();}} catch (Exception e) {mLogger.fatal("NagiosThread caught Exception" + e.getMessage());}}}