{
  "name": "HoL — Grafana L5: Grafana alerts",
  "nodes": [
    {
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [-520, 0],
      "parameters": {
        "httpMethod": "POST",
        "path": "grafana-alert",
        "authentication": "headerAuth",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "name": "Firing or resolved",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [-280, 0],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "g1",
                    "leftValue": "={{ $json.body.status }}",
                    "rightValue": "firing",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "firing"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "g2",
                    "leftValue": "={{ $json.body.status }}",
                    "rightValue": "resolved",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "resolved"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "name": "Firing message",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-40, -160],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "m1",
              "name": "message",
              "value": "={{ $json.body.commonLabels.alertname }} is firing on {{ $json.body.commonLabels.host || 'the box' }} — {{ $json.body.commonAnnotations.summary || $json.body.title }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "name": "Resolved message",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-40, 160],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "m2",
              "name": "message",
              "value": "={{ $json.body.commonLabels.alertname }} resolved — {{ $json.body.commonAnnotations.summary || $json.body.title }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "name": "Waking hours?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [200, -160],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "version": 2
          },
          "conditions": [
            {
              "id": "h1",
              "leftValue": "={{ $now.hour }}",
              "rightValue": 8,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            },
            {
              "id": "h2",
              "leftValue": "={{ $now.hour }}",
              "rightValue": 22,
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "name": "Telegram (loud)",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [440, -260],
      "parameters": {
        "chatId": "YOUR_TELEGRAM_LOUD_CHAT_ID",
        "text": "={{ $json.message }}",
        "additionalFields": {}
      }
    },
    {
      "name": "Telegram (quiet)",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [440, -60],
      "parameters": {
        "chatId": "YOUR_TELEGRAM_QUIET_CHAT_ID",
        "text": "={{ $json.message }}",
        "additionalFields": {}
      }
    },
    {
      "name": "Telegram (resolved)",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [200, 160],
      "parameters": {
        "chatId": "YOUR_TELEGRAM_QUIET_CHAT_ID",
        "text": "={{ $json.message }}",
        "additionalFields": {}
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Firing or resolved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Firing or resolved": {
      "main": [
        [
          {
            "node": "Firing message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Resolved message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Firing message": {
      "main": [
        [
          {
            "node": "Waking hours?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Waking hours?": {
      "main": [
        [
          {
            "node": "Telegram (loud)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram (quiet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Resolved message": {
      "main": [
        [
          {
            "node": "Telegram (resolved)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
