Merge pull request 'Added unicode icons in messages' (#10) from v1 into master
Reviewed-on: https://www.cainet.info/git/cai/CAI-Watchdog/pulls/10
This commit is contained in:
commit
7ad6b001eb
@ -103,6 +103,10 @@ Next you need to find 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
|
||||
|
||||
### 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)
|
||||
|
||||
Watchdog can send notifications on user login. Just add to ```/etc/profile.d/sshinfo.sh``` next lines:
|
||||
|
||||
@ -6,6 +6,8 @@ User=wwwrun
|
||||
Group=www
|
||||
Type=simple
|
||||
ExecStart=/usr/local/sbin/cai-watchdog
|
||||
#ExecStopPost=/usr/local/sbin/cai-watchdog-stopped
|
||||
#ExecStopPost=send-telegram 'ATTENTION! Watchdog is stopped!'
|
||||
|
||||
KillMode=control-group
|
||||
NotifyAccess=all
|
||||
3
scripts/unix/usr/local/sbin/cai-watchdog-stopped
Normal file
3
scripts/unix/usr/local/sbin/cai-watchdog-stopped
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
ICON_WARNING=$(echo -e "\U26A0")
|
||||
send-telegram "${ICON_WARNING} ATTENTION! Watchdog is stopped!"
|
||||
@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
rcpt=$1
|
||||
subj=$2
|
||||
message=$3
|
||||
@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_NAME=$0
|
||||
MESSAGE_TEXT=$1
|
||||
|
||||
@ -26,4 +25,4 @@ if [ -z "${MESSAGE_TEXT}" ]
|
||||
exit 0
|
||||
fi
|
||||
|
||||
curl -s --data "text=${MESSAGE_TEXT}" --data "chat_id=$GROUP_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null
|
||||
curl -s --data "text=${MESSAGE_TEXT}" --data "chat_id=$GROUP_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null
|
||||
29
src/main.rs
29
src/main.rs
@ -165,7 +165,7 @@ fn main() {
|
||||
};
|
||||
|
||||
if !Path::new(cfg_file).exists() {
|
||||
println!("Error! Can't find configuration file.");
|
||||
println!("\u{26a0} Error! Can't find configuration file.");
|
||||
println!("Exiting...");
|
||||
|
||||
std::process::exit(exitcode::CONFIG);
|
||||
@ -248,12 +248,12 @@ fn main() {
|
||||
};
|
||||
|
||||
if start_notification && notification_command.to_string() != "" {
|
||||
debug_log(format!("Service started"));
|
||||
debug_log("\u{2139} Service started".to_string());
|
||||
|
||||
let shell_cmd = notification_command.to_string()
|
||||
.replace("<email>", ¬ification_email.to_string())
|
||||
.replace("<subject>", &format!("\"Watchdog service started\""))
|
||||
.replace("<message>", &format!("\"Watchdog service started\""));
|
||||
.replace("<subject>", "\"\u{2139} Watchdog service started\"")
|
||||
.replace("<message>", "\"\u{2139} Watchdog service started\"");
|
||||
|
||||
debug_log(format!("execute {}", shell_cmd));
|
||||
|
||||
@ -268,14 +268,14 @@ fn main() {
|
||||
if check(tasks[i].uri.clone()).await {
|
||||
if tasks[i].last_state != true || just_started {
|
||||
if tasks[i].command.to_string() == "".to_string() {
|
||||
println!("{} state changed to true", tasks[i].uri);
|
||||
println!("\u{2705} {} state changed to true", tasks[i].uri);
|
||||
} else {
|
||||
debug_log(format!("{} state changed to true", tasks[i].uri));
|
||||
debug_log(format!("\u{2705} {} state changed to true", tasks[i].uri));
|
||||
|
||||
let shell_cmd = tasks[i].command.to_string()
|
||||
.replace("<email>", &tasks[i].email)
|
||||
.replace("<subject>", &format!("\"Service {} ({}) is online\"", tasks[i].service, tasks[i].uri))
|
||||
.replace("<message>", &format!("\"Service {} ({}) is now online\"", tasks[i].service, tasks[i].uri));
|
||||
.replace("<subject>", &format!("\"\u{2705} Service {} ({}) is online\"", tasks[i].service, tasks[i].uri))
|
||||
.replace("<message>", &format!("\"\u{2705} Service {} ({}) is now online\"", tasks[i].service, tasks[i].uri));
|
||||
|
||||
debug_log(format!("execute {}", shell_cmd));
|
||||
|
||||
@ -283,27 +283,28 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
debug_log(format!("{} check is ok", tasks[i].uri));
|
||||
debug_log(format!("\u{2705} {} check is ok", tasks[i].uri));
|
||||
|
||||
tasks[i].last_state = true;
|
||||
} else {
|
||||
if tasks[i].last_state != false || just_started {
|
||||
if tasks[i].command.to_string() == "".to_string() {
|
||||
println!("{} state changed to false", tasks[i].uri);
|
||||
println!("\u{274c} {} state changed to false", tasks[i].uri);
|
||||
} else {
|
||||
debug_log(format!("{} state changed to false", tasks[i].uri));
|
||||
debug_log(format!("\u{274c} {} state changed to false", tasks[i].uri));
|
||||
|
||||
let shell_cmd = tasks[i].command.to_string()
|
||||
.replace("<email>", &tasks[i].email)
|
||||
.replace("<subject>", &format!("\"Service {} ({}) is offline\"", tasks[i].service, tasks[i].uri))
|
||||
.replace("<message>", &format!("\"Service {} ({}) is now offline\"", tasks[i].service, tasks[i].uri));
|
||||
.replace("<subject>", &format!("\"\u{274c} 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("<icon>", "WARNING");
|
||||
|
||||
debug_log(format!("execute {}", shell_cmd));
|
||||
execute(shell_cmd);
|
||||
}
|
||||
}
|
||||
|
||||
debug_log(format!("{} check failed", tasks[i].uri));
|
||||
debug_log(format!("\u{274c} {} check failed", tasks[i].uri));
|
||||
|
||||
tasks[i].last_state = false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user