Using Environment Variables in resource.cfg file


#1

Is there a way to reference an environment variable in a resource.cfg file.
Specifically I want to set
xsddb_host=$DATABASE_IP.

I have this env. variable defined in my etc/profile and when I log in as nagios I can echo this value.

Thanks,


#2

why would you want this?
you always use the same IP for the DB… so there’s not much use in this… or am i missing something?

Luca


#3

Let’s say I have a user with an environment variable of:
$ORACLE_BASE=/orabin
Per a quote right out of the resource.cfg file is this:
"Nagios supports up to 32 $USERx$ macros ($USER1$ through $USER32$)"
So, I would put this in my resource.cfg file like this:
$USER3$=/orabin
So yes, nagios is able to reference an envornment variable, but not like you suggested it could.
In your example you have an env variable like this:
$DATABASE_IP=123.123.123.123
So in resource.cfg you would put this:
$USER3$=123.123.123.123
xsddb_host=$USER3$
I can see why you might want to do this. If your DB ip changes alot, then you would only have to modify the $USER3$= ip change and it would apply to all the other definitions that utilize $USER3$.


#4

Hello, in response to Jakkedup and luca.

Luca - Nagios is running on one box and my db is on another. I need to change this for development->testing->production. The IP’s will definitely change between these environments.

Jakkedup - The macro’s are helpful but… if I understand the approach, I would have to change the DB IP in the Nagios file and in my .conf file that stores my export statements for all the other programs that need this IP. I’m trying to only do it in one place. As I’m sure you can imagine if there are two places to make the change, there’s a good chance one of them will get missed.