관리 메뉴

Sysops Notepad

[linux] bash 명령어 기록 rsyslog에 기록하기 본문

업무/etc

[linux] bash 명령어 기록 rsyslog에 기록하기

sysops 2019. 2. 11. 20:27
728x90

1. vi /etc/bash.bashrc


export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'


2. vi /etc/rsyslog.d/bash.conf 


local6.* /var/log/commands.log


template(name="json-template"

type="list") {

constant(value="{")

constant(value="\"@timestamp\":\"") property(name="timereported" dateFormat="rfc3339")

constant(value="\",\"@version\":\"1")

constant(value="\",\"message\":\"") property(name="msg" format="json")

constant(value="\",\"sysloghost\":\"") property(name="hostname")

constant(value="\",\"severity\":\"") property(name="syslogseverity-text")

constant(value="\",\"facility\":\"") property(name="syslogfacility-text")

constant(value="\",\"programname\":\"") property(name="programname")

constant(value="\",\"procid\":\"") property(name="procid")

constant(value="\"}\n")

}


*.* @x.x.x.x:514;json-template


3. systemctl restart rsyslog



참고:

http://blog.plura.io/?p=7547

728x90
Comments