Skip to main content
Question

Nested Arguments/Variables in Command

  • 13 June 2024
  • 4 replies
  • 71 views

I am trying to do the following

i would like to establis a command like this:

$USER1$/check_cluster --host -l $ARG1$ -w $ARG2$ -c $ARG3$ -d $HOSTSTATEID:'$ARG4$'$,$HOSTSTATEID:'$ARG5$'$,$HOSTSTATEID:'$ARG6$'$,$HOSTSTATEID:#$ARG7$'$ but as expected it won’t work.

 

Is there any way to use a $ARGx$ inside the on-demand Macro : $HOSTSTATEID:hostname$ instead of the “hardcoded” Hostname which i do not want to have inside the command-definition?

 

Regards

Timo

4 replies

Userlevel 1
Badge +8

Gentle Bump. No Ideas, guys/gals?

Userlevel 2
Badge +9

I don’t really understand what you are doing

 

But $HOSTSTATEID  is a system macro, you can’t modify it.

Userlevel 1
Badge +8

I’ll try to explain better ;)

I want to use $HOSTSTATEID according to this Documentation for check_cluster:

https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/clusters.html

 

The command-line would now be:

$USER1$/check_cluster --host -l Cluster-Name -w 1 -c 0 -d $HOSTSTATEID:Testhost1$,$HOSTSTATEID:Testhost2$,$HOSTSTATEID:Testhost3$,$HOSTSTATEID:Testhost4$

 

Testhostx is the Name of the Host in Centreon-Config for which you want to have the Hoststate-ID to be output for.

After replacing the ARGs it would be:

$USER1$/check_cluster --host -l Cluster-Name -w 1 -c 0 -d 0,0,0,0

 

This means i have to use the Name of my Hosts in the Argument itself, i.e ,$HOSTSTATEID:Testhost3$ as the $-Sign starts and ends the Macro.

This would mean, when creating the command to use in my Service/Service-Template i will have to write the Names of the Hosts in each command itself. So if i have different Cluster-Checks, each would have its own command with Hostnames written in there specifically for this one issue where i would need to use THIS command.

 

I am now looking for a way to fill the Part inside the HOSTSTATEID-Macro after the “:” with something i can set right inside the Service itself as an Arguemnt , i.e. $ARG4$

$HOSTSTATEID:”$ARG4$”$ wouldn’t work though as the engine rightfully Ends the Macro at the second “$” which would make it $HOSTSTATEID:”$ followed by non-interpretable String “ARG4 befor he sees another Macro-description $”$ which doesn’t make any sense to the engine.

 

Is there any way i can make this right?


Hope it’s beter to understand now ;)

 

Regards

Timo

 

 

Userlevel 1
Badge +8

Bump?

Reply