Ask Your Question
0

multiple elsif-else in nrpe template file

asked 2017-09-03 08:02:26 -0600

sinaowolabi gravatar image

updated 2017-09-03 08:29:28 -0600

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-09-03 09:02:57 -0600

sinaowolabi gravatar image

I had a typo:

@fqdn =

instead of

@fqdn ==

in one section. All is well now.

I feel so dumb.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-09-03 08:02:26 -0600

Seen: 19 times

Last updated: Sep 03