Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Chunked messages header fix #9

Open
wants to merge 1 commit into from

2 participants

ronen Philip Stehlik
ronen

Iv fixed the chunked header implementation for graylog2-server, the current gelf4j implementation uses 36 characters for the header while the current spec supports only 12, iv followed the same algorithm as the gelf4r implementation (using md5 on the current time) and verified the the graylog2 server works,

Best regards
Ronen

ronen

Note that I didn't cleanup much, just illustrated a possible solution, also in further commits iv cleared some printing

ef199d9

Philip Stehlik
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 11, 2012
ronen narkisr fixing chunked header ec11f24
This page is out of date. Refresh to see the latest.
6 build.gradle
... ... @@ -1,7 +1,9 @@
1 1 apply plugin: 'groovy'
  2 +apply plugin: 'maven'
2 3 apply plugin: 'idea'
3   -version = 0.86
  4 +version = '0.86'
4 5
  6 +group='org.graylog2'
5 7 repositories {
6 8 mavenCentral()
7 9 }
@@ -18,4 +20,4 @@ jar {
18 20 'Implementation-Version': version,
19 21 'Author':'Philip Stehlik - p@pstehlik.com'
20 22 }
21   -}
  23 +}
29 src/main/groovy/com/pstehlik/groovy/gelf4j/net/GelfTransport.groovy
@@ -7,6 +7,7 @@ package com.pstehlik.groovy.gelf4j.net
7 7 import com.pstehlik.groovy.gelf4j.appender.Gelf4JAppender
8 8 import com.pstehlik.groovy.graylog.Graylog2UdpSender
9 9 import java.nio.ByteBuffer
  10 +import java.security.MessageDigest
10 11
11 12 /**
12 13 * Transports GELF messages over the wire to a graylog2 server based on the config on a <code>Gelf4JAppender</code>
@@ -45,11 +46,10 @@ class GelfTransport {
45 46
46 47 //set up chunked transfer if larger than maxChunkSize
47 48 if (appender.maxChunkSize < gzipMessage.size()) {
48   -
49 49 Integer chunkCount = (((gzipMessage.size() / appender.maxChunkSize) + 0.5) as Double).round().toInteger()
50 50 String messageId = generateMessageId()
51 51 chunkCount.times {
52   - byte[] messageChunkPrefix = createChunkedMessagePart(messageId, it + 1, chunkCount)
  52 + byte[] messageChunkPrefix = createChunkedMessagePart(messageId, it , chunkCount)
53 53 Integer endOfChunk
54 54 Integer messagePartSize
55 55 if (gzipMessage.size() < ((it + 1) * appender.maxChunkSize)) {
@@ -95,19 +95,16 @@ class GelfTransport {
95 95 * @return The prepared byte array
96 96 */
97 97 private byte[] createChunkedMessagePart(String messageId, Integer sequenceNo, Integer sequenceCount) {
98   - sequenceNo = sequenceNo -1
99 98 Collection ret = []
100 99 ret << 30.byteValue()
101 100 ret << 15.byteValue()
102 101 messageId.getBytes('ISO-8859-1').each {
103 102 ret << it
104 103 }
105   -
106   - ret << (byte)(sequenceNo >>> 8)
107   - ret << (byte)(sequenceNo)
108   -
109   - ret << (byte)(sequenceCount >>> 8)
110   - ret << (byte)(sequenceCount)
  104 + ret << (sequenceNo.byteValue())
  105 + ret << (sequenceCount.byteValue())
  106 + println "${sequenceNo} ${sequenceCount}"
  107 + println (ret as byte[])
111 108 return ret as byte[]
112 109 }
113 110
@@ -132,16 +129,10 @@ class GelfTransport {
132 129 * @return
133 130 */
134 131 private String generateMessageId() {
135   - return new StringBuffer(36)
136   - .append(format(getIP()))
137   - .append(sep)
138   - .append(format(getJVM()))
139   - .append(sep)
140   - .append(format(getHiTime()))
141   - .append(sep)
142   - .append(format(getLoTime()))
143   - .append(sep)
144   - .append(format(getCount())).toString()
  132 + MessageDigest digest = MessageDigest.getInstance("MD5")
  133 + digest.update(System.currentTimeMillis().byteValue())
  134 + BigInteger big = new BigInteger(1,digest.digest())
  135 + big.toString(16).padLeft(32,"0")[0..7]
145 136 }
146 137
147 138 protected String format(int intval) {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.