ServerStatus-Rust icon indicating copy to clipboard operation
ServerStatus-Rust copied to clipboard

[Bug] webook notification test for Bark is not work

Open Youngv opened this issue 1 year ago • 1 comments

Checklist

  • [X] I have updated the version to the latest Release version
  • [X] I've read the documentation in detail and still can't solve it
  • [X] I have searched existing Issues | Discussions, but still can't solve it
  • [X] I've tried a Google search and still can't figure it out

💻 Operating System

Ubuntu

🐛 Bug Description

stat server version:

stat_server v1.8.1 (1dd5c41, 2024-03-18 14:18:45 UTC, rustc 1.76.0, x86_64-unknown-linux-musl)

bark server version:

finab/bark-server                   latest    348ffa515115   15 months ago   25.9MB

config:

[webhook]
# 总开关
enabled = true
  # 可多个 webhook.receiver
  [[webhook.receiver]] # Bark
  enabled = true
  # https://github.com/Finb/Bark
  # https://day.app/2021/06/barkfaq/
  url = "https://self.deploy.server/push"
  headers = { content-type = "application/json; charset=utf-8" }
  timeout = 5 #s
  script = """
    let message = "";
    switch event {
      "Custom" => {      // 自定义事件
          // 使用率阈值,这里是磁盘 超 70% 告警
          let threshold = 90;
          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: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      // 后面为可选字段参考 https://github.com/Finb/bark-server/blob/master/docs/API_V2.md
      // 其它角标, 铃声, icon, 参考 app 里面的说明即可
      badge: 1,
      sound: "minuet.caf",
      icon: "https://day.app/assets/images/avatar.jpg",
      group: "SSR",
      url: ""
    }]
  """

run command:

./stat_server -c config.toml --notify-test
✨ stat_server v1.8.1 (1dd5c41, 2024-03-18 14:18:45 UTC, rustc 1.76.0, x86_64-unknown-linux-musl)
✨ run in normal mode, load conf from local file `config.toml
✨ admin_user: admin
✨ admin_pass: xxxxxxxxxxxxxxxxxxxxxxxxx
send test message to log
send test message to webhook
Please check for notifications

bark server log:

2024-07-30 15:39:42     INFO    172.19.0.1 -> [ 400 ]  POST     390.687µs /push => /push ❗ServerStatus test msg

Bark returned a 400 error, and the JSON request was not received.

🚦 Expected Behavior

curl -X "POST" "https://self.deploy.server/push" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "body": "Test Bark Server",
  "device_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "title": "bleem",
  "badge": 1,
  "category": "myNotificationCategory",
  "sound": "minuet.caf",
  "icon": "https://day.app/assets/images/avatar.jpg",
  "group": "test",
  "url": "https://mritd.com"
}'

bark server log:

2024-07-30 15:42:43     INFO    172.19.0.1 -> [ 200 ]  POST     475.910315ms /push => /push {
  "body": "Test Bark Server",
  "device_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "title": "bleem",
  "badge": 1,
  "category": "myNotificationCategory",
  "sound": "minuet.caf",
  "icon": "https://day.app/assets/images/avatar.jpg",
  "group": "test",
  "url": "https://mritd.com"
}

📷 Recurrence Steps

No response

📝 Additional Information

No response

Youngv avatar Jul 30 '24 08:07 Youngv

The data structure of the test message passed by bark is not a JSON structure, which causes an exception. I will fix it later. Skip the notification test and it will work normally.

zdz avatar Jul 31 '24 03:07 zdz