sensu / sensu-go

Simple. Scalable. Multi-cloud monitoring.
https://sensu.io
MIT License
1.02k stars 176 forks source link

Token substitution to get iface address from entity attributes is too complex #4144

Open raags opened 3 years ago

raags commented 3 years ago

Feature Suggestion

The default system entity attribute structure is too complex to get the IP address out when using token substitution. The current structure is:

    network:
      interfaces:
      - addresses:
        - 127.0.0.1/8
        - ::1/128
        name: lo
      - addresses:
        - 10.0.2.15/24
        - fe80::26a5:54ec:cf0d:9704/64
        mac: 08:00:27:11:ad:d2
        name: enp0s3
      - addresses:
        - 172.28.128.3/24
        - fe80::a00:27ff:febc:be60/64
        mac: 08:00:27:bc:be:60
        name: enp0s8

The closest I could come up with is:

{{range $iface := .system.network.interfaces }}{{if eq $iface.name "eth0" }}{{index $iface.addresses 0}}{{end}}{{end}}

That still doesn't give the IPaddress due to the cider suffix.

Possible Implementation

  1. Add a ipv4, cidr, mac, ipv6, etc key to the addresses dict
  2. Change structure to be easier to write go template for, for e.g. system.interfaces.eth0.addresses.{ipv4, cidr, mac, ipv6, etc}
  3. Make the keys flat, e.g. system_interfaces_eth0_addr_ipv4
  4. Use a library like Sprig, but the template should ideally be straightforward, and this would make it more complicated.

Context

I have a check that needs the host eth0 IP address. I could have it available in a label or annotation, but it would be good to use the information already collected as an entity attribute.

raags commented 3 years ago

Looks like annotations are also not available via tokens. It'll be good to have access to them as well.

calebhailey commented 3 years ago

Related: https://github.com/sensu/sensu-go/issues/2884