[Nagiosplug-devel] [RFC] Plugins config file

Vonnahme, Nathan nathan.vonnahme at bannerhealth.com
Thu Oct 19 21:49:23 CEST 2006


Ton Voon wrote,

> 	However, if you use Nathan's separate args form, you'd have to
parse all the options before you can replace (as you may not want the
default stanza name). Also where do you replace?
> 
> 	./check_mysql -S --cfg-file= -H localhost --cfg-stanza=
> 
> 	Do you replace --cfg-file or --cfg-stanza? I think to avoid the
confusion (at the expense of a more obscure syntax), it should be a
single option. This then allows Gavin's request of having multiple
options. So:
> 
> 	./check_mysql -S --extra-opts= --extra-opts=more_options -H
localhost
> 
> 	Is effectively:
> 
> 	./check_mysql -S --username=tonvoon --password=secret
--username=altinity --warning=10 --critical=15 -H localhost
> 
> 	I think this is fairly intuitive. Notice username is listed
twice. I don't think the "replacement opts" function should care what
has passed before or after - it just puts everything down since some
plugins expect arguments a multiple number of times (check_disk -p / -p
/var). How the plugin responds to double requests is the plugin's
responsibility.



I guess I was thinking you'd parse the options and then load the config
files, but always allow explicit command line options to override things
in the cfg files.  

something like this (Perlishly... sorry my C is too rusty):


given the invocation
	./check_mysql -S --extra-opts= --extra-opts=more_options -H
localhost --critical=99

and the files default.cfg (username=tonvoon, password, warning,
critical) and more_options (username=altinity)


get all the command line options, giving you a data structure like this:
	$opts = [
		{name=>S, value=>undef},
		{name=>host , value=>localhost},
		{name=>extra-opts, value=>undef},
		{name=>extra-opts, value=>more_options},
		{name=>critical, value=>99},
	];

then, for each extra-opts arg, slurp the appropriate part of the
appropriate config file into the $opts array, and delete the extra-opts
options.  In this case the username from the second config file would
overwrite the first, and the data structure would end up:
	$opts = [
		{name=>S, value=>undef},
		{name=>host , value=>localhost},
		{name=>username , value=>altinity},
		{name=>password, value=>secret},
		{name=>warning, value=>10},
		{name=>critical, value=>99},
	];


If you are parsing it this way, having two separate options for file and
stanza makes sense, and allows you to, for example:

load all args from the 'my_plugin' stanza of the default cfg file
	my_plugin --cfg-file			

load from the mysql stanza of the default cfg file instead
	my_plugin --cfg-stanza=mysql

load all args from the 'my_plugin' stanza of the /other/file cfg file
	my_plugin --cfg-file=/other/file	

load args from the default cfg file, but then override from the mysql
stanza from /other/file, but override any definition of 'critical' in
the cfg files with critical=99
	my_plugin --critical=99 --cfg-file --cfg-file=/other/file
--cfg-stanza=mysql


So we would have clear syntax, and clear expectations that command line
options override things in the cfg files and the second cfg file
mentioned in the command line options overrides the first.  






More information about the Devel mailing list