Custom function stopped working

After updating to icinga2 2.14, I have stopped getting problem notifications and mu recovery notifications are coming multiple times from escalations. I tracked it down to the following error:

Error: Namespace is read-only and must not be modified.

In my notification_commands.conf, I have the following custom function:

globals.set_escalation = function(hostName, serviceName, escalation){
    if( !serviceName ){
        myhost = get_host(hostName)
        myhost.vars.current_escalation = escalation
        log(LogInformation, "User", "SETTING Escalation "+hostName+" to "+escalation)
    } else {
        myservice = get_service(hostName, serviceName)
        myservice.vars.current_escalation = escalation
        log(LogInformation, "User", "SETTING Escalation "+hostName+"!"+serviceName+" to "+escalation)

    return escalation

Said function is called when the notiofication type is “PROBLEM”, and then the current_escalation value is passed to the recovery notification which will suppress recovery notices for other escalations. This worked just fine until the new version, which apparently sets the globals namespace to be read-only, making said function not work. I can’t tell if the issue is in setting the function to be global to begin with, or setting the current_escalation value in the host/service, but either way I need to find out how to resolve this. If it’s the function itself, I make it local to the notification commands themselves, but if it’s setting the current_escalation value then I’m not sure how to do this inside icinga2.

Any and all suggestions would be greatly appreciated!

Found the solution - I needed to declare var my{host|service} to make it work. I had originally had it as just host|service and it didn’t like that after 2.14, so I added the my but didn’t declare as var. At least it works now!

1 Like