Ad Widget

Collapse

Template help to read host json files?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • G0nz0uk
    Member
    • Apr 2021
    • 46

    #1

    Template help to read host json files?

    Hello,

    I'm still learning how to use Zabbix and quickly finding out how powerful it is. I've managed to created my own SNMP template to monitor a few hundred hosts/devices. These devices also have a json file attached to them on something like:



    Not all hosts have this URL but eventually they all will and I need to alert on information in that json file should we hit a threshold.

    Now I'm a bit lost on this next bit.

    So I've already learnt on how scrape/discovery a json file if it's a large json file dump and pick out what date I need from that. I've done this for another json output I needed Zabbix to read, but this is 1 large json file containing devices/host names and metrics, I used a LLD and Macros and all works nicely.

    This time I need to do the same or similar thing, but for each host/device instead and read their individual json file.

    Do I create a new template and add this as a second template for each host/device to use so they will have an SNMP template and this JSON template I need to create one or is there a better way? I wanted if I can run the SNMP discovery and link this new discovery or template after?

    Also on the discovery I'd need to point to the devices IP address on the url, what would the variable look like to insert the IP URL to scrape/discover?

    https://{HOST.IP}/agent/metrics.json

    Apologies if I've not explained that properly. If I've missed anything off please let me know.

    Thanks
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4806

    #2
    I would keep different things in different tempaltes... If nothing else, at least it makes testing easier, if you can only apply it to some hosts instead of all..
    {HOST:IP} is the one pointing to hosts registered IP (first agent interface, if that is missing, then SNMP, then JMX, then IPMI, then *unknown*)

    Comment

    • G0nz0uk
      Member
      • Apr 2021
      • 46

      #3
      I’ll keep as separate. The thing is not all devices will have the info I need that the 2nd template will try and get. Over time they will though.

      if assign to all and it can’t get that info will it just quickly skip and then try the next host anyway?

      thanks

      Comment

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

        #4
        If you attach a template, which tries to read nonexistent file, you get a "not supprted" item there and It will try again time to time... you can have items disabled in template and only enable those on hosts, where you know this file to be present...

        Comment

        • G0nz0uk
          Member
          • Apr 2021
          • 46

          #5
          Originally posted by cyber
          I would keep different things in different tempaltes... If nothing else, at least it makes testing easier, if you can only apply it to some hosts instead of all..
          {HOST:IP} is the one pointing to hosts registered IP (first agent interface, if that is missing, then SNMP, then JMX, then IPMI, then *unknown*)
          Hello,

          Is it {HOST:IP} or {HOST.IP} ?

          I'd like to use that name to show in the trigger alerts too and I assume this will be {HOST.NAME}

          Comment

          • irontmp
            Member
            • Sep 2023
            • 36

            #6
            Originally posted by G0nz0uk
            Hello,

            I'm still learning how to use Zabbix and quickly finding out how powerful it is. I've managed to created my own SNMP template to monitor a few hundred hosts/devices. These devices also have a json file attached to them on something like:



            Not all hosts have this URL but eventually they all will and I need to alert on information in that json file should we hit a threshold.

            Now I'm a bit lost on this next bit.

            So I've already learnt on how scrape/discovery a json file if it's a large json file dump and pick out what date I need from that. I've done this for another json output I needed Zabbix to read, but this is 1 large json file containing devices/host names and metrics, I used a LLD and Macros and all works nicely.

            This time I need to do the same or similar thing, but for each host/device instead and read their individual json file.

            Do I create a new template and add this as a second template for each host/device to use so they will have an SNMP template and this JSON template I need to create one, or is there a better way? Similar to how seo services for architects optimize multiple aspects of a site, you can keep SNMP and JSON templates separate for clarity and efficiency. I wanted to know if I can run the SNMP discovery and link this new discovery or template after?

            Also on the discovery I'd need to point to the devices IP address on the url, what would the variable look like to insert the IP URL to scrape/discover?

            https://{HOST.IP}/agent/metrics.json

            Apologies if I've not explained that properly. If I've missed anything off please let me know.

            Thanks
            You should create a separate JSON template and link it to each host alongside your SNMP template. Use {HOST.IP} in the URL like https://{HOST.IP}/agent/metrics.json so Zabbix fetches the JSON from the correct host. Then use LLD or dependent items within that template to parse the metrics and trigger alerts. SNMP discovery and JSON discovery can run independently on the same host; there’s no need to combine them.

            Comment

            Working...