icinga2 icon indicating copy to clipboard operation
icinga2 copied to clipboard

log object attributes

Open dwt opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe.

I am currently debugging notifications and am missing a way to log all the attributes that have been assigned to the object.

I have tried several ways to get at the information (see below) but none has given me the information neccessary. What does somewhat work is icinga2 object list as that outputs all the information, but it would be much easier to be able to log that information programmatically with log() during configuration check time.

Describe the solution you'd like

I would like to be able to do something like this (pick any)

apply Notification "mail-icingaadmin" to Service {
  import "mail-service-notification"
  user_groups = host.vars.notification.mail.groups
  users = host.vars.notification.mail.users

  if (service.vars.notification.times) {
    times = service.vars.notification.times
  }
  if ("some-host" == host.name) {
    log(LogCritical, "config", this)
    log(LogCritical, "config", Json.encode(this))
    log(LogCritical, "config", this.as_dict())
  }
  
  assign where host.vars.notification.mail
}

Describe alternatives you've considered

I have tried

log(LogCritical, "config", this)
log(LogCritical, "config", string(this))
log(LogCritical, "config", String(this))
log(LogCritical, "config", Json.encode(this))
log(LogCritical, "config", Dictionary(this))

However none of these seem able to get at the attributes of the object that where set above.

Additional context

This is part of me debugging the config that I am writing.

dwt avatar Jan 12 '22 13:01 dwt

Another thing that does not work:

    for (var key => var value in this) {
      log("Key: " + key + ", Value: " + String(value))
    }

dwt avatar Jan 19 '22 07:01 dwt

I'm not aware of any way to do this from within the config right now. Is it important for you to do it there or is running icinga2 daemon -C and then using icinga2 object list good enough for your scenario?

julianbrost avatar Feb 18 '22 16:02 julianbrost

Well, It is a workaround, but it is really annoying because for all other attributes you can just log() them and see them during icinga daemon -C.

Also log() can easily be combined with if to log only specific stuff - which makes it very convenient when actually using all of the power of the icinga config language.

dwt avatar Feb 18 '22 17:02 dwt