line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Armadito::Agent::Task::AVConfig; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
6038990
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
98
|
|
5
|
2
|
|
|
2
|
|
9
|
use base 'Armadito::Agent::Task'; |
|
2
|
|
|
|
|
34
|
|
|
2
|
|
|
|
|
786
|
|
6
|
2
|
|
|
2
|
|
13
|
use JSON; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
33
|
|
7
|
2
|
|
|
2
|
|
296
|
use Data::Dumper; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
686
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
0
|
|
|
0
|
1
|
|
my ( $class, %params ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(%params); |
13
|
|
|
|
|
|
|
|
14
|
0
|
0
|
|
|
|
|
if ( $params{debug} ) { |
15
|
0
|
|
|
|
|
|
$self->{debug} = 1; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $task = { |
19
|
|
|
|
|
|
|
name => "AVConfig", |
20
|
|
|
|
|
|
|
antivirus => $self->{agent}->{antivirus}->getJobj() |
21
|
0
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$self->{jobj}->{task} = $task; |
24
|
0
|
|
|
|
|
|
$self->{glpi_url} = $self->{agent}->{config}->{server}[0]; |
25
|
0
|
|
|
|
|
|
$self->{avconfig} = []; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _handleError { |
31
|
0
|
|
|
0
|
|
|
my ( $self, $response ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$self->{logger}->info( "Error Response : " . $response->content() ); |
34
|
0
|
|
|
|
|
|
my $obj = from_json( $response->content(), { utf8 => 1 } ); |
35
|
0
|
|
|
|
|
|
$self->{logger}->error( Dumper($obj) ); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _addConfEntry { |
41
|
0
|
|
|
0
|
|
|
my ( $self, $attr, $value ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$attr =~ s/^://; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $conf_entry = { |
46
|
|
|
|
|
|
|
attr => $attr, |
47
|
|
|
|
|
|
|
value => $value |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
push( @{ $self->{avconfig} }, $conf_entry ); |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _sendToGLPI { |
54
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->{jobj}->{task}->{obj} = $self->{avconfig}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $json_text = to_json( $self->{jobj} ); |
59
|
0
|
|
|
|
|
|
$self->{logger}->debug($json_text); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $response = $self->{glpi_client}->sendRequest( |
62
|
0
|
|
|
|
|
|
"url" => $self->{glpi_url} . "/api/avconfigs", |
63
|
|
|
|
|
|
|
message => $json_text, |
64
|
|
|
|
|
|
|
method => "POST" |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if ( $response->is_success() ) { |
68
|
0
|
|
|
|
|
|
$self->{logger}->info("AVConfig successful..."); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
0
|
|
|
|
|
|
$self->_handleError($response); |
72
|
0
|
|
|
|
|
|
$self->{logger}->info("AVConfig failed..."); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return 1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Armadito::Agent::Task::AVConfig - AVConfig Task base class |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 DESCRIPTION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This task inherits from L<Armadito::Agent::Task>. Get Antivirus configuration and send them as json messages to armadito glpi plugin. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 FUNCTIONS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 run ( $self, %params ) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Run the task. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 new ( $self, %params ) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Instanciate Task. |
99
|
|
|
|
|
|
|
|