-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogWrapper.pl
193 lines (158 loc) · 3.74 KB
/
logWrapper.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Time::HiRes qw( usleep );
use Switch;
use Linux::Inotify2;
use File::Find;
use TerminalControl;
use BufferControl;
use Stream;
use Data::Dumper;
#########################
# CONFIG #
#########################
our $FILE_GROUPS = {
# The regex that will match the filename
'syslog_auth' => [ '(auth.log|syslog)' ],
'auth' => [ 'auth.log' ],
'stats' => [ '(resourceagent|clustermanager)_[0-9]*\.log' ],
'ocperf' => [ 'ocperf_ag_[0-9]*\.log' ],
};
# This is the regex configuration
our $AGGREGATE_REG = {
# Name for the group that will aggregate lines
"Stat debugs" => {
# This is a regex group to match the filename
"files" => 'stats',
# Regexes that if matched will aggregate the line into a previous one that
# has matched the same group.
"regs" => [
'DBG',
],
},
'Cron' => {
'files' => 'syslog_auth',
'regs' => [ 'CRON\[[0-9]*\]:' ]
},
};
# This is the regex configuration
our $COLOR_REG = {
"Timestamps" => {
"files" => 'stats',
"color" => '118',
"regs" => [
'(^[^,]*)',
],
},
"Timestamps2" => {
"files" => 'ocperf',
"color" => '118',
"regs" => [
'^\(([^\)]*)\)',
],
},
'ProcName' => {
'files' => 'syslog_auth',
'color' => '64',
'regs' => [ '[0-9]{2}:[0-9]{2}[^ ]* [^ ]* ([^:\[]*)' ]
},
'ProcID' => {
'files' => 'syslog_auth',
'color' => '160',
'regs' => [ '[0-9]{2}:[0-9]{2}[^ ]* [^ ]* [^\[]*\[([0-9]*)\]' ]
},
};
# Any reg_groups from above that are found in this array will be skipped entierly
our $OMMIT_GROUPS = [ ];
#########################
# HELPER FUNCTIONS #
#########################
sub quit {
our $termCon;
our $buffCon;
#print STDERR Dumper($buffCon);
$termCon->endAlternate();
exit;
}
sub terminalUpdated {
our $termCon;
our $refresh;
$termCon->updateWinsize();
$refresh = 1;
}
my $inotify;
sub handleFile {
our $buffCon;
our @inStreams;
my $file = shift;
if (-d $file) {
print STDERR "Found DIR $file. \n";
$inotify->watch (
$file,
IN_CREATE,
sub {
my $e = shift;
find(
sub {
handleFile($File::Find::name);
},
$e->fullname
);
}
);
} else {
print STDERR "Found FILE $file. Adding...\n";
$buffCon->addLine(" ### New File: $file ###", "", 1);
push @inStreams, Stream->new($file);
}
}
#########################
# INIT #
#########################
$|=1;
our $refresh = 0;
our $buffCon = BufferControl->new($AGGREGATE_REG, $COLOR_REG, $FILE_GROUPS, $OMMIT_GROUPS);
our $termCon = TerminalControl->new($buffCon, "/dev/tty");
our @inStreams = ();
$inotify = new Linux::Inotify2 or die "unable to create new inotify object: $!";
$inotify->blocking (0);
foreach my $file (@ARGV) {
if (-d $file) {
find(sub { handleFile($File::Find::name); }, $file);
} else {
push @inStreams, Stream->new($file);
}
}
$SIG{INT} = \&quit;
$SIG{WINCH} = \&terminalUpdated;
#########################
# MAIN #
#########################
$termCon->startAlternate();
while (1) {
foreach my $c (@{$termCon->getCommands()}) {
switch ($c) {
case 'quit' { quit() }
case "separator" { $buffCon->addSeparator(); }
case "up" { $termCon->scroll(-1); }
case "down" { $termCon->scroll(1); }
case "pageUp" { $termCon->scroll(-10); }
case "pageDown" { $termCon->scroll(10); }
case "end" { $termCon->scroll(); }
case "invalid" { print STDERR "Invalid command received\n" }
#print STDERR "0x$_ " for unpack "(H2)*",$opt; print STDERR "\n";
}
}
foreach my $stream (@inStreams) {
if ( $stream->read() ) {
$buffCon->proccessLines($stream->getLines(), $stream->{file});
}
}
$termCon->output($refresh);
$refresh = 0;
$inotify->poll;
usleep(100);
}
$termCon->endAlternate();