{
  "$schema": "./.schemas/page.schema.json",
  "title": "Certificates",
  "icon": "lock",
  "sidebar": false,
  "sources": {
    "kuma": {
      "url": "https://kuma.example.com",
      "secret": "kuma",
      "every": "1m",
      "auth": {
        "type": "basic"
      },
      "requests": {
        "monitors": {
          "path": "/metrics",
          "format": "prometheus",
          "group_by": "monitor_id",
          "split_by": [
            "window"
          ]
        }
      },
      "derive": [
        {
          "name": "cert_count",
          "value": {
            "count": "monitors",
            "where": {
              "path": "monitor_cert_days_remaining",
              "gte": -36500
            }
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "certs",
      "type": "list",
      "label": "Expiring soonest",
      "max_items": 15,
      "items": [],
      "source": {
        "ref": "kuma",
        "map": {
          "items": {
            "each": "monitors",
            "where": {
              "path": "monitor_cert_days_remaining",
              "gte": -36500
            },
            "sort": "monitor_cert_days_remaining",
            "limit": 20,
            "fields": {
              "text": "monitor_name",
              "url": {
                "template": "legato://page/uptime-monitor?id={monitor_id|raw}"
              },
              "detail": {
                "if": {
                  "path": "monitor_cert_days_remaining",
                  "lt": 0
                },
                "then": {
                  "template": "Expired"
                },
                "else": {
                  "template": "{monitor_cert_days_remaining} days left"
                }
              }
            }
          }
        }
      }
    },
    {
      "id": "more",
      "type": "text",
      "tone": "info",
      "body": "",
      "source": {
        "ref": "kuma",
        "when": {
          "path": "cert_count",
          "gt": 20
        },
        "map": {
          "body": {
            "template": "The 20 expiring soonest of {cert_count}. [Uptime Kuma](https://kuma.example.com) lists them all."
          }
        }
      }
    }
  ]
}
