custom variables reset with an 'Apply Configuration'?

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
mon-team
Posts: 171
Joined: Thu Jun 28, 2012 9:22 am

custom variables reset with an 'Apply Configuration'?

Post by mon-team »

Hi,
I've created a custom variable inside a service template, the variable is inherited by the services using this service template.
The default value is zero.

I'd like to use this variable to store a specific value, different for each service. The important thing is that this value should be stored.
However I've seen that after an 'Apply configuration' the value is restored (for all services) at the default value (zero).

Is this behavior correct?
Is there a way to indicate Nagios that the value must not be restored?

Has someone an idea on how to get the result I'm expecting for?

Regards,
Francesco
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: custom variables reset with an 'Apply Configuration'?

Post by rkennedy »

As an example, can you post the template you're using?

Just to clarify -- are you looking to have a variable saved on-going throughout service restarts?
Former Nagios Employee
mon-team
Posts: 171
Joined: Thu Jun 28, 2012 9:22 am

Re: custom variables reset with an 'Apply Configuration'?

Post by mon-team »

Hi rkennedy,
thanks for your quick reply.

I defined the '_HIDDEN' custom variable in the following template

define service {
name BPPM relationship
service_description Define a custom variable to decide if sending an event to BPPM
use generic-service
_HIDDEN 0
register 0

}

I changed to 1 the variable value for a specific service (which uses this template), by running the external command CHANGE_CUSTOM_SVC_VAR. After launching an 'apply configuration', the variable value has been set back to 0.
I 'd like to keep the saved variable value even after service restarts.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: custom variables reset with an 'Apply Configuration'?

Post by tmcdonald »

This looks awfully similar to your other thread which I addressed: https://support.nagios.com/forum/viewto ... 58#p180358

Please in the future only open one thread per issue so we can focus our efforts in one places instead of two.
Former Nagios employee
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: custom variables reset with an 'Apply Configuration'?

Post by rkennedy »

To add to what @tmcdonald mentioned - this is expected behavior. I just finished confirming with our development team. If you're looking to store dynamic variables, you'll need to do so a different way.
Former Nagios Employee
mon-team
Posts: 171
Joined: Thu Jun 28, 2012 9:22 am

Re: custom variables reset with an 'Apply Configuration'?

Post by mon-team »

Hi all,
sorry for the double post @tmcdonald!
Thanks for the information, the situation is now clear to me.
Do you have any suggestion about storing dynamic variables?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: custom variables reset with an 'Apply Configuration'?

Post by rkennedy »

You could probably do so fairly easily with flat files, depending on what the information is / how it is used.

Can you provide a bit more information so we can understand what you're looking to accomplish?
Former Nagios Employee
mon-team
Posts: 171
Joined: Thu Jun 28, 2012 9:22 am

Re: custom variables reset with an 'Apply Configuration'?

Post by mon-team »

Hi,
we want to associate a variable to a service. This variable has to be readable and writeable by external scripts which execute some actions based on the variable value.

In the previous example the custom variable _HIDDEN, is used as a flag. An external script (used as event handler), checks if the service is in UNKNOWN state and has "not valid value" as Status information. If so, it sets the variable to 1 and exits, otherwise it execute an action on an third-party tool.
A second external script periodically calculates the number of services having _HIDDEN=1 and the number of those having _HIDDEN=0.

How can we do that?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: custom variables reset with an 'Apply Configuration'?

Post by ssax »

The only way I can think of is like rkennedy stated, you would need to write it out to a file (or a DB if you're so inclined).
Locked