Skip to content

Commit

Permalink
disable_notify->notify
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz committed Apr 17, 2022
1 parent 07e5c5d commit c5369d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ http_addr = "0.0.0.0:8080"
offline_threshold = 30

# name 主机唯一标识,不可重复,alias 为展示名
# disable_notify = true 是可以单独禁止单台机器的告警,一般针对网络差,频繁上下线
# disabled = true
# notify = false 是可以单独禁止单台机器的告警,一般针对网络差,频繁上下线
# ansible 批量部署时可以用主机 hostname 作为 name,统一密码
hosts = [
{name = "h1", password = "p1", alias = "n1", location = "🏠", type = "kvm", disable_notify = false},
{name = "h2", password = "p2", alias = "n2", location = "🏢", type = "kvm", monthstart = 1},
{name = "h1", password = "p1", alias = "n1", location = "🏠", type = "kvm", notify = true},
{name = "h2", password = "p2", alias = "n2", location = "🏢", type = "kvm", monthstart = 1, disabled = false},
]

# 使用vnstat来更精准统计月流量,开启参考下面 vnstat 一节
Expand Down
7 changes: 4 additions & 3 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ http_addr = "0.0.0.0:8080"
offline_threshold = 30

# name 主机唯一标识,不可重复,alias 为展示名
# disable_notify = true 是可以单独禁止单台机器的告警,一般针对网络差,频繁上下线
# disabled = true
# notify = false 是可以单独禁止单台机器的告警,一般针对网络差,频繁上下线
# ansible 批量部署时可以用主机 hostname 作为 name,统一密码
hosts = [
{name = "h1", password = "p1", alias = "n1", location = "🏠", type = "kvm", disable_notify = false},
{name = "h2", password = "p2", alias = "n2", location = "🏢", type = "kvm", monthstart = 1},
{name = "h1", password = "p1", alias = "n1", location = "🏠", type = "kvm", notify = true},
{name = "h2", password = "p2", alias = "n2", location = "🏢", type = "kvm", monthstart = 1, disabled = false},
]

# 使用vnstat来更精准统计月流量,开启参考下面 vnstat 一节
Expand Down
8 changes: 6 additions & 2 deletions server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::fs;

use crate::notifier;

fn default_as_true() -> bool {
true
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Host {
pub name: String,
Expand All @@ -18,8 +22,8 @@ pub struct Host {
pub host_type: String,
#[serde(default = "u32::default")]
pub monthstart: u32,
#[serde(default = "bool::default")]
pub disable_notify: bool,
#[serde(default = "default_as_true")]
pub notify: bool,
#[serde(default = "bool::default")]
pub disabled: bool,

Expand Down
4 changes: 2 additions & 2 deletions server/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl StatsMgr {
{
let mut host_stat_map = stat_dict_1.lock().unwrap();
if let Some(pre_stat) = host_stat_map.get(&info.name) {
if !info.disable_notify
if info.notify
&& (pre_stat.latest_ts + cfg.offline_threshold < stat_t.latest_ts)
{
// node up notify
Expand Down Expand Up @@ -182,7 +182,7 @@ impl StatsMgr {
}

if let Some(info) = cfg.get_host(o.name.as_str()) {
if !info.disable_notify {
if info.notify {
// notify check /30 s
if latest_notify_ts + cfg.notify_interval < resp.updated {
if o.online4 || o.online6 {
Expand Down

0 comments on commit c5369d8

Please sign in to comment.