#!/bin/ksh # # syslog2ng # # Translator from syslog.conf to syslog-ng.conf # by Jonathan W. Marks awk ' BEGIN { "/bin/uname -s" | getline sysname; close("/bin/uname -s"); if (sysname == "SunOS") { LOGDEVTYPE="sun-streams"; } else if (sysname == "AIX") { LOGDEVTYPE="unix-dgram"; } else { print "!!! Unsupported system: " sysname "."; exit 1; } } $1 !~ /^[:space:]*#/ && NF == 2 { $2 in destinations ? \ destinations[$2] = destinations[$2] " " $1 : \ destinations[$2] = $1; } END { print \ "options { dir_perm(0755); perm(0644); chain_hostnames(no);\n" \ " keep_hostname(yes); };\n"; print \ "source local {\n" \ " " LOGDEVTYPE "(\"/dev/log\");\n" \ " udp(ip(0.0.0.0) port(514));\n" \ " internal();\n" \ "};\n"; for (dest in destinations) { make_filters(dest, destinations[dest]); make_destination(dest); make_log(dest); } } function make_filters(dest, filterstr) { split(filterstr, specentries, " "); for (entryNo in specentries) { entry = specentries[entryNo]; split(entry, termlist, ";"); newFilterNumbers = ""; for (termNo in termlist) { newNum = make_filter(termlist[termNo]); if (newNum) { newFilterNumbers = newFilterNumbers " " \ newNum; } } destinations[dest] = destination[dest] " " \ newFilterNumbers; } } function make_filter(spec) { dot = index(spec, "."); split(substr(spec, 1, (dot - 1)), faclist, ","); severity = substr(spec, (dot + 1)); negate = 0; if (severity == "none") { negate = 1 }; filterID = severity; for (facno in faclist) { filterID = filterID " " faclist[facno]; } if (! (filterID in all_filters)) { all_filters[filterID] = ++filterNum; printf "filter f_" filterNum " {\n\t"; nPrinted = 0; if (faclist[1] != "*") { printf("%sfacility(", (negate ? "not " : "")); for (facno in faclist) { printf("%s" faclist[facno], \ (nPrinted++ > 0 ? "," : "")); } printf(")%s", (severity != "none" ? " and " : "")); } if (severity != "none") { printf("level(" severity "%s)", (severity == "emerg" ? "" : "...emerg")); } printf(";\n};\n\n"); } return all_filters[filterID]; } function make_destination(d) { destinations[d] = ++dno " " destinations[d]; printf "destination d_" dno " { \n"; if (d ~ /^\//) { printf "\tfile(\"" d "\"\n"; printf "\t\tcreate_dirs(yes) perm(0640));\n"; } else if (d ~ /^@/) { printf "\tudp(\"" substr(d, 2) "\" port(514));\n"; } else { printf "\tusertty(\"" d "\");\n"; } print "};\n"; } function make_log(d) { n_entries = split(destinations[d], filters, " "); printf "log { source(local); " ; for (i = 2; i <= n_entries; i++) { printf "filter(f_" filters[i] "); "; } print "destination(d_" filters[1] "); };\n"; }'