Skip to content

Commit

Permalink
Some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaso-ascani committed Jun 24, 2024
1 parent 572e43a commit 4831dec
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 78 deletions.
25 changes: 17 additions & 8 deletions imageroot/actions/get-configuration/10get
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ from datetime import datetime, timezone
import os
import json
import sys
import subprocess

# Cloud Log Manager

cloud_log_manager = {}

if os.system("systemctl is-active --user --quiet cloud-log-manager-forwarder") == 0:
cloud_log_manager["active"] = True
else:
cloud_log_manager["active"] = False
with subprocess.Popen(['systemctl', '--user', 'is-active', 'cloud-log-manager-forwarder'], stdout=subprocess.PIPE, stderr=sys.stderr) as pipe:
response = pipe.stdout.readline().decode('utf-8').replace('\n', '')
if 'inactive' in response:
cloud_log_manager["status"] = 'inactive'
elif 'active' in response:
cloud_log_manager["status"] = 'active'
elif 'failed' in response:
cloud_log_manager["status"] = 'failed'

cloud_log_manager["address"] = os.getenv('CLOUD_LOG_MANAGER_ADDRESS', '')
cloud_log_manager["tenant"] = os.getenv('CLOUD_LOG_MANAGER_TENANT', '')
Expand All @@ -33,10 +38,14 @@ except:

syslog = {}

if os.system("systemctl is-active --user --quiet syslog-forwarder") == 0:
syslog["active"] = True
else:
syslog["active"] = False
with subprocess.Popen(['systemctl', '--user', 'is-active', 'syslog-forwarder'], stdout=subprocess.PIPE, stderr=sys.stderr) as pipe:
response = pipe.stdout.readline().decode('utf-8').replace('\n', '')
if 'inactive' in response:
syslog["status"] = 'inactive'
elif 'active' in response:
syslog["status"] = 'active'
elif 'failed' in response:
syslog["status"] = 'failed'

syslog["address"] = os.getenv('SYSLOG_ADDRESS', '')
syslog["port"] = os.getenv('SYSLOG_PORT', '')
Expand Down
63 changes: 62 additions & 1 deletion imageroot/actions/get-configuration/validate-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"type": "object",
"required": [
"retention_days",
"active_from"
"active_from",
"cloud_log_manager",
"syslog"
],
"properties": {
"retention_days": {
Expand All @@ -23,6 +25,65 @@
"type": "string",
"format": "date-time",
"description": "The ISO 8601 date-time when the Loki instance was deactivated."
},
"cloud_log_manager": {
"type": "object",
"description": "Cloud Log Manager forwarder configuration.",
"required": [
"status"
],
"properties": {
"status": {
"type": "string",
"description": "Forwarder state."
},
"address": {
"type": "string",
"description": "Forwarder address where datas are sent."
},
"tenant": {
"type": "string",
"description": "Cloud Log Manager internal data."
},
"last_timestamp": {
"type": "string",
"description": "Timestamp of the last log sent."
}
}

},
"syslog": {
"type": "object",
"description": "Syslog forwarder configuration.",
"required": [
"status"
],
"properties": {
"status": {
"type": "string",
"description": "Forwarder state."
},
"address": {
"type": "string",
"description": "Forwarder address where data are sent."
},
"port": {
"type": "string",
"description": "External server port."
},
"protocol": {
"type": "string",
"description": "Protocol used to send datas."
},
"format": {
"type": "string",
"description": "Log format."
},
"last_timestamp": {
"type": "string",
"description": "Timestamp of the last log sent."
}
}
}
}
}
19 changes: 18 additions & 1 deletion imageroot/actions/set-clm-forwarder/10set
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#

import subprocess
import agent
import json
import uuid
Expand All @@ -27,8 +28,24 @@ if (request['active']):

if (request['start_time'] != ''):
agent.set_env('CLOUD_LOG_MANAGER_START_TIME', f"{request['start_time']}")

