0

I have hostgroups.cfg file in which i have different hosts with different port no. I want to pass port no for every host to services.cfg file where i have put check_http command.

As my different hosts have different http processes with different port no, so I want to pass port no directly from hosts.cfg file. Is it possible?

Below are my sample entries in hosts and services.cfg file

host file:

        define host{
          use                    abc
          host_name               test
          alias                   /test/
          address                 192.168.0.24
         hostgroups              testgroup
        }

services.cfg file

      define service{
         use                             critical-service
         hostgroup_name                  test
         service_description             HTTP
        check_command                   check_http!8080!7!5
     }

commands.cfg file

    define command{
        command_name    check_http
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -p          
                     $ARG1$ --url $HOSTALIAS$ -c $ARG2$ -w $ARG3$
    }

1 Answer 1

1

In your host config, add a custom variable like so:

define host {
      use                    abc
      host_name              test
      alias                  /test/
      address                192.168.0.24
      hostgroups             testgroup
      _port                  8080
}

Then in your services.cfg, swap the port out for the variable you've set (you'll need to set it for all hosts):

define service {
     use                             critical-service
     hostgroup_name                  test
     service_description             HTTP
     check_command                   check_http!$_HOSTPORT$!7!5
 }
2
  • This is a good idea. You might want to name it __port, so that the variable is $_HOST_PORT$ so it's slightly more readable.
    – Keith
    Apr 13, 2015 at 20:32
  • @Huzefa - Please mark the answer correct if you deem it so.
    – Taz
    Jan 21, 2016 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .