{
  "$schema": "./.schemas/page.schema.json",
  "title": "Unraid",
  "icon": "externaldrive.connected.to.line.below",
  "sources": {
    "unraid": {
      "collect": {
        "dataset": "unraid-containers",
        "each": "ctr",
        "key": "{name}",
        "sample": {
          "every": "5m"
        },
        "fields": {
          "state": "state"
        },
        "readers": [
          "unraid-container"
        ]
      },
      "fail": {
        "when": {
          "any": [
            {
              "value": {
                "count": "gql.errors",
                "where": {
                  "path": "path[0]",
                  "not_in": [
                    "docker",
                    "vms"
                  ]
                },
                "default": 0
              },
              "gt": 0
            },
            {
              "all": [
                {
                  "path": "gql.errors",
                  "exists": true
                },
                {
                  "path": "gql.data.array.state",
                  "exists": false
                }
              ]
            }
          ]
        },
        "message": "gql.errors[0].message"
      },
      "url": "http://tower.local",
      "secret": "unraid",
      "auth": {
        "type": "header",
        "name": "x-api-key"
      },
      "every": "1m",
      "requests": {
        "gql": {
          "path": "/graphql",
          "method": "POST",
          "body": {
            "query": "{ array { state capacity { kilobytes { free used total } } parityCheckStatus { status progress speed date } parities { name status temp numErrors isSpinning } disks { name status temp numErrors fsSize fsFree warning critical isSpinning } caches { name status temp numErrors fsSize fsFree warning critical isSpinning } } vars { mdResyncAction mdNumDisabled mdNumInvalid mdNumMissing sbSyncErrs sbSyncExit } info { display { k: __typename warning critical hot max unit } os { uptime } versions { core { unraid } } } metrics { cpu { percentTotal } memory { percentTotal } } docker { containers { id names state status autoStart isUpdateAvailable } } vms { domains { id name state } } notifications { overview { unread { alert warning total } } list(filter: { type: UNREAD, offset: 0, limit: 4 }) { id subject description importance timestamp } alert: list(filter: { type: UNREAD, importance: ALERT, offset: 0, limit: 1 }) { subject } warning: list(filter: { type: UNREAD, importance: WARNING, offset: 0, limit: 1 }) { subject } } }"
          }
        }
      },
      "derive": [
        {
          "name": "array",
          "value": "gql.data.array"
        },
        {
          "name": "parity0",
          "value": {
            "each": "gql.data.array.parities",
            "fields": {
              "name": "name",
              "status": "status",
              "temp": "temp",
              "numErrors": "numErrors",
              "fsSize": "fsSize",
              "fsFree": "fsFree",
              "warning": "warning",
              "critical": "critical",
              "isSpinning": "isSpinning",
              "kind": {
                "template": "parity"
              },
              "k": {
                "template": "InfoDisplay"
              }
            }
          }
        },
        {
          "name": "disks0",
          "value": {
            "each": "gql.data.array.disks",
            "fields": {
              "name": "name",
              "status": "status",
              "temp": "temp",
              "numErrors": "numErrors",
              "fsSize": "fsSize",
              "fsFree": "fsFree",
              "warning": "warning",
              "critical": "critical",
              "isSpinning": "isSpinning",
              "kind": {
                "template": "data"
              },
              "k": {
                "template": "InfoDisplay"
              }
            }
          }
        },
        {
          "name": "pools0",
          "value": {
            "each": "gql.data.array.caches",
            "fields": {
              "name": "name",
              "status": "status",
              "temp": "temp",
              "numErrors": "numErrors",
              "fsSize": "fsSize",
              "fsFree": "fsFree",
              "warning": "warning",
              "critical": "critical",
              "isSpinning": "isSpinning",
              "kind": {
                "template": "pool"
              },
              "k": {
                "template": "InfoDisplay"
              }
            }
          }
        },
        {
          "name": "disks1",
          "value": {
            "each": [
              "parity0",
              "disks0",
              "pools0"
            ],
            "lookup": {
              "from": "gql.data.info.display",
              "by": "k",
              "on": "k",
              "as": "d"
            },
            "fields": {
              "name": "name",
              "status": "status",
              "temp": "temp",
              "numErrors": "numErrors",
              "fsSize": "fsSize",
              "fsFree": "fsFree",
              "warning": "warning",
              "critical": "critical",
              "isSpinning": "isSpinning",
              "kind": "kind",
              "d": "d",
              "pct": {
                "if": {
                  "path": "fsSize",
                  "gt": 0
                },
                "then": {
                  "subtract": [
                    100,
                    {
                      "multiply": [
                        {
                          "divide": [
                            "fsFree",
                            "fsSize"
                          ]
                        },
                        100
                      ],
                      "round": 0
                    }
                  ]
                },
                "else": {
                  "path": "no_such_field"
                }
              },
              "temp_f": {
                "path": "temp",
                "scale": 1.8,
                "offset": 32,
                "round": 0
              },
              "warn": {
                "if": {
                  "path": "warning",
                  "exists": true
                },
                "then": "warning",
                "else": "d.warning"
              },
              "crit": {
                "if": {
                  "path": "critical",
                  "exists": true
                },
                "then": "critical",
                "else": "d.critical"
              }
            }
          }
        },
        {
          "name": "disks2",
          "value": {
            "each": "disks1",
            "fields": {
              "name": "name",
              "status": "status",
              "temp": "temp",
              "numErrors": "numErrors",
              "fsSize": "fsSize",
              "fsFree": "fsFree",
              "warning": "warning",
              "critical": "critical",
              "isSpinning": "isSpinning",
              "kind": "kind",
              "pct": "pct",
              "temp_f": "temp_f",
              "warn": "warn",
              "crit": "crit",
              "d": "d",
              "state": {
                "if": {
                  "any": [
                    {
                      "all": [
                        {
                          "path": "status",
                          "exists": true
                        },
                        {
                          "path": "status",
                          "not": "DISK_OK"
                        }
                      ]
                    },
                    {
                      "all": [
                        {
                          "path": "crit",
                          "gt": 0
                        },
                        {
                          "path": "pct",
                          "gte": {
                            "path": "crit"
                          }
                        }
                      ]
                    }
                  ]
                },
                "then": {
                  "template": "critical"
                },
                "else": {
                  "if": {
                    "any": [
                      {
                        "path": "numErrors",
                        "gt": 0
                      },
                      {
                        "all": [
                          {
                            "path": "warn",
                            "gt": 0
                          },
                          {
                            "path": "pct",
                            "gte": {
                              "path": "warn"
                            }
                          }
                        ]
                      }
                    ]
                  },
                  "then": {
                    "template": "warning"
                  },
                  "else": {
                    "template": "ok"
                  }
                }
              },
              "why": {
                "if": {
                  "all": [
                    {
                      "path": "status",
                      "exists": true
                    },
                    {
                      "path": "status",
                      "not": "DISK_OK"
                    }
                  ]
                },
                "then": {
                  "path": "status",
                  "values": {
                    "DISK_DSBL": "disabled",
                    "DISK_NP_DSBL": "disabled",
                    "DISK_DSBL_NEW": "disabled",
                    "DISK_INVALID": "invalid",
                    "DISK_WRONG": "wrong disk",
                    "DISK_NP_MISSING": "missing",
                    "DISK_NEW": "new",
                    "DISK_NP": "not present"
                  },
                  "default": "not OK"
                },
                "else": {
                  "if": {
                    "any": [
                      {
                        "all": [
                          {
                            "path": "crit",
                            "gt": 0
                          },
                          {
                            "path": "pct",
                            "gte": {
                              "path": "crit"
                            }
                          }
                        ]
                      },
                      {
                        "all": [
                          {
                            "path": "warn",
                            "gt": 0
                          },
                          {
                            "path": "pct",
                            "gte": {
                              "path": "warn"
                            }
                          }
                        ]
                      }
                    ]
                  },
                  "then": {
                    "template": "{pct}% full"
                  },
                  "else": {
                    "if": {
                      "path": "numErrors",
                      "gt": 0
                    },
                    "then": {
                      "template": "{numErrors} I/O errors"
                    },
                    "else": {
                      "template": ""
                    }
                  }
                }
              },
              "shown": {
                "if": {
                  "path": "d.unit",
                  "equals": "FAHRENHEIT"
                },
                "then": {
                  "template": "{temp_f} °F"
                },
                "else": {
                  "template": "{temp} °C"
                }
              }
            }
          }
        },
        {
          "name": "disks",
          "value": {
            "each": "disks2",
            "fields": {
              "name": "name",
              "status": "status",
              "temp": "temp",
              "numErrors": "numErrors",
              "fsSize": "fsSize",
              "fsFree": "fsFree",
              "warning": "warning",
              "critical": "critical",
              "isSpinning": "isSpinning",
              "kind": "kind",
              "pct": "pct",
              "temp_f": "temp_f",
              "warn": "warn",
              "crit": "crit",
              "state": "state",
              "why": "why",
              "shown": "shown",
              "label": {
                "if": {
                  "path": "isSpinning",
                  "equals": false
                },
                "then": {
                  "template": "{name}"
                },
                "else": {
                  "if": {
                    "path": "temp",
                    "gt": 0
                  },
                  "then": {
                    "template": "{name} · {shown}"
                  },
                  "else": {
                    "template": "{name}"
                  }
                }
              }
            }
          }
        },
        {
          "name": "bad_disks",
          "value": {
            "each": "disks",
            "where": {
              "path": "state",
              "equals": "critical"
            },
            "fields": {
              "name": "name",
              "why": "why"
            }
          }
        },
        {
          "name": "warn_disks",
          "value": {
            "each": "disks",
            "where": {
              "path": "state",
              "equals": "warning"
            },
            "fields": {
              "name": "name",
              "why": "why"
            }
          }
        },
        {
          "name": "bad_count",
          "value": {
            "count": "bad_disks",
            "default": 0
          }
        },
        {
          "name": "warn_count",
          "value": {
            "count": "warn_disks",
            "default": 0
          }
        },
        {
          "name": "bad_more",
          "value": {
            "subtract": [
              "bad_count",
              1
            ]
          }
        },
        {
          "name": "warn_more",
          "value": {
            "subtract": [
              "warn_count",
              1
            ]
          }
        },
        {
          "name": "used_bars",
          "value": {
            "each": "disks",
            "where": {
              "all": [
                {
                  "path": "kind",
                  "not": "parity"
                },
                {
                  "path": "pct",
                  "exists": true
                }
              ]
            },
            "fields": {
              "label": "label",
              "value": "pct"
            }
          }
        },
        {
          "name": "bar_count",
          "value": {
            "count": "used_bars",
            "default": 0
          }
        },
        {
          "name": "missing",
          "value": {
            "add": [
              {
                "path": "gql.data.vars.mdNumDisabled",
                "default": 0
              },
              {
                "path": "gql.data.vars.mdNumInvalid",
                "default": 0
              },
              {
                "path": "gql.data.vars.mdNumMissing",
                "default": 0
              }
            ]
          }
        },
        {
          "name": "total_tb",
          "value": {
            "path": "gql.data.array.capacity.kilobytes.total",
            "match": "^([0-9]+)$",
            "scale": 1e-09,
            "round": 1
          }
        },
        {
          "name": "used_tb",
          "value": {
            "path": "gql.data.array.capacity.kilobytes.used",
            "match": "^([0-9]+)$",
            "scale": 1e-09,
            "round": 1
          }
        },
        {
          "name": "op",
          "value": {
            "if": {
              "value": {
                "path": "gql.data.vars.mdResyncAction",
                "match": "^(check P)"
              },
              "exists": true
            },
            "then": {
              "template": "Parity check"
            },
            "else": {
              "if": {
                "value": {
                  "path": "gql.data.vars.mdResyncAction",
                  "match": "^(check)"
                },
                "exists": true
              },
              "then": {
                "template": "Read check"
              },
              "else": {
                "if": {
                  "value": {
                    "path": "gql.data.vars.mdResyncAction",
                    "match": "^(recon P)"
                  },
                  "exists": true
                },
                "then": {
                  "template": "Parity sync"
                },
                "else": {
                  "if": {
                    "value": {
                      "path": "gql.data.vars.mdResyncAction",
                      "match": "^(recon D)"
                    },
                    "exists": true
                  },
                  "then": {
                    "template": "Disk rebuild"
                  },
                  "else": {
                    "if": {
                      "value": {
                        "path": "gql.data.vars.mdResyncAction",
                        "match": "^(clear)"
                      },
                      "exists": true
                    },
                    "then": {
                      "template": "Disk clear"
                    },
                    "else": {
                      "template": "Array operation"
                    }
                  }
                }
              }
            }
          }
        },
        {
          "name": "op_status",
          "value": {
            "path": "gql.data.array.parityCheckStatus.status",
            "default": "NEVER_RUN"
          }
        },
        {
          "name": "is_check",
          "value": {
            "if": {
              "value": {
                "path": "gql.data.vars.mdResyncAction",
                "match": "^(check)"
              },
              "exists": true
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "sync_errors",
          "value": {
            "path": "gql.data.vars.sbSyncErrs",
            "default": 0
          }
        },
        {
          "name": "up_days",
          "value": {
            "since": "gql.data.info.os.uptime",
            "scale": 1.1574074074074073e-05,
            "round": 0
          }
        },
        {
          "name": "ctr0",
          "value": {
            "each": "gql.data.docker.containers",
            "fields": {
              "name": {
                "path": "names[0]",
                "match": "^/?(.+)$"
              },
              "id": "id",
              "status": "status",
              "state_word": "state",
              "auto": "autoStart",
              "update": "isUpdateAvailable"
            }
          }
        },
        {
          "name": "ctr",
          "value": {
            "each": "ctr0",
            "fields": {
              "name": "name",
              "id": "id",
              "state_word": "state_word",
              "status": "status",
              "auto": "auto",
              "update": "update",
              "state": {
                "if": {
                  "path": "state_word",
                  "equals": "RUNNING"
                },
                "then": {
                  "template": "ok"
                },
                "else": {
                  "if": {
                    "all": [
                      {
                        "path": "auto",
                        "equals": true
                      },
                      {
                        "path": "state_word",
                        "equals": "EXITED"
                      }
                    ]
                  },
                  "then": {
                    "template": "warning"
                  },
                  "else": {
                    "template": "off"
                  }
                }
              },
              "group": {
                "if": {
                  "path": "state_word",
                  "equals": "RUNNING"
                },
                "then": {
                  "template": "Running"
                },
                "else": {
                  "if": {
                    "all": [
                      {
                        "path": "auto",
                        "equals": true
                      },
                      {
                        "path": "state_word",
                        "equals": "EXITED"
                      }
                    ]
                  },
                  "then": {
                    "template": "Needs attention"
                  },
                  "else": {
                    "template": "Stopped"
                  }
                }
              },
              "words": {
                "if": {
                  "all": [
                    {
                      "path": "auto",
                      "equals": true
                    },
                    {
                      "path": "state_word",
                      "equals": "EXITED"
                    }
                  ]
                },
                "then": {
                  "template": "{status} · set to autostart"
                },
                "else": {
                  "if": {
                    "path": "update",
                    "equals": true
                  },
                  "then": {
                    "template": "{status} · update ready"
                  },
                  "else": {
                    "template": "{status}"
                  }
                }
              }
            }
          }
        },
        {
          "name": "ctr_attention",
          "value": {
            "each": "ctr",
            "where": {
              "path": "state",
              "equals": "warning"
            },
            "sort": "name",
            "fields": {
              "name": "name",
              "id": "id",
              "state_word": "state_word",
              "status": "status",
              "auto": "auto",
              "update": "update",
              "state": "state",
              "group": "group",
              "words": "words"
            }
          }
        },
        {
          "name": "ctr_running",
          "value": {
            "each": "ctr",
            "where": {
              "path": "state",
              "equals": "ok"
            },
            "sort": "name",
            "fields": {
              "name": "name",
              "id": "id",
              "state_word": "state_word",
              "status": "status",
              "auto": "auto",
              "update": "update",
              "state": "state",
              "group": "group",
              "words": "words"
            }
          }
        },
        {
          "name": "ctr_stopped",
          "value": {
            "each": "ctr",
            "where": {
              "path": "state",
              "equals": "off"
            },
            "sort": "name",
            "fields": {
              "name": "name",
              "id": "id",
              "state_word": "state_word",
              "status": "status",
              "auto": "auto",
              "update": "update",
              "state": "state",
              "group": "group",
              "words": "words"
            }
          }
        },
        {
          "name": "ctr_ordered",
          "value": {
            "each": [
              "ctr_attention",
              "ctr_running",
              "ctr_stopped"
            ],
            "fields": {
              "name": "name",
              "id": "id",
              "state_word": "state_word",
              "status": "status",
              "auto": "auto",
              "update": "update",
              "state": "state",
              "group": "group",
              "words": "words"
            }
          }
        },
        {
          "name": "ctr_total",
          "value": {
            "count": "ctr",
            "default": 0
          }
        },
        {
          "name": "ctr_up",
          "value": {
            "count": "ctr",
            "where": {
              "path": "state",
              "equals": "ok"
            },
            "default": 0
          }
        },
        {
          "name": "ctr_updates",
          "value": {
            "count": "ctr",
            "where": {
              "path": "update",
              "equals": true
            },
            "default": 0
          }
        },
        {
          "name": "vm_total",
          "value": {
            "count": "gql.data.vms.domains",
            "default": 0
          }
        },
        {
          "name": "vm_up",
          "value": {
            "count": "gql.data.vms.domains",
            "where": {
              "path": "state",
              "in": [
                "RUNNING",
                "IDLE"
              ]
            },
            "default": 0
          }
        },
        {
          "name": "docker_error",
          "value": {
            "each": "gql.errors",
            "where": {
              "path": "path[0]",
              "equals": "docker"
            },
            "limit": 1,
            "fields": {
              "m": "message"
            }
          }
        },
        {
          "name": "vms_error",
          "value": {
            "each": "gql.errors",
            "where": {
              "path": "path[0]",
              "equals": "vms"
            },
            "limit": 1,
            "fields": {
              "m": "message"
            }
          }
        },
        {
          "name": "alerts",
          "value": {
            "path": "gql.data.notifications.overview.unread.alert",
            "default": 0
          }
        },
        {
          "name": "warnings",
          "value": {
            "path": "gql.data.notifications.overview.unread.warning",
            "default": 0
          }
        },
        {
          "name": "parity_count",
          "value": {
            "count": "gql.data.array.parities",
            "default": 0
          }
        },
        {
          "name": "alert_words",
          "value": {
            "path": "gql.data.notifications.alert[0].subject",
            "match": "^(?:[A-Za-z]+ \\[[^\\]]*\\] - )?(.+)$"
          }
        },
        {
          "name": "warning_words",
          "value": {
            "path": "gql.data.notifications.warning[0].subject",
            "match": "^(?:[A-Za-z]+ \\[[^\\]]*\\] - )?(.+)$"
          }
        },
        {
          "name": "alerts_more",
          "value": {
            "subtract": [
              "alerts",
              1
            ]
          }
        },
        {
          "name": "warnings_more",
          "value": {
            "subtract": [
              "warnings",
              1
            ]
          }
        },
        {
          "name": "unread",
          "value": {
            "path": "gql.data.notifications.overview.unread.total",
            "default": 0
          }
        },
        {
          "name": "notes",
          "value": {
            "each": "gql.data.notifications.list",
            "limit": 4,
            "fields": {
              "id": "id",
              "importance": "importance",
              "timestamp": "timestamp",
              "description": "description",
              "subject": {
                "path": "subject",
                "match": "^(?:[A-Za-z]+ \\[[^\\]]*\\] - )?(.+)$"
              }
            }
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "health",
      "type": "status",
      "width": "full",
      "label": "Server",
      "state": "unknown",
      "placement": "page_info",
      "url": "http://tower.local",
      "source": {
        "ref": "unraid",
        "map": {
          "state": {
            "if": {
              "path": "array.state",
              "equals": "STOPPED"
            },
            "then": {
              "template": "off"
            },
            "else": {
              "if": {
                "path": "array.state",
                "not": "STARTED"
              },
              "then": {
                "template": "critical"
              },
              "else": {
                "if": {
                  "any": [
                    {
                      "path": "missing",
                      "gt": 0
                    },
                    {
                      "path": "bad_count",
                      "gt": 0
                    },
                    {
                      "path": "alerts",
                      "gt": 0
                    }
                  ]
                },
                "then": {
                  "template": "critical"
                },
                "else": {
                  "if": {
                    "any": [
                      {
                        "path": "warn_count",
                        "gt": 0
                      },
                      {
                        "path": "warnings",
                        "gt": 0
                      },
                      {
                        "all": [
                          {
                            "path": "op_status",
                            "in": [
                              "COMPLETED",
                              "FAILED"
                            ]
                          },
                          {
                            "path": "sync_errors",
                            "gt": 0
                          }
                        ]
                      },
                      {
                        "path": "op_status",
                        "equals": "FAILED"
                      }
                    ]
                  },
                  "then": {
                    "template": "warning"
                  },
                  "else": {
                    "template": "ok"
                  }
                }
              }
            }
          },
          "detail": {
            "if": {
              "path": "array.state",
              "not": "STARTED"
            },
            "then": {
              "path": "array.state",
              "values": {
                "STOPPED": "Array stopped",
                "NEW_ARRAY": "New array, not started",
                "RECON_DISK": "Disk to rebuild",
                "DISABLE_DISK": "A disk is disabled",
                "SWAP_DSBL": "Disk swap waiting",
                "INVALID_EXPANSION": "Invalid expansion",
                "PARITY_NOT_BIGGEST": "Parity isn't the largest disk",
                "TOO_MANY_MISSING_DISKS": "Too many disks missing",
                "NEW_DISK_TOO_SMALL": "New disk too small",
                "NO_DATA_DISKS": "No data disks"
              },
              "default": "Array not started"
            },
            "else": {
              "if": {
                "path": "missing",
                "gt": 0
              },
              "then": {
                "if": {
                  "path": "missing",
                  "equals": 1
                },
                "then": {
                  "template": "1 disk disabled or missing"
                },
                "else": {
                  "template": "{missing} disks disabled or missing"
                }
              },
              "else": {
                "if": {
                  "all": [
                    {
                      "path": "bad_count",
                      "equals": 0
                    },
                    {
                      "path": "alerts",
                      "gt": 0
                    }
                  ]
                },
                "then": {
                  "if": {
                    "path": "alert_words",
                    "exists": true
                  },
                  "then": {
                    "if": {
                      "path": "alerts",
                      "gt": 1
                    },
                    "then": {
                      "template": "{alert_words|clip:70} and {alerts_more} more"
                    },
                    "else": {
                      "template": "{alert_words|clip:90}"
                    }
                  },
                  "else": {
                    "if": {
                      "path": "alerts",
                      "equals": 1
                    },
                    "then": {
                      "template": "1 unread alert"
                    },
                    "else": {
                      "template": "{alerts} unread alerts"
                    }
                  }
                },
                "else": {
                  "if": {
                    "path": "bad_count",
                    "gt": 0
                  },
                  "then": {
                    "if": {
                      "path": "bad_count",
                      "equals": 1
                    },
                    "then": {
                      "template": "{bad_disks[0].name} {bad_disks[0].why}"
                    },
                    "else": {
                      "template": "{bad_disks[0].name} {bad_disks[0].why} and {bad_more} more"
                    }
                  },
                  "else": {
                    "if": {
                      "path": "warn_count",
                      "gt": 0
                    },
                    "then": {
                      "if": {
                        "path": "warn_count",
                        "equals": 1
                      },
                      "then": {
                        "template": "{warn_disks[0].name} {warn_disks[0].why}"
                      },
                      "else": {
                        "template": "{warn_disks[0].name} {warn_disks[0].why} and {warn_more} more"
                      }
                    },
                    "else": {
                      "if": {
                        "all": [
                          {
                            "path": "op_status",
                            "in": [
                              "COMPLETED",
                              "FAILED"
                            ]
                          },
                          {
                            "path": "sync_errors",
                            "gt": 0
                          }
                        ]
                      },
                      "then": {
                        "template": "Last parity check found {sync_errors} errors"
                      },
                      "else": {
                        "if": {
                          "path": "op_status",
                          "equals": "FAILED"
                        },
                        "then": {
                          "template": "Last parity check didn't finish"
                        },
                        "else": {
                          "if": {
                            "path": "warnings",
                            "gt": 0
                          },
                          "then": {
                            "if": {
                              "path": "warning_words",
                              "exists": true
                            },
                            "then": {
                              "if": {
                                "path": "warnings",
                                "gt": 1
                              },
                              "then": {
                                "template": "{warning_words|clip:70} and {warnings_more} more"
                              },
                              "else": {
                                "template": "{warning_words|clip:90}"
                              }
                            },
                            "else": {
                              "if": {
                                "path": "warnings",
                                "equals": 1
                              },
                              "then": {
                                "template": "1 unread warning"
                              },
                              "else": {
                                "template": "{warnings} unread warnings"
                              }
                            }
                          },
                          "else": {
                            "if": {
                              "path": "op_status",
                              "in": [
                                "RUNNING",
                                "PAUSED"
                              ]
                            },
                            "then": {
                              "template": "{op} {gql.data.array.parityCheckStatus.progress}%"
                            },
                            "else": {
                              "template": "Array started"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "failed": {
          "state": "critical",
          "detail": "Unraid isn't answering",
          "after": 3
        }
      }
    },
    {
      "id": "operation",
      "type": "bars",
      "label": "Parity check",
      "unit": "%",
      "max": 100,
      "items": [
        {
          "label": "Started",
          "value": 0
        }
      ],
      "source": {
        "ref": "unraid",
        "when": {
          "path": "op_status",
          "in": [
            "RUNNING",
            "PAUSED"
          ]
        },
        "map": {
          "label": "op",
          "items[0].value": {
            "path": "gql.data.array.parityCheckStatus.progress",
            "default": 0
          },
          "items[0].label": {
            "if": {
              "path": "op_status",
              "equals": "PAUSED"
            },
            "then": {
              "template": "Paused"
            },
            "else": {
              "template": "{gql.data.array.parityCheckStatus.speed} MB/s"
            }
          }
        }
      },
      "actions_placement": "corner",
      "actions": [
        {
          "label": "Pause",
          "icon": "pause.fill",
          "path": "/graphql",
          "graphql": {
            "query": "mutation { parityCheck { pause } }"
          },
          "when": {
            "all": [
              {
                "path": "is_check",
                "equals": "yes"
              },
              {
                "path": "op_status",
                "equals": "RUNNING"
              }
            ]
          }
        },
        {
          "label": "Resume",
          "icon": "play.fill",
          "path": "/graphql",
          "graphql": {
            "query": "mutation { parityCheck { resume } }"
          },
          "when": {
            "all": [
              {
                "path": "is_check",
                "equals": "yes"
              },
              {
                "path": "op_status",
                "equals": "PAUSED"
              }
            ]
          }
        }
      ]
    },
    {
      "id": "server",
      "type": "facts",
      "label": "Server",
      "items": [
        {
          "key": "Array",
          "value": "—"
        },
        {
          "key": "Parity",
          "value": "—"
        },
        {
          "key": "Containers",
          "value": "—"
        },
        {
          "key": "VMs",
          "value": "—"
        },
        {
          "key": "Unraid",
          "value": "—"
        }
      ],
      "source": {
        "ref": "unraid",
        "map": {
          "items[0].value": {
            "if": {
              "path": "array.state",
              "equals": "STARTED"
            },
            "then": {
              "if": {
                "path": "total_tb",
                "gt": 0
              },
              "then": {
                "template": "Started · {used_tb} of {total_tb} TB used"
              },
              "else": {
                "template": "Started"
              }
            },
            "else": {
              "path": "array.state",
              "values": {
                "STOPPED": "Array stopped",
                "NEW_ARRAY": "New array, not started",
                "RECON_DISK": "Disk to rebuild",
                "DISABLE_DISK": "A disk is disabled",
                "SWAP_DSBL": "Disk swap waiting",
                "INVALID_EXPANSION": "Invalid expansion",
                "PARITY_NOT_BIGGEST": "Parity isn't the largest disk",
                "TOO_MANY_MISSING_DISKS": "Too many disks missing",
                "NEW_DISK_TOO_SMALL": "New disk too small",
                "NO_DATA_DISKS": "No data disks"
              },
              "default": "Not started"
            }
          },
          "items[1].value": {
            "if": {
              "path": "op_status",
              "in": [
                "RUNNING",
                "PAUSED"
              ]
            },
            "then": {
              "template": "{op} under way"
            },
            "else": {
              "if": {
                "path": "parity_count",
                "equals": 0
              },
              "then": {
                "template": "No parity disk"
              },
              "else": {
                "if": {
                  "any": [
                    {
                      "path": "op_status",
                      "equals": "NEVER_RUN"
                    },
                    {
                      "path": "gql.data.array.parityCheckStatus.date",
                      "exists": false
                    }
                  ]
                },
                "then": {
                  "template": "Never checked"
                },
                "else": {
                  "if": {
                    "path": "op_status",
                    "equals": "CANCELLED"
                  },
                  "then": {
                    "template": "Cancelled · started {gql.data.array.parityCheckStatus.date|ago}"
                  },
                  "else": {
                    "if": {
                      "path": "op_status",
                      "equals": "FAILED"
                    },
                    "then": {
                      "template": "Didn't finish · started {gql.data.array.parityCheckStatus.date|ago}"
                    },
                    "else": {
                      "if": {
                        "path": "sync_errors",
                        "gt": 0
                      },
                      "then": {
                        "template": "Checked {gql.data.array.parityCheckStatus.date|ago} · {sync_errors} errors"
                      },
                      "else": {
                        "template": "Checked {gql.data.array.parityCheckStatus.date|ago} · no errors"
                      }
                    }
                  }
                }
              }
            }
          },
          "items[2].value": {
            "if": {
              "path": "gql.data.docker",
              "exists": true
            },
            "then": {
              "if": {
                "path": "ctr_updates",
                "gt": 1
              },
              "then": {
                "template": "{ctr_up} of {ctr_total} running · {ctr_updates} updates"
              },
              "else": {
                "if": {
                  "path": "ctr_updates",
                  "equals": 1
                },
                "then": {
                  "template": "{ctr_up} of {ctr_total} running · 1 update"
                },
                "else": {
                  "template": "{ctr_up} of {ctr_total} running"
                }
              }
            },
            "else": {
              "if": {
                "path": "docker_error[0].m",
                "exists": true
              },
              "then": {
                "template": "{docker_error[0].m|clip:70}"
              },
              "else": {
                "template": "Docker isn't answering"
              }
            }
          },
          "items[3].value": {
            "if": {
              "path": "gql.data.vms.domains",
              "exists": true
            },
            "then": {
              "template": "{vm_up} of {vm_total} running"
            },
            "else": {
              "if": {
                "path": "vms_error[0].m",
                "exists": true
              },
              "then": {
                "template": "{vms_error[0].m|clip:70}"
              },
              "else": {
                "template": "No VMs"
              }
            }
          },
          "items[4].value": {
            "if": {
              "path": "up_days",
              "equals": 1
            },
            "then": {
              "template": "{gql.data.info.versions.core.unraid} · up 1 day"
            },
            "else": {
              "template": "{gql.data.info.versions.core.unraid} · up {up_days} days"
            }
          }
        }
      }
    },
    {
      "id": "cpu",
      "type": "sparkline",
      "label": "CPU",
      "unit": "%",
      "width": "half",
      "change": false,
      "points": [],
      "source": {
        "ref": "unraid",
        "map": {
          "points": {
            "history": {
              "path": "gql.data.metrics.cpu.percentTotal",
              "round": 0
            },
            "every": "10m",
            "keep": 36
          }
        }
      }
    },
    {
      "id": "memory",
      "type": "sparkline",
      "label": "Memory",
      "unit": "%",
      "width": "half",
      "change": false,
      "points": [],
      "source": {
        "ref": "unraid",
        "map": {
          "points": {
            "history": {
              "path": "gql.data.metrics.memory.percentTotal",
              "round": 0
            },
            "every": "10m",
            "keep": 36
          }
        }
      }
    },
    {
      "id": "disks",
      "type": "bars",
      "label": "Disks",
      "unit": "%",
      "max": 100,
      "items": [
        {
          "label": "disk1",
          "value": 0
        }
      ],
      "source": {
        "ref": "unraid",
        "empty": {
          "when": {
            "path": "bar_count",
            "equals": 0
          },
          "text": "No disk is mounted while the array is stopped"
        },
        "map": {
          "items": {
            "if": {
              "path": "bar_count",
              "gt": 12
            },
            "then": {
              "each": "used_bars",
              "sort": {
                "by": "value",
                "order": "desc"
              },
              "limit": 12,
              "fields": {
                "label": "label",
                "value": "value"
              }
            },
            "else": {
              "each": "used_bars",
              "fields": {
                "label": "label",
                "value": "value"
              }
            }
          },
          "label": {
            "if": {
              "path": "bar_count",
              "gt": 12
            },
            "then": {
              "template": "Disks, fullest 12 of {bar_count}"
            },
            "else": {
              "template": "Disks"
            }
          }
        }
      }
    },
    {
      "id": "containers",
      "type": "fleet",
      "label": "Containers",
      "max_items": 60,
      "items": [],
      "source": {
        "ref": "unraid",
        "when": {
          "path": "gql.data.docker",
          "exists": true
        },
        "map": {
          "items": {
            "each": "ctr_ordered",
            "limit": 60,
            "fields": {
              "name": {
                "template": "{name|clip:24}"
              },
              "state": "state",
              "detail": {
                "template": "{words}"
              },
              "url": {
                "template": "legato://page/unraid-container?name={name}"
              },
              "group": "group"
            }
          },
          "label": {
            "if": {
              "path": "ctr_total",
              "gt": 60
            },
            "then": {
              "template": "Containers, 60 of {ctr_total}"
            },
            "else": {
              "template": "Containers"
            }
          }
        }
      }
    },
    {
      "id": "vms",
      "type": "list",
      "label": "Virtual machines",
      "max_items": 7,
      "items": [],
      "source": {
        "ref": "unraid",
        "when": {
          "value": {
            "count": "gql.data.vms.domains",
            "default": 0
          },
          "gt": 0
        },
        "map": {
          "items": {
            "each": "gql.data.vms.domains",
            "sort": "name",
            "fields": {
              "key": "id",
              "text": "name",
              "detail": {
                "path": "state",
                "values": {
                  "RUNNING": "Running",
                  "IDLE": "Idle",
                  "PAUSED": "Paused",
                  "PMSUSPENDED": "Suspended",
                  "SHUTDOWN": "Shutting down",
                  "SHUTOFF": "Stopped",
                  "CRASHED": "Crashed",
                  "NOSTATE": "No state"
                },
                "default": "—"
              },
              "id": "id",
              "name": "name",
              "state": "state"
            }
          }
        }
      },
      "row_actions": [
        {
          "label": "Start",
          "icon": "play.fill",
          "path": "/graphql",
          "graphql": {
            "query": "mutation($id: PrefixedID!) { vm { start(id: $id) } }",
            "variables": {
              "id": "{id}"
            }
          },
          "when": {
            "path": "state",
            "equals": "SHUTOFF"
          },
          "success": {
            "path": "data.vm.start",
            "equals": true
          }
        },
        {
          "label": "Resume",
          "icon": "playpause.fill",
          "path": "/graphql",
          "graphql": {
            "query": "mutation($id: PrefixedID!) { vm { resume(id: $id) } }",
            "variables": {
              "id": "{id}"
            }
          },
          "when": {
            "path": "state",
            "equals": "PAUSED"
          },
          "success": {
            "path": "data.vm.resume",
            "equals": true
          }
        },
        {
          "label": "Shut down",
          "icon": "stop.fill",
          "path": "/graphql",
          "graphql": {
            "query": "mutation($id: PrefixedID!) { vm { stop(id: $id) } }",
            "variables": {
              "id": "{id}"
            }
          },
          "when": {
            "path": "state",
            "in": [
              "RUNNING",
              "PAUSED"
            ]
          },
          "success": {
            "path": "data.vm.stop",
            "equals": true
          },
          "confirm": {
            "message": "Shut down {name}? Unraid turns it off if it's still running after about 10 seconds.",
            "button": "Shut down"
          }
        }
      ]
    },
    {
      "id": "notifications",
      "type": "list",
      "label": "Notifications",
      "items": [],
      "source": {
        "ref": "unraid",
        "empty": {
          "when": {
            "path": "unread",
            "equals": 0
          },
          "text": "No unread notifications"
        },
        "map": {
          "items": {
            "each": "notes",
            "fields": {
              "key": "id",
              "text": {
                "template": "{subject|clip:120}"
              },
              "subtitle": {
                "template": "{description|clip:80}"
              },
              "detail": {
                "template": "{timestamp|ago}"
              },
              "icon": {
                "if": {
                  "path": "importance",
                  "equals": "ALERT"
                },
                "then": {
                  "template": "xmark.octagon.fill"
                },
                "else": {
                  "if": {
                    "path": "importance",
                    "equals": "WARNING"
                  },
                  "then": {
                    "template": "exclamationmark.triangle.fill"
                  },
                  "else": {
                    "template": "info.circle"
                  }
                }
              }
            }
          },
          "label": {
            "if": {
              "path": "unread",
              "gt": 4
            },
            "then": {
              "template": "Notifications, 4 of {unread} unread"
            },
            "else": {
              "template": "Notifications"
            }
          }
        }
      },
      "actions_placement": "corner",
      "actions": [
        {
          "label": "Mark all read",
          "icon": "checkmark.circle",
          "path": "/graphql",
          "graphql": {
            "query": "mutation { archiveAll { unread { total } } }"
          },
          "when": {
            "path": "unread",
            "gt": 0
          }
        }
      ]
    }
  ]
}
