Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

multiple elsif-else in template files

Hi!

I am trying to generate an nrpe template file that is used by all the servers on the network. I have a general command section which is used by all the servers to have a default set of commands, and I am trying to use if-elsif-else to have commands that would apply to specific servers based on @fqdn regexes. The nrpe file looks somewhat like this:

# -- all servers section --
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
......

#--per server section --
<% if $ipaddress_docker0 -%>
command[docker_command1]....
command[docker_command2]...
<% end -%>
<% if  @fqdn == 'server1.internal.com' -%>
command[server1_command1]....
command[server1_command2]...
<% elsif  @fqdn == 'server2.testing.internal.com' -%>
command[server2.testing_command1]....
command[server2.testing_command2]...
<% elsif  @fqdn =~ /^(pushserver|pullserver)\d\.internal\.com/ -%>
command[pushserver_command1]....
command[pullserver_command2]...
<% elsif  @fqdn =~ /^(aliveserver|deadserver)\.internal\.com/ -%>
command[deadserver_command1]....
command[aliveserver_server_command2]...
<% end -%>

The problem is, not all servers get the correct set of commands, and some get extra. For instance I might find the commands specific to deadserver and aliveserver in the nrpe config file for server2.testing, and server1 might not have its complete set of commands.

Please what am I doing wrong, and how can I fix it?

multiple elsif-else in template files

Hi!

I am trying to generate an nrpe template file that is used by all the servers on the network. I have a general command section which is used by all the servers to have a default set of commands, and I am trying to use if-elsif-else to have commands that would apply to specific servers based on @fqdn regexes. The nrpe file looks somewhat like this:

# -- all servers section --
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
......

#--per server section --
<% if $ipaddress_docker0 -%>
command[docker_command1]....
command[docker_command2]...
<% end -%>
<% if  @fqdn == 'server1.internal.com' -%>
command[server1_command1]....
command[server1_command2]...
<% elsif  @fqdn == 'server2.testing.internal.com' -%>
command[server2.testing_command1]....
command[server2.testing_command2]...
<% elsif  @fqdn =~ /^(pushserver|pullserver)\d\.internal\.com/ -%>
command[pushserver_command1]....
command[pullserver_command2]...
<% elsif  @fqdn =~ /^(aliveserver|deadserver)\.internal\.com/ -%>
command[deadserver_command1]....
command[aliveserver_server_command2]...
<% end -%>

The problem is, not all servers get the correct set of commands, and some get extra. For instance I might find the commands specific to deadserver and aliveserver in the nrpe config file for server2.testing, and server1 might not have its complete set of commands.

Please what am I doing wrong, and how can I fix it?