Elastaticsearch日志告警(elastalert)

Elastaticsearch日志告警

elastalert正确使用姿势

前言

五月份网上寻找ELK日志告警解决方案,Github发现一款开源软件elastalert 传送门

看最近更新时间为两年前,所以一直处于半质疑状态看待该软件,直到进一步...深入...

最新消息: 截止发稿时间,看该项目已经有最新改动,新增Kibana插件支持!

错误姿势

由于对elastalert了解不深,前期使用过程中没有使用ES查询(可能当时ES6刚发布,对ES6版本没针对性修改),进行一些没必要的二次开发.

后面随时不断尝试,发现elastalert还是蛮强大的,越来越看好,且渐渐了解到真正用法 ...领悟到正确姿势...

正确姿势

针对需求

监控站点50X告警, 当一分钟内出现100个50X时告警

name: nginx access 50X rule
type: frequency
index: access*
num_events: 100
timeframe:
    minutes: 1
filter:
- range:
    status:
      from: 500
      to: 599
alert: "modules.eagle_post.EagleAlerter"
eagle_post_url: ""
eagle_post_all_values: False
eagle_time_start: "02:00"
eagle_time_end: "06:00"
eagle_post_payload:
  host: "host"
  status: "status"
  request: "request_uri"
  remoteaddr: "remote_addr"
  requesttime: "request_time"
  useragent: "http_user_agent"
  method: "request_method"
  time: "time_local"

效果图
Elastaticsearch日志告警(elastalert)

监控系统执行危险操作

index: system_history*
timeframe:
    minutes: 0
filter:
- query:
    - bool:
        should:
            - match: {"command":"mysqldump"}
            - match: {"command":"rm -rf"}
            - match: {"command":"shutdown"}
            - match: {"command":"passwd"}
            ...

监控数据库错误日志

type: blacklist_v2
index: mysql_log*
timeframe:
    minutes: 1
reverse: False
compare_key: message
filter:
- query:
    - bool:
        must:
            - term: {"tag":"error_log"}
        must_not:
            - match: {"message":"[Warning]"}
            - match: {"message":"[Note]"}
blacklist_v2:
    - "Too many connections"
    - "ERROR"
    - "error"
    - "table full"

后语

技术人员不能稍微了解后就妄下定论!

后续将会继续关注elastalert,欢迎各位大佬经验交流.

猜你喜欢

转载自blog.51cto.com/maoyao/2314789