zdz / ServerStatus-Rust

✨ Rust 版 ServerStatus 探针、威力加强版
https://ssr.rs
Apache License 2.0
1.75k stars 317 forks source link

建议增加告警方式 Bark #101

Closed A5123 closed 1 year ago

A5123 commented 1 year ago

建议加入Bark来推送告警通知。

项目地址:https://github.com/Finb/Bark

zdz commented 1 year ago

使用 webhook 就能支持,参考下面的配置,记得修改下面你的 device_key 和设置两个 enabled = true 完整的配置 https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/config.toml 最后面部分

image
## script 使用脚本引擎 https://rhai.rs/book/
[webhook]
# 总开关
enabled = false

  [[webhook.receiver]] # Bark
  enabled = false
  # https://github.com/Finb/Bark
  # https://day.app/2021/06/barkfaq/
  url = "https://api.day.app/push"
  headers = { content-type = "application/json; charset=utf-8" }
  timeout = 5 #s
  script = """
    let message = "";
    switch event {
      "Custom" => {      // 自定义事件
          // 使用率阈值,这里是磁盘 超 65% 告警
          let threshold = 65;
          let msgs = [];
          let memory_usage = round(host.memory_used * 100.0 / host.memory_total);
          if memory_usage > threshold {
             msgs.push(`😲 ${host.location} ${host.name} 主机内存使用率超${threshold}%, 当前 ${memory_usage}%`);
          }
          let hdd_usage = round(host.hdd_used * 100.0 / host.hdd_total);
          if hdd_usage > threshold {
              msgs.push(`😲 ${host.location} ${host.name} 主机硬盘使用率超${threshold}%, 当前 ${hdd_usage}%`);
          }
          message = join(msgs, "\\n");
      },
      "NodeDown" => {   // 掉线
          message = `😱 ${host.location} ${host.name} 主机已经掉线啦`;
      },
      "NodeUp" => {     // 上线
          message = `😆 ${host.location} ${host.name} 主机恢复上线啦`;
      }
    }

    // 最终结果, 固定结构 [是否发送通知,结果对象]
    [message.len() > 0, #{
      // 标题
      title: "ServerStatusRust",
      // 告警内容,这里不用修改
      body: message,
      // 修改成你的设备 key, app 内获取
      device_key: "fLLBrV****kM5H",
      // 其它角标, 铃声, icon, 参考 app 里面的说明即可
      // 后面为可选字段参考 https://github.com/Finb/bark-server/blob/master/docs/API_V2.md
      badge: 1,
      sound: "minuet.caf",
      icon: "https://day.app/assets/images/avatar.jpg",
      group: "SSR",
      url: "https://github.com/zdz/ServerStatus-Rust"

    }]
  """
A5123 commented 1 year ago

好的 感谢你的回复。