Skip to content

Notification support Brak #102

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

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,54 @@ 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" => { // 自定义事件
// 使用率阈值,这里是磁盘 超 70% 告警
let threshold = 70;
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 里面的说明即可
badge: 1,
sound: "minuet.caf",
icon: "https://day.app/assets/images/avatar.jpg",
group: "SSR",
url: "https://github.com/zdz/ServerStatus-Rust"

}]
"""

###################### webhook end ##########################