diff --git a/nixos/hosts/asxpio-ops/monitoring/alert-rules.yaml b/nixos/hosts/asxpio-ops/monitoring/alert-rules.yaml index 37725cf..e05a6aa 100644 --- a/nixos/hosts/asxpio-ops/monitoring/alert-rules.yaml +++ b/nixos/hosts/asxpio-ops/monitoring/alert-rules.yaml @@ -325,7 +325,8 @@ groups: - refId: A relativeTimeRange: { from: 900, to: 0 } datasourceUid: prometheus - model: { refId: A, expr: "changes(security_fileset_hash[15m])", instant: true, intervalMs: 30000, maxDataPoints: 43200 } + # Not within 20 minutes of a NixOS activation: deploys rewrite accounts and authorized_keys + model: { refId: A, expr: "changes(security_fileset_hash[15m]) unless on(host) (time() - nixos_activation_timestamp_seconds < 1200)", instant: true, intervalMs: 30000, maxDataPoints: 43200 } - refId: C datasourceUid: __expr__ model: { refId: C, type: threshold, expression: A, conditions: [ { evaluator: { type: gt, params: [0] } } ] } diff --git a/nixos/modules/monitoring-agent.nix b/nixos/modules/monitoring-agent.nix index eee9df9..49cbdd7 100644 --- a/nixos/modules/monitoring-agent.nix +++ b/nixos/modules/monitoring-agent.nix @@ -190,6 +190,19 @@ in systemd.tmpfiles.rules = [ "d ${textfile} 0755 root root -" ]; + # When this host last activated a NixOS configuration (deploy or + # boot). Activations rewrite accounts and authorized_keys by design; + # the "Access files changed" alert stays quiet around them and still + # fires for a change outside a deploy, which here means a hand edit. + system.activationScripts.activationMetric = { + deps = [ ]; + text = '' + mkdir -p ${textfile} + printf '# HELP nixos_activation_timestamp_seconds Last NixOS activation (deploy or boot).\n# TYPE nixos_activation_timestamp_seconds gauge\nnixos_activation_timestamp_seconds %s\n' "$(${pkgs.coreutils}/bin/date +%s)" > ${textfile}/nixos.prom.tmp + mv ${textfile}/nixos.prom.tmp ${textfile}/nixos.prom + ''; + }; + services.prometheus.exporters.node = { enable = true; listenAddress = ip;