Solved Dont send alert to slack using alertmanager

Hi All, Please help me!

I can’t send alerts to slack using alertmanager.

tree /etc/loki/
/etc/loki/
├── config.yaml
├── rules
│   └── alerts.yaml
└── rulestorage

2 directories, 2 files

alertmanager config

cat /etc/alertmanager/alertmanager.yaml


route:
  group_wait: 10s
  group_by: ['job', 'severity', 'instance', 'region', 'hostname', 'category']
  group_interval: 30s
  repeat_interval: 1h
  receiver: slack


receivers:
  - name: slack
    slack_configs:
      - api_url: "https://hooks.slack.com/services/___slack_token___"
        send_resolved: True
        channel: "alarms"
        color: '{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}'
        pretext: '{{ .CommonAnnotations.summary }}'
        text: |-
          {{ range .Alerts }}
          *Severity:* {{ .Labels.severity }}
          *Alert:* {{ .Annotations.summary }}
          *Description:* {{ .Annotations.description }}
          *Region:* {{ .Labels.region }}
          *IP:* {{ .Labels.instance }}
          *Hostname:* {{ .Labels.hostname }}
          *Details:* {{ .Annotations.dashboard }}
          *Dashboard:* {{ .Annotations.dashboard }}
          *WIKI:* {{ .Annotations.wiki }}
            {{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
            {{ end }}
          {{ end }}

loki config

cat config.yaml

auth_enabled: false

server:
  http_listen_port: 3100

ingester:
  lifecycler:
    address: 127.0.0.1
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
    final_sleep: 0s
  chunk_idle_period: 1h
  max_chunk_age: 1h
  chunk_retain_period: 30s

  wal:
    enabled: true
    dir: /opt/loki/data/wal
    # min_age: 5m
    # max_age: 4h

schema_config:
  configs:
    - from: 2021-11-26
      store: boltdb-shipper
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 24h

storage_config:
  boltdb_shipper:
    active_index_directory: /opt/loki/data/boltdb-shipper-active
    cache_location: /opt/loki/data/boltdb-shipper-cache
    cache_ttl: 1h         # Can be increased for faster performance over longer query periods, uses more disk space
    shared_store: filesystem
  filesystem:
    directory: /opt/loki/data/chunks

compactor:
  working_directory: /opt/loki/data/boltdb-shipper-compactor/
  shared_store: filesystem
  compaction_interval: 10m
  retention_enabled: true
  retention_delete_delay: 720h
  retention_delete_worker_count: 150

limits_config:
  reject_old_samples: true
  reject_old_samples_max_age: 24h # TMP
  retention_period: 720h

chunk_store_config:
  max_look_back_period: 720h

ruler:
  storage:
    type: local
    local:
      directory: /etc/loki/rules
  rule_path: /tmp/loki/rules-temp
  alertmanager_url: http://10.144.46.50:9093
  ring:
    kvstore:
      store: inmemory
  enable_api: true
  enable_alertmanager_v2: true

Alerts:

cat /etc/loki/rules/alerts.yaml
groups:
  - name: patroni-alert
    rules:
      - alert: PatroniSwitchMaster
        expr: 'count_over_time({job="systemd-journal"} |~ "fail" [1m]) > 1'
        for: 1m
        labels:
          severity: warning
        annotations:
          summary: "alert"
          description: "alert desc"
          details: ""
          dashboard: ""
          wiki: ""

where can i wrong?

alerts rule need create in subdir
exemple:

cat /etc/loki/rules/sub_dir/alerts.yaml