sshikov / jsendnsca

Automatically exported from code.google.com/p/jsendnsca
0 stars 0 forks source link

multi-byte message fails to send #46

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a message payload with multi-byte text, over the maximum amount of 
characters allowed for the message (512 bytes)
2. try to send it

What is the expected output? What do you see instead?
com.googlecode.jsendnsca.NagiosException: Error occurred while sending passive 
alert
        at com.googlecode.jsendnsca.NagiosPassiveCheckSender.send(NagiosPassiveCheckSender.java:95)
        at com.gsm.nsca.Alerter$AlertSender.process(Alerter.java:553)
        at com.gsm.lib.BatchRunner.processElements(BatchRunner.java:316)
        at com.gsm.lib.BatchRunner.flushBatch(BatchRunner.java:164)
        at com.gsm.lib.BatchRunner.run(BatchRunner.java:87)

Caused By: java.lang.ArrayIndexOutOfBoundsException
        at java.lang.System.arraycopy(Native Method)
        at com.googlecode.jsendnsca.utils.ByteArrayUtils.getFixedSizeBytes(ByteArrayUtils.java:98)
        at com.googlecode.jsendnsca.utils.ByteArrayUtils.writeFixedString(ByteArrayUtils.java:44)
        at com.googlecode.jsendnsca.PassiveCheckBytesBuilder.writeFixedString(PassiveCheckBytesBuilder.java:88)
        at com.googlecode.jsendnsca.PassiveCheckBytesBuilder.withMessage(PassiveCheckBytesBuilder.java:61)
        at com.googlecode.jsendnsca.NagiosPassiveCheckSender.send(NagiosPassiveCheckSender.java:80)
        at com.gsm.nsca.Alerter$AlertSender.process(Alerter.java:553)
        at com.gsm.lib.BatchRunner.processElements(BatchRunner.java:316)
        at com.gsm.lib.BatchRunner.flushBatch(BatchRunner.java:164)
        at com.gsm.lib.BatchRunner.run(BatchRunner.java:87)

What version of the product are you using? On what operating system?
2.0.1

Please provide any additional information below.

ByteArratUtils.getFixedSizeBytes() is broken.
At first, it uses character length to cap the string to maximum bytes allowed, 
but then uses byte length to copy the string into the array.

Considering that it would be as bad to convert the string into the array, and 
then cut it (as it can cut through a multi-byte character), it may be best to 
estimate using the character length first, and then keep dropping characters 
from the end until the byte length is satisfied. I don't know of any tricks 
that would make it more efficient.

Original issue reported on code.google.com by pawel.ve...@gmail.com on 27 Feb 2014 at 6:58

GoogleCodeExporter commented 9 years ago
Sounds like a genuine one.

If you are using NSCA version 2.9.1+ which supports 4096 characters, as a 
workaround you can enable long message support in JSendNSCA 2.1-RC1 as below

MessagePayload messagePayload = new MessagePayloadBuilder()
    .withSupportForLargeMessages()
...
    .create();

Meanwhile, will work on a fix for this.

Original comment by rajneeshpatel on 27 Feb 2014 at 9:21