使用GrayLog对PrometheusAlert推送的安全告警进行图形报表统计与分析

简介: 使用GrayLog对PrometheusAlert推送的安全告警进行图形报表统计与分析

640.jpg

需求


GrayLog每天每周产生的安全告警数量较多,这些产生的告警都通过PrometheusAlert推送到钉钉webhook告警机器人 想对这些告警做一些汇总统计,报表分析


640.png

解决思路:


由于GrayLog Web界面上的告警界面无汇总统计的功能,只能寻找其他解决思路,查询prometheusalert是否有统计功能 但搜索过PrometheusAlert的相关功能,与需求不太吻合。突发奇想,看能否从PrometheusAlert.log的日志进行下手通过查看


PrometheusAlert.log的一些规律,最终确定的解决方法 包含value.go的这一行就是所需要的告警日志


2022/10/14 14:15:15.735 [D] [value.go:476]  [1665728115735353131] {"event_definition_id":"62d40b5bfbbe0a2fd4faf65d","event_definition_type":"aggregation-v1","event_definition_title":"堡垒机绕过提醒","event_definition_description":"安全助手检测到绕过堡垒机直接登陆服务器行为","job_definition_id":"62d3ff2bfbbe0a2fd4fadd35","job_trigger_id":"6348fe7213d8e16f7fe61732","event":{"id":"01GFAJ3W0SZSGJNTK01QKMRQXB","event_definition_type":"aggregation-v1","event_definition_id":"62d40b5bfbbe0a2fd4faf65d","origin_context":"urn:graylog:message:es:linuxserver_23:e6490781-4b86-11ed-aea0-005056b6acae","timestamp":"2022-10-14T06:10:46.428Z","timestamp_processing":"2022-10-14T06:15:14.713Z","timerange_start":null,"timerange_end":null,"streams":[],"source_streams":["62d3eed0fbbe0a2fd4facacd"],"message":"堡垒机绕过提醒","source":"localhost","key_tuple":[],"key":"","priority":2,"alert":true,"fields":{},"group_by_fields":{}},"backlog":[{"index":"linuxserver_23","message":"Accepted password for root from 192.168.29.41 port 60382 ssh2","timestamp":"2022-10-14T06:10:46.428Z","fields":{"process_id":"3194","gl2_accounted_message_size":292,"application_name":"sshd","level":6,"gl2_remote_ip":"172.16.252.134","gl2_remote_port":64781,"facility_num":10,"Linux_server_ssh_login_ip":"192.168.29.41","gl2_message_id":"01GFAHV3ZRYPS0G895J23348A6","gl2_source_node":"d20e3549-da0a-4ae9-af4a-d352e1c3deb5","gl2_source_input":"62d3ec98fbbe0a2fd4fac816","facility":"security/authorization"},"id":"e6490781-4b86-11ed-aea0-005056b6acae","source":"ec-server-test-172-16-252-134","stream_ids":["62d3eed0fbbe0a2fd4facacd"]}]}

1、使用rsyslog服务来读取prometheusalert.log日志文件


[root@centos ~]# cd /etc/rsyslog.d/
[root@centos rsyslog.d]# vi prometheusalert_read.conf 
[root@centos rsyslog.d]# cat prometheusalert_read.conf 
module(load="imfile" PollingInterval="1")
# Input for FILE1
#wildcard is allowed at file level only
input(
      type="imfile"
      tag="Alertlog"
      ruleset="filelog"
      Facility="local0"
      Severity="info"
      PersistStateInterval="1"
      reopenOnTruncate="on"
      freshStartTail="on"
      file="/opt/PrometheusAlert/logs/prometheusalertcenter.log"
) 
# Define a template for file events
template(name="GraylogFormatFilelog" type="string" string="%msg%\n")
#Replace the Target and Port values with your GrayLogServer IP address and port.
ruleset(name="filelog") {
   action(
        type="omfwd"
        protocol="udp"
        target="192.168.31.170"
        port="1524"
        template="GraylogFormatFilelog"
        queue.type="LinkedList"
        queue.filename="fileq1"
        queue.saveonshutdown="on"
        action.resumeRetryCount="-1"
   ) stop
}
[root@centos rsyslog.d]# systemctl restart rsyslog

640.png

2、创建Index,Input和Stream2、创建Index,Input和Stream

[root@centos ~]# firewall-cmd --permanent --zone=public --add-port=1524/udp
success
[root@centos ~]# firewall-cmd --reload
success
[root@centos ~]# systemctl restart rsyslog.service 
[root@centos ~]#

640.png

640.png


640.png

640.png

640.png

3、字段提取


在日志搜索栏中搜索告警日志后进行提取器配置,提取所需的字段

640.png


例如这里使用正则表达式进行字段的提取


640.png



640.png

以下为导出的提取器语法配置文件

