-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New services: Cloud Log Manager and Syslog forwarders
Implemented following parts: - Systemd services file - Python scripts - API Actions
- Loading branch information
1 parent
377499a
commit b28af3c
Showing
12 changed files
with
674 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import subprocess | ||
import hashlib | ||
import agent | ||
import json | ||
import uuid | ||
import sys | ||
|
||
request = json.load(sys.stdin) | ||
|
||
rdb = agent.redis_connect() | ||
cluster_uuid = rdb.get('cluster/uuid') | ||
subscription = rdb.hgetall('cluster/subscription') | ||
|
||
if not bool(subscription): | ||
print("No subscription found !") | ||
sys.exit(1) | ||
|
||
if (request['active']): | ||
agent.set_env('CLOUD_LOG_MANAGER_UUID', uuid.uuid5(uuid.NAMESPACE_DNS, cluster_uuid)) | ||
agent.set_env('CLOUD_LOG_MANAGER_HOSTNAME', 'cluster-' + hashlib.sha256(cluster_uuid.encode("utf-8")).hexdigest()[:8]) | ||
agent.set_env('CLOUD_LOG_MANAGER_ADDRESS', f"{request['address']}") | ||
agent.set_env('CLOUD_LOG_MANAGER_TENANT', f"{request['tenant']}") | ||
|
||
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') | ||
|
||
action = 'disable' | ||
|
||
subprocess.run(["systemctl", "--user", action, "--now", "cloud-log-manager-forwarder.service"], | ||
stdout=subprocess.PIPE, | ||
stderr=sys.stderr, | ||
text=True, | ||
check=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import subprocess | ||
import agent | ||
import json | ||
import sys | ||
|
||
request = json.load(sys.stdin) | ||
|
||
if (request['active']): | ||
rdb = agent.redis_connect() | ||
cluster_uuid = rdb.get('cluster/uuid') | ||
|
||
agent.set_env('SYSLOG_ADDRESS', f"{request['address']}") | ||
agent.set_env('SYSLOG_PORT', f"{request['port']}") | ||
agent.set_env('SYSLOG_PROTOCOL', f"{request['protocol']}") | ||
agent.set_env('SYSLOG_FORMAT', f"{request['format']}") | ||
|
||
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') | ||
|
||
action = 'disable' | ||
|
||
subprocess.run(["systemctl", "--user", action, "--now", "syslog-forwarder.service"], | ||
stdout=subprocess.PIPE, | ||
stderr=sys.stderr, | ||
text=True, | ||
check=True) |
36 changes: 36 additions & 0 deletions
36
imageroot/actions/set-syslog-forwarder/validate-input.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} |
Oops, something went wrong.