View Full Version : Command Line Arguments to User Parameters
I've recently upgraded to 1.1alpha6 and I noticed in the ChangeLog that Zabbix now supports the passing of command line arguments to user parameters? How do we use such arguments? What is an example UserParameter= line for the zabbix_agent/d.conf file?
-Azrael
It is not documented yet.
First, you create a flexible user parameter:
UserParameter=lineno
, command
You may substitute '*' with any argument and the argument will be passed to the command untouched:
lineno[/] will be trasformed to 'command /'
lineno[/tmp] will be transformed to 'command /tmp'
Though I'm concerned about security and usability of this solution. Perhaps I'll rewrite it to pass parameter in an environment variable.
Awesome stuff.
Do you think at some point you'll change it so the argument is more flexible, as in it isn't just appended to the end of the command? Maybe something where you can specify the location of the argument with $1 or whatever... and support for more than one argument?
Yeah security can definitely be a big issue here. Perhaps wait till a better authentication system is in place between the agents and the server? As well as encryption?
Great work btw. I look forward to the official 1.1 release.
-Azrael
Do you think at some point you'll change it so the argument is more flexible, as in it isn't just appended to the end of the command? Maybe something where you can specify the location of the argument with $1 or whatever... and support for more than one argument? Actually I'd like arguments to be passed as environment variables, like $1. Then I could implement multi-parameters, so something[a,b,c] will be translated to command $1 $2 $3, where $1=a, $2=b, $3=c.
mdeavila
22-03-2005, 21:13
Can I pass multiple values to a UserParameter defined in the agentd config file?
I want to specify a key like this on the zabbix server side,
apmonitor[cee272,cee27b,submitted]
In the agetnd config file I have a UserParameter defined as
UserParameter=apmonitor ,apmonitor
The goal is to invoke the command
apmonitor cee272 cee27b submitted
Is this doable in 1.1alpha7?
thanks,
Miguel DeAvila
ZABBIX will invoke apmonitor cee272,cee27b,submitted in your case. It is up-to your script to parse command line arguments.
Alternatively you may use apmonitor[cee272 cee27b submitted] to get rid of commas.
mdeavila
23-03-2005, 00:45
I've defined an item on the zabbix server using the key
apmonitor[cee272 cee27b submitted]
On the agent side, I've defined a UserParameter,
UserParameter=apmonitor ,apmonitor
In the agent log I see the following message,
001537:20050322:144108 Got line:apmonitor[cee272 cee27b submitted]
001537:20050322:144111 Sending back:ZBX_NOTSUPPORTED
I'm trying to determine why. I can run the agent from the command line as the zabbix user,
laverne init.d # su - zabbix
zabbix@laverne zabbix $ apmonitor cee272 cee27b submitted
4027
Any suggestions how I can determine why the agentd is sending back ZBX_NOTSUPPORTED?
thanks,
Miguel
mdeavila
24-03-2005, 02:51
The trouble was that command-line arguments are passed to the UserParameter script as a single argument.
In the UserParameter script I was expecting to process the 3 args as $1, $2, and $3. Instead, the args are passed to the script as "arg1 arg2 arg3".
I altered my script so that it accepted a single argument and then parsed it into 3 separate values.
It is not documented yet.
First, you create a flexible user parameter:
UserParameter=lineno
, command
...
Though I'm concerned about security and usability of this solution. Perhaps I'll rewrite it to pass parameter in an environment variable.
well, it seems to be rewritten/changed :)
it now works as i tried to describe in http://www.zabbix.com/forum/showpost.php?p=16553&postcount=22