Skip to main content
Question

How to search for all hosts belonging to two hostgroups? (ie: intersection of two hostgroups)

  • Oct 30, 2026 3:16 PM UTC
  • 1 reply
  • 5 views

1 reply

Forum|alt.badge.img+11
  • Centreonian
  • Nov 4, 2026 12:27 PM UTC

Hello,

 

Unfortunately, this is not possible with the Centreon UI

You can do that with a simple bash script and Centreon Command Line API:

#!/bin/bash

while (($# > 0)); do
case $1 in
--hg1)
hg1=${2:?missing HG1 value}
shift 2
;;

--hg2)
hg2=${2:?missing HG2 value}
shift 2
;;
esac
done

read -p "User (must be an admin account): " user
read -p "Password: " password


list_host1=$(centreon -u $user -p "$password" -o HG -a Getmember -v "$hg1" | tail -n +2 | cut -d ';' -f2 | sort -u)
list_host2=$(centreon -u $user -p "$password" -o HG -a Getmember -v "$hg2" | tail -n +2 | cut -d ';' -f2 | sort -u)

intersec=$(comm -12 <(echo "$list_host1") <(echo "$list_host2"))
echo "Hosts in both '$hg1' and '$hg2' ($(echo "$intersec" | wc -l)):"
echo $intersec

Note: I did not bother to handle errors.

 

With Centreon 26.10, the API can be used instead of CLAPI