| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Armadito::Agent::Task::Alerts; |
|
2
|
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
6631473
|
use strict; |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
218
|
|
|
4
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
244
|
|
|
5
|
6
|
|
|
6
|
|
23
|
use base 'Armadito::Agent::Task'; |
|
|
6
|
|
|
|
|
53
|
|
|
|
6
|
|
|
|
|
2173
|
|
|
6
|
6
|
|
|
6
|
|
39
|
use JSON; |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
80
|
|
|
7
|
6
|
|
|
6
|
|
821
|
use Data::Dumper; |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
1717
|
|
|
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 => "Alerts", |
|
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
|
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return $self; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _handleError { |
|
30
|
0
|
|
|
0
|
|
|
my ( $self, $response ) = @_; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self->{logger}->info( "Error Response : " . $response->content() ); |
|
33
|
0
|
|
|
|
|
|
my $obj = from_json( $response->content(), { utf8 => 1 } ); |
|
34
|
0
|
|
|
|
|
|
$self->{logger}->error( Dumper($obj) ); |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $self; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _sendAlerts { |
|
40
|
0
|
|
|
0
|
|
|
my ( $self, $alerts ) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$self->{jobj}->{task}->{obj} = $alerts; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $json_text = to_json( $self->{jobj} ); |
|
45
|
0
|
|
|
|
|
|
$self->{logger}->debug($json_text); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $response = $self->{glpi_client}->sendRequest( |
|
48
|
0
|
|
|
|
|
|
"url" => $self->{glpi_url} . "/api/alerts", |
|
49
|
|
|
|
|
|
|
message => $json_text, |
|
50
|
|
|
|
|
|
|
method => "POST" |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if ( $response->is_success() ) { |
|
54
|
0
|
|
|
|
|
|
$self->{logger}->info("Alerts successful..."); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
else { |
|
57
|
0
|
|
|
|
|
|
$self->_handleError($response); |
|
58
|
0
|
|
|
|
|
|
$self->{logger}->info("Alerts failed..."); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return 1; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Armadito::Agent::Task::Alerts - Alerts Task base class |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This task inherits from L<Armadito::Agent::Task>. Get Antivirus alerts and send them as json messages to armadito glpi plugin. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 run ( $self, %params ) |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Run the task. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 new ( $self, %params ) |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Instanciate Task. |
|
85
|
|
|
|
|
|
|
|