原始需要是如果零碎的明码被批改,或者创立了新用户,就告警进去。实质上,只须要监控 /etc/shadow 文件变动即可。然而在指标监控体系里,这个事件就比拟辣手,只能把文件的 mtime 作为指标的值上报,服务端再利用 delta 或者 increase 函数来判断 mtime 是否产生了变动。告警进去的文本也会比拟简陋。

应用 catpaw 搭配 FlashDuty 则能够很好的解决这个问题。告警的样例成果如下:

上面咱们来看看如何实现。

1. 下载 catpaw

最新版本是 0.6.0,下载地址是:https://download.flashcat.cloud/catpaw-v0.6.0-linux-amd64.tar.gz 目前只提供了 linux-amd64 版本,如有其余版本的需要能够分割我。

解压后能够看到如下内容:

.├── catpaw├── conf.d│   ├── config.toml│   ├── p.exec│   │   └── exec.toml│   ├── p.filechange│   │   └── filechange.toml│   ├── p.http│   │   └── http.toml│   ├── p.journaltail│   │   └── journaltail.toml│   ├── p.mtime│   │   └── mtime.toml│   ├── p.net│   │   └── net.toml│   ├── p.ping│   │   └── ping.toml│   └── p.sfilter│       └── sfilter.toml└── scripts    ├── demo.sh    ├── df.sh    ├── greplog.sh    └── ulimit.sh11 directories, 14 files

其中 catpaw 是二进制文件,conf.d 目录下是各个插件的配置文件,scripts 目录下是一些示例脚本。

2. 主配置

这里最外围的配置是conf.d/config.toml,须要配置一下 flashduty.url,您须要先注册 FlashDuty,注册地址是:https://console.flashcat.cloud/signup。

FlashDuty 是一个事件 OnCall 核心,能够聚合各类监控零碎的事件,比方 Zabbix、Prometheus、PagerDuty、云监控、蓝鲸、Nightingale、Elastalert 等等,而后对立进行事件聚合降噪、排班、认领、降级等等。

注册 FlashDuty 之后,零碎会疏导你创立合作空间,您能够在合作空间上面增加一个自定义集成:

完事点击这个自定义集成,就能够拿到 url 了,拷贝一下 url,贴到 catpaw 的 conf.d/config.toml 中即可。

3. 配置插件

监控文件变动,能够应用 filechange 插件,配置文件在 conf.d/p.filechange/filechange.toml,样例如下:

[[instances]]time_span = "3m"filepaths = ["/etc/shadow"]check = "file changed"interval = "30s"[instances.alerting]## Enable alerting or notenabled = true## Same functionality as Prometheus keyword 'for'for_duration = 0## Minimum interval duration between notificationsrepeat_interval = "5m"## Maximum number of notificationsrepeat_number = 3## Whether notify recovery eventrecovery_notification = true## Choice: Critical, Warning, Infodefault_severity = "Warning"

4. 启动 catpaw

我这里简略测试,应用 nohup 启动,如果生产环境,天然是倡议 systemd 或者 supervisor 托管:

nohup ./catpaw &> stdout.log &

5. 测试

手工创立个用户,比方 sudo useradd qinxiaohui,就会导致 /etc/shadow 文件发生变化,进而产生告警,大家能够自行尝试一下。成果如下:

扩大浏览

  • 太卷了,史上最简略的监控零碎 catpaw 简介
  • 告警聚合降噪、告警降级、告警认领、告警排班、告警协同,一网打尽