import type { HomarrCustomWidgetV2Input } from "../../core/custom-jsx-schema"; export const PORTAINER_REFERENCE_WIDGET: HomarrCustomWidgetV2Input = { $schema: "homarr-custom-widget-v2", name: "Portainer containers", description: "Monitor and control Docker containers through Portainer.", iconUrl: "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons@master/svg/portainer.svg", sources: { default: { name: "Portainer", baseUrl: "https://portainer.example.com", networkScope: "private", auth: { type: "apiKeyHeader", name: "X-API-Key" }, }, }, requests: { containers: { path: "/api/endpoints/{option:endpointId}/docker/containers/json", query: { all: { $option: "showAll" } }, cacheSeconds: 20, }, start: { kind: "action", method: "POST", path: "/api/endpoints/{option:endpointId}/docker/containers/{param:id}/start", confirmation: "Start this container?", invalidates: ["containers"], }, stop: { kind: "action", method: "POST", path: "/api/endpoints/{option:endpointId}/docker/containers/{param:id}/stop", confirmation: { title: "Stop container", message: "The service will become unavailable.", destructive: true }, invalidates: ["containers"], }, restart: { kind: "action", method: "POST", path: "/api/endpoints/{option:endpointId}/docker/containers/{param:id}/restart", confirmation: "Restart this container?", invalidates: ["containers"], }, }, options: { endpointId: { label: "Environment ID", control: "number", default: 2, min: 1 }, showAll: { label: "Include stopped containers", control: "switch", default: true }, }, template: ` ContainersPortainer environment {options.endpointId} {status.containers?.loading ? : status.containers?.error ? {status.containers.error} : (data.containers ?? []).length === 0 ? No containers matched this environment. : Total{data.containers.length} Running{data.containers.filter(container => container.State === "running").length} Stopped{data.containers.filter(container => container.State !== "running").length} {data.containers.map(container => {container.Names?.[0]?.replace("/", "") ?? container.Id.slice(0, 12)}{container.State}{container.Image}{container.Status}{container.State === "running" ? Stop : Start}Restart)} } `, };