log object attributes
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.
Another thing that does not work:
for (var key => var value in this) {
log("Key: " + key + ", Value: " + String(value))
}
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?
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.