Rewrite the Telegram notifications to writeShellScript
This commit is contained in:
parent
db328bd2f6
commit
625d407195
|
@ -1,27 +1,23 @@
|
||||||
{ custom, inputs, pkgs, ... }:
|
{ custom, inputs, pkgs, ... }:
|
||||||
let
|
let
|
||||||
telegram-notify-env = "/home/${custom.username}/.nixos/secrets/passwords/telegram_notify_env";
|
telegram-notify-env = "/home/${custom.username}/.nixos/secrets/passwords/telegram_notify_env";
|
||||||
send-to-telegram = pkgs.writeShellScriptBin "send-to-telegram" ''
|
|
||||||
|
send-to-telegram = pkgs.writeShellScript "send-to-telegram" ''
|
||||||
export $(${pkgs.gnugrep}/bin/grep -v '^#' ${telegram-notify-env} | ${pkgs.findutils}/bin/xargs)
|
export $(${pkgs.gnugrep}/bin/grep -v '^#' ${telegram-notify-env} | ${pkgs.findutils}/bin/xargs)
|
||||||
URL="https://api.telegram.org/bot$TELEGRAM_KEY/sendMessage"
|
URL="https://api.telegram.org/bot$TELEGRAM_KEY/sendMessage"
|
||||||
${pkgs.curl}/bin/curl -s -d "chat_id=$CHAT_ID&disable_web_page_preview=1&text=$1" $URL > /dev/null
|
${pkgs.curl}/bin/curl -s -d "chat_id=$CHAT_ID&disable_web_page_preview=1&text=$1" $URL > /dev/null'';
|
||||||
'';
|
|
||||||
unit-status-telegram = pkgs.writeShellScriptBin "unit-status-telegram" ''
|
unit-status-telegram = pkgs.writeShellScript "unit-status-telegram" ''
|
||||||
UNIT="$1"
|
UNIT="$1"
|
||||||
|
|
||||||
UNITSTATUS="$(systemctl status $UNIT)"
|
UNITSTATUS="$(systemctl status $UNIT)"
|
||||||
ALERT="$(echo -e "\u26A0")"
|
ALERT="$(echo -e "\u26A0")"
|
||||||
|
|
||||||
/run/current-system/sw/bin/send-to-telegram "$ALERT Unit failed $UNIT $ALERT
|
${send-to-telegram} "$ALERT Unit failed $UNIT $ALERT
|
||||||
Status:
|
Status:
|
||||||
$UNITSTATUS"'';
|
$UNITSTATUS"'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
environment.systemPackages = with pkgs;
|
|
||||||
[
|
|
||||||
send-to-telegram
|
|
||||||
unit-status-telegram
|
|
||||||
];
|
|
||||||
systemd.services."unit-status-telegram@" = {
|
systemd.services."unit-status-telegram@" = {
|
||||||
description = "Unit Status Telegram Service";
|
description = "Unit Status Telegram Service";
|
||||||
unitConfig = {
|
unitConfig = {
|
||||||
|
@ -29,7 +25,7 @@ in
|
||||||
};
|
};
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
ExecStart = "/run/current-system/sw/bin/unit-status-telegram %I";
|
ExecStart = "${unit-status-telegram} %I";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user