Check_tcp in HostGroups


(Arethusa) #1

Hello,

With Nicolai help,my check_tcp work for machine, but one by one.

So now, I try to add it on machines groups.

groups.conf:

object HostGroup "mariaDB" {
   display_name = "mariaDB"

 vars.tcp["3306"] = {
	tcp_port = 3306
	}

 assign where host.address == "192.168.1.10"
 assign where host.address == "192.168.1.11"
 assign where host.address == "192.168.1.12"
}


apply Service "tcp" for ( tcp => config in host.vars.tcp ){
  import “generic-service”

  check_command = “tcp”
  vars += config

  assign where host.address
}

My group apear on icingaweb2, but not the service.

Maybe I do somthing bad ?

Or maybe it’s not possible do to like that.

Thank you.


#2

I don’t see any reference to the group?!


(Arethusa) #3

Hello, thank to answer.

I have try " assign where “mariaDB” in host.groups":

apply Service "tcp" for ( tcp => config in host.vars.tcp ){
  import “generic-service”

  check_command = “tcp”
  vars += config

  assign where "mariaDB" in host.groups
}

The problem is the same.


(Nicolai) #4

You define your customvars inside your host group, but the check is accessing the host variables.

I’d suggest to define your customvars in a host template which is imported by the specific hosts:

template Host "mariadb-host" {
  vars.tcp["MariaDB"] = {
    tcp_port = 3306
  }
}

object Host "your-db-server" {
  import "mariadb-host"

  // [..]
}

apply Service "tcp" for ( name => config in host.vars.tcp ){
  import “generic-service”

  check_command = “tcp”
  vars += config
}

(Arethusa) #5

Hello,

I understand you idea.
The problem is I have lot of type of server ( one by port in this case).
And If I have to do template for each type, that will be more fast to do like this:

   #-------------------------------
    object Host "mariaDB1" {
      import "generic-host"
      address = "192.168.1.10"

      vars.tcp["3306"] = {
           tcp_port = 3306
    }
    }
    #-------------------------------
    object Host "mariaDB2" {
      import "generic-host"
      address = "192.168.1.11"

      vars.tcp["3306"] = {
           tcp_port = 3306
    }
    }
    #-------------------------------
    object Host "mariaDB3" {
      import "generic-host"
      address = "192.168.1.12"

      vars.tcp["3306"] = {
           tcp_port = 3306
    }
    }
    #-------------------------------

Thank you for suggestion.


(Nicolai) #6

No, you just need to import the template: import "mariadb-host" in each db server object (like the generic-host).

Or with a fitting host naming schema create the service with matching the hostname in the assign part.


(Arethusa) #7

Yes, but, for exemple, I have cluster Elasticsearch, mongoDB, Graylog, web, influxdb, DNS… and they dont use the same port.

So with your idea, I have to do one template by type of server ( import "graylog-host" , import "elasticsearch-host" , import "mongoDB-host" .


(Nicolai) #8

Is there a consistent naming scheme (like mariadb01, mariadb02, …) on which you could assign services?


(Arethusa) #9

In my case I already use template, but I just try a thing:

    object Host "mariaDB1" {
      import "custom_template"
      import "mariaDB_template"
      address = "192.168.1.10"

and I add the:

template Host "mariaDB_template"
      vars.tcp["3306"] = {
           tcp_port = 3306
    }

That works, I can importe 2 templates, it’s good to know.

So your idea is feasable.

And yes, my naming is like you say (elasticsearch1, elasticsearch2 …)

But for me the best way could be to have ALL on my other services, but I don’t know if it’s possible.

I know it’s not like that but is it possible do a thing like this exemple ?:

apply Service "tcp" {
  import "generic-service"
  check_command = "tcp" port 3306
  vars += config
  assign where "mariaDB" in host.groups
}

(Nicolai) #10

A simple check would look like this:

apply Service "tcp-mariadb" {
  import "generic-service"
  check_command = "tcp"

  vars.tcp_port = 3306

  assign where "mariaDB" in host.groups
}

With this service definition there is no need for the definition inside the template respectively the template itself.


(Arethusa) #11

This one looks good, and in my case more logical as template (but template are realy good idea :wink: )

apply Service "tcp-mariadb" {
  import "generic-service"
  check_command = "tcp"

  vars.tcp_port = 3306

  assign where "mariaDB" in host.groups
}

I will create a port.conf with my all ports.

Maybe you have a last suggestion.

For exemple, I will do the same with Elasticsearch, like that (with port 9200 and 9300):

apply Service "tcp-ELS-9200" {
  import "generic-service"
  check_command = "tcp"

  vars.tcp_port = 9200

  assign where "ELS" in host.groups
}
apply Service "tcp-ELS-9300" {
  import "generic-service"
  check_command = "tcp"

  vars.tcp_port = 9300

  assign where "ELS" in host.groups
}

Is it possible to have 2 port on same service ?

    apply Service "tcp-ELS-$port" {
      import "generic-service"
      check_command = "tcp"

      vars.tcp_port = 9200
      vars.tcp_port = 9300

      assign where "ELS" in host.groups
    }

It’s not very important, one service by port is good solution in my case, but if I have less lignes…

Thank you.


(Nicolai) #12

No this is not possible. This is why I suggested the template solution. A single service might be sufficient for simple services, but with more complex software (for example your ELK) it is easier to have a template in which you define list or dicts with your config an use simple apply rules.


(Arethusa) #13

Hello,

The 2 way are good.

If I use template, I must have one template by type of server:

template Host "mariadb-host" {
  vars.tcp["MariaDB"] = {
    tcp_port = 3306
  }
}

template Host "elasticsearch" {
  vars.tcp["elasticsearch"] = {
    tcp_port = 9200
    tcp_port = 9300

  }
}

template Host "DNS" {
  vars.tcp["DNS"] = {
    tcp_port = 53
  }
}

And lot of other template…

So create one service by port is good to, but one service by ports, for example:

apply Service "tcp-mariadb" {
  import "generic-service"
  check_command = "tcp"

  vars.tcp_port = 3306

  assign where "mariaDB" in host.groups
}

apply Service "tcp-elasticsearch" {
  import "generic-service"
  check_command = "tcp"

  vars.tcp_port = 9200

  assign where "elasticsearch" in host.groups
}


apply Service "tcp-elasticsearch" {
  import "generic-service"
  check_command = "tcp"

  vars.tcp_port = 9300

  assign where "elasticsearch" in host.groups
}

apply Service "tcp-DNS" {
  import "generic-service"
  check_command = "tcp"

  vars.tcp_port = 53

  assign where "DNS" in host.groups
}

Finally, with your help, I learn 2 good solution to supervise my port with check_tcp.

Thank you very much for you advisement, and high availability.