| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Armadito::Agent::Scheduler::Win32Native; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
10089767
|
use strict; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
45
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
110
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use base 'Armadito::Agent::Task::Scheduler'; |
|
|
1
|
|
|
|
|
36
|
|
|
|
1
|
|
|
|
|
435
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Armadito::Agent::Tools::File qw (writeFile readFile); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
42
|
|
|
8
|
1
|
|
|
1
|
|
341
|
use Armadito::Agent::Tools::Time qw (nowToISO8601); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
49
|
|
|
9
|
1
|
|
|
1
|
|
349
|
use Armadito::Agent::Patterns::Matcher; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
10
|
1
|
|
|
1
|
|
23
|
use IPC::System::Simple qw(capture $EXITVAL EXIT_ANY); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
92
|
|
|
11
|
1
|
|
|
1
|
|
4
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
689
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _loadConf { |
|
14
|
0
|
|
|
0
|
|
|
my ( $self, %params ) = @_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
$self->{config} = $self->_parseConf( $self->_getConfPath() ); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _parseConf { |
|
20
|
0
|
|
|
0
|
|
|
my ( $self, $conf_path ) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $conf_file = readFile( filepath => $conf_path ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $parser = Armadito::Agent::Patterns::Matcher->new( logger => $self->{logger} ); |
|
25
|
0
|
|
|
|
|
|
$parser->addExclusionPattern('^#'); |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $labels = [ 'options', 'name', 'args' ]; |
|
28
|
0
|
|
|
|
|
|
my $pattern = '^(.*?);(.*?);(.*?)$'; |
|
29
|
0
|
|
|
|
|
|
$parser->addPattern( 'tasks', $pattern, $labels ); |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$parser->run( $conf_file, '\n' ); |
|
32
|
0
|
|
|
|
|
|
$parser->addHookForLabel( 'options', \&trimSpaces ); |
|
33
|
0
|
|
|
|
|
|
$parser->addHookForLabel( 'name', \&trimSpaces ); |
|
34
|
0
|
|
|
|
|
|
$parser->addHookForLabel( 'args', \&trimSpaces ); |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $parser->getResults(); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub trimSpaces { |
|
40
|
0
|
|
|
0
|
0
|
|
my ($match) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$match =~ s/\s+$//ms; |
|
43
|
0
|
|
|
|
|
|
$match =~ s/^\s+//ms; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return $match; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _getDefaultConf { |
|
49
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return { |
|
52
|
0
|
|
|
|
|
|
'user' => undef, |
|
53
|
|
|
|
|
|
|
'Logfile' => undef |
|
54
|
|
|
|
|
|
|
}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _getConfPath { |
|
58
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $self->{agent}->{confdir} . "/scheduler-" . lc( $self->{scheduler}->{name} ) . ".cfg"; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _createScheduledTask { |
|
64
|
0
|
|
|
0
|
|
|
my ( $self, $task ) = @_; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $taskname = "ArmaditoAgentTask" . $task->{name}; |
|
67
|
0
|
|
|
|
|
|
my $cmdline = "schtasks /Create /F /RU SYSTEM "; |
|
68
|
0
|
|
|
|
|
|
$cmdline .= $task->{options} . " /TN " . $taskname . " "; |
|
69
|
0
|
|
|
|
|
|
$cmdline .= "/TR \"\\\"C:\\Program Files\\Armadito-Agent\\bin\\armadito-agent.bat\\\" -t "; |
|
70
|
0
|
|
|
|
|
|
$cmdline .= "'" . $task->{name} . "' " . $task->{args} . " "; |
|
71
|
0
|
|
|
|
|
|
$cmdline .= "1>> \\\"C:\\Program Files\\Armadito-Agent\\var\\armadito-agent-" . $task->{name} . ".log\\\" 2>>&1 \""; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$self->{logger}->info($cmdline); |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $output = capture( EXIT_ANY, $cmdline ); |
|
76
|
0
|
|
|
|
|
|
$self->{logger}->info($output); |
|
77
|
0
|
|
|
|
|
|
$self->{logger}->info( "Program exited with " . $EXITVAL . "\n" ); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _createAllTasks { |
|
81
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
foreach ( @{ $self->{config}->{tasks} } ) { |
|
|
0
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->_createScheduledTask($_); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _getExistingTasks { |
|
89
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $cmdline = "schtasks /Query /FO CSV"; |
|
92
|
0
|
|
|
|
|
|
my $output = capture( EXIT_ANY, $cmdline ); |
|
93
|
0
|
|
|
|
|
|
$self->{logger}->info( "Program exited with " . $EXITVAL . "\n" ); |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $parser = Armadito::Agent::Patterns::Matcher->new( logger => $self->{logger} ); |
|
96
|
0
|
|
|
|
|
|
my $labels = ['name']; |
|
97
|
0
|
|
|
|
|
|
my $pattern = '^"(\\\\ArmaditoAgentTask.*?)"'; |
|
98
|
0
|
|
|
|
|
|
$parser->addPattern( 'tasks', $pattern, $labels ); |
|
99
|
0
|
|
|
|
|
|
$parser->run( $output, '\n' ); |
|
100
|
0
|
|
|
|
|
|
$parser->addHookForLabel( 'name', \&trimSlashes ); |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
return $parser->getResults(); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub trimSlashes { |
|
106
|
0
|
|
|
0
|
0
|
|
my ($match) = @_; |
|
107
|
0
|
|
|
|
|
|
$match =~ s/^\\+//ms; |
|
108
|
0
|
|
|
|
|
|
return $match; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _deleteExistingTask { |
|
112
|
0
|
|
|
0
|
|
|
my ( $self, $task ) = @_; |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $cmdline = "schtasks /Delete /F /TN \"" . $task->{name} . "\""; |
|
115
|
0
|
|
|
|
|
|
$self->{logger}->info($cmdline); |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $output = capture( EXIT_ANY, $cmdline ); |
|
118
|
0
|
|
|
|
|
|
$self->{logger}->info($output); |
|
119
|
0
|
|
|
|
|
|
$self->{logger}->info( "Program exited with " . $EXITVAL . "\n" ); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _deleteExistingTasks { |
|
123
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $existing_tasks = $self->_getExistingTasks(); |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
foreach ( @{ $existing_tasks->{tasks} } ) { |
|
|
0
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$self->_deleteExistingTask($_); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub run { |
|
133
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$self = $self->SUPER::run(%params); |
|
136
|
0
|
|
|
|
|
|
$self->_loadConf(); |
|
137
|
0
|
|
|
|
|
|
$self->_deleteExistingTasks(); |
|
138
|
0
|
|
|
|
|
|
$self->_createAllTasks(); |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return $self; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 NAME |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Armadito::Agent::Scheduler::Win32Native - class for managing native Win32 Scheduler. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This task inherits from L<Armadito::Agent::Task::Scheduler>. It allows remote management of agent's crontab configuration. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 run ( $self, %params ) |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Run the task. |
|
160
|
|
|
|
|
|
|
|