Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] webook notification test for Bark is not work #332

Open
4 tasks done
Youngv opened this issue Jul 30, 2024 · 1 comment
Open
4 tasks done

[Bug] webook notification test for Bark is not work #332

Youngv opened this issue Jul 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Youngv
Copy link

Youngv commented Jul 30, 2024

Checklist

  • I have updated the version to the latest Release version
  • I've read the documentation in detail and still can't solve it
  • I have searched existing Issues | Discussions, but still can't solve it
  • 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 Youngv added the bug Something isn't working label Jul 30, 2024
@zdz
Copy link
Owner

zdz commented Jul 31, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants