当前位置:网站首页>Logstash - logstash sends an alarm email to email
Logstash - logstash sends an alarm email to email
2022-06-26 06:05:00 【Big wind】
email Data output
logstash The output plug-in of provides email The data output source of . So when logstash When you encounter something that needs early warning , An alert letter can be sent by mail to a specified user .
Configurable parameters
About email The parameters of are as follows
| Field | Parameter type | explain |
|---|---|---|
| address | string | Mail server address |
| username | string | The user name used to verify the server |
| password | string | Password used to verify the server |
| port | number | The port used to communicate with the mail server |
| authentication | string | How the server identifies itself |
| attachments | array | Attachment address |
| body | string | Email body |
| cc | string | CC address of the mail |
| bcc | string | BCC address of the mail |
| contenttype | string | Set up HTML The content type and / Or character set . |
| debug | boolean | Run mail relay in debug mode |
| domain | string | Connect to remote SMTP Server HELO / EHLO domain name |
| from | string | Sender |
| htmlbody | string | E-mail HTML Text |
| replyto | string | Mail reply fields |
| subject | string | Email subject |
| to | string | Email destination |
| use_tls | boolean | Enable when communicating with the server TLS |
| via | string | Logstash How to pass SMTP Or by calling sendmail Send email . |
| template_file | path | For email templates [Mustache Templates ](https://mustache.github.io/) Path to file . |
Take Tencent email as an example
- First, start relevant service support
Need to open Settings - account number

- Open the corresponding service

- Application authorization code
We need to pay attention to , After that, the mailbox password in all configurations refers to the authorization code
According to its file Introduction to
- Receiving mail server :imap.qq.com, Use SSL, Port number 993
- Send mail server :smtp.qq.com, Use SSL, Port number 465 or 587
Mail targeted configuration
email {
port => 587
address => "smtp.qq.com"
username => " mailbox @qq.com"
password => " Authorization code "
authentication => "plain"
contenttype => ""
from => " mailbox @qq.com"
subject => " Error alarm "
to => " mailbox @qq.com"
use_tls => true
via => "smtp"
domain => "smtp.qq.com"
body => " Error alarm :120 Error log exceeded... Seconds 3 strip , Please check "
debug => true
}
About logstash Before sending the alarm message, I had an article Use throttle The filter sends an alert message to the nail
Use the configuration inside , Replace with the mail target. The final configuration is as follows
input {
redis {
key => "logstash-email"
host => "localhost"
password => "dailearn"
port => 6379
db => "0"
data_type => "list"
type => "email"
codec => plain{
charset=>"UTF-8"
}
}
}
filter {
grok {
match => {
"message" => "%{TIMESTAMP_ISO8601:log_date} %{LOGLEVEL:log_info} %{DATA:thread} %{NOTSPACE} %{SPACE} %{NOTSPACE} %{JAVACLASS:log_class} %{SPACE}: %{GREEDYDATA:log_message}" }
}
if "_grokparsefailure" in [tags] {
drop {
}
}
if [log_info] == "INFO" {
drop {
}
}
if [log_info] == "ERROR" {
throttle {
before_count => -1
after_count => 3
period => 120
max_age => 240
key => "%{[log_info]}"
add_tag => "throttled"
}
}
if "throttled" in [tags] {
aggregate{
task_id => "%{log_info}"
code => "event.set('throttled_time',Time.parse(event.get('log_date')).to_f*1000)
map['throttled_time'] ||= 0
event.set('throttled_time_out', (event.get('throttled_time') - map['throttled_time']) > 10000)"
}
if [throttled_time_out] {
aggregate{
task_id => "%{log_info}"
code => "map['throttled_time'] = event.get('throttled_time')
event.set('throttled_time_test',map['throttled_time'])"
}
}
}
}
output {
if [throttled_time_out] {
email {
port => 587
address => "smtp.qq.com"
username => " mailbox @qq.com"
password => " Authorization code "
authentication => "plain"
contenttype => ""
from => " mailbox @qq.com"
subject => " Error alarm "
to => " mailbox @qq.com"
use_tls => true
via => "smtp"
domain => "smtp.qq.com"
body => " Error alarm :120 Error log exceeded... Seconds 3 strip , Please check "
debug => true
}
}
stdout {
codec => rubydebug
}
}
Using the above configuration, you can send alert messages by email .

Possible problems
Generally, if there is a problem, you need to check whether it is turned on POP3 and SMTP service
- Something happen while delivering an email {:exception=>#<Net::OpenTimeout: execution expired>}
At this point, you need to pay attention to the configuration address Whether the active port is correct .
- Something happen while delivering an email {:exception=>#<EOFError: end of file reached>}
According to the text description, there should be something wrong with the email content or attachments , And in GitHub It was also mentioned in the problem , But in fact, the above situation is most likely caused by the timeout problem . At this time, you need to try to use non SSL Send E-mail . Or use another port ( If there is one , For example, Tencent provides 465 and 587 port )
Limited personal level , The above content may not be clearly described or wrong , If development students find , Please let me know in time , I will revise the relevant contents as soon as possible . If my article is of any help to you , Please give it to me Like it . Your praise is my driving force .
边栏推荐
- MEF framework learning record
- Vs2022 offline installation package download and activation
- "= =" difference from "equals"
- Source code of findcontrol
- MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
- Selective search for object recognition paper notes [image object segmentation]
- Multi thread synchronous downloading of network pictures
- kolla-ansible部署openstack yoga版本
- String类学习
- Factory method pattern, abstract factory pattern
猜你喜欢

类和对象的学习

【Spark】Spark SQL 字段血缘如何实现

Redis多线程与ACL

Class and object learning

Pytorch (environment, tensorboard, transforms, torchvision, dataloader)

Selective Search for Object Recognition 论文笔记【图片目标分割】

MySQL-09

Household accounting procedures (the second edition includes a cycle)

Redis underlying data structure

Adapter mode
随机推荐
tf. nn. top_ k()
Household accounting procedures (the second edition includes a cycle)
Pytorch (environment, tensorboard, transforms, torchvision, dataloader)
数据可视化实战:实验报告
电商借助小程序技术发力寻找增长突破口
Easy to understand from the IDE, and then talk about the applet IDE
Solve the problem that Cmdr cannot use find command under win10
Spark source code analysis (I): RDD collection data - partition data allocation
numpy. exp()
[intra group questions semester summary] some reference questions for beginners
Definition of Halcon hand eye calibration
421-二叉树(226. 翻转二叉树、101. 对称二叉树、104.二叉树的最大深度、222.完全二叉树的节点个数)
Project suspension
MySQL database-01 database overview
423- binary tree (110. balanced binary tree, 257. all paths of binary tree, 100. same tree, 404. sum of left leaves)
NPM private server problem of peanut shell intranet penetration mapping
Redis underlying data structure
REUSE_ ALV_ GRID_ Display event implementation (data_changed)
工厂方法模式、抽象工厂模式
Machine learning 05: nonlinear support vector machines