@Test( expected = IOException.class ) public void testFailedConnection() throws Exception { LiveStatusClient client = new LiveStatusClient( null, -45 ); client.queryLivestatus( "whatever" ); }
public String queryLivestatus( String nagiosQuery ) throws UnknownHostException, IOException { Socket liveStatusSocket = null; try { this.logger.fine( "About to open a connection through Live Status..." ); liveStatusSocket = new Socket( this.host, this.port ); this.logger.fine( "A connection was established through Live Status." ); Writer osw = new OutputStreamWriter( liveStatusSocket.getOutputStream(), StandardCharsets.UTF_8 ); PrintWriter printer = new PrintWriter( osw, false ); printer.print( nagiosQuery ); printer.flush(); liveStatusSocket.shutdownOutput(); ByteArrayOutputStream os = new ByteArrayOutputStream(); Utils.copyStreamSafely( liveStatusSocket.getInputStream(), os ); String result = os.toString( "UTF-8" ); result = format( nagiosQuery, result ); return result; } finally { if( liveStatusSocket != null ) liveStatusSocket.close(); this.logger.fine( "The Live Status connection was closed." ); } }
LiveStatusClient { public String queryLivestatus( String nagiosQuery ) throws UnknownHostException, IOException { Socket liveStatusSocket = null; try { this.logger.fine( "About to open a connection through Live Status..." ); liveStatusSocket = new Socket( this.host, this.port ); this.logger.fine( "A connection was established through Live Status." ); Writer osw = new OutputStreamWriter( liveStatusSocket.getOutputStream(), StandardCharsets.UTF_8 ); PrintWriter printer = new PrintWriter( osw, false ); printer.print( nagiosQuery ); printer.flush(); liveStatusSocket.shutdownOutput(); ByteArrayOutputStream os = new ByteArrayOutputStream(); Utils.copyStreamSafely( liveStatusSocket.getInputStream(), os ); String result = os.toString( "UTF-8" ); result = format( nagiosQuery, result ); return result; } finally { if( liveStatusSocket != null ) liveStatusSocket.close(); this.logger.fine( "The Live Status connection was closed." ); } } }
LiveStatusClient { public String queryLivestatus( String nagiosQuery ) throws UnknownHostException, IOException { Socket liveStatusSocket = null; try { this.logger.fine( "About to open a connection through Live Status..." ); liveStatusSocket = new Socket( this.host, this.port ); this.logger.fine( "A connection was established through Live Status." ); Writer osw = new OutputStreamWriter( liveStatusSocket.getOutputStream(), StandardCharsets.UTF_8 ); PrintWriter printer = new PrintWriter( osw, false ); printer.print( nagiosQuery ); printer.flush(); liveStatusSocket.shutdownOutput(); ByteArrayOutputStream os = new ByteArrayOutputStream(); Utils.copyStreamSafely( liveStatusSocket.getInputStream(), os ); String result = os.toString( "UTF-8" ); result = format( nagiosQuery, result ); return result; } finally { if( liveStatusSocket != null ) liveStatusSocket.close(); this.logger.fine( "The Live Status connection was closed." ); } } LiveStatusClient( String host, int port ); }
LiveStatusClient { public String queryLivestatus( String nagiosQuery ) throws UnknownHostException, IOException { Socket liveStatusSocket = null; try { this.logger.fine( "About to open a connection through Live Status..." ); liveStatusSocket = new Socket( this.host, this.port ); this.logger.fine( "A connection was established through Live Status." ); Writer osw = new OutputStreamWriter( liveStatusSocket.getOutputStream(), StandardCharsets.UTF_8 ); PrintWriter printer = new PrintWriter( osw, false ); printer.print( nagiosQuery ); printer.flush(); liveStatusSocket.shutdownOutput(); ByteArrayOutputStream os = new ByteArrayOutputStream(); Utils.copyStreamSafely( liveStatusSocket.getInputStream(), os ); String result = os.toString( "UTF-8" ); result = format( nagiosQuery, result ); return result; } finally { if( liveStatusSocket != null ) liveStatusSocket.close(); this.logger.fine( "The Live Status connection was closed." ); } } LiveStatusClient( String host, int port ); String queryLivestatus( String nagiosQuery ); }
LiveStatusClient { public String queryLivestatus( String nagiosQuery ) throws UnknownHostException, IOException { Socket liveStatusSocket = null; try { this.logger.fine( "About to open a connection through Live Status..." ); liveStatusSocket = new Socket( this.host, this.port ); this.logger.fine( "A connection was established through Live Status." ); Writer osw = new OutputStreamWriter( liveStatusSocket.getOutputStream(), StandardCharsets.UTF_8 ); PrintWriter printer = new PrintWriter( osw, false ); printer.print( nagiosQuery ); printer.flush(); liveStatusSocket.shutdownOutput(); ByteArrayOutputStream os = new ByteArrayOutputStream(); Utils.copyStreamSafely( liveStatusSocket.getInputStream(), os ); String result = os.toString( "UTF-8" ); result = format( nagiosQuery, result ); return result; } finally { if( liveStatusSocket != null ) liveStatusSocket.close(); this.logger.fine( "The Live Status connection was closed." ); } } LiveStatusClient( String host, int port ); String queryLivestatus( String nagiosQuery );  }