Subversion Repositories DevTools

Rev

Rev 7033 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7033 Rev 7176
Line 55... Line 55...
55
        this.mBuildDaemon = bd;
55
        this.mBuildDaemon = bd;
56
    }
56
    }
57
 
57
 
58
    // Method for terminating the listener
58
    // Method for terminating the listener
59
    public void terminate() {
59
    public void terminate() {
60
        mLogger.error("NagiosThread terminate");
60
        mLogger.warn("NagiosThread terminate");
61
        this.isRunning = false;
61
        this.isRunning = false;
62
        try  {
62
        try  {
63
            srv.close();
63
            srv.close();
64
        }
64
        }
65
        catch (IOException e) {
65
        catch (IOException e) {
66
            mLogger.error("NagiosThread terminate Exception on srv.close: " + e.getMessage());
66
            mLogger.error("NagiosThread terminate Exception on srv.close: {}", e.getMessage());
67
        }
67
        }
68
    }
68
    }
69
   
69
   
70
    /** 
70
    /** 
71
     * Sleep and handle exceptions
71
     * Sleep and handle exceptions
Line 82... Line 82...
82
    /**
82
    /**
83
     * This method start the thread and performs all the operations.
83
     * This method start the thread and performs all the operations.
84
     */
84
     */
85
    @Override
85
    @Override
86
    public void run() {
86
    public void run() {
87
        mLogger.error("NagiosThread Run");
87
        mLogger.warn("NagiosThread Run");
88
        setName("Nagios");
88
        setName("Nagios");
89
 
89
 
90
        // Wait for connection from client.
90
        // Wait for connection from client.
91
        // Process one command than then close the socket
91
        // Process one command than then close the socket
92
        // This is not an interactive session
92
        // This is not an interactive session
Line 98... Line 98...
98
                mLogger.info("Nagios Socket Accepted");
98
                mLogger.info("Nagios Socket Accepted");
99
                processSocketRequest(socket);
99
                processSocketRequest(socket);
100
                try {
100
                try {
101
                    socket.close();
101
                    socket.close();
102
                } catch (IOException e) {
102
                } catch (IOException e) {
103
                    mLogger.error("NagiosThread Exception on socket opr: " + e.getMessage());
103
                    mLogger.error("NagiosThread Exception on socket opr: {}", e.getMessage());
104
                    sleep(1000);
104
                    sleep(1000);
105
                }
105
                }
106
            }
106
            }
107
 
107
 
108
            catch (IOException e) {
108
            catch (IOException e) {
109
                mLogger.error("NagiosThread Exception on srv.accept: " + e.getMessage());
109
                mLogger.error("NagiosThread Exception on srv.accept: {}", e.getMessage());
110
                sleep(1000);
110
                sleep(1000);
111
            }
111
            }
112
        }
112
        }
113
        
113
        
114
        //
114
        //
Line 135... Line 135...
135
        //      Insert a dummy 'status' command if no input is received in 3 seconds
135
        //      Insert a dummy 'status' command if no input is received in 3 seconds
136
        //
136
        //
137
        try {
137
        try {
138
            socket.setSoTimeout(3000);
138
            socket.setSoTimeout(3000);
139
        } catch (SocketException e) {
139
        } catch (SocketException e) {
140
            mLogger.error("NagiosThread Exception on setSoTimeout: " + e.getMessage());
140
            mLogger.error("NagiosThread Exception on setSoTimeout: {}", e.getMessage());
141
        }
141
        }
142
        
142
        
143
        ;
143
        ;
144
        try {
144
        try {
145
            BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
145
            BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
146
            processRequest(socket, rd);
146
            processRequest(socket, rd);
147
            rd.close();
147
            rd.close();
148
        } catch (IOException e) {
148
        } catch (IOException e) {
149
            mLogger.error("NagiosThread Exception on getInputStream: " + e.getMessage());
149
            mLogger.error("NagiosThread Exception on getInputStream: {}", e.getMessage());
150
        }
150
        }
151
    }
151
    }
152
    
152
    
153
    /** Process the request
153
    /** Process the request
154
     *  Have a BufferedReader that will contain the socket data
154
     *  Have a BufferedReader that will contain the socket data
Line 198... Line 198...
198
        {
198
        {
199
            mLogger.warn("Nagios Socket read timeout");
199
            mLogger.warn("Nagios Socket read timeout");
200
            request = "status";
200
            request = "status";
201
            
201
            
202
        } catch (IOException e) {
202
        } catch (IOException e) {
203
            mLogger.error("NagiosThread Exception on processRequest: " + e.getMessage());
203
            mLogger.error("NagiosThread Exception on processRequest: {}", e.getMessage());
204
            return;
204
            return;
205
        }
205
        }
206
       
206
       
207
        //  Process the users request and generate a response
207
        //  Process the users request and generate a response
208
        
208
        
Line 229... Line 229...
229
            //  Flush out the input stream
229
            //  Flush out the input stream
230
            wr.flush();
230
            wr.flush();
231
            wr.close();
231
            wr.close();
232
 
232
 
233
        } catch (IOException e) {
233
        } catch (IOException e) {
234
            mLogger.error("NagiosThread caught Exception writing to port:" + e.getMessage() );
234
            mLogger.error("NagiosThread caught Exception writing to port: {}", e.getMessage() );
235
        }
235
        }
236
    }
236
    }
237
    
237
    
238
    /**
238
    /**
239
     * Generate a response to the Nagios (or user ) request 
239
     * Generate a response to the Nagios (or user ) request 
Line 322... Line 322...
322
        String outBody = dumpJson(status, "");
322
        String outBody = dumpJson(status, "");
323
        resp.append(outBody);
323
        resp.append(outBody);
324
    }
324
    }
325
    else if ( request.equals( "shutdown") ) {
325
    else if ( request.equals( "shutdown") ) {
326
        resp.append("Gracefull shutdown\n");
326
        resp.append("Gracefull shutdown\n");
327
        mLogger.error("Gracefull shutdown requested");
327
        mLogger.warn("Gracefull shutdown requested");
328
        BuildDaemon.mShutDown = true;
328
        BuildDaemon.mShutDown = true;
329
    }
329
    }
330
    else if ( request.equals( "kill") ) {
330
    else if ( request.equals( "kill") ) {
331
        resp.append("Will commit suicide\n");
331
        resp.append("Will commit suicide\n");
332
        mLogger.error("Immediate program termination");
332
        mLogger.error("Immediate program termination");