Compare commits

...

3 Commits

Author SHA1 Message Date
Arvindsrinivasan Lakshmi Narasimhan
aa106fda40 removed unwanted file 2023-11-20 23:47:18 +00:00
Arvindsrinivasan Lakshmi Narasimhan
7f1e2a0587 add plugin and rsyslog changes to change sonic_name to alias 2023-09-13 02:28:28 +00:00
Arvindsrinivasan Lakshmi Narasimhan
b2757b14c0 add chassis_name and slot_name for sonic chassis 2023-09-13 02:27:50 +00:00
4 changed files with 92 additions and 6 deletions

View File

@ -1,6 +1,8 @@
#!/bin/bash
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
CHASSIS_NAME=`sonic-cfggen -d -v DEVICE_METADATA.localhost.chassis_name`
SLOT_ID=`sonic-cfggen -d -v DEVICE_METADATA.localhost.slot_id`
# Parse the device specific asic conf file, if it exists
ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf
@ -19,8 +21,15 @@ else
fi
hostname=$(hostname)
sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 \
-a "{\"udp_server_ip\": \"$udp_server_ip\", \"hostname\": \"$hostname\"}" \
> /etc/rsyslog.conf
template="\"udp_server_ip\": \"$udp_server_ip\", \"hostname\": \"$hostname\""
echo $template
if [ -n "$CHASSIS_NAME" ]; then
template="$template, \"chassis_name_marker\": \"CHASSIS_NAME:\""
fi
systemctl restart rsyslog
if [ -n "$SLOT_ID" ]; then
template="$template, \"slot_id_marker\": \"SLOT_ID:\""
fi
sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 -a "{$template}" >/etc/rsyslog.conf
systemctl restart rsyslog

View File

@ -14,7 +14,6 @@
#################
$ModLoad imuxsock # provides support for local system logging
{% set gconf = (SYSLOG_CONFIG | d({})).get('GLOBAL', {}) -%}
{% set rate_limit_interval = gconf.get('rate_limit_interval') %}
{% set rate_limit_burst = gconf.get('rate_limit_burst') %}
@ -34,6 +33,9 @@ $ModLoad imudp
$UDPServerAddress {{udp_server_ip}} #bind to localhost before udp server run
$UDPServerRun 514
# provides support to use external plugins
$ModLoad mmexternal
# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
@ -51,7 +53,7 @@ $UDPServerRun 514
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# Define a custom template
$template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
$template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% {{chassis_name_marker}}{{DEVICE_METADATA['localhost']['chassis_name']}} {{slot_id_marker}}{{DEVICE_METADATA.localhost.slot_id}} %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
$ActionFileDefaultTemplate SONiCFileFormat
template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall time=\"%timereported\

View File

@ -37,3 +37,9 @@ if $msg startswith " telemetry" or ($msg startswith " dialout" )then {
/var/log/telemetry.log
stop
}
if $msg contains "Ethernet" then {
action(type="mmexternal"
binary="/etc/rsyslog.d/port_name_mod.py"
interface.input="msg")
}

View File

@ -0,0 +1,69 @@
#!/usr/bin/python3
import sys
import re
import json
from sonic_py_common import multi_asic
from swsscommon import swsscommon
def onInit():
global pattern
global port_alias_mapping
num_asics = multi_asic.get_namespaces_from_linux()
port_alias_mapping = {}
swsscommon.SonicDBConfig.load_sonic_global_db_config()
for asic in num_asics:
cfg_db = multi_asic.connect_config_db_for_ns(asic)
port_table = cfg_db.get_table('PORT')
for port, values in port_table.items():
port_alias_mapping[port] = values['alias']
pattern = 'Ethernet[\d]+'
def onReceive(msg):
global pattern
global port_alias_mapping
matches = re.findall(pattern, msg)
found_match = False
for match in matches:
if match in port_alias_mapping.keys():
new_log= re.sub(match, port_alias_mapping[match],msg)
msg = new_log
found_match = True
if found_match:
print(json.dumps({'msg': new_log}))
else:
print(json.dumps({}))
def onExit():
pass
## source https://github.com/rsyslog/rsyslog/blob/master/plugins/external/messagemod/anon_cc_nbrs/anon_cc_nbrs.py
"""
-------------------------------------------------------
This is plumbing that DOES NOT need to be CHANGED
-------------------------------------------------------
Implementor's note: Python seems to very agressively
buffer stdouot. The end result was that rsyslog does not
receive the script's messages in a timely manner (sometimes
even never, probably due to races). To prevent this, we
flush stdout after we have done processing. This is especially
important once we get to the point where the plugin does
two-way conversations with rsyslog. Do NOT change this!
See also: https://github.com/rsyslog/rsyslog/issues/22
"""
onInit()
keepRunning = 1
while keepRunning == 1:
msg = sys.stdin.readline()
if msg:
msg = msg[:-1] # remove LF
onReceive(msg)
sys.stdout.flush() # very important, Python buffers far too much!
else: # an empty line means stdin has been closed
keepRunning = 0
onExit()
sys.stdout.flush() # very important, Python buffers far too much!