summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2017-02-10 09:38:21 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2017-02-10 09:38:21 (GMT)
commit304127cdec228e72ea3b12d3ee1bcd3fc5f0e893 (patch) (side-by-side diff)
tree0f750373d698f73c314580d7b7b0ed0781f6f29f
downloadsyslogck-304127cdec228e72ea3b12d3ee1bcd3fc5f0e893.tar.gz
syslogck-304127cdec228e72ea3b12d3ee1bcd3fc5f0e893.tar.bz2
Initial commit
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--syslogck109
1 files changed, 109 insertions, 0 deletions
diff --git a/syslogck b/syslogck
new file mode 100644
index 0000000..c59cb6d
--- a/dev/null
+++ b/syslogck
@@ -0,0 +1,109 @@
+#!/usr/bin/perl
+
+use strict;
+use Sys::Syslog qw(:standard :macros);
+use Data::Dumper;
+
+my $facility = 'user';
+
+my %prio_order = ('debug' => 0,
+ 'info' => 1,
+ 'notice' => 2,
+ 'warn' => 3,
+ 'warning' => 3,
+ 'err' => 4,
+ 'error' => 4,
+ 'crit' => 5,
+ 'alert' => 6,
+ 'emerg' => 7,
+ 'panic' => 7);
+
+my $priority = $prio_order{info};
+
+sub match_selector {
+ my ($sel) = @_;
+ my $match;
+ $sel =~ s/\s+//g;
+ print "matching $sel\n";
+ foreach my $ent (split /;/, $sel) {
+ print " ent=$ent\n";
+ if ($ent =~ /^(?<fac>.+)\.(?<pri>.*)$/) {
+ print " f=$+{fac},p=$+{pri}\n";
+ if (match_facility($+{fac})) {
+ if ($+{pri} eq 'none') {
+ $match = 0;
+ } elsif (match_priority($+{pri})) {
+ $match = 1;
+ }
+ }
+ }
+ print "M $match\n"
+ }
+ print ($match ? "+MATCH\n" : "-NOPE\n");
+ return $match;
+}
+
+sub match_facility {
+ my ($arg) = @_;
+ foreach my $f (split /,/, $arg) {
+ $f =~ s/\..*//;
+ print " f=$f\n";
+ return 1 if $f eq '*' || $f eq $facility;
+ }
+ return 0;
+}
+
+sub match_priority {
+ my ($pri) = @_;
+ my $match = 0;
+
+ print " p=$pri :: ";
+ my $neg = $pri =~ s/^!(.+)/$1/;
+ print " not " if ($neg);
+ my $eq = $pri =~ s/^=(.+)/$1/;
+ if ($pri eq '*') {
+ print "*";
+ $match = 1;
+ } else {
+ next unless exists($prio_order{$pri});
+ if ($eq) {
+ print $prio_order{$pri}." == $priority";
+ $match = $prio_order{$pri} == $priority;
+ } else {
+ print $prio_order{$pri}." <= $priority";
+ $match = $prio_order{$pri} <= $priority;
+ }
+ }
+ $match = !$match if $neg;
+ print ":: $match\n";
+ return $match;
+}
+
+sub find_actions {
+ my $file = shift;
+ my @actions;
+ if (open(my $fd, '<', $file)) {
+ while (<$fd>) {
+ chomp;
+ s/^\s+//;
+ next if /^#/;
+ if (/\\$/) {
+ chop;
+ $_ .= <$fd>;
+ redo;
+ }
+ if (/^(?<sel>.+?)\s+(?<buf>-?)(?<stream>[^\s]+)$/) {
+ push @actions, $+{stream} if match_selector($+{sel});
+ }
+ }
+ } else {
+ warn "can't open $file: $!";
+ return undef;
+ }
+ return @actions;
+}
+
+my @act = find_actions("/etc/syslog.conf");
+print Dumper([ @act ]);
+
+

Return to:

Send suggestions and report system problems to the System administrator.