Use closure-like statement to manipulate response

Hi,

I often have to deal with weird units returned by snmp devices (like temp values * 10; 34,2 degrees = 342). Warn an crit values are no problem but the frontend users in icingaweb2 may don’t know the correct interpretation of the value. I know I could write a python/bash wrapper script to get the snmp value, calculate it to my desired unit and output it back to icinga2 but it would be cool to use just a simple closure script to edit values like below in var.snmp_perfdata:

apply Service for (snmp_command => command in host.vars.snmp) {
  import "generic-service"

  check_command = "snmp"
  display_name = snmp_command

  vars.snmp_oid = command.oid
  vars.snmp_warn = command.warn
  vars.snmp_crit = command.crit

  vars.snmp_perfdata = {
    return command.perfdata / 10
  }

  assign where host.vars.snmp
}

Does this make sense? Is there any interest in this? Does it make sense to file this in github? I would expect it would take a lot of effort…

Sounds like useful feature in general, so yeah, why not (but no guarantee that this will happen soon).

I think the most useful and probably least painful way to realize would be to add some kind of transform_checkresult attribute to checkables that can be set to a function, so that you could use it something like this:

object Service ... {
  transform_checkresult = (cr) => {
    // update `cr.performance_data` here
  }
}

This should then also allow things like this as well: Add support for in-memory negation of CheckCommand results · Issue #6937 · Icinga/icinga2 · GitHub