Xymon Mailing List Archive search

Variables in config files

4 messages in this thread

list Scot Kreienkamp · Wed, 16 May 2018 17:53:38 +0000 ·
Hi everyone,

Is there a way to define a line or part of a line as a variable in the config files, then use that variable in other places, other than the .default line?  I know it's possible in alerts, but how about hosts.cfg and hosts.d/*, or analysis.cfg and analysis.d/*?

For example, like this:

$DOWNTIME='DOWNTIME=*:6:2200:2359:Scheduled maintenance,*:0:0000:0400:Scheduled maintenance'


0.0.0.0   test1.lzb.hq # $DOWNTIME

0.0.0.0   test2.lzb.hq # $DOWNTIME


Yes, I realize I could use the .default line, but I can't set that once then have that available everywhere.  If I change it later in the config then it won't be available to the rest of the config yet to come.  For the variables I'd like to be able to set the variable and have it available throughout the entire config.  That way I only have to change it in one place.  Right now I have the .default line duplicated many times in my config, and if I have to make a change to them all it starts to become a lot of work.


Thanks!

Scot Kreienkamp | Senior Systems Engineer | La-Z-Boy Corporate
One La-Z-Boy Drive | Monroe, Michigan 48162  | * XXX-XXX-XXXX | | * 7349151444 | *  user-9678697f1438@xymon.invalid<mailto:%7BE-mail%7D>
www<http://www.la-z-boy.com/>.la-z-boy.com<http://www.la-z-boy.com/>; | facebook.<https://www.facebook.com/lazboy>com<https://www.facebook.com/lazboy>/<https://www.facebook.com/lazboy>lazboy<http://facebook.com/lazboy>; | twitter.com/lazboy<https://twitter.com/lazboy>; | youtube.com/<https://www.youtube.com/user/lazboy>lazboy<https://www.youtube.com/user/lazboy>;

[cid:lzbVertical_hres.jpg]


This message is intended only for the individual or entity to which it is addressed.  It may contain privileged, confidential information which is exempt from disclosure under applicable laws.  If you are not the intended recipient, you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information.  If you have received this communication in error, please notify us immediately by e-mail or by telephone at the above number. Thank you.
Attachments (1)
list Scot Kreienkamp · Wed, 16 May 2018 18:13:52 +0000 ·
As a followup, the other problem with the .default line is that it ignores any custom tags that I have on the hosts.  I have custom tags on many hosts that I use with custom tests and xymongrep, and the custom tags on .default lines are never matched.


Scot Kreienkamp |Senior Systems Engineer | La-Z-Boy Corporate
One La-Z-Boy Drive| Monroe, Michigan 48162 | Office: XXX-XXX-XXXX | | Mobile: XXXXXXXXXX | Email: user-9678697f1438@xymon.invalid
quoted from Scot Kreienkamp
From: Scot Kreienkamp
Sent: Wednesday, May 16, 2018 1:54 PM
To: 'xymon >> xymon at xymon.com' <xymon at xymon.com>
Subject: Variables in config files

Hi everyone,

Is there a way to define a line or part of a line as a variable in the config files, then use that variable in other places, other than the .default line?  I know it's possible in alerts, but how about hosts.cfg and hosts.d/*, or analysis.cfg and analysis.d/*?

For example, like this:

$DOWNTIME='DOWNTIME=*:6:2200:2359:Scheduled maintenance,*:0:0000:0400:Scheduled maintenance'


0.0.0.0   test1.lzb.hq # $DOWNTIME

0.0.0.0   test2.lzb.hq # $DOWNTIME


Yes, I realize I could use the .default line, but I can't set that once then have that available everywhere.  If I change it later in the config then it won't be available to the rest of the config yet to come.  For the variables I'd like to be able to set the variable and have it available throughout the entire config.  That way I only have to change it in one place.  Right now I have the .default line duplicated many times in my config, and if I have to make a change to them all it starts to become a lot of work.


Thanks!

Scot Kreienkamp | Senior Systems Engineer | La-Z-Boy Corporate
One La-Z-Boy Drive | Monroe, Michigan 48162  | * XXX-XXX-XXXX | | * 7349151444 | *  user-9678697f1438@xymon.invalid<mailto:%7BE-mail%7D>
www<http://www.la-z-boy.com/>.la-z-boy.com<http://www.la-z-boy.com/>; | facebook.<https://www.facebook.com/lazboy>com<https://www.facebook.com/lazboy>/<https://www.facebook.com/lazboy>lazboy<http://facebook.com/lazboy>; | twitter.com/lazboy<https://twitter.com/lazboy>; | youtube.com/<https://www.youtube.com/user/lazboy>lazboy<https://www.youtube.com/user/lazboy>;

