Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
Created July 28, 2011 17:22
Show Gist options
  • Select an option

  • Save leandrosilva/1112021 to your computer and use it in GitHub Desktop.

Select an option

Save leandrosilva/1112021 to your computer and use it in GitHub Desktop.
Nano Syslog deamon + ElasticSearch back-end for awesomeness
import java.net.*;
import java.io.*;
public class ElasticSysjog {
public static void main(String[] args) throws IOException {
System.out.println("=== ElasticSysjog up and running ===");
final int PORT = 1514; // default Syslog UDP port is 514
final int BUFFER_SIZE = 10000;
DatagramSocket socket = new DatagramSocket(PORT);
DatagramPacket packet = new DatagramPacket(new byte[BUFFER_SIZE], BUFFER_SIZE);
while (true) {
packet.setLength(BUFFER_SIZE);
socket.receive(packet);
System.out.printf("Posting %d bytes to ElasticSearch from %s\n", packet.getLength(), packet.getSocketAddress());
postToElasticSearch(packet.getData());
}
}
private static void postToElasticSearch(byte[] message) throws IOException {
// Let say it's an amazing ElasticSearch driver, ok? ;-)
System.out.write(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment