79 lines
2.1 KiB
Nix
79 lines
2.1 KiB
Nix
{ config, pkgs, ... }: {
|
|
services.prometheus = {
|
|
enable = true;
|
|
exporters.node.enable = true;
|
|
scrapeConfigs = [
|
|
{
|
|
job_name = "node";
|
|
static_configs = [
|
|
{
|
|
targets = [
|
|
"localhost:${toString config.services.prometheus.exporters.node.port}"
|
|
];
|
|
}
|
|
];
|
|
}
|
|
];
|
|
};
|
|
sops.secrets.tgbot-env = { };
|
|
systemd = {
|
|
services = {
|
|
network-watchdog = {
|
|
script = ''
|
|
if [ ! -e /run/network.failures ] || [ ! -e /run/network.limit ] || \
|
|
${pkgs.curl}/bin/curl --head --max-time 3 https://bogaledev.ru; then
|
|
limit=3
|
|
failures=0
|
|
else
|
|
limit=$(cat /run/network.limit)
|
|
failures=$((1+$(cat /run/network.failures)))
|
|
fi
|
|
if [ $failures -ge $limit ]; then
|
|
echo "<4>restarting network"
|
|
systemctl restart NetworkManager.service
|
|
sleep 1
|
|
systemctl restart wg-quick-awg0.service
|
|
[ $limit -lt 360 ] && limit=$((2*$limit))
|
|
failures=0
|
|
fi
|
|
echo $limit > /run/network.limit
|
|
echo $failures > /run/network.failures
|
|
'';
|
|
serviceConfig = {
|
|
LogLevelMax = "warning";
|
|
Type = "oneshot";
|
|
};
|
|
};
|
|
tgbot-send = {
|
|
script = ''
|
|
. ${config.sops.secrets.tgbot-env.path}
|
|
for msg in "''${MESSAGES[@]}"; do
|
|
CHAT_ID="''${msg%%:*}"
|
|
TEXT="''${msg#*:}"
|
|
${pkgs.curl}/bin/curl -X POST "https://api.telegram.org/$BOT/sendMessage" \
|
|
-d "chat_id=$CHAT_ID" -d "text=$TEXT" 2> /dev/null | ${pkgs.jq}/bin/jq
|
|
sleep 1
|
|
done
|
|
'';
|
|
serviceConfig.Type = "oneshot";
|
|
};
|
|
};
|
|
timers = {
|
|
network-watchdog = {
|
|
timerConfig = {
|
|
AccuracySec = 1;
|
|
OnBootSec = 30;
|
|
OnUnitActiveSec = 10;
|
|
};
|
|
wantedBy = [ "timers.target" ];
|
|
};
|
|
tgbot-send = {
|
|
timerConfig = {
|
|
OnCalendar = "*-*-01 16:00";
|
|
Persistent = true;
|
|
};
|
|
wantedBy = [ "timers.target" ];
|
|
};
|
|
};
|
|
};
|
|
}
|