crawler: use the tool's own flake instead of a copy of the script
All checks were successful
nixos / nixos (push) Successful in 21s
All checks were successful
nixos / nixos (push) Successful in 21s
crawler-alert.py was a byte-identical copy of the one in asxpi/traefik-crawlers-statistics. That repository now has a package and a NixOS module with the same three units and timers; iac takes it as a flake input and keeps only the settings. The package also puts dig on the script's path, which the Meta ASN check needs and lacked here. Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
2cde6aafbb
commit
35bc42b01b
1 changed files with 39 additions and 938 deletions
|
|
@ -1,19 +1,12 @@
|
|||
# Crawler watch for Forgejo: separates real AI crawlers from traffic that
|
||||
# only claims to be one, from Traefik's access log. A daily mail when
|
||||
# yesterday crossed the threshold, a weekly summary, and metrics every
|
||||
# five minutes for the Crawlers dashboard.
|
||||
# five minutes for the Crawlers dashboard. The tool and its units are
|
||||
# asxpi/traefik-crawlers-statistics (flake input crawler-alert).
|
||||
{ config, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
# flag: "" (daily alert), "--weekly" or "--metrics"
|
||||
run = flag: extra: {
|
||||
description = "Crawler report ${flag}";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
services.crawler-alert = {
|
||||
enable = true;
|
||||
environment = {
|
||||
CRAWLER_SITE = "git.asxp.io";
|
||||
CRAWLER_THRESHOLD = "100000";
|
||||
|
|
@ -25,58 +18,13 @@ let
|
|||
CRAWLER_SMTP_ADDR = "smtp.fastmail.com";
|
||||
CRAWLER_SMTP_PORT = "587";
|
||||
CRAWLER_SMTP_FROM = "Czechoslovakia Git <noreply@asxp.io>";
|
||||
}
|
||||
// extra;
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
EnvironmentFile = config.sops.templates."crawler.env".path;
|
||||
CacheDirectory = "crawler-alert";
|
||||
ExecStart = "${pkgs.python3}/bin/python3 ${./crawler-alert.py} ${flag}";
|
||||
};
|
||||
environmentFile = config.sops.templates."crawler.env".path;
|
||||
};
|
||||
in
|
||||
{
|
||||
|
||||
sops.templates."crawler.env".content = ''
|
||||
CRAWLER_RECIPIENT=${config.sops.placeholder."alert/recipient"}
|
||||
CRAWLER_SMTP_USER=${config.sops.placeholder."alert/smtp_user"}
|
||||
CRAWLER_SMTP_PASSWORD=${config.sops.placeholder."alert/smtp_password"}
|
||||
'';
|
||||
|
||||
systemd.services = {
|
||||
crawler-alert = run "" { };
|
||||
crawler-weekly = run "--weekly" { };
|
||||
# Every router, not only Forgejo's; fewer DNS lookups per run
|
||||
crawler-metrics = lib.recursiveUpdate (run "--metrics" {
|
||||
CRAWLER_METRICS_ROUTER = "";
|
||||
CRAWLER_RDNS_MAX = "100";
|
||||
}) {
|
||||
serviceConfig = {
|
||||
Nice = 10;
|
||||
TimeoutStartSec = "4min";
|
||||
};
|
||||
};
|
||||
};
|
||||
systemd.timers = {
|
||||
crawler-alert = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "*-*-* 00:15:00";
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
crawler-weekly = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "Mon *-*-* 12:00:00";
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
crawler-metrics = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "*:0/5";
|
||||
RandomizedDelaySec = 30;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue