line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::MonM::Checkit::Command; # $Id: Command.pm 133 2022-09-09 07:49:00Z abalama $ |
2
|
1
|
|
|
1
|
|
317
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=encoding utf-8 |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
App::MonM::Checkit::Command - Checkit Command subclass |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VIRSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 1.01 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Enable yes |
20
|
|
|
|
|
|
|
Type command |
21
|
|
|
|
|
|
|
Command ls -la |
22
|
|
|
|
|
|
|
Target content |
23
|
|
|
|
|
|
|
IsTrue !!perl/regexp (?i-xsm:README) |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# . . . |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Or with STDIN pipe: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Enable yes |
34
|
|
|
|
|
|
|
Type command |
35
|
|
|
|
|
|
|
Command perl |
36
|
|
|
|
|
|
|
Content "print q/Oops/" |
37
|
|
|
|
|
|
|
Target content |
38
|
|
|
|
|
|
|
IsTrue Oops |
39
|
|
|
|
|
|
|
Timeout 5s |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# . . . |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Checkit Command subclass |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 check |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Checkit method. |
52
|
|
|
|
|
|
|
This is backend method of L |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Returns: |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=over 4 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item B |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The exit status code (ERRORLEVEL, EXITCODE) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item B |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The STDOUT response content |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item B |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The STDERR response content |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item B |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
OK or ERROR value, see "status" |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item B |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Command string |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item B |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
0 if error occured (code != 0); 1 if no errors found (code == 0) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 CONFIGURATION DIRECTIVES |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The basic Checkit configuration options (directives) detailed describes in L |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over 4 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item B |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Command "perl -w" |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Defines full path to external program (command line) |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Default: none |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item B |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Content "print q/Blah-Blah-Blah/" |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Sets the content for command STDIN |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Default: no content |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item B |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Timeout 1m |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Defines the execute timeout |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Default: off |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 HISTORY |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
See C file |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 TO DO |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
See C file |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 BUGS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
* none noted |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SEE ALSO |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 LICENSE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
143
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
See C file and L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
1
|
|
33
|
use vars qw/$VERSION/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
150
|
|
|
|
|
|
|
$VERSION = '1.01'; |
151
|
|
|
|
|
|
|
|
152
|
1
|
|
|
1
|
|
4
|
use CTK::Util qw/ execute /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
153
|
1
|
|
|
1
|
|
6
|
use CTK::ConfGenUtil; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
154
|
1
|
|
|
1
|
|
5
|
use App::MonM::Util qw/getTimeOffset run_cmd/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
212
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub check { |
157
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
158
|
0
|
|
|
|
|
|
my $type = $self->type; |
159
|
0
|
0
|
0
|
|
|
|
return $self->maybe::next::method() unless $type && $type eq 'command'; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# Init |
162
|
0
|
|
|
|
|
|
my $to = CTK::Timeout->new(); # Create the timeout object |
163
|
0
|
|
0
|
|
|
|
my $command = lvalue($self->config, 'command') || ''; |
164
|
0
|
|
0
|
|
|
|
my $content = lvalue($self->config, 'content') // ''; |
165
|
0
|
0
|
|
|
|
|
$content = undef unless length $content; |
166
|
0
|
|
0
|
|
|
|
my $timeout = getTimeOffset(lvalue($self->config, 'timeout') || 0); |
167
|
0
|
0
|
|
|
|
|
unless (length($command)) { |
168
|
0
|
|
|
|
|
|
$self->status(0); |
169
|
0
|
|
|
|
|
|
$self->source("NOOP"); |
170
|
0
|
|
|
|
|
|
$self->message('Command not specified'); |
171
|
0
|
|
|
|
|
|
return; |
172
|
|
|
|
|
|
|
} |
173
|
0
|
|
|
|
|
|
$self->source($command); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# Run command |
176
|
0
|
|
|
|
|
|
my $r = run_cmd($command, $timeout, $content); |
177
|
0
|
|
|
|
|
|
$self->status($r->{status}); |
178
|
0
|
|
|
|
|
|
$self->message($r->{message}); |
179
|
0
|
|
|
|
|
|
$self->code($r->{code}); |
180
|
0
|
|
|
|
|
|
$self->content($r->{stdout}); |
181
|
0
|
|
|
|
|
|
$self->error($r->{stderr}); |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
return; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
__END__ |