Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaso-ascani committed Jun 18, 2024
1 parent 27f7585 commit 569af5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions imageroot/actions/get-configuration/10get
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cloud_log_manager["tenant"] = os.getenv('CLOUD_LOG_MANAGER_TENANT', '')

try:
with open("./cloud_log_manager_last_timestamp", "r") as clm_file:
cloud_log_manager["last_timestamp"] = datetime.strptime(clm_file.read(), '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%z")
cloud_log_manager["last_timestamp"] = clm_file.read()
except:
cloud_log_manager["last_timestamp"] = ""

Expand All @@ -45,7 +45,7 @@ syslog["format"] = os.getenv('SYSLOG_FORMAT', '')

try:
with open("./syslog_last_timestamp", "r") as syslog_file:
syslog["last_timestamp"] = datetime.strptime(syslog_file.read(), '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%z")
syslog["last_timestamp"] = syslog_file.read()
except:
syslog["last_timestamp"] = ""

Expand Down
11 changes: 5 additions & 6 deletions imageroot/bin/cloud-log-manager-forwarder
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if START_TIME == '':
with open("./cloud_log_manager_last_timestamp", "r") as tf:
last_timestamp = tf.read()
else:
last_timestamp = (datetime.now()).strftime('%Y-%m-%dT%H:%M:%S.%fZ')
last_timestamp = (datetime.now()).strftime('%Y-%m-%dT%H:%M:%S.%f%z')
else:
last_timestamp = START_TIME
agent.unset_env('CLOUD_LOG_MANAGER_START_TIME')
Expand All @@ -88,7 +88,7 @@ logs_list = []
while True:
try:
# LogCLI command
logcli_command = """logcli query --limit=0 --forward --from='""" + last_timestamp + """' --timezone=UTC --no-labels -q -o jsonl '{node_id=~".+"} | json severity="PRIORITY", priority="SYSLOG_IDENTIFIER", pid="_PID", message="MESSAGE" | line_format "<{{.priority}}> [{{.node_id}}:{{.module_id}}:{{.process}}] {{.process}}[{{.pid}}]: {{.message}}"'"""
logcli_command = """logcli query --limit=0 --forward --from='""" + last_timestamp + """' --no-labels -q -o jsonl '{node_id=~".+"} | json severity="PRIORITY", priority="SYSLOG_IDENTIFIER", pid="_PID", message="MESSAGE" | line_format "<{{.priority}}> [{{.node_id}}:{{.module_id}}:{{.process}}] {{.process}}[{{.pid}}]: {{.message}}"'"""
with subprocess.Popen(logcli_command, shell=True, text=True, stdout=subprocess.PIPE) as logs:
for log in logs.stdout.readlines():
try:
Expand All @@ -107,8 +107,8 @@ while True:
json_log = {
"UUID": UUID,
"PC": HOSTNAME,
"DTA": datetime.strptime(json_object["timestamp"], '%Y-%m-%dT%H:%M:%S.%fZ').strftime("%Y-%m-%d"),
"TIME": datetime.strptime(json_object["timestamp"], '%Y-%m-%dT%H:%M:%S.%fZ').strftime("%H:%M:%S"),
"DTA": datetime.strptime(json_object["timestamp"], '%Y-%m-%dT%H:%M:%S.%f%z').strftime("%Y-%m-%d"),
"TIME": datetime.strptime(json_object["timestamp"], '%Y-%m-%dT%H:%M:%S.%f%z').strftime("%H:%M:%S"),
"MSG": line[line.find("]")+2:],
"SOURCE": line[line.find("["):line.find("]")+1],
"LOGTYPE": severity.get(priority, 6),
Expand All @@ -130,8 +130,7 @@ while True:
# When loop terminate, if list isn't empty, send
if len(logs_list) > 0:
# Increment timestamp by 1 microsecond to prevent sending the same log multiple times
date_time = datetime.strptime(last_timestamp, '%Y-%m-%dT%H:%M:%S.%fZ') + timedelta(microseconds=1)
last_timestamp = date_time.isoformat() + "Z"
date_time = datetime.strptime(last_timestamp, '%Y-%m-%dT%H:%M:%S.%f%z') + timedelta(microseconds=1)

# Send logs to gigasys server
send_logs_list(logs_list, last_timestamp)
Expand Down
13 changes: 6 additions & 7 deletions imageroot/bin/syslog-forwarder
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import sys

try:
ADDRESS = os.environ.get('SYSLOG_ADDRESS')
PORT = os.environ.get('SYSLOG_PORT', "514")
PORT = os.environ.get('SYSLOG_PORT', '514')
PROTOCOL = os.environ.get('SYSLOG_PROTOCOL', 'udp')
FORMAT = os.environ.get('SYSLOG_FORMAT', 'rfc3164')
START_TIME = os.environ.get('SYSLOG_START_TIME', '')
Expand Down Expand Up @@ -61,7 +61,7 @@ if START_TIME == '':
with open("./syslog_last_timestamp", "r") as tf:
last_timestamp = tf.read()
else:
last_timestamp = (datetime.now()).strftime('%Y-%m-%dT%H:%M:%S.%fZ')
last_timestamp = (datetime.now()).strftime('%Y-%m-%dT%H:%M:%S.%f%z')
else:
last_timestamp = START_TIME
agent.unset_env('SYSLOG_START_TIME')
Expand All @@ -70,7 +70,7 @@ else:
while True:
try:
# LogCLI command
logcli_command = """logcli query --limit=0 --forward --from='""" + last_timestamp + """' --timezone=UTC --no-labels -q -o jsonl '{node_id=~".+"}'"""
logcli_command = """logcli query --limit=0 --forward --from='""" + last_timestamp + """' --no-labels -q -o jsonl '{node_id=~".+"}'"""
with subprocess.Popen(logcli_command, shell=True, text=True, stdout=subprocess.PIPE) as logs:
for log in logs.stdout.readlines():
try:
Expand Down Expand Up @@ -126,18 +126,17 @@ while True:
# Save log timestamp only when socket send succeed
last_timestamp = json_object["timestamp"]
except:
pass
sys.exit(1)

# Increment timestamp by 1 microsecond to prevent sending the same log multiple times
date_time = datetime.strptime(last_timestamp, '%Y-%m-%dT%H:%M:%S.%fZ') + timedelta(microseconds=1)
last_timestamp = date_time.isoformat() + "Z"
date_time = datetime.strptime(last_timestamp, '%Y-%m-%dT%H:%M:%S.%f%z') + timedelta(microseconds=1)

# Write on file the last log sent timestamp
timestamp_file = open("./syslog_last_timestamp", "w")
timestamp_file.write(last_timestamp)
timestamp_file.close()

except:
pass
sys.exit(1)
finally:
time.sleep(10)

0 comments on commit 569af5e

Please sign in to comment.