官方文檔:https://docs.graylog.org/en/3.0/index.html
前面我們已經了解了Graylog的搭建,以及日志的接入方法。我們知道graylog可以將收集的的日志通過web界面展示出來,但隨着日志量的增加,我們可能不能及時的發現一些異常日志。為了避免這種情況出現,告警通知可以說很有必要了。
1.先在graylog server 的配置文件中添加Email配置,並重啟服務。默認graylog的配置文件在/etc/graylog/server/server.conf
1vim /etc/graylog/server/server.conf 2 3#Email transport 4transport_email_enabled = true 5transport_email_hostname = smtp.exmail.qq.com 6transport_email_port = 465 7transport_email_use_auth = true 8transport_email_auth_username = you@example.com #修改成自己的名字 9transport_email_auth_password = secret #設置密碼 10transport_email_subject_prefix = [graylog] 11transport_email_from_email = graylog@example.com #修改example 12 13# systemctl restart graylog-server
2. Graylog web界面配置
1)新建告警條件:點擊“Alerts”--“Mange condition”--“Add new condition”


2) 選擇想要添加告警的stream和條件類型

Condition type:
-
Field Content Alert Condition
Field表示字段,Value是字段的值,Grace Period是指當一個告警恢復時下一個告警的等待時間,Message Backlog是指包含在告警通知中的信息數量,Search Query(optional)查詢搜索(可選的),可以匹配查詢內容,默認是全部。例如下圖告警條件是nginx日志中出現字段ERROR的內容。

-
Field Aggregation Alert Condition
Threshold Type閾值類型,Aggregation Type聚合類型。可以根據自己的需求設置對應的參數。

-
Message Count Alert Condition
選擇閾值類型,統計消息數量是否超過或者低於設定閾值,否則觸發告警。

Condition配置完成

3) 配置告警通知:點擊“Notifications”--“Add new Notification ”

4) 選擇告警stream和通知類型

Notification type:
-
HTTP Alarm Callback
添加一條url到告警平台,告警平台可以通過配置發送到釘釘

-
Email Alert Callback
E-Mail Receivers選擇接收郵件人的郵箱,Sender發生告警的發送方

5) 測試郵件:點擊Test查看收到郵件內容,配置完成

