diff --git a/core/imageroot/var/lib/nethserver/cluster/actions/list-loki-instances/10get b/core/imageroot/var/lib/nethserver/cluster/actions/list-loki-instances/10get new file mode 100755 index 0000000000..160be12dbf --- /dev/null +++ b/core/imageroot/var/lib/nethserver/cluster/actions/list-loki-instances/10get @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import json +import sys + +import agent +from cluster import modules + +redis_client = agent.redis_connect() +default_instance = redis_client.get("cluster/default_instance/loki") +instances = modules.list_installed(redis_client).get("ghcr.io/nethserver/loki", []) + +response = [] +for instance in instances: + item = { + "instance_id": instance["id"], + "instance_label": instance["ui_name"], + "node_id": instance["node"], + "node_label": instance["node_ui_name"], + "active": instance["id"] == default_instance + } + + task_response = agent.tasks.run( + agent_id=f'module/{instance["id"]}', + action='get-configuration', + endpoint="redis://cluster-leader" + ) + if task_response["exit_code"] == 0: + item["retention_days"] = task_response["output"]["retention_days"] + item["active_from"] = "1970-01-01T00:00:00Z+00:00" + if not item["active"]: + item["active_to"] = "2024-12-31T23:59:59Z+00:00" + + response.append(item) + +json.dump({ + 'applications': response +}, sys.stdout) diff --git a/core/imageroot/var/lib/nethserver/cluster/actions/list-loki-instances/validate-output.json b/core/imageroot/var/lib/nethserver/cluster/actions/list-loki-instances/validate-output.json new file mode 100644 index 0000000000..6e2721dc5b --- /dev/null +++ b/core/imageroot/var/lib/nethserver/cluster/actions/list-loki-instances/validate-output.json @@ -0,0 +1,60 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "List loki instances", + "$id": "http://schema.nethserver.org/cluster/list-loki-instances-output.json", + "type": "object", + "required": [ + "instances" + ], + "properties": { + "instances": { + "type": "array", + "items": { + "type": "object", + "required": [ + "instance_id", + "instance_label", + "node_id", + "node_label", + "active" + ], + "properties": { + "instance_id": { + "type": "string", + "description": "The Loki instance identifier." + }, + "instance_label": { + "type": "string", + "description": "The Loki instance label, if empty string, there's no label." + }, + "node_id": { + "type": "string", + "description": "The node identifier where the Loki instance is running." + }, + "node_label": { + "type": "string", + "description": "The node label where the Loki instance is running, can be empty." + }, + "active": { + "type": "boolean", + "description": "The Loki instance is the currently active." + }, + "retention_days": { + "type": "integer", + "description": "The retention days for the Loki instance." + }, + "active_from": { + "type": "string", + "format": "date-time", + "description": "The ISO 8601 date-time when the Loki instance was activated." + }, + "active_to": { + "type": "string", + "format": "date-time", + "description": "The ISO 8601 date-time when the Loki instance was deactivated." + } + } + } + } + } +}