Created
July 28, 2011 17:22
-
-
Save leandrosilva/1112021 to your computer and use it in GitHub Desktop.
Nano Syslog deamon + ElasticSearch back-end for awesomeness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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