config.alloy.j2 82 lignes · 2602 octets
// {{ ansible_managed }}
// Collecte des journaux vers Loki et comptage des échecs de connexion LDAP (alerte Prometheus).

loki.write "local" {
  endpoint {
    url = "http://{{ oiam_supervision_adresse }}:3100/loki/api/v1/push"
  }
}

loki.relabel "journal" {
  forward_to = []
  rule {
    source_labels = ["__journal__systemd_unit"]
    target_label  = "unit"
  }
  rule {
    source_labels = ["__journal_syslog_identifier"]
    target_label  = "identifiant"
  }
}

loki.source.journal "systeme" {
  forward_to    = [loki.process.journal.receiver]
  relabel_rules = loki.relabel.journal.rules
  max_age       = "12h"
  labels        = { job = "journal", hote = "{{ inventory_hostname }}" }
}

loki.process "journal" {
  forward_to = [loki.write.local.receiver]

  // Une connexion LDAP refusée pour identifiants invalides : « RESULT tag=97 err=49 ».
  stage.match {
    selector = "{unit=\"slapd-ltb.service\"} |= \"RESULT tag=97 err=49\""
    stage.metrics {
      metric.counter {
        name        = "oiam_ldap_bind_echecs_total"
        description = "Connexions LDAP refusées (identifiants invalides)"
        match_all   = true
        action      = "inc"
      }
    }
  }
}

local.file_match "web" {
  path_targets = [
    { __path__ = "/var/log/nginx/*.log", job = "nginx", hote = "{{ inventory_hostname }}" },
    { __path__ = "/var/log/self-service-password/*.log", job = "ssp", hote = "{{ inventory_hostname }}" },
    { __path__ = "/var/log/white-pages/*.log", job = "white-pages", hote = "{{ inventory_hostname }}" },
    { __path__ = "/var/log/service-desk/*.log", job = "service-desk", hote = "{{ inventory_hostname }}" },
  ]
}

loki.source.file "web" {
  targets    = local.file_match.web.targets
  forward_to = [loki.write.local.receiver]
}

// Journal d'audit de l'annuaire (overlay auditlog, LDIF) : une entrée Loki par opération, mots de
// passe masqués avant envoi.
local.file_match "ldap_audit" {
  path_targets = [{ __path__ = "{{ oiam_ldap_var | default('/usr/local/openldap/var') }}/auditlog/audit.ldif", job = "ldap-audit", hote = "{{ inventory_hostname }}" }]
}

loki.source.file "ldap_audit" {
  targets    = local.file_match.ldap_audit.targets
  forward_to = [loki.process.ldap_audit.receiver]
}

loki.process "ldap_audit" {
  forward_to = [loki.write.local.receiver]
  stage.multiline {
    firstline     = "^# (add|modify|delete|modrdn) [0-9]+"
    max_wait_time = "3s"
  }
  // Seul le groupe capturé est remplacé : la valeur, base64 (« :: ») ou non.
  stage.replace {
    expression = "(?m)^userPassword::? (.*)$"
    replace    = "[masqué]"
  }
}