Ad Widget

Collapse

Cannot find the "data" array in the received JSON object - Custom LLD rules

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pengels
    Junior Member
    • Feb 2021
    • 6

    #1

    Cannot find the "data" array in the received JSON object - Custom LLD rules


    Hello! I'm trying to get automatic monitoring of remote mounts going, but I'm getting this error: I have this script that is run by the discovery rule:

    Code:
    #!/usr/bin/env python3
    
    import re
    
    # Empty dictionary for later
    mounts_dict = {"data": []}
    
    # read /etc/fstab to get any permanent mounts
    f = open("/etc/fstab", "r")
    fstab = f.read()
    
    # search through /etc/fstab to find IP addresses
    list_of_ips = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", fstab)
    
    # Search through all the lines in /etc/fstab
    for line in fstab.split('\n'):
    # search each line to see if it's a remote mount
    for entry in list_of_ips:
    # append the local path to the mount dictionary if it's valid
    if line.find(entry) != -1:
    mount_name = line.split()[1]
    formatted_entry = ({"{#MOUNTPOINT}":"%s" % (mount_name)})
    if formatted_entry not in mounts_dict["data"]:
    mounts_dict["data"].append(formatted_entry)
    
    # Print it out and hope Zabbix understands
    print(mounts_dict)
    This script is run via this in Zabbix:
    template->Discovery Rules->This item, which does
    system.run[/path/to/script/zabbix_enumerate_mounts.py]

    When I run this on the command line, I get this output:
    root@system $ /path/to/script/zabbix_enumerate_mounts.py
    Code:
    {'data': [{'{#MOUNTPOINT}': '/mount/orders'}, {'{#MOUNTPOINT}': '/mount/downloads'}]}
    Item prototype is to check for a .placeholder file inside that mount to check if the mount is working. It's running this:
    vfs.file.exists[{#MOUNTPOINT}/.placeholder]

    When I try to run the discovery rule in Zabbix by checking the box and clicking "Execute Now", I get this error: Cannot find the "data" array in the received JSON object.

    I tried to follow this format:https://www.zabbix.com/documentation...stom_lld_rules

    I've also tried it where I get this output, with the same error message:
    Code:
    [{'{#MOUNTPOINT}': '/mount/orders'}, {'{#MOUNTPOINT}': '/mount/downloads'}]
    I accomplish this by making mounts_dict just a list instead of a dictionary with the data key.

    I've tried copying/pasting the sample output from the above link and just writing a script that spits that out, and I still get the same error, so I don't know if the format is the issue. I've also tried the lowercase macro names and the JSONpath thingy too.

    Running Zabbix 5.0.8 on CentOS 7. Remote systems are also CentOS 7. Does anyone have any insight?
    Last edited by pengels; 09-02-2021, 22:54.
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    Try
    Code:
    [{"{#MOUNTPOINT}": "/mount/orders"}, {"{#MOUNTPOINT}": "/mount/downloads"}]
    Code:
    {"data":[{"{#MOUNTPOINT}": "/mount/orders"}, {"{#MOUNTPOINT}": "/mount/downloads"}]}
    Last edited by Hamardaban; 10-02-2021, 20:30.

    Comment

    • pengels
      Junior Member
      • Feb 2021
      • 6

      #3
      Still nothing. Thanks for the suggestion, though. The error stayed the same and everything.

      Comment


      • Hamardaban
        Hamardaban commented
        Editing a comment
        Tested (again) the lld operation on your json-items are being created. The syntax I wrote is correct. (zabbix 5.2)
    • pengels
      Junior Member
      • Feb 2021
      • 6

      #4
      Here's what the log says:
      Code:
      102160:20210211:080414.160 End of zbx_waitpid():88993
      102160:20210211:080414.160 EXECUTE_STR() command:'/opt/scripts/zabbix_enumerate_mounts.py' len:99 cmd_result:'
      {"data":[{"{#MOUNTP'
      102160:20210211:080414.160 Sending back [
      {"data":[{"{#MOUNTPOINT}": "/mount/orders"}, {"{#MOUNTPOINT}": "/mount/downloads"}]}]
      102160:20210211:080414.160 zbx_setproctitle() title:'listener #1 [waiting for connection]'
      102162:20210211:080414.160 In zbx_tls_accept()
      To test your syntax, I just copied/pasted it into a print statement, so it should only have returned what you sent. I believe you that the syntax is correct, and it looks like it's sending back correctly. Is there something goofy somewhere else? Is the server just confused about it?

      Comment

      • pengels
        Junior Member
        • Feb 2021
        • 6

        #5
        Here's what it looks like in the server template config:
        Click image for larger version

Name:	find_all_mounts.png
Views:	5690
Size:	30.4 KB
ID:	418609

        I left Preprocessing, LLD Macros, Filters, and Overrides default. Here's the item prototype:

        Click image for larger version

Name:	item_prototype.png
Views:	5634
Size:	40.2 KB
ID:	418610

        Comment

        • pengels
          Junior Member
          • Feb 2021
          • 6

          #6
          oh goodness gracious. I had a silly thing in preprocessing left over from testing a week ago that was goofing it all up. Thank you for your replies.

          Comment

          Working...