[cid:image001.jpg at 01D3ED20.1BE22C20]
quoted from Scot Kreienkamp


This message is intended only for the individual or entity to which it is addressed.  It may contain privileged, confidential information which is exempt from disclosure under applicable laws.  If you are not the intended recipient, you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information.  If you have received this communication in error, please notify us immediately by e-mail or by telephone at the above number. Thank you.
list John Thurston · Wed, 16 May 2018 10:18:21 -0800 ·
quoted from Scot Kreienkamp
On 5/16/2018 9:53 AM, Scot Kreienkamp wrote:
Yes, I realize I could use the .default line, but I can’t set that once then have that available everywhere.  If I change it later in the config then it won’t be available to the rest of the config yet to come.

I'm not contesting your desire for a variable (or 'macro'), but ponder your statement about .default. lines.

Something set in a .default. line remains the 'default' until changed in a later .default. line. It can be altered per-host without affecting its status as a 'default'.

0.0.0.0  .default.   # nopropred:+msgs

0.0.0.0  foo.xyz.com # nopropred:-msgs
0.0.0.0  bar.xyz.com #

0.0.0.0  .default.   #
0.0.0.0  baz.xyz.com #

In the above example, hosts foo and baz will propagate their red msgs results. Foo, because the default value has been overridden with a specific tag. Baz, because the default value has been changed.


Answering your specific question about variables. The 'macro' capability available in alerts.cfg is not available in hosts.cfg


If I had to solve the problem you are describing, I'd probably create create a meta-hosts.cfg and a post-edit-processing script to implement a macro function similar to what is available in alerts.cfg. It wouldn't be too hard to:
  grep all lines leading with $
  build a sed command file with search/replace from those lines
  sed the meta-hosts.cfg to create an active hosts.cfg


-- 
    Do things because you should, not just because you can.

John Thurston    XXX-XXX-XXXX
user-ce4d79d99bab@xymon.invalid
Department of Administration
State of Alaska
list Scot Kreienkamp · Mon, 21 May 2018 13:16:12 +0000 ·
That's what I was afraid of.  If the macro functionality could be extended to all the config files that would make things much simpler.

JC, can I put in a feature request for extending the macro to all the config files?
signature


Scot Kreienkamp |Senior Systems Engineer | La-Z-Boy Corporate
One La-Z-Boy Drive| Monroe, Michigan 48162 |  Office: XXX-XXX-XXXX |  |  Mobile: XXXXXXXXXX | Email: user-9678697f1438@xymon.invalid
-----Original Message-----

quoted from John Thurston
From: Xymon [mailto:xymon-bounces at xymon.com] On Behalf Of John Thurston
Sent: Wednesday, May 16, 2018 2:18 PM
To: xymon at xymon.com
Subject: Re: [Xymon] Variables in config files


On 5/16/2018 9:53 AM, Scot Kreienkamp wrote:
Yes, I realize I could use the .default line, but I can’t set that once
then have that available everywhere.  If I change it later in the config
then it won’t be available to the rest of the config yet to come.

I'm not contesting your desire for a variable (or 'macro'), but ponder
your statement about .default. lines.

Something set in a .default. line remains the 'default' until changed in
a later .default. line. It can be altered per-host without affecting its
status as a 'default'.

0.0.0.0  .default.   # nopropred:+msgs

0.0.0.0  foo.xyz.com # nopropred:-msgs
0.0.0.0  bar.xyz.com #

0.0.0.0  .default.   #
0.0.0.0  baz.xyz.com #

In the above example, hosts foo and baz will propagate their red msgs
results. Foo, because the default value has been overridden with a
specific tag. Baz, because the default value has been changed.


Answering your specific question about variables. The 'macro' capability
available in alerts.cfg is not available in hosts.cfg


If I had to solve the problem you are describing, I'd probably create
create a meta-hosts.cfg and a post-edit-processing script to implement a
macro function similar to what is available in alerts.cfg. It wouldn't
be too hard to:
  grep all lines leading with $
  build a sed command file with search/replace from those lines
  sed the meta-hosts.cfg to create an active hosts.cfg


--
    Do things because you should, not just because you can.

John Thurston    XXX-XXX-XXXX
user-ce4d79d99bab@xymon.invalid
Department of Administration
State of Alaska


This message is intended only for the individual or entity to which it is addressed.  It may contain privileged, confidential information which is exempt from disclosure under applicable laws.  If you are not the intended recipient, you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information.  If you have received this communication in error, please notify us immediately by e-mail or by telephone at the above number. Thank you.