{
  "extractors": [
    {
      "title": "alert_json_message",
      "extractor_type": "regex",
      "converters": [],
      "order": 1,
      "cursor_strategy": "copy",
      "source_field": "message",
      "target_field": "alert_json_message",
      "extractor_config": {
        "regex_value": "^.*\\[[0-9]{19}\\](.+)$"
      },
      "condition_type": "string",
      "condition_value": "value.go"
    },
    {
      "title": "json_extractor",
      "extractor_type": "json",
      "converters": [],
      "order": 2,
      "cursor_strategy": "copy",
      "source_field": "alert_json_message",
      "target_field": "",
      "extractor_config": {
        "list_separator": ", ",
        "kv_separator": "=",
        "key_prefix": "",
        "key_separator": "_",
        "replace_key_whitespace": false,
        "key_whitespace_replacement": "_"
      },
      "condition_type": "none",
      "condition_value": ""
    },
    {
      "title": "field_cut",
      "extractor_type": "copy_input",
      "converters": [
        {
          "type": "tokenizer",
          "config": {}
        }
      ],
      "order": 3,
      "cursor_strategy": "copy",
      "source_field": "backlog",
      "target_field": "backlog_detail",
      "extractor_config": {},
      "condition_type": "none",
      "condition_value": ""
    },
    {
      "title": "level_replace",
      "extractor_type": "regex_replace",
      "converters": [],
      "order": 0,
      "cursor_strategy": "copy",
      "source_field": "message",
      "target_field": "message",
      "extractor_config": {
        "replacement": "\"alertlevel\"",
        "regex": "\"level\""
      },
      "condition_type": "none",
      "condition_value": ""
    },
    {
      "title": "facility_num_replace",
      "extractor_type": "regex_replace",
      "converters": [],
      "order": 0,
      "cursor_strategy": "copy",
      "source_field": "message",
      "target_field": "message",
      "extractor_config": {
        "replacement": "\"alert_facility_num\"",
        "regex": "\"facility_num\""
      },
      "condition_type": "none",
      "condition_value": ""
    }
  ],
  "version": "4.2.10"
}


4、字段展示和报表大屏配置

640.png

最后的效果

640.png


相关文章
|
Arthas Prometheus Kubernetes
K8S pod内存告警分析
K8S pod内存告警分析
2395 0
|
机器学习/深度学习 运维 数据挖掘
运维告警不是“玄学”:聊聊怎么用机器学习优化事件关联分析
运维告警不是“玄学”:聊聊怎么用机器学习优化事件关联分析
586 3
|
运维 监控 前端开发
Zabbix告警分析新革命:DeepSeek四大创新场景助力智能运维
面对日益复杂的IT环境,高效分析监控数据并快速响应成为运维的关键挑战。本文深入探讨了DeepSeek与Zabbix结合的创新应用,包括一键式智能告警分析、Zabbix文档知识库助手及钉钉告警增强功能。通过部署指南和实用脚本,展示了如何提升故障排查效率,为运维工程师提供高效解决方案。
1730 5
|
人工智能 运维 监控
Zabbix告警分析新纪元:本地DeepSeek大模型实现智能化告警分析
本文由Zabbix中国峰会演讲嘉宾张世宏撰写,介绍如何通过集成Zabbix监控系统与深度求索(DeepSeek)AI助手,构建智能化告警处理方案。该方案利用Webhook机制传递告警信息,借助DeepSeek的智能分析能力,帮助运维团队快速识别问题根源并提供解决方案。文章详细描述了技术架构、环境搭建、Webhook配置及实际案例,展示了AI在运维领域的应用前景和优势。
3237 0
|
SQL JSON 网络协议
告警流量特征分析(护网蓝初面试干货)
告警流量特征分析(护网蓝初面试干货)
1798 0
|
存储 监控 索引
SLS告警最佳实践——自定义分析告警历史
在SLS告警评估、触发到通知的整个生命周期过程中,都会有一些日志记录,通过这些日志我们可以借助告警对系统的整体健康状况、稳定性等有一个相对全面的了解。
956 0
|
消息中间件 监控 关系型数据库
134 日志监控告警系统案例(功能架构分析)
134 日志监控告警系统案例(功能架构分析)
525 0
|
安全 关系型数据库 MySQL
关于Aborted connection告警日志的分析
有时候,连接MySQL的会话经常会异常退出,错误日志里会看到"Got an error reading communication packets"类型的告警。本篇文章我们一起来讨论下该错误可能的原因以及如何来规避。
1344 0
关于Aborted connection告警日志的分析
|
存储 监控 Java
1个小时接入友盟+ U-APM:解决移动应用崩溃、性能、内存的云监控分析
本文主要是一次产品需求讨论之后的功能论证,公司正式的APP接入友盟+ U-APM还未上线。而本文也是花了一个小时尝试接入U-APM的一种实验,过程比较顺利,而产品部对于这种性能指标的监控方式也比较认可,毕竟一次接入之后就可以实现多种应用。而友盟+ U-APM的功能不止于此,后续对于U-APM的深入对接也不会止步。
1个小时接入友盟+ U-APM:解决移动应用崩溃、性能、内存的云监控分析
|
机器学习/深度学习 存储 SQL
SLS新版告警入门-统一的查询分析语法
SLS新版告警支持多种监控目标,如SLS的日志存储,时序存储;也支持对外部系统如Promethus,Grafana,Zabbix产生的告警进行管理;在对SLS的存储进行监控时,用户可以自定义告警监控规则或者使用内置的告警规则。自定义告警监控规则主要包括监控目标,触发条件,行动配置等。本文主要介绍在创建自定义告警规则时,如何使用统一的查询分析语法来查询并定义监控目标。
2500 0

热门文章

最新文章