Ad Widget

Collapse

Need help creating a template with HTTP Agent and nested JSON

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bpmbee
    Junior Member
    • Sep 2021
    • 1

    #1

    Need help creating a template with HTTP Agent and nested JSON

    Hi!

    I am trying to create a template for Hetzner Cloud to monitor all the infrastructure there that I cannot install an agent on (mainly loadbalancers). I've been able to discover the loadbalancers and add them as discovered items using item prototypes. This gives me basic information like its ID, name and location and whether delete protection is on.

    Now, I would like to add the health status of all the targets but I haven't been able to do so. I have an item prototype that collects all the targets and was hoping to use that to filter this information. What I would like to end up with are multiple loadbalancer items that use its name and then have information on all the target health checks.

    I currently have a master item that returns the JSON at the bottom of this post and then create {#LB_NAME} and {#LB_ID} using a discovery rule with a JavaScript preprocessing rule like this:

    Code:
    var result = [];
    var loadbalancers = JSON.parse(value);
    
    loadbalancers.forEach(function(lb) {
    
    result.push({
    '{#LB_ID}': lb.id,
    '{#LB_NAME}': lb.name,
      });
    });
    
    return JSON.stringify(result);​
    I then collect the protection status using another item prototype with JSONPath preprocessing:

    Code:
    $.[?(@.id == {#LB_ID})].protection.delete.first()
    I then name (key) these items using {#LB_NAME}.

    I am wondering if I should continue going down this road or if I should consider using host prototypes? I could maybe create a host for every loadbalancer and collect the information from there? Not sure if that would make it easier (will try) but I was simply wondering if anyone can give me some pointers on how to resolve an issue like this.


    return from master item:
    Code:
    [{"included_traffic":21990232555520,"ingoing_traffic":3740000,"targets":[{"type":"server","health_status":[{"listen_port":443,"status":"healthy"},{"listen_port":80,"status":"healthy"}],"use_private_ip":true,"server":{"id":41892916}},{"type":"server","health_status":[{"listen_port":443,"status":"healthy"},{"listen_port":80,"status":"healthy"}],"use_private_ip":true,"server":{"id":41892914}},{"type":"server","health_status":[{"listen_port":443,"status":"healthy"},{"listen_port":80,"status":"healthy"}],"use_private_ip":true,"server":{"id":41892951}}],"private_net":[{"ip":"10.6.0.4","network":3319470}],"services":[{"proxyprotocol":true,"listen_port":443,"protocol":"tcp","health_check":{"timeout":10,"retries":3,"port":443,"interval":15,"protocol":"tcp"},"destination_port":443},{"proxyprotocol":true,"listen_port":80,"protocol":"tcp","health_check":{"timeout":10,"retries":3,"port":80,"interval":15,"protocol":"tcp"},"destination_port":80}],"public_net":{"ipv4":{"ip":"1.1.1.1","dns_ptr":"static.1.1.1.1.clients.your-server.de"},"ipv6":{"ip":"ipv6_address","dns_ptr":""},"enabled":true},"name":"load-balancer-1","load_balancer_type":{"deprecated":null,"max_connections":10000,"max_targets":25,"max_assigned_certificates":10,"id":1,"max_services":5,"description":"LB11","prices":[{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"hel1"},{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"ash"},{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"nbg1"},{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"hil"},{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"fsn1"}],"name":"lb11"},"labels":{},"protection":{"delete":false},"algorithm":{"type":"round_robin"},"created":"2023-09-09T09:18:41Z","id":1437869,"outgoing_traffic":170065000,"location":{"network_zone":"eu-central","city":"Nuremberg","longitude":11.076665,"id":2,"description":"Nuremberg DC Park 1","latitude":49.452102,"country":"DE","name":"nbg1"}},{"included_traffic":21990232555520,"ingoing_traffic":3985000,"targets":[{"type":"server","health_status":[{"listen_port":443,"status":"healthy"},{"listen_port":80,"status":"healthy"}],"use_private_ip":true,"server":{"id":41892914}},{"type":"server","health_status":[{"listen_port":443,"status":"healthy"},{"listen_port":80,"status":"healthy"}],"use_private_ip":true,"server":{"id":41892916}},{"type":"server","health_status":[{"listen_port":443,"status":"healthy"},{"listen_port":80,"status":"healthy"}],"use_private_ip":true,"server":{"id":41892951}}],"private_net":[{"ip":"10.6.0.6","network":3319470}],"services":[{"proxyprotocol":true,"listen_port":443,"protocol":"tcp","health_check":{"timeout":10,"retries":3,"port":443,"interval":15,"protocol":"tcp"},"destination_port":443},{"proxyprotocol":true,"listen_port":80,"protocol":"tcp","health_check":{"timeout":10,"retries":3,"port":80,"interval":15,"protocol":"tcp"},"destination_port":80}],"public_net":{"ipv4":{"ip":"2.2.2.2","dns_ptr":"static.2.2.2.2.clients.your-server.de"},"ipv6":{"ip":"2a01:4f8:c01e:e4::1","dns_ptr":""},"enabled":true},"name":"load-balancer-2","load_balancer_type":{"deprecated":null,"max_connections":10000,"max_targets":25,"max_assigned_certificates":10,"id":1,"max_services":5,"description":"LB11","prices":[{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"hel1"},{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"ash"},{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"nbg1"},{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"hil"},{"price_monthly":{"net":"5.3900000000","gross":"5.3900000000000000"},"price_hourly":{"net":"0.0088000000","gross":"0.0088000000000000"},"location":"fsn1"}],"name":"lb11"},"labels":{},"protection":{"delete":false},"algorithm":{"type":"round_robin"},"created":"2024-01-09T21:14:20Z","id":1633077,"outgoing_traffic":2345000,"location":{"network_zone":"eu-central","city":"Falkenstein","longitude":12.370071,"id":1,"description":"Falkenstein DC Park 1","latitude":50.47612,"country":"DE","name":"fsn1"}}]
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    For the sake of clarity, I would create host per LB...

    Comment

    Working...