OS/Linux

[Centos 8] Nagios Core - 슬랙 연동

_눙이_ 2021. 4. 20. 18:28
반응형

 

Nagios Core - 슬랙 연동

 

Nagios 토큰값 받기 및 설정방법

https://slack.com/apps/A0F81R747-nagios

이미지 썸네일 삭제

Nagios

Nagios is an IT management system that organizations use to identify and resolve IT infrastructure problems. This integration will post Nagios alerts to a channel.

slack.com

필수 패키지 설치

sudo apt-get install libwww-perl libcrypt-ssleay-perl

(yum install perl-libwww-perl perl-LWP-Protocol-https)

 

wget https://raw.github.com/tinyspeck/services-examples/master/nagios.pl

cp nagios.pl /usr/local/bin/slack_nagios.pl

chmod 755 /usr/local/bin/slack_nagios.pl

chown apache:nagios slack_nagios.pl

 

 

vi slack_nagios.pl

slack_nagios.pl을 편집하고 $opt_domain 및 $opt_token 변수 설정

my $opt_domain = "도메인.com"; # 팀의 도메인

my $opt_token = "받은 토큰 값"; # Nagios 서비스 페이지의 토큰

Nagios 구성의 나머지 부분과 함께 slack_nagios.cfg 파일을 생성하여 플러그인을 사용하도록 Nagios를 구성합니다. 여기서는 /etc/icinga/에서 구성합니다. 다음 콘텐츠로 시작합니다.

define contact { contact_name slack alias Slack service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,r service_notification_commands notify-service-by-slack host_notification_commands notify-host-by-slack } define command { command_name notify-service-by-slack command_line /usr/local/bin/slack_nagios.pl -field slack_channel=#alerts } define command { command_name notify-host-by-slack command_line /usr/local/bin/slack_nagios.pl -field slack_channel=#ops }

 

 

slack_channel 명령 옵션을 사용자 지정하여 알림을 보낼 채널을 지정합니다.

Nagios contacts.cfg 파일을 편집하여 새 Slack 연락처 그룹을 사용하도록 Nagios에 전달합니다(여기서는 /etc/icinga/conf.d/). "관리자" 연락처 그룹을 찾아 slack을 멤버로 추가합니다. 예:

define contactgroup { contactgroup_name admins alias Nagios Administrators members root,slack }

 

Nagios XI의 경우 기본 nagios.cfg 파일에 enable_environment_macros=1이 설정되어 있어야 합니다(이미 활성화되어 있을 수 있음).

 

이전 버전과 Nagios Core의 경우에는 변수를 다음과 같이 전달해야 합니다.

define command { command_name notify-service-by-slack command_line /usr/local/bin/slack_nagios.pl -field slack_channel=#alerts -field HOSTALIAS="$HOSTNAME$" -field SERVICEDESC="$SERVICEDESC$" -field SERVICESTATE="$SERVICESTATE$" -field SERVICEOUTPUT="$SERVICEOUTPUT$" -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" } define command { command_name notify-host-by-slack command_line /usr/local/bin/slack_nagios.pl -field slack_channel=#ops -field HOSTALIAS="$HOSTNAME$" -field HOSTSTATE="$HOSTSTATE$" -field HOSTOUTPUT="$HOSTOUTPUT$" -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" }

 

Nagios를 다시 시작하고 알림을 기다려주세요. (아니면 일부러 알림을 유발할 수도 있습니다. Slack은 까다롭지 않습니다.)

사진 삭제

사진 설명을 입력하세요.

출처: <https://w1618802361-n9r230120.slack.com/services/B01UGH76XQE?added=1>

 

 

 

반응형