Rewrite the Telegram notifications to writeShellScript
This commit is contained in:
parent
db328bd2f6
commit
625d407195
|
@ -1,27 +1,23 @@
|
|||
{ custom, inputs, pkgs, ... }:
|
||||
let
|
||||
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)
|
||||
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
|
||||
'';
|
||||
unit-status-telegram = pkgs.writeShellScriptBin "unit-status-telegram" ''
|
||||
${pkgs.curl}/bin/curl -s -d "chat_id=$CHAT_ID&disable_web_page_preview=1&text=$1" $URL > /dev/null'';
|
||||
|
||||
unit-status-telegram = pkgs.writeShellScript "unit-status-telegram" ''
|
||||
UNIT="$1"
|
||||
|
||||
UNITSTATUS="$(systemctl status $UNIT)"
|
||||
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:
|
||||
$UNITSTATUS"'';
|
||||
in
|
||||
{
|
||||
environment.systemPackages = with pkgs;
|
||||
[
|
||||
send-to-telegram
|
||||
unit-status-telegram
|
||||
];
|
||||
systemd.services."unit-status-telegram@" = {
|
||||
description = "Unit Status Telegram Service";
|
||||
unitConfig = {
|
||||
|
@ -29,7 +25,7 @@ in
|
|||
};
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
ExecStart = "/run/current-system/sw/bin/unit-status-telegram %I";
|
||||
ExecStart = "${unit-status-telegram} %I";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue