Compare commits
No commits in common. "7ad6b001eb0ee8fb37dcb297c9e1d682574e8dcd" and "171361480dd724e38e73de642f4fdfe12d9e68c0" have entirely different histories.
7ad6b001eb
...
171361480d
@ -103,10 +103,6 @@ Next you need to find your Telegram Chat ID.
|
|||||||
1. Enter ```/start``` to get the bot to send you your Telegram Chat ID
|
1. Enter ```/start``` to get the bot to send you your Telegram Chat ID
|
||||||
1. Take note of the Telegram Chat ID returned
|
1. Take note of the Telegram Chat ID returned
|
||||||
|
|
||||||
### Service configuration (*nix)
|
|
||||||
|
|
||||||
If you want to get messages when watchdog service is stopped, uncomment following line: ```ExecStopPost=send-telegram 'ATTENTION! Watchdog is stopped!'``` or ```#ExecStopPost=/usr/local/sbin/cai-watchdog-stopped``` if you want message with exclamation icon (⚠)
|
|
||||||
|
|
||||||
## User logins monitoring (*nix)
|
## User logins monitoring (*nix)
|
||||||
|
|
||||||
Watchdog can send notifications on user login. Just add to ```/etc/profile.d/sshinfo.sh``` next lines:
|
Watchdog can send notifications on user login. Just add to ```/etc/profile.d/sshinfo.sh``` next lines:
|
||||||
|
|||||||
@ -6,8 +6,6 @@ User=wwwrun
|
|||||||
Group=www
|
Group=www
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/local/sbin/cai-watchdog
|
ExecStart=/usr/local/sbin/cai-watchdog
|
||||||
#ExecStopPost=/usr/local/sbin/cai-watchdog-stopped
|
|
||||||
#ExecStopPost=send-telegram 'ATTENTION! Watchdog is stopped!'
|
|
||||||
|
|
||||||
KillMode=control-group
|
KillMode=control-group
|
||||||
NotifyAccess=all
|
NotifyAccess=all
|
||||||
@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
rcpt=$1
|
rcpt=$1
|
||||||
subj=$2
|
subj=$2
|
||||||
message=$3
|
message=$3
|
||||||
@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
SCRIPT_NAME=$0
|
SCRIPT_NAME=$0
|
||||||
MESSAGE_TEXT=$1
|
MESSAGE_TEXT=$1
|
||||||
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
ICON_WARNING=$(echo -e "\U26A0")
|
|
||||||
send-telegram "${ICON_WARNING} ATTENTION! Watchdog is stopped!"
|
|
||||||
29
src/main.rs
29
src/main.rs
@ -165,7 +165,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if !Path::new(cfg_file).exists() {
|
if !Path::new(cfg_file).exists() {
|
||||||
println!("\u{26a0} Error! Can't find configuration file.");
|
println!("Error! Can't find configuration file.");
|
||||||
println!("Exiting...");
|
println!("Exiting...");
|
||||||
|
|
||||||
std::process::exit(exitcode::CONFIG);
|
std::process::exit(exitcode::CONFIG);
|
||||||
@ -248,12 +248,12 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if start_notification && notification_command.to_string() != "" {
|
if start_notification && notification_command.to_string() != "" {
|
||||||
debug_log("\u{2139} Service started".to_string());
|
debug_log(format!("Service started"));
|
||||||
|
|
||||||
let shell_cmd = notification_command.to_string()
|
let shell_cmd = notification_command.to_string()
|
||||||
.replace("<email>", ¬ification_email.to_string())
|
.replace("<email>", ¬ification_email.to_string())
|
||||||
.replace("<subject>", "\"\u{2139} Watchdog service started\"")
|
.replace("<subject>", &format!("\"Watchdog service started\""))
|
||||||
.replace("<message>", "\"\u{2139} Watchdog service started\"");
|
.replace("<message>", &format!("\"Watchdog service started\""));
|
||||||
|
|
||||||
debug_log(format!("execute {}", shell_cmd));
|
debug_log(format!("execute {}", shell_cmd));
|
||||||
|
|
||||||
@ -268,14 +268,14 @@ fn main() {
|
|||||||
if check(tasks[i].uri.clone()).await {
|
if check(tasks[i].uri.clone()).await {
|
||||||
if tasks[i].last_state != true || just_started {
|
if tasks[i].last_state != true || just_started {
|
||||||
if tasks[i].command.to_string() == "".to_string() {
|
if tasks[i].command.to_string() == "".to_string() {
|
||||||
println!("\u{2705} {} state changed to true", tasks[i].uri);
|
println!("{} state changed to true", tasks[i].uri);
|
||||||
} else {
|
} else {
|
||||||
debug_log(format!("\u{2705} {} state changed to true", tasks[i].uri));
|
debug_log(format!("{} state changed to true", tasks[i].uri));
|
||||||
|
|
||||||
let shell_cmd = tasks[i].command.to_string()
|
let shell_cmd = tasks[i].command.to_string()
|
||||||
.replace("<email>", &tasks[i].email)
|
.replace("<email>", &tasks[i].email)
|
||||||
.replace("<subject>", &format!("\"\u{2705} Service {} ({}) is online\"", tasks[i].service, tasks[i].uri))
|
.replace("<subject>", &format!("\"Service {} ({}) is online\"", tasks[i].service, tasks[i].uri))
|
||||||
.replace("<message>", &format!("\"\u{2705} Service {} ({}) is now online\"", tasks[i].service, tasks[i].uri));
|
.replace("<message>", &format!("\"Service {} ({}) is now online\"", tasks[i].service, tasks[i].uri));
|
||||||
|
|
||||||
debug_log(format!("execute {}", shell_cmd));
|
debug_log(format!("execute {}", shell_cmd));
|
||||||
|
|
||||||
@ -283,28 +283,27 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_log(format!("\u{2705} {} check is ok", tasks[i].uri));
|
debug_log(format!("{} check is ok", tasks[i].uri));
|
||||||
|
|
||||||
tasks[i].last_state = true;
|
tasks[i].last_state = true;
|
||||||
} else {
|
} else {
|
||||||
if tasks[i].last_state != false || just_started {
|
if tasks[i].last_state != false || just_started {
|
||||||
if tasks[i].command.to_string() == "".to_string() {
|
if tasks[i].command.to_string() == "".to_string() {
|
||||||
println!("\u{274c} {} state changed to false", tasks[i].uri);
|
println!("{} state changed to false", tasks[i].uri);
|
||||||
} else {
|
} else {
|
||||||
debug_log(format!("\u{274c} {} state changed to false", tasks[i].uri));
|
debug_log(format!("{} state changed to false", tasks[i].uri));
|
||||||
|
|
||||||
let shell_cmd = tasks[i].command.to_string()
|
let shell_cmd = tasks[i].command.to_string()
|
||||||
.replace("<email>", &tasks[i].email)
|
.replace("<email>", &tasks[i].email)
|
||||||
.replace("<subject>", &format!("\"\u{274c} Service {} ({}) is offline\"", tasks[i].service, tasks[i].uri))
|
.replace("<subject>", &format!("\"Service {} ({}) is offline\"", tasks[i].service, tasks[i].uri))
|
||||||
.replace("<message>", &format!("\"\u{274c} Service {} ({}) is now offline\"", tasks[i].service, tasks[i].uri))
|
.replace("<message>", &format!("\"Service {} ({}) is now offline\"", tasks[i].service, tasks[i].uri));
|
||||||
.replace("<icon>", "WARNING");
|
|
||||||
|
|
||||||
debug_log(format!("execute {}", shell_cmd));
|
debug_log(format!("execute {}", shell_cmd));
|
||||||
execute(shell_cmd);
|
execute(shell_cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_log(format!("\u{274c} {} check failed", tasks[i].uri));
|
debug_log(format!("{} check failed", tasks[i].uri));
|
||||||
|
|
||||||
tasks[i].last_state = false;
|
tasks[i].last_state = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user