Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaso-ascani committed Oct 14, 2024
1 parent 891a8f9 commit bd209d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions imageroot/actions/get-configuration/10get
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ match clm_status.stdout.strip():

cloud_log_manager["address"] = os.getenv('CLOUD_LOG_MANAGER_ADDRESS', '')
cloud_log_manager["tenant"] = os.getenv('CLOUD_LOG_MANAGER_TENANT', '')
cloud_log_manager["filter"] = os.getenv('CLOUD_LOG_MANAGER_FILTER', '')

try:
with open("./cloud_log_manager_last_timestamp", "r") as clm_file:
Expand All @@ -55,6 +56,7 @@ match syslog_status.stdout.strip():
syslog["address"] = os.getenv('SYSLOG_ADDRESS', '')
syslog["port"] = os.getenv('SYSLOG_PORT', '')
syslog["protocol"] = os.getenv('SYSLOG_PROTOCOL', '')
syslog["filter"] = os.getenv('SYSLOG_FILTER', '')
syslog["format"] = os.getenv('SYSLOG_FORMAT', '')

try:
Expand Down
4 changes: 2 additions & 2 deletions imageroot/actions/set-clm-forwarder/10set
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
#

import subprocess
import hashlib
import agent
import json
import uuid
import sys

request = json.load(sys.stdin)
Expand All @@ -24,6 +22,7 @@ if not bool(subscription):
if (request['active']):
agent.set_env('CLOUD_LOG_MANAGER_ADDRESS', f"{request['address']}")
agent.set_env('CLOUD_LOG_MANAGER_TENANT', f"{request['tenant']}")
agent.set_env('CLOUD_LOG_MANAGER_FILTER', f"{request['filter']}")

if 'start_time' in request and request['start_time'] != '':
agent.set_env('CLOUD_LOG_MANAGER_START_TIME', f"{request['start_time']}")
Expand All @@ -38,6 +37,7 @@ else:
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_FILTER')

action = 'disable'

Expand Down
4 changes: 4 additions & 0 deletions imageroot/actions/set-clm-forwarder/validate-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"start_time": {
"type": "string",
"description": "Log forwarding start time."
},
"filter": {
"type": "string",
"description": "Log filter type"
}
},
"oneOf": [
Expand Down
8 changes: 7 additions & 1 deletion imageroot/bin/cloud-log-manager-forwarder
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ try:
START_TIME = os.environ.get('CLOUD_LOG_MANAGER_START_TIME', '')
ADDRESS = os.environ.get('CLOUD_LOG_MANAGER_ADDRESS', 'https://nar.nethesis.it')
TENANT = os.environ.get('CLOUD_LOG_MANAGER_TENANT')
FILTER = os.environ.get('CLOUD_LOG_MANAGER_FILTER')

os.environ['LOKI_ADDR'] = f"http://127.0.0.1:{os.environ['LOKI_HTTP_PORT']}"
os.environ['LOKI_USERNAME'] = os.environ['LOKI_API_AUTH_USERNAME']
Expand Down Expand Up @@ -76,7 +77,7 @@ logs_list = []
while True:
try:
# LogCLI command
logcli_command = ["logcli", "query", "--limit", "2000", "--forward", "--timezone", "UTC", "--from", last_timestamp, "--no-labels", "-q", "-o", "jsonl",
logcli_command = ["logcli", "query", "--limit", "2000", "--forward", "--timezone", "UTC", "--from", last_timestamp, "-q", "-o", "jsonl",
'{node_id=~".+"} | json identifier="SYSLOG_IDENTIFIER", priority="PRIORITY", message="MESSAGE" | line_format "<{{.priority}}> [{{.node_id}}:{{.module_id}}:{{.identifier}}]: {{.message}}"']
response = subprocess.run(logcli_command, capture_output=True, text=True, timeout=300)

Expand All @@ -87,6 +88,11 @@ while True:
# Log if stdout contains something new
if log:
json_object = json.loads(log)
labels = json_object["labels"]

if FILTER != None and FILTER not in labels:
continue

line = str(json_object["line"])

if line[line.find(":")+1:line.find(":", line.find(":")+1)] != '':
Expand Down

0 comments on commit bd209d7

Please sign in to comment.