# If process is running, restart with new env variables, otherwise enable it
with subprocess.Popen(['systemctl', '--user', 'is-active', 'cloud-log-manager-forwarder'], stdout=subprocess.PIPE, stderr=sys.stderr) as pipe:
response = pipe.stdout.readline().decode('utf-8').replace('\n', '')
if response in {'active', 'failed'}:
action = 'restart'
else:
action = 'enable'
else:
agent.unset_env('CLOUD_LOG_MANAGER_UUID')
agent.unset_env('CLOUD_LOG_MANAGER_START_TIME')
agent.unset_env('CLOUD_LOG_MANAGER_ADDRESS')
agent.unset_env('CLOUD_LOG_MANAGER_TENANT')
agent.unset_env('CLOUD_LOG_MANAGER_TENANT')

action = 'disable'

subprocess.run(["systemctl", "--user", action, "--now", "cloud-log-manager-forwarder.service"],
stdout=subprocess.PIPE,
stderr=sys.stderr,
text=True,
check=True)
15 changes: 0 additions & 15 deletions imageroot/actions/set-clm-forwarder/20start-stop

This file was deleted.

28 changes: 28 additions & 0 deletions imageroot/actions/set-clm-forwarder/validate-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "http://schema.nethserver.org/loki/configure-module.json",
"title": "Configure Cloud Log Manager Forwarder",
"description": "Configure Cloud Log Manager Forwarder service.",
"type": "object",
"required": [
"active"
],
"properties": {
"active": {
"type": "boolean",
"description": "Action condition to be set."
},
"address": {
"type": "string",
"description": "Cloud log manager server address."
},
"tenant": {
"type": "string",
"description": "Cloud log manager tenant."
},
"start_time": {
"type": "string",
"description": "Log forwarding start time."
}
}
}
19 changes: 18 additions & 1 deletion imageroot/actions/set-syslog-forwarder/10set
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#

import subprocess
import agent
import json
import sys
Expand All @@ -22,9 +23,25 @@ if (request['active']):

if (request['start_time'] != ''):
agent.set_env('SYSLOG_START_TIME', f"{request['start_time']}")

# If process is running, restart with new env variables, otherwise enable it
with subprocess.Popen(['systemctl', '--user', 'is-active', 'syslog-forwarder'], stdout=subprocess.PIPE, stderr=sys.stderr) as pipe:
response = pipe.stdout.readline().decode('utf-8').replace('\n', '')
if response in {'active', 'failed'}:
action = 'restart'
else:
action = 'enable'
else:
agent.unset_env('SYSLOG_ADDRESS')
agent.unset_env('SYSLOG_PORT')
agent.unset_env('SYSLOG_PROTOCOL')
agent.unset_env('SYSLOG_FORMAT')
agent.unset_env('SYSLOG_START_TIME')
agent.unset_env('SYSLOG_START_TIME')

action = 'disable'

subprocess.run(["systemctl", "--user", action, "--now", "syslog-forwarder.service"],
stdout=subprocess.PIPE,
stderr=sys.stderr,
text=True,
check=True)
14 changes: 0 additions & 14 deletions imageroot/actions/set-syslog-forwarder/20start-stop

This file was deleted.

36 changes: 36 additions & 0 deletions imageroot/actions/set-syslog-forwarder/validate-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "http://schema.nethserver.org/loki/configure-module.json",
"title": "Configure Syslog Forwarder",
"description": "Configure Syslog Forwarder service.",
"type": "object",
"required": [
"active"
],
"properties": {
"active": {
"type": "boolean",
"description": "Action condition to be set."
},
"address": {
"type": "string",
"description": "Syslog server address."
},
"port": {
"type": "string",
"description": "Syslog server port."
},
"protocol": {
"type": "string",
"description": "Protocol to send datas."
},
"format": {
"type": "string",
"description": "Log format."
},
"start_time": {
"type": "string",
"description": "Log forwarding start time."
}
}
}
Loading

0 comments on commit 4831dec

Please sign in to comment.