| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAS::Apps::Logmon::Monitor; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
13280
|
use XAS::Lib::Process; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use XAS::Class |
|
8
|
|
|
|
|
|
|
debug => 0, |
|
9
|
|
|
|
|
|
|
version => $VERSION, |
|
10
|
|
|
|
|
|
|
base => 'XAS::Lib::App::Service', |
|
11
|
|
|
|
|
|
|
mixin => 'XAS::Lib::Mixins::Configs', |
|
12
|
|
|
|
|
|
|
utils => 'dotid trim :env', |
|
13
|
|
|
|
|
|
|
constants => 'TRUE FALSE', |
|
14
|
|
|
|
|
|
|
accessors => 'cfg', |
|
15
|
|
|
|
|
|
|
filesystem => 'File Dir', |
|
16
|
|
|
|
|
|
|
vars => { |
|
17
|
|
|
|
|
|
|
SERVICE_NAME => 'XAS_Log', |
|
18
|
|
|
|
|
|
|
SERVICE_DISPLAY_NAME => 'XAS Log Monitor', |
|
19
|
|
|
|
|
|
|
SERVICE_DESCRIPTION => 'XAS log file monitor' |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
24
|
|
|
|
|
|
|
# Public Methods |
|
25
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub setup { |
|
28
|
|
|
|
|
|
|
my $self = shift; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @sections = $self->cfg->Sections(); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
foreach my $section (@sections) { |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
next if ($section !~ /^logmon:/); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $env = {}; |
|
37
|
|
|
|
|
|
|
my ($alias) = $section =~ /^logmon:(.*)/; |
|
38
|
|
|
|
|
|
|
my $ignore = $self->cfg->val($section, 'ignore', '30'); |
|
39
|
|
|
|
|
|
|
my $filename = File($self->cfg->val($section, 'filename', '/var/logs/xas/xas-spooler.log')); |
|
40
|
|
|
|
|
|
|
my $spooldir = Dir($self->cfg->val($section, 'spooldir', '/var/spool/xas/logs')); |
|
41
|
|
|
|
|
|
|
my $cmd = File($self->cfg->val($section, 'command')); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $command = sprintf('%s --filename %s --spooldir %s --ignore %s --process %s --log-type console', |
|
44
|
|
|
|
|
|
|
$cmd, |
|
45
|
|
|
|
|
|
|
$filename, |
|
46
|
|
|
|
|
|
|
$spooldir, |
|
47
|
|
|
|
|
|
|
$ignore, |
|
48
|
|
|
|
|
|
|
$alias |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$alias = trim($alias); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if (my $e = $self->cfg->val($section, 'environment', undef)) { |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$env = env_parse($e); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $process = XAS::Lib::Process->new( |
|
60
|
|
|
|
|
|
|
-alias => $alias, |
|
61
|
|
|
|
|
|
|
-pty => 1, |
|
62
|
|
|
|
|
|
|
-command => $command, |
|
63
|
|
|
|
|
|
|
-auto_start => 1, |
|
64
|
|
|
|
|
|
|
-auto_restart => 1, |
|
65
|
|
|
|
|
|
|
-directory => Dir($self->cfg->val($section, 'directory', "/")), |
|
66
|
|
|
|
|
|
|
-environment => $env, |
|
67
|
|
|
|
|
|
|
-exit_codes => $self->cfg->val($section, 'exit-codes', '0,1'), |
|
68
|
|
|
|
|
|
|
-exit_retries => $self->cfg->val($section, 'exit-retires', -1), |
|
69
|
|
|
|
|
|
|
-group => $self->cfg->val($section, 'group', 'xas'), |
|
70
|
|
|
|
|
|
|
-priority => $self->cfg->val($section, 'priority', '0'), |
|
71
|
|
|
|
|
|
|
-umask => $self->cfg->val($section, 'umask', '0022'), |
|
72
|
|
|
|
|
|
|
-user => $self->cfg->val($section, 'user', 'xas'), |
|
73
|
|
|
|
|
|
|
-redirect => 1, |
|
74
|
|
|
|
|
|
|
-output_handler => sub { |
|
75
|
|
|
|
|
|
|
my $output = shift; |
|
76
|
|
|
|
|
|
|
$output = trim($output); |
|
77
|
|
|
|
|
|
|
if (my ($level, $line) = $output =~/\s+(\w+)\s+-\s+(.*)/ ) { |
|
78
|
|
|
|
|
|
|
$level = lc(trim($level)); |
|
79
|
|
|
|
|
|
|
$line = trim($line); |
|
80
|
|
|
|
|
|
|
$self->log->$level(sprintf('%s: %s', $alias, $line)); |
|
81
|
|
|
|
|
|
|
} else { |
|
82
|
|
|
|
|
|
|
$self->log->info(sprintf('%s: -> %s', $alias, $output)); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$self->service->register($alias); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub main { |
|
94
|
|
|
|
|
|
|
my $self = shift; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$self->log->info_msg('startup'); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$self->setup(); |
|
99
|
|
|
|
|
|
|
$self->service->run(); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$self->log->info_msg('shutdown'); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
106
|
|
|
|
|
|
|
# Private Methods |
|
107
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub init { |
|
110
|
|
|
|
|
|
|
my $class = shift; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$self->load_config(); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
return $self; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |