line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Apps::Logmon::XAS::Process; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
289623
|
use DateTime; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
442
|
use DateTime::Span; |
|
1
|
|
|
|
|
25227
|
|
|
1
|
|
|
|
|
23
|
|
7
|
1
|
|
|
1
|
|
484
|
use XAS::Logmon::Input::Tail; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
8
|
1
|
|
|
1
|
|
361
|
use XAS::Logmon::Filter::Merge; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
22
|
|
9
|
1
|
|
|
1
|
|
343
|
use XAS::Logmon::Output::Spool; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
10
|
1
|
|
|
1
|
|
360
|
use XAS::Logmon::Format::Logstash; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
11
|
1
|
|
|
1
|
|
382
|
use XAS::Logmon::Parser::XAS::Logs; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use XAS::Class |
14
|
1
|
|
|
|
|
5
|
debug => 0, |
15
|
|
|
|
|
|
|
version => $VERSION, |
16
|
|
|
|
|
|
|
base => 'XAS::Lib::App', |
17
|
|
|
|
|
|
|
accessors => 'filename spooldir ignore process', |
18
|
|
|
|
|
|
|
utils => 'dotid trim level2syslog', |
19
|
|
|
|
|
|
|
filesystem => 'Dir File', |
20
|
1
|
|
|
1
|
|
4
|
; |
|
1
|
|
|
|
|
2
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
23
|
|
|
|
|
|
|
# Public Methods |
24
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub reject { |
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
28
|
0
|
|
|
|
|
|
my $data = shift; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $now = DateTime->now(time_zone => 'local'); |
31
|
0
|
|
|
|
|
|
my $span = DateTime::Span->from_datetimes( |
32
|
|
|
|
|
|
|
start => $now->clone->subtract(days => $self->ignore), |
33
|
|
|
|
|
|
|
end => $now |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
return 0 if ($span->contains($data->{'datetime'})); |
37
|
0
|
|
|
|
|
|
return 1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub setup { |
42
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
unless (defined($self->{'filename'})) { |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->throw_msg( |
47
|
|
|
|
|
|
|
dotid($self->class) . '.nofilename', |
48
|
|
|
|
|
|
|
'logmon_nofilename' |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub main { |
56
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$self->setup(); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $input = XAS::Logmon::Input::Tail->new( |
61
|
|
|
|
|
|
|
-filename => $self->filename |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $output = XAS::Logmon::Output::Spool->new(); |
65
|
0
|
|
|
|
|
|
my $merge = XAS::Logmon::Filter::Merge->new(); |
66
|
0
|
|
|
|
|
|
my $logstash = XAS::Logmon::Format::Logstash->new(); |
67
|
0
|
|
|
|
|
|
my $default = XAS::Logmon::Parser::XAS::Logs->new(); |
68
|
0
|
|
|
|
|
|
my $tasks = XAS::Logmon::Parser::XAS::Logs->new(format => ':tasks'); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
while (my $line = $input->get()) { |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->log->debug(sprintf("line: %s", $line)); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if (my $data = $tasks->parse($line)) { |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
next if ($self->reject($data)); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->log->debug("found tasks"); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$data = $merge->filter($data, { |
81
|
|
|
|
|
|
|
'@message' => trim($line), |
82
|
|
|
|
|
|
|
hostname => $self->env->host, |
83
|
|
|
|
|
|
|
facility => $self->env->log_facility, |
84
|
|
|
|
|
|
|
priority => level2syslog(lc($data->{'level'})), |
85
|
0
|
|
|
|
|
|
tid => $data->{'task'}, |
86
|
|
|
|
|
|
|
pid => '0', |
87
|
|
|
|
|
|
|
msgid => '0', |
88
|
|
|
|
|
|
|
process => $self->process, |
89
|
|
|
|
|
|
|
}); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $event = $logstash->format($data); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$output->put($event); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
next; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if (my $data = $default->parse($line)) { |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
next if ($self->reject($data)); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$self->log->debug("found default"); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$data = $merge->filter($data, { |
106
|
|
|
|
|
|
|
'@message' => trim($line), |
107
|
|
|
|
|
|
|
hostname => $self->env->host, |
108
|
|
|
|
|
|
|
facility => $self->env->log_facility, |
109
|
0
|
|
|
|
|
|
priority => level2syslog(lc($data->{'level'})), |
110
|
|
|
|
|
|
|
tid => '0', |
111
|
|
|
|
|
|
|
pid => '0', |
112
|
|
|
|
|
|
|
msgid => '0', |
113
|
|
|
|
|
|
|
process => $self->process, |
114
|
|
|
|
|
|
|
}); |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $event = $logstash->format($data); |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$output->put($event); |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
next; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->log->error_msg('logmon_parserr', trim($line)); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub options { |
131
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$self->{'ignore'} = 300; |
134
|
0
|
|
|
|
|
|
$self->{'process'} = 'xas-spooler'; |
135
|
0
|
|
|
|
|
|
$self->{'spooldir'} = Dir($self->env->spool, 'logs'); |
136
|
0
|
|
|
|
|
|
$self->{'filename'} = File($self->env->log, 'xas-spooler.log'); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
return { |
139
|
|
|
|
|
|
|
'ignore=s' => \$self->{'ignore'}, |
140
|
|
|
|
|
|
|
'process=s' => \$self->{'process'}, |
141
|
|
|
|
|
|
|
'spooldir=s' => sub { |
142
|
0
|
|
|
0
|
|
|
$self->{'spooldir'} = Dir($_[1]); |
143
|
|
|
|
|
|
|
}, |
144
|
|
|
|
|
|
|
'filename=s' => sub { |
145
|
0
|
|
|
0
|
|
|
$self->{'filename'} = File($_[1]); |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
}; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
152
|
|
|
|
|
|
|
# Private Methods |
153
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__END__ |