1
votes

I have a Syslog Server (receive log event and store in file) working in 514 port. The syslog server is operating good, becase was tested with Router, configuring the router with IP of Syslog Server and Port, and Router Sent Log to Syslog Server.

But, Now I want to make a application that replace the router (when send event/log to server).

I have this:

Logger mylogger;
mylogger = Logger.getLogger(this.getClass().getName());
SocketHandler myhandler = null;
try {
  myhandler = new SocketHandler("localhost", 514); //With Port 80 Work!
  myhandler.setLevel(Level.FINEST);
  mylogger.setLevel(Level.CONFIG);
  mylogger.addHandler (myhandler);
  mylogger.log(Level.SEVERE, "SEVERE LOG...");
  mylogger.log(Level.WARNING, "WARNING LOG...");
  mylogger.log(Level.INFO, "INFO LOG...");
  mylogger.log(Level.CONFIG, "CONFIG LOG...");
  mylogger.log(Level.FINE, "FINE LOG...");
  mylogger.log(Level.FINER, "FINER LOG...");
  mylogger.log(Level.FINEST, "FINEST LOG...");
  myhandler.close();
}
catch (IllegalArgumentException e) { System.out.println("IllegalArgumentException:"+e.toString()); }
catch (IOException e) { System.out.println("IOException:"+e.toString()); }
catch (SecurityException  e) { System.out.println("SecurityException0:"+e.toString()); }

I have this message:

IOException:java.net.ConnectException: Connection refused: connect

and the problem is with Socket Handler in 514 Port.

I need replace the "localhost" by my real IP of Syslog Server and port What Can I do?

Please help me.

Best Regards,

Bernal

1
Is your syslog server listening over TCP or UDP? - fge
The syslog server is based on Datagrams - bernal

1 Answers

1
votes

the problem is bad.

If you work with UDP, you must use UDP not TCP.

For testing your UDP Syslog, you must use something like this:

DatagramSocket dgSocket;
DatagramPacket dgPacket;
byte[] buf;
buf = "<67>Test Message".getBytes();
try {
  InetAddress addr; 
  dgSocket = new DatagramSocket();

  byte[] ipAddr = new byte[] { (byte)192, (byte)168, (byte)1, (byte)8 };//IP of Server Log
  addr = InetAddress.getByAddress(ipAddr);
  //instead of bytes using strings
  String sRemIP = "192.168.1.8"; //Ip of Syslog Server
  addr = InetAddress.getByName(sRemIP);

  int iPort = 514;//Number of Port where listening the Syslog Server
  dgPacket = new DatagramPacket(buf, buf.length, addr, iPort);
  dgSocket.send(dgPacket);
  System.out.println("Sending to IP:"+sRemIP+"  Port:"+sPort+"  The Message:"+new String(buf, "UTF8"));
}
catch (SocketException e) { System.out.println("SocketException:" + e.getMessage());}
catch (SecurityException e) { System.out.println("SecurityException:" + e.getMessage());}
catch (UnknownHostException e) { System.out.println("UnknownHostException:" + e.getMessage());}
catch (IOException e) { System.out.println("IOException:" + e.getMessage());}