@version: 3.5
@include "scl.conf"

options {
        flush_lines (0);
        time_reopen (10);
        log_fifo_size (1000);
        chain_hostnames (off);
        use_dns (no);
        use_fqdn (no);
        create_dirs (no);
        keep_hostname (yes);
#	stats_level (1);
};

source s_local {
        system();
        internal();
};

source s_network { udp(); };

source s_snmptrapd {
	file("/proc/kmsg");
	unix-stream("/dev/log");
};

template t_field_detail {
        template("Time_received: ${R_FULLDATE} | Time_local: ${S_FULLDATE} | DEVICE_IP: ${SOURCEIP} | Hostname: ${HOST} | Facility: ${FACILITY} | Severity: ${LEVEL} | Program: ${PROGRAM} | PID: ${PID} | Message: ${MSG}\n");
        template_escape(no);
};

filter f_snmptrapd { program("snmptrapd"); };

rewrite r_snmptrapd { 
        subst("^([^ ]+) (.*)$ ", "${2}"); 
        set("${1}" value("HOST")); 
        };

destination d_local { file("/var/log/messages"); };

destination d_router {
        file (
                "/var/log/router/$R_YEAR$R_MONTH$R_DAY/$SOURCEIP-$R_YEAR$R_MONTH$R_DAY.log"
		dir_perm(0755)
                perm(644)
                create_dirs(yes)
        );
};

destination d_router_detail {
        file (
                "/var/log/router-detail/$R_YEAR$R_MONTH$R_DAY/$SOURCEIP-$R_YEAR$R_MONTH$R_DAY.log"
		template(t_field_detail)
                dir_perm(0755)
                perm(644)
                create_dirs(yes)
        );
};

destination d_snmptrap {
        file("/var/log/snmptrap-syslog/$R_YEAR$R_MONTH$R_DAY.log"
		dir_perm(0755)
                perm(644)
                create_dirs(yes)	
	);
};

destination d_snmptrap_detail {
        file(
                "/var/log/snmptrap-syslog-detail/$R_YEAR$R_MONTH$R_DAY.log"
                template(t_field_detail)
		dir_perm(0755)
                perm(644)
                create_dirs(yes)
        );
};

destination d_sql_syslog_temp_table {
	sql(	type(oracle)
		username("syslog_vtn") password("123")
		database("PTUD_SYSLOG")
		table("SLG_LOG_TEMP")
		columns("DATETIME varchar(25)", "SOURCE_IP varchar(15)", "HOST varchar(32)", "FACILITY_NUM number (2,0)", "LEVEL_NUM number (1,0)", "program varchar(60)", "pid varchar(8)", "message varchar(1024)")
		values("${R_FULLDATE}", "${SOURCEIP}", "${HOST}", "${FACILITY_NUM}", "${LEVEL_NUM}", "${PROGRAM}", "${PID}", "${MSGONLY}")
		indexes("datetime", "source_ip", "host", "FACILITY_NUM", "LEVEL_NUM", "program", "pid", "message"));
};

destination d_sql_snmp_temp_table {
        sql(	type(oracle)
	        username("syslog_vtn") password("123")
	        database("PTUD_SYSLOG")
	        table("SLG_LOGS_SNMPTRAP_TEMP")
	        columns("datetime varchar(25)", "message varchar(1500)")
	        values("${R_FULLDATE}", "${MSGONLY}")
	        indexes("datetime", "message")
	);
};

log {
        source(s_local);
        destination(d_local);
};

log { 
	source(s_network);
#       destination(d_router);
#	destination(d_router_detail);
        destination(d_sql_syslog_temp_table);
};

log { 
        source(s_snmptrapd); 
        filter(f_snmptrapd);
        rewrite(r_snmptrapd);
        destination(d_snmptrap);
#       destination(d_snmptrap_detail);
       destination(d_sql_snmp_temp_table);
        flags(final);
};
