
test.domain.local 도메인에 새 호스트를 설정하는 프로비저닝 시스템이 있고 client44.test.domain.local
, 처럼 정규식을 사용하여 이러한 모든 호스트를 자동으로 모니터링하려는 Icinga 서버가 있습니다 *.test.domain.local
.
모든 클라이언트는 nagios-nrpe-server
icinga-server가 클라이언트에서 데이터를 가져올 수 있도록 구성된 패키지(버전 2.13-3)를 받게 되며 이것이 작동하는 것으로 확인되었습니다.
지금은 SSH, 핑에 대한 응답 등 모든 노드가 갖게 될 서비스/사물을 모니터링하겠습니다.
나는 보았다이 링크하지만 호스트, 호스트 그룹 및 서비스 클래스 간의 관계가 확실하지 않습니까?
Icinga 서버와 모든 클라이언트는 모두 Debian을 실행합니다.
답변1
저는 이 문제에 대해 fredmu와 협력해 왔으며 Tim Brigham의 답변에서 영감을 받아 작동하는 솔루션을 생각해 냈습니다.
기본 generic-host
정의를 사용하면 템플릿을 기반으로 호스트 구성 파일을 자동으로 생성하는 스크립트를 사용하여 이 문제를 해결할 수 있습니다. 선택적으로 정기적으로 이러한 파일을 생성하기 위해 cronjob을 수행할 수도 있습니다.
generate_host_cfg.sh
#!/usr/bin/env bash
icinga_root="/etc/icinga/objects"
subnet="10.0.0.*"
template="template_icinga.cfg"
alias_file="alias.txt"
# navigate to the Icinga configuration directory
cd $icinga_root
# create first server alias if doesn't exist
if [ ! -e $alias_file ]; then
echo "1" > $alias_file
fi
# iterate through subnet, store "hostname:ip" in associative array
declare -A address
for host in $(nmap -sP $subnet | awk -F '[ ()]' '/for [a-z]+/ {print $5 ":" $7}'); do
address[$(echo $host | cut -d: -f1)]=$(echo $host | cut -d: -f2)
done
# iterate through hosts, create files if not exist based off template
for host in ${!address[@]}; do
host_file=${host}_icinga.cfg
if [ ! -e $host_file ]; then
# fetch new server alias
alias=$(cat $alias_file)
# create the next server alias
expr $alias + 1 > $alias_file
# create hostname_icinga.cfg if doesn't exist, based off template
cp $template $host_file
# replace contents of new template; hostname, alias and ip
sed -i -r \
-e "s/tmp-hostname/$host/" \
-e "s/tmp-alias/Server$alias/" \
-e "s/tmp-address/${address[$host]}/" $host_file
fi
done
template_icinga.cfg
define host{
use generic-host
host_name tmp-hostname
alias tmp-alias
address tmp-address
}
결과적으로 다음과 같은 파일이 생성됩니다.
define host{
use generic-host
host_name monitor.company.local
alias Server1
address 10.0.0.1
}
답변2
이 문제를 해결하는 방법에는 여러 가지가 있습니다.
나는 이전에 단일 icinga 검사로 실행될 bash 스크립트를 조립했습니다. 그런 다음 스크립트는 하위 도메인의 모든 호스트를 확인하고 발견된 오류 수 또는 발견된 오류 수에 따라 상태를 반환합니다.
최근에 나는 꼭두각시에서 사용자 정의 사실의 팬이 되었습니다. Well writeb 템플릿과 결합하면 for 루프를 사용하여 수많은 노드에 검사를 쉽게 추가할 수 있습니다.