{
  "$schema": "./.schemas/page.schema.json",
  "title": "Proxmox",
  "icon": "server.rack",
  "period": {
    "choices": [
      {
        "id": "hour",
        "label": "Hour",
        "last_days": 1
      },
      {
        "id": "day",
        "label": "Day",
        "last_days": 1
      },
      {
        "id": "week",
        "label": "Week",
        "last_days": 7
      },
      {
        "id": "month",
        "label": "Month",
        "last_days": 30
      }
    ]
  },
  "sources": {
    "host-history": {
      "auth": {
        "name": "Authorization",
        "type": "header"
      },
      "derive": [
        {
          "name": "readings",
          "value": {
            "count": "data.data",
            "where": {
              "gte": 0,
              "path": "cpu"
            }
          }
        },
        {
          "name": "shown",
          "value": {
            "template": "{period.id}"
          }
        }
      ],
      "every": "1m",
      "requests": {
        "data": "/api2/json/nodes/pve1/rrddata?timeframe={period.id}&cf=AVERAGE"
      },
      "secret": "proxmox",
      "url": "https://proxmox.example.com:8006"
    },
    "maintenance": {
      "auth": {
        "name": "Authorization",
        "type": "header"
      },
      "derive": [
        {
          "name": "installed",
          "value": {
            "each": "versions.data",
            "fields": {
              "candidate": {
                "first": "Version",
                "of": "rows"
              },
              "installed": {
                "first": "OldVersion",
                "of": "rows"
              },
              "package": "key"
            },
            "group": "Package",
            "where": {
              "equals": "Installed",
              "path": "CurrentState"
            }
          }
        },
        {
          "name": "changes",
          "value": {
            "each": "installed",
            "fields": {
              "candidate": "candidate",
              "installed": "installed",
              "package": "package"
            },
            "where": {
              "all": [
                {
                  "not": {
                    "path": "installed"
                  },
                  "path": "candidate"
                },
                {
                  "not": "",
                  "path": "installed"
                }
              ]
            }
          }
        },
        {
          "name": "updates",
          "value": {
            "count": "changes"
          }
        },
        {
          "name": "running_kernel",
          "value": {
            "first": "RunningKernel",
            "of": "versions.data",
            "where": {
              "equals": "proxmox-ve",
              "path": "Package"
            }
          }
        },
        {
          "name": "newest_kernel",
          "value": {
            "first": "Package",
            "of": "versions.data",
            "where": {
              "all": [
                {
                  "equals": "Installed",
                  "path": "CurrentState"
                },
                {
                  "contains": "-pve-signed",
                  "path": "Package"
                }
              ]
            }
          }
        },
        {
          "name": "up_days",
          "value": {
            "divide": [
              "node.data.uptime",
              86400
            ],
            "round": 0
          }
        }
      ],
      "every": "1m",
      "requests": {
        "node": "/api2/json/nodes/pve1/status",
        "time": "/api2/json/nodes/pve1/time",
        "versions": "/api2/json/nodes/pve1/apt/versions"
      },
      "secret": "proxmox",
      "url": "https://proxmox.example.com:8006"
    },
    "pve": {
      "auth": {
        "name": "Authorization",
        "type": "header"
      },
      "derive": [
        {
          "name": "host_status",
          "value": {
            "first": "status",
            "of": "resources.data",
            "where": {
              "equals": "node",
              "path": "type"
            }
          }
        },
        {
          "name": "up_days",
          "value": {
            "divide": [
              "node.data.uptime",
              86400
            ],
            "round": 0
          }
        },
        {
          "name": "cpu_pct",
          "value": {
            "path": "node.data.cpu",
            "round": 0,
            "scale": 100
          }
        },
        {
          "name": "mem_pct",
          "value": {
            "divide": [
              "node.data.memory.used",
              "node.data.memory.total"
            ],
            "round": 0,
            "scale": 100
          }
        },
        {
          "name": "mem_used_gb",
          "value": {
            "path": "node.data.memory.used",
            "round": 1,
            "scale": 1e-09
          }
        },
        {
          "name": "mem_total_gb",
          "value": {
            "path": "node.data.memory.total",
            "round": 0,
            "scale": 1e-09
          }
        },
        {
          "name": "guests",
          "value": {
            "each": "resources.data",
            "fields": {
              "cpu_pct": {
                "path": "cpu",
                "round": 1,
                "scale": 100
              },
              "max_gb": {
                "path": "maxmem",
                "round": 0,
                "scale": 1e-09
              },
              "mem_gb": {
                "path": "mem",
                "round": 1,
                "scale": 1e-09
              },
              "name": "name",
              "status": "status",
              "tags": "tags",
              "up_days": {
                "divide": [
                  "uptime",
                  86400
                ],
                "round": 0
              },
              "vmid": "vmid",
              "id": {
                "template": "{vmid|raw}"
              }
            },
            "sort": "vmid",
            "where": {
              "equals": "qemu",
              "path": "type"
            }
          }
        },
        {
          "name": "running",
          "value": {
            "count": "guests",
            "where": {
              "equals": "running",
              "path": "status"
            }
          }
        },
        {
          "name": "guest_count",
          "value": {
            "count": "guests"
          }
        },
        {
          "name": "guest_rows",
          "value": {
            "each": "guests",
            "fields": {
              "cpu": {
                "else": {
                  "template": "—"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "template": "{cpu_pct}%"
                }
              },
              "memory": {
                "else": {
                  "template": "{max_gb} GB given"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "template": "{mem_gb} of {max_gb} GB"
                }
              },
              "name": "name",
              "state": {
                "else": {
                  "template": "Stopped"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "template": "Running"
                }
              },
              "up": {
                "else": {
                  "template": "—"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "else": {
                    "template": "{up_days} days"
                  },
                  "if": {
                    "equals": 0,
                    "path": "up_days"
                  },
                  "then": {
                    "template": "Started today"
                  }
                }
              },
              "vmid": "vmid"
            }
          }
        }
      ],
      "every": "1m",
      "requests": {
        "node": "/api2/json/nodes/pve1/status",
        "resources": "/api2/json/cluster/resources",
        "time": "/api2/json/nodes/pve1/time",
        "version": "/api2/json/version"
      },
      "secret": "proxmox",
      "url": "https://proxmox.example.com:8006",
      "collect": {
        "dataset": "proxmox-guest-samples",
        "each": "guests",
        "key": "{id}",
        "sample": {
          "every": "5m"
        },
        "fields": {
          "state": {
            "else": {
              "else": {
                "template": "critical"
              },
              "if": {
                "contains": "standby",
                "path": "tags"
              },
              "then": {
                "template": "off"
              }
            },
            "if": {
              "equals": "running",
              "path": "status"
            },
            "then": {
              "template": "ok"
            }
          }
        },
        "readers": [
          "proxmox-vm"
        ]
      }
    },
    "pve-backup": {
      "auth": {
        "name": "Authorization",
        "type": "header"
      },
      "derive": [
        {
          "name": "backup_age",
          "value": {
            "subtract": [
              "time.data.time",
              "backup.data[0].endtime"
            ]
          }
        },
        {
          "name": "backup_min",
          "value": {
            "divide": [
              {
                "subtract": [
                  "backup.data[0].endtime",
                  "backup.data[0].starttime"
                ]
              },
              60
            ],
            "round": 0
          }
        },
        {
          "name": "backup_state",
          "value": {
            "else": {
              "template": "warning"
            },
            "if": {
              "all": [
                {
                  "equals": "OK",
                  "path": "backup.data[0].status"
                },
                {
                  "lt": 93600,
                  "path": "backup_age"
                }
              ]
            },
            "then": {
              "template": "ok"
            }
          }
        },
        {
          "name": "backing_up",
          "value": {
            "count": "active.data",
            "where": {
              "equals": "vzdump",
              "path": "type"
            }
          }
        }
      ],
      "every": "1m",
      "requests": {
        "active": "/api2/json/nodes/pve1/tasks?source=active",
        "backup": "/api2/json/nodes/pve1/tasks?typefilter=vzdump&limit=1",
        "time": "/api2/json/nodes/pve1/time"
      },
      "secret": "proxmox",
      "url": "https://proxmox.example.com:8006"
    },
    "pve-slow": {
      "auth": {
        "name": "Authorization",
        "type": "header"
      },
      "derive": [
        {
          "name": "unas_pct",
          "value": {
            "first": "used_fraction",
            "of": "storage.data",
            "round": 0,
            "scale": 100,
            "where": {
              "equals": "backup-nas",
              "path": "storage"
            }
          }
        },
        {
          "name": "lvm_pct",
          "value": {
            "first": "used_fraction",
            "of": "storage.data",
            "round": 0,
            "scale": 100,
            "where": {
              "equals": "local-lvm",
              "path": "storage"
            }
          }
        },
        {
          "name": "newest",
          "value": {
            "each": "backups.data",
            "fields": {
              "at": {
                "max": "ctime",
                "of": "rows"
              },
              "count": "count",
              "gb": {
                "max": "size",
                "of": "rows",
                "round": 1,
                "scale": 1e-09
              },
              "name": {
                "first": "notes",
                "of": "rows"
              },
              "vmid": "key"
            },
            "group": "vmid"
          }
        },
        {
          "name": "uncovered",
          "value": {
            "count": "notbacked.data"
          }
        }
      ],
      "every": "15m",
      "requests": {
        "backups": "/api2/json/nodes/pve1/storage/backup-nas/content?content=backup",
        "jobs": "/api2/json/cluster/backup",
        "notbacked": "/api2/json/cluster/backup-info/not-backed-up",
        "storage": "/api2/json/nodes/pve1/storage"
      },
      "secret": "proxmox",
      "url": "https://proxmox.example.com:8006"
    }
  },
  "cards": [
    {
      "id": "host",
      "label": "pve1",
      "source": {
        "failed": {
          "after": 3,
          "detail": "Proxmox isn't answering",
          "state": "critical"
        },
        "map": {
          "detail": {
            "else": {
              "template": "Up {up_days} days · PVE {version.data.version}"
            },
            "if": {
              "any": [
                {
                  "gte": 85,
                  "path": "cpu_pct"
                },
                {
                  "gte": 90,
                  "path": "mem_pct"
                }
              ]
            },
            "then": {
              "template": "CPU {cpu_pct}% · memory {mem_pct}%"
            }
          },
          "state": {
            "else": {
              "else": {
                "else": {
                  "template": "ok"
                },
                "if": {
                  "any": [
                    {
                      "gte": 85,
                      "path": "cpu_pct"
                    },
                    {
                      "gte": 90,
                      "path": "mem_pct"
                    }
                  ]
                },
                "then": {
                  "template": "warning"
                }
              },
              "if": {
                "any": [
                  {
                    "gte": 95,
                    "path": "cpu_pct"
                  },
                  {
                    "gte": 97,
                    "path": "mem_pct"
                  }
                ]
              },
              "then": {
                "template": "critical"
              }
            },
            "if": {
              "not": "online",
              "path": "host_status"
            },
            "then": {
              "template": "critical"
            }
          }
        },
        "ref": "pve"
      },
      "state": "ok",
      "type": "status",
      "placement": "page_info",
      "url": "https://proxmox.example.com:8006"
    },
    {
      "id": "backup",
      "label": "Nightly backup",
      "source": {
        "map": {
          "detail": {
            "else": {
              "template": "Finished {backup.data[0].endtime|ago} · {backup_min} min"
            },
            "if": {
              "gt": 0,
              "path": "backing_up"
            },
            "then": {
              "template": "Backing up now"
            }
          },
          "state": "backup_state"
        },
        "ref": "pve-backup"
      },
      "state": "ok",
      "type": "status",
      "placement": "page_info",
      "url": "legato://page/proxmox-backups"
    },
    {
      "change": false,
      "id": "cpu",
      "label": "CPU",
      "points": [
        0,
        0
      ],
      "source": {
        "empty": {
          "text": "No readings in this period",
          "when": {
            "lt": 2,
            "path": "readings"
          }
        },
        "map": {
          "axis_labels": {
            "else": {
              "else": {
                "else": {
                  "buckets": 240,
                  "each": "data.data",
                  "template": "{time|date}",
                  "where": {
                    "gte": 0,
                    "path": "cpu"
                  }
                },
                "if": {
                  "equals": "week",
                  "path": "shown"
                },
                "then": {
                  "buckets": 240,
                  "each": "data.data",
                  "template": "{time|weekday}",
                  "where": {
                    "gte": 0,
                    "path": "cpu"
                  }
                }
              },
              "if": {
                "equals": "day",
                "path": "shown"
              },
              "then": {
                "buckets": 240,
                "each": "data.data",
                "template": "{time|clock_hour}",
                "where": {
                  "gte": 0,
                  "path": "cpu"
                }
              }
            },
            "if": {
              "equals": "hour",
              "path": "shown"
            },
            "then": {
              "buckets": 240,
              "each": "data.data",
              "template": "{time|clock}",
              "where": {
                "gte": 0,
                "path": "cpu"
              }
            }
          },
          "labels": {
            "else": {
              "else": {
                "else": {
                  "buckets": 240,
                  "each": "data.data",
                  "template": "{time|date}, {time|clock_hour}",
                  "where": {
                    "gte": 0,
                    "path": "cpu"
                  }
                },
                "if": {
                  "equals": "week",
                  "path": "shown"
                },
                "then": {
                  "buckets": 240,
                  "each": "data.data",
                  "template": "{time|weekday} {time|clock_hour}",
                  "where": {
                    "gte": 0,
                    "path": "cpu"
                  }
                }
              },
              "if": {
                "equals": "day",
                "path": "shown"
              },
              "then": {
                "buckets": 240,
                "each": "data.data",
                "template": "{time|clock}",
                "where": {
                  "gte": 0,
                  "path": "cpu"
                }
              }
            },
            "if": {
              "equals": "hour",
              "path": "shown"
            },
            "then": {
              "buckets": 240,
              "each": "data.data",
              "template": "{time|clock}",
              "where": {
                "gte": 0,
                "path": "cpu"
              }
            }
          },
          "points": {
            "buckets": 240,
            "each": "data.data",
            "value": {
              "path": "cpu",
              "round": 1,
              "scale": 100
            },
            "where": {
              "gte": 0,
              "path": "cpu"
            }
          }
        },
        "ref": "host-history"
      },
      "type": "sparkline",
      "unit": "%",
      "width": "half"
    },
    {
      "change": false,
      "id": "memory",
      "label": "Memory",
      "points": [
        0,
        0
      ],
      "source": {
        "empty": {
          "text": "No readings in this period",
          "when": {
            "lt": 2,
            "path": "readings"
          }
        },
        "map": {
          "axis_labels": {
            "else": {
              "else": {
                "else": {
                  "buckets": 240,
                  "each": "data.data",
                  "template": "{time|date}",
                  "where": {
                    "gte": 0,
                    "path": "cpu"
                  }
                },
                "if": {
                  "equals": "week",
                  "path": "shown"
                },
                "then": {
                  "buckets": 240,
                  "each": "data.data",
                  "template": "{time|weekday}",
                  "where": {
                    "gte": 0,
                    "path": "cpu"
                  }
                }
              },
              "if": {
                "equals": "day",
                "path": "shown"
              },
              "then": {
                "buckets": 240,
                "each": "data.data",
                "template": "{time|clock_hour}",
                "where": {
                  "gte": 0,
                  "path": "cpu"
                }
              }
            },
            "if": {
              "equals": "hour",
              "path": "shown"
            },
            "then": {
              "buckets": 240,
              "each": "data.data",
              "template": "{time|clock}",
              "where": {
                "gte": 0,
                "path": "cpu"
              }
            }
          },
          "labels": {
            "else": {
              "else": {
                "else": {
                  "buckets": 240,
                  "each": "data.data",
                  "template": "{time|date}, {time|clock_hour}",
                  "where": {
                    "gte": 0,
                    "path": "cpu"
                  }
                },
                "if": {
                  "equals": "week",
                  "path": "shown"
                },
                "then": {
                  "buckets": 240,
                  "each": "data.data",
                  "template": "{time|weekday} {time|clock_hour}",
                  "where": {
                    "gte": 0,
                    "path": "cpu"
                  }
                }
              },
              "if": {
                "equals": "day",
                "path": "shown"
              },
              "then": {
                "buckets": 240,
                "each": "data.data",
                "template": "{time|clock}",
                "where": {
                  "gte": 0,
                  "path": "cpu"
                }
              }
            },
            "if": {
              "equals": "hour",
              "path": "shown"
            },
            "then": {
              "buckets": 240,
              "each": "data.data",
              "template": "{time|clock}",
              "where": {
                "gte": 0,
                "path": "cpu"
              }
            }
          },
          "max": {
            "max": "memtotal",
            "of": "data.data",
            "round": 0,
            "scale": 1e-09
          },
          "points": {
            "buckets": 240,
            "each": "data.data",
            "value": {
              "path": "memused",
              "round": 1,
              "scale": 1e-09
            },
            "where": {
              "gte": 0,
              "path": "cpu"
            }
          }
        },
        "ref": "host-history"
      },
      "type": "sparkline",
      "unit": "GB",
      "width": "half"
    },
    {
      "id": "maintenance",
      "items": [
        {
          "key": "Package changes",
          "url": "legato://page/proxmox-maintenance",
          "value": "—"
        },
        {
          "key": "Running kernel",
          "value": "—"
        },
        {
          "key": "Newest installed",
          "value": "—"
        },
        {
          "key": "Uptime",
          "value": "—"
        },
        {
          "key": "Checked",
          "value": "—"
        }
      ],
      "label": "Host",
      "source": {
        "map": {
          "items[0].value": {
            "else": {
              "template": "Unavailable"
            },
            "if": {
              "gt": 0,
              "value": {
                "count": "versions.data"
              }
            },
            "then": {
              "template": "{updates} Proxmox packages"
            }
          },
          "items[1].value": "running_kernel",
          "items[2].value": "newest_kernel",
          "items[3].value": {
            "if": {
              "path": "up_days",
              "equals": 0
            },
            "then": {
              "template": "Started today"
            },
            "else": {
              "if": {
                "path": "up_days",
                "equals": 1
              },
              "then": {
                "template": "1 day"
              },
              "else": {
                "template": "{up_days} days"
              }
            }
          },
          "items[4].value": {
            "template": "{time.data.time|ago}"
          }
        },
        "ref": "maintenance"
      },
      "type": "facts"
    },
    {
      "id": "guests",
      "items": [],
      "label": "Guests",
      "source": {
        "map": {
          "items": {
            "each": "guests",
            "fields": {
              "detail": {
                "else": {
                  "template": "Stopped"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "else": {
                    "template": "Up {up_days} days · {cpu_pct}% CPU"
                  },
                  "if": {
                    "equals": 0,
                    "path": "up_days"
                  },
                  "then": {
                    "template": "Started today · {cpu_pct}% CPU"
                  }
                }
              },
              "name": "name",
              "state": {
                "else": {
                  "else": {
                    "template": "critical"
                  },
                  "if": {
                    "contains": "standby",
                    "path": "tags"
                  },
                  "then": {
                    "template": "off"
                  }
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "template": "ok"
                }
              },
              "url": {
                "template": "legato://page/proxmox-vm?vmid={vmid|raw}&name={name}"
              }
            }
          }
        },
        "ref": "pve"
      },
      "type": "fleet"
    },
    {
      "id": "explore",
      "items": [
        {
          "text": "Guests",
          "url": "legato://page/proxmox-guests"
        },
        {
          "text": "Backups",
          "url": "legato://page/proxmox-backups"
        }
      ],
      "label": "Explore",
      "type": "list"
    }
  ]
}
