Ad Widget

Collapse

http_agent lld missing Convert to Json (output_format) option

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gchalmers_aus
    Junior Member
    • Apr 2019
    • 2

    #1

    http_agent lld missing Convert to Json (output_format) option

    Hello forum,
    In low level discovery I have created a http agent rule to return data from a REST API.
    It connects and returns data successfully however without a "data" tag on the front.

    If I create an item directly I have the option to "convert to JSON" which works as expect, however this option is not available when creating a lld.

    It is documented in api/reference/discoveryrule/object as output_format with a value of 0 or 1


    Troubleshooting:
    Versions:
    I have tried on both 4.05 and 4.2-1.el7 (latest).

    Export/Import:
    I have tried exporting the template adding the "output_format" and importing it back in however that errors with a message about the unknown tag "output_format".

    API:
    I have tried using the api to get the discovery rule - success but no output_format tag,
    Using the api to get the item with the convert to json ticked returns the item with the output_format tag

    updating the discovery rule with output_format
    {
    "jsonrpc": "2.0",
    "method": "discoveryrule.update",
    "params": {
    "itemid": "237182",
    "output_format": "1"

    },
    "id": 1,
    "auth": "xxxxxx"
    }

    success:

    {
    "jsonrpc": "2.0",
    "result": {
    "itemids": [
    "237182"
    ]
    },
    "id": 1
    }

    however the discovery rule does not convert to json as expected.



    Is this by design or a bug that low level discovery using http_agent does not allow convert to json?


  • mariusl
    Junior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Aug 2024
    • 25

    #2
    Stumbeled upon the same issue in Zabbix 7.2. Trying to create a LLD rule from an URL that is returning clear text data, but don't have the convert to JSON option so i get an error

    > Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: '0'

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #3
      Originally posted by mariusl
      Stumbeled upon the same issue in Zabbix 7.2. Trying to create a LLD rule from an URL that is returning clear text data, but don't have the convert to JSON option so i get an error

      > Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: '0'
      Is there by any chance some headers in output? Something like
      HTTP/1.1 200 OK
      Connection: close
      Content-Length: 86944
      Content-Type: application/json
      X-Content-Type-Options: nosniff
      you should run some preprocessing, to get rid of that...

      Comment

      • mariusl
        Junior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Aug 2024
        • 25

        #4
        Originally posted by cyber

        Is there by any chance some headers in output? Something like

        you should run some preprocessing, to get rid of that...
        Thanks for your reply. It doesn't seem to be headers that are the problem. The returned data is simply "mydata=0" which is not in JSON format. This is what the error message indicates.
        Our problem is that the function "Convert to JSON" on HTTP agent is missing when using it in a discovery rule.

        This item is present and available when creating a regular item:
        Click image for larger version  Name:	image.png Views:	0 Size:	22.4 KB ID:	498702

        But missing from when HTTP agent is used in a discovery rule:
        Click image for larger version  Name:	image.png Views:	0 Size:	25.0 KB ID:	498703

        Only workaround i have found it to create a regular item converting to JSON, then use that as a master item a dependent discovery rule.
        However, my next problem is that the converted JSON is in wrong format as there is no array. Have tried using multiple different JSONPaths:
        * $..body
        * $.body
        * $.. (terminates unexpectedly)

        Returned data from the item before converting to JSON is "mydata=0" in clear text. After using the "convert to JSON" function i get this, without an array:
        Code:
        {"body":"mydata=0"}
        Click image for larger version  Name:	image.png Views:	0 Size:	8.5 KB ID:	498704

        I should probably create a new thread about this though.
        Last edited by mariusl; 07-02-2025, 11:08.

        Comment

        • cyber
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Dec 2006
          • 4807

          #5
          You could submit a bug about htis... I dont see any reason why this should be different if used in discovery vs used in normal item.

          Comment

          • mariusl
            Junior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Aug 2024
            • 25

            #6
            Bug report submitted in [ZBX-26022]

            Comment

            Working...