ZABBIX Notifications with graphs in Telegram

ZABBIX 알람을 텔레그램으로 받기

ZABBIX 는 알람 미디어로 email, sms 등을 사용할 수 있으며 Telegram 의 API 를 이용하여 Telegram 으로 받도록 설정할 수가 있습니다.

알람을 설정하기 전에 반드시 미리 챗봇 설정을 해 주셔야 합니다.

이 가이드는 4.0 LTS 버전 기준으로 작성되었으며, GitHub – ableev/Zabbix-in-Telegram: Zabbix Notifications with graphs in Telegram 을 참고하였습니다.

자빅스 서버 설정

의존성 패키지 설치

[root@172-16-11-5 /]# yum install -y epel-release
[root@172-16-11-5 /]# yum install -y python python-pip
[root@172-16-11-5 /]# pip install request

텔레그램 연동 스크립트 생성
: vi /etc/zabbix/bin/zbxtg.py

https://github.com/ableev/Zabbix-in-Telegram/blob/master/zbxtg.py

: vi /etc/zabbix/bin/zbxtg_settings.py (아래 나열된 변수는 자신의 환경에 맞게 편집해 주시기 바랍니다.)

https://github.com/ableev/Zabbix-in-Telegram/blob/master/zbxtg_settings.example.py
tg_key          =        ## 자신의 텔레그램 bot API의 키
zbx_server      =        ## 자신의 서버 URL을 입력
zbx_api_user    =        ## 자빅스 프론트엔드 접속 계정 입력
zbx_api_pass    =        ## 자빅스 프론트엔드 접속 계정의 비밀번호 입력
zbx_db_host     =        ## 자빅스 DB의 호스트 입력
zbx_db_database =        ## 자빅스 DB 이름 입력
zbx_db_user     =        ## 자빅스 DB 계정 입력
zbx_db_password =        ## 자빅스 DB 계정의 비밀번호 입력

스크립트 권한 수정

[root@172-16-11-5 /]# chmod 755 /etc/zabbix/bin/zbxtg.py /etc/zabbix/bin/zbxtg_settings.py

스크립트가 정상작동하는지 CLI (커맨드 라인 인터페이스) 에서 아래와 같이 테스트 발송을 꼭 해주시기 바랍니다.

/etc/zabbix/bin/zbxtg.py "Your_Telegram_Account" "Subject" "Ceontent"
ex)
[root@172-16-11-5 /]# /etc/zabbix/bin/zbxtg.py "umount" "test_Sub" "hello telegram"

자빅스 재시작

[root@172-16-11-5 /]# systemctl restart zabbix_server

자빅스 프론트엔드 설정

Administration -> Media types -> Create media type

Name               ## 미디어 이름 입력
Type               ## Script 선택
Script name        ## zbxtg.py 입력
Script parameters  ## {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE} 3가지는 필수 항목이며, 그룹으로 알람을 보낼때는 --group 파라미터를 추가
zabbix media type

Administration -> Users -> [알람받을 유저] 선택 -> Media -> Add

Type                  ## Telegram
Send to               ## 텔레그램 계정명 or 그룹명
When active           ## DEFAULT 
Use if severity       ## Use Custom
telegram-zabbix-media-user1
telegram-zabbix-media-user2

Configuration -> Actions -> Create action

telegram-zabbix-action1
telegram-zabbix-action2
telegram-zabbix-action3
telegram-zabbix-action4

텔레그램에 발송된 자빅스 알람

telegram-zabbix-screen

5.0 LTS 버전에서는 텔레그램을 이용한 알람 기능이 별도의 스크립트 필요없이 자빅스와 통합되었습니다. 관련 설정 방법은 Telegram monitoring and integration with Zabbix 5.0 | Umount Blog 포스팅을 참고하시면 됩니다.

You may also like...

Subscribe
Notify of
guest

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x