Added unicode icons in messages
Added unicode icons in messages
This commit is contained in:
parent
2605fef9be
commit
56d738bf8e
@ -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. 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,6 +6,8 @@ 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
|
||||||
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
|
#!/bin/bash
|
||||||
|
|
||||||
rcpt=$1
|
rcpt=$1
|
||||||
subj=$2
|
subj=$2
|
||||||
message=$3
|
message=$3
|
||||||
@ -1,5 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
SCRIPT_NAME=$0
|
SCRIPT_NAME=$0
|
||||||
MESSAGE_TEXT=$1
|
MESSAGE_TEXT=$1
|
||||||
|
|
||||||
@ -26,4 +25,4 @@ if [ -z "${MESSAGE_TEXT}" ]
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
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() {
|
if !Path::new(cfg_file).exists() {
|
||||||
println!("Error! Can't find configuration file.");
|
println!("\u{26a0} 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(format!("Service started"));
|
debug_log("\u{2139} Service started".to_string());
|
||||||
|
|
||||||
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>", &format!("\"Watchdog service started\""))
|
.replace("<subject>", "\"\u{2139} Watchdog service started\"")
|
||||||
.replace("<message>", &format!("\"Watchdog service started\""));
|
.replace("<message>", "\"\u{2139} 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!("{} state changed to true", tasks[i].uri);
|
println!("\u{2705} {} state changed to true", tasks[i].uri);
|
||||||
} else {
|
} 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()
|
let shell_cmd = tasks[i].command.to_string()
|
||||||
.replace("<email>", &tasks[i].email)
|
.replace("<email>", &tasks[i].email)
|
||||||
.replace("<subject>", &format!("\"Service {} ({}) is online\"", tasks[i].service, tasks[i].uri))
|
.replace("<subject>", &format!("\"\u{2705} Service {} ({}) is online\"", tasks[i].service, tasks[i].uri))
|
||||||
.replace("<message>", &format!("\"Service {} ({}) is now 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));
|
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;
|
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!("{} state changed to false", tasks[i].uri);
|
println!("\u{274c} {} state changed to false", tasks[i].uri);
|
||||||
} else {
|
} 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()
|
let shell_cmd = tasks[i].command.to_string()
|
||||||
.replace("<email>", &tasks[i].email)
|
.replace("<email>", &tasks[i].email)
|
||||||
.replace("<subject>", &format!("\"Service {} ({}) is offline\"", tasks[i].service, tasks[i].uri))
|
.replace("<subject>", &format!("\"\u{274c} Service {} ({}) is offline\"", tasks[i].service, tasks[i].uri))
|
||||||
.replace("<message>", &format!("\"Service {} ({}) is now 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));
|
debug_log(format!("execute {}", shell_cmd));
|
||||||
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;
|
tasks[i].last_state = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user