From 56d738bf8e8282dd39ff1d6ee2a1db8131d91b80 Mon Sep 17 00:00:00 2001 From: "Alexander I. Chebykin" Date: Wed, 29 Jun 2022 01:38:00 +0300 Subject: [PATCH] Added unicode icons in messages Added unicode icons in messages --- README.md | 4 +++ .../lib/systemd/system}/cai-watchdog.service | 2 ++ .../unix/usr/local/sbin/cai-watchdog-stopped | 3 ++ .../unix/usr/local/{bin => sbin}/send-mail | 1 - .../usr/local/{bin => sbin}/send-telegram | 3 +- src/main.rs | 29 ++++++++++--------- 6 files changed, 25 insertions(+), 17 deletions(-) rename scripts/unix/{ => usr/lib/systemd/system}/cai-watchdog.service (67%) create mode 100644 scripts/unix/usr/local/sbin/cai-watchdog-stopped rename scripts/unix/usr/local/{bin => sbin}/send-mail (99%) rename scripts/unix/usr/local/{bin => sbin}/send-telegram (99%) diff --git a/README.md b/README.md index 596ed8f..7321491 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/scripts/unix/cai-watchdog.service b/scripts/unix/usr/lib/systemd/system/cai-watchdog.service similarity index 67% rename from scripts/unix/cai-watchdog.service rename to scripts/unix/usr/lib/systemd/system/cai-watchdog.service index 7034f36..0e69852 100644 --- a/scripts/unix/cai-watchdog.service +++ b/scripts/unix/usr/lib/systemd/system/cai-watchdog.service @@ -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 diff --git a/scripts/unix/usr/local/sbin/cai-watchdog-stopped b/scripts/unix/usr/local/sbin/cai-watchdog-stopped new file mode 100644 index 0000000..6b3e527 --- /dev/null +++ b/scripts/unix/usr/local/sbin/cai-watchdog-stopped @@ -0,0 +1,3 @@ +#!/bin/bash +ICON_WARNING=$(echo -e "\U26A0") +send-telegram "${ICON_WARNING} ATTENTION! Watchdog is stopped!" diff --git a/scripts/unix/usr/local/bin/send-mail b/scripts/unix/usr/local/sbin/send-mail similarity index 99% rename from scripts/unix/usr/local/bin/send-mail rename to scripts/unix/usr/local/sbin/send-mail index a522dbf..007c275 100644 --- a/scripts/unix/usr/local/bin/send-mail +++ b/scripts/unix/usr/local/sbin/send-mail @@ -1,5 +1,4 @@ #!/bin/bash - rcpt=$1 subj=$2 message=$3 diff --git a/scripts/unix/usr/local/bin/send-telegram b/scripts/unix/usr/local/sbin/send-telegram similarity index 99% rename from scripts/unix/usr/local/bin/send-telegram rename to scripts/unix/usr/local/sbin/send-telegram index 3bc127a..fab1bba 100644 --- a/scripts/unix/usr/local/bin/send-telegram +++ b/scripts/unix/usr/local/sbin/send-telegram @@ -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 \ No newline at end of file +curl -s --data "text=${MESSAGE_TEXT}" --data "chat_id=$GROUP_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null diff --git a/src/main.rs b/src/main.rs index 7961456..cb20074 100644 --- a/src/main.rs +++ b/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("", ¬ification_email.to_string()) - .replace("", &format!("\"Watchdog service started\"")) - .replace("", &format!("\"Watchdog service started\"")); + .replace("", "\"\u{2139} Watchdog service started\"") + .replace("", "\"\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("", &tasks[i].email) - .replace("", &format!("\"Service {} ({}) is online\"", tasks[i].service, tasks[i].uri)) - .replace("", &format!("\"Service {} ({}) is now online\"", tasks[i].service, tasks[i].uri)); + .replace("", &format!("\"\u{2705} Service {} ({}) is online\"", tasks[i].service, tasks[i].uri)) + .replace("", &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("", &tasks[i].email) - .replace("", &format!("\"Service {} ({}) is offline\"", tasks[i].service, tasks[i].uri)) - .replace("", &format!("\"Service {} ({}) is now offline\"", tasks[i].service, tasks[i].uri)); + .replace("", &format!("\"\u{274c} Service {} ({}) is offline\"", tasks[i].service, tasks[i].uri)) + .replace("", &format!("\"\u{274c} Service {} ({}) is now offline\"", tasks[i].service, tasks[i].uri)) + .replace("", "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; }