Ad Widget

Collapse

JSON Message Length Problem with Zabbix 3.2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • estein
    Junior Member
    • Mar 2017
    • 4

    #1

    JSON Message Length Problem with Zabbix 3.2

    All,

    We have been using Zabbix 2.2 for years and finally updated to 3.2, and now we are having issues with the JSON length that we try to send to Zabbix. I haven't been able to determine but what is the maximum length that one can send to Zabbix through java code. Below is sample java code I use to send a json message along with th esample message.

    Excuse the lack of declarations in the code. This forum apparently doesn't like multiple equal declarations even within code blocks.

    Sample Code:

    Code:
    	
            Socket zabbixSocket = new Socket(zabbixServer, port);    
            zabbixSocket.setSoTimeout(30000);
                
            out   zabbixSocket.getOutputStream();
            is   new DataInputStream(zabbixSocket.getInputStream());
           
    
    	int length = data.length;
    
            out.write(new byte[] { 'Z', 'B', 'X', 'D', '\1',
                    (byte) (length & 0xFF), (byte) ((length & 0x00FF) >> 8),
                    (byte) ((length & 0x0000FF) >> 16),
                    (byte) ((length & 0x000000FF) >> 24), '\0', '\0', '\0', '\0' });
    
            out.write(data);
            out.flush();
    
    
            is.read
    ...

    Sample Message:
    Code:
    "request":"sender data",
    "data":[
    {
    "host":"myserver.abc.com",
    "key":"tnail-avail",
    "value":"1"
    },
    {
    "host":"myserver.abc.com",
    "key":"tnail-valid",
    "value":"1"
    },
    {
    "host":"myserver.abc.com",
    "key":"tnail-ms",
    "value":"0"
    },
    {
    "host":"myserver.abc.com",
    "key":"tnail-version",
    "value":"7.3.0000"
    }]
    Oddly enough, if I remove the last key/value entry, then Zabbix receives it perfectly fine regardless of whether it's Zabbix 2.2 or 3.2. So there is clearly a limiting factor there but I am unsure what it is exactly.


    We need to do this through java code and not the standalone utility. So if someone provide a better method or a wait to increase the Json limit without decompiling/recompiling server code, I would really appreciate it.

    Bear in mind there are hundred of these agents running and recording data, so we need a solution that is easy to distribute.
  • glebs.ivanovskis
    Senior Member
    • Jul 2015
    • 237

    #2
    I guess you are missing top-level {} around your JSON. And maybe you are miscalculating message length, validation is stricter since 3.0. What is in response of Zabbix server? Have you checked log file for errors?

    Comment

    • estein
      Junior Member
      • Mar 2017
      • 4

      #3
      The JSON is fine. I just forgot some brackets in the posting to this forum.

      Also, I forgot to indicate that

      Code:
      data = jsonString.getBytes();
      The log reports the following:

      Code:
      371:20170105:152004.579 Message from x.x.x.x is longer than expected xxx bytes. Message ignored.
      And the Zabbix socket input stream is empty as a result of the message being discarded.

      How is the validation determined? What is the maximum byte length allowed? Can this be changed somewhere?

      Comment

      • estein
        Junior Member
        • Mar 2017
        • 4

        #4
        RESOLVED: Json Message Length issue

        Looks the problem was how we were building the byte message. Needed SHIFTRIGHT and then AND

        Code:
         out.write(new byte[] { 
                		'Z', 'B', 'X', 'D', '\1',
                        (byte) ((length >> 0)  & 0xFF), 
                        (byte) ((length >> 8)  & 0x00FF),
                        (byte) ((length >> 16) & 0x0000FF),
                        (byte) ((length >> 24) & 0x000000FF), 
                        '\0', '\0', '\0', '\0' });

        Comment

        • wang.hy8166
          Junior Member
          • Nov 2018
          • 1

          #5
          mark for:
          293:20181106:000531.093 Message from 172.18.0.1 is shorter than expected 12435439 bytes. Message ignored.

          Comment

          Working...