Servicegroup definition (?)

Dear community,

i have a little issue, with the migration from Icinga 1.8.4 to Icinga 2, with the servicegroups.
Our old definition looks like :
define servicegroup{
servicegroup_name Test
members
SER-TEST-VM-1,CPU-Load,
SER-TEST-VM-1,MEM,
.
.
}

So we got our Host with the Service-check.

But how i can migrate it to the new Icinga 2, with the “assign where” rule in the groups.conf file
The documentation dont gives any information about it.

Best regards,
Fischeertrinken

Hi,

how do your service objects/apply rules and hosts look like? That would help to get a better idea what you’re trying to achieve here. Is it about all services with a specific name being put into such a group, or do you follow a different pattern here? (Hint: Group assign is explained in the docs).

Cheers,
Michael

I think the most efficient way is to set some vars in your service objects. Based on these vars, you can create servicegroup apply rules. You don’t have to use vars - you can also apply based on the check_command (see my example below).

Having this, newly added service objects are automatically (if you set the vars accordingly) added to the servicegroup.

For example, I have different disk check commands. I’ve created one servicegroup object for all of them:

object ServiceGroup "disk" {
  display_name = "Disk Checks"

  assign where match("disk*", service.check_command) || match("check_disk*", service.check_command) || match("*/check_disk", service.vars.by_ssh_command)
}

Maybe it’s a bit clearer having an example for hosts:

object HostGroup "proxmox-vms" {
  display_name = "Proxmox-VMs"

  assign where host.vars.vm == "proxmox"
}

object HostGroup "proxmox-lxcs" {
  display_name = "Proxmox-LXCs"

  assign where host.vars.lxc == "proxmox"
}

The hosts get included to the hostgroups if defined like the following:

object Host "ansible.lan" {
  import "generic-host"

  address = "192.168.2.170"

  vars.os = "Linux"
  vars.lxc = "proxmox"
}

object Host "docker1.lan" {
  import "generic-host"

  address = "192.168.2.34"

  vars.os = "Linux"
  vars.vm = "proxmox"
}

So when I create another lxc container it is sufficient to set the vars.lxc variable to “proxmox” to get that new host assigned to the “proxmox-lxcs” hostgroup.

1 Like

Dear Michael and Bernd,
i don’t want to configure the checks automatically. Our old Configuration looks like this:

define servicegroup{
	servicegroup_name	Test_servicegroup
	alias			Test_servicegroup
	members			SERVER1,PING,\\
SERVER1,CPU-Load,\\
SERVER1,FTP,\\
SERVER1,JWALK,\\
SERVER1,DISK,\\
SERVER2,PING,\\
SERVER2,CPU-Load,\\
SERVER2,FTP,\\
SERVER2,JWALK,\\
SERVER2,DISK
}

Can i migrate it like this: (?)

object ServiceGroup "Test_servicegroup" {
  display_name = "Test_servicegroup"

  assign where host.name == "SERVER1" || assign where  match("PING",service_name]
  assign where host.name == "SERVER1" || assign where  match("CPU-Load",service_name]
  assign where host.name == "SERVER1" || assign where  match("JWALK",service_name]
  assign where host.name == "SERVER1" ||assign where  match("DISK",service_name]
  assign where host.name == "SERVER1" || assign where  match("FTP",service_name]

  assign where host.name == "SERVER2" || assign where  match("PING",service_name]
  assign where host.name == "SERVER2" || assign where  match("CPU-Load",service_name]
  assign where host.name == "SERVER2" || assign where  match("JWALK",service_name]
  assign where host.name == "SERVER2" || assign where  match("DISK",service_name]
  assign where host.name == "SERVER2" || assign where match("FTP",service_name]

}

Best regards

Hi,

the more assign where expressions are chained together, the slower the overall configuration validation becomes. Avoid that at all cost, and consider a more simple solution.

Is there a specific reason to only match this on SERVER1 and SERVER2? I’d rather recommend building something like this for service names - all hosts being added later, with their services, will become part of this automatically.

Longer version for better understanding:

assign where service.name == "PING"
          || service.name == "CPU-Load"
          || service.name == "JWALK"
          || service.name == "DISK"
          || service.name == "FTP"

This always uses service.name in a duplicated fashion. The algorithm can be optimized by using a list of service names and let Icinga just evaluate whether the name is in there or not.

Simplified logic with a list and the in operator:

assign where service.name in [ "PING", "CPU-Load", "JWALK", "DISK", "FTP" ]

References:

Cheers,
Michael

1 Like

Hi,

my example wasn’t the best i think, the main problem is that, there are a lot of checks for a special software from us. And there are some hosts, with complete different checks, they have to be together to monitor the backend of the software.
So it is important for me, that i can connect one host, with one service_check_command, with another host and one service_check_command.
I can’t post the complete orignal configuration, cause it would be against our data privacy.

The question is, is there an easy way, like in Icinga 1.8. just to add the services from one host to a servicegroup, without any assign-rules?

Best regards

Hi,

wondering why you need so many service groups in general then … is it for better visualization in your frontend? Modern best practices involve custom variables and host groups.

If the service groups are for instrumenting a different combined cluster check, I would truly recommend to define a custom variable (or more) and rely on that.

Icinga 2 doesn’t support direct group members via a long list of names and name tuples. Either use the assign rules, or specify the service group membership via the groups attribute directly on the service object.

Cheers,
Michael

I found a better solution, and this would is Icinga Buisness Process Modelling, that is what we needed. But thanks for your help!

Best regards

Ah ok. I would have come to that after getting towards the check direction. Next time, please mention that intention sooner :slight_smile:

Cheers,
Michael

Hi,
Michael already covered the performance issues about your assign rules. I just like to add some notes about the syntax if someone likes to copy some parts of your snippet.

You can replace match("PING",service_name] with service.name == "PING" if you don’t need wildcard pattern matching (you don’t use * or ?).

|| in assign rules means or. So when you specify assign where host.name == "SERVER1" || service.name == "PING" the service group is assigned if the host name matches or the service name (or both). I think what you originally meant was assign where host.name == "SERVER1" && service.name == "PING" (only assign if both conditions evaluate to true using the && operator).

Kind regards,
Bernd

1 Like