File Coverage

blib/lib/Armadito/Agent/Task/Scan.pm
Criterion Covered Total %
statement 18 48 37.5
branch 0 14 0.0
condition n/a
subroutine 6 10 60.0
pod 1 2 50.0
total 25 74 33.7


line stmt bran cond sub pod time code
1             package Armadito::Agent::Task::Scan;
2              
3 4     4   4391018 use strict;
  4         8  
  4         129  
4 4     4   24 use warnings;
  4         7  
  4         158  
5 4     4   18 use base 'Armadito::Agent::Task';
  4         36  
  4         1681  
6              
7 4     4   1697 use MIME::Base64;
  4         1688  
  4         222  
8 4     4   20 use Data::Dumper;
  4         6  
  4         187  
9 4     4   22 use JSON;
  4         4  
  4         68  
10              
11             sub new {
12 0     0 1   my ( $class, %params ) = @_;
13              
14 0           my $self = $class->SUPER::new(%params);
15              
16 0 0         if ( $params{debug} ) {
17 0           $self->{debug} = 1;
18             }
19              
20             my $task = {
21             name => "Scan",
22             antivirus => $self->{agent}->{antivirus}->getJobj()
23 0           };
24              
25 0           $self->{jobj}->{task} = $task;
26 0           $self->{job} = $params{job};
27 0           $self->_validateScanObj( $self->{job}->{obj} );
28              
29 0           return $self;
30             }
31              
32             sub _validateScanObj {
33 0     0     my ( $self, $scanobj ) = @_;
34              
35 0 0         die "undefined scan_type." if ( !defined( $scanobj->{scan_name} ) );
36 0 0         die "undefined scan_path." if ( !defined( $scanobj->{scan_path} ) );
37 0 0         die "undefined scan_options." if ( !defined( $scanobj->{scan_options} ) );
38 0 0         die "Empty scan_path." if ( $scanobj->{scan_path} eq "" );
39              
40 0 0         if ( $scanobj->{scan_options} ne "" ) {
41 0           $scanobj->{scan_options} = decode_base64( $scanobj->{scan_options} );
42             }
43              
44 0           $scanobj->{scan_path} = decode_base64( $scanobj->{scan_path} );
45             }
46              
47             sub _handleError {
48 0     0     my ( $self, $response ) = @_;
49              
50 0           $self->{logger}->info( "Error Response : " . $response->content() );
51 0           my $obj = from_json( $response->content(), { utf8 => 1 } );
52 0           $self->{logger}->error( Dumper($obj) );
53              
54 0           return $self;
55             }
56              
57             sub sendScanResults {
58 0     0 0   my ( $self, $scanresults ) = @_;
59              
60 0           $self->{jobj}->{task}->{obj} = $scanresults;
61 0           my $json_text = to_json( $self->{jobj} );
62              
63             my $response = $self->{glpi_client}->sendRequest(
64 0           "url" => $self->{agent}->{config}->{server}[0] . "/api/scans",
65             message => $json_text,
66             method => "POST"
67             );
68              
69 0 0         if ( $response->is_success() ) {
70 0           $self->{logger}->info("Send Scan results successful...");
71             }
72             else {
73 0           $self->_handleError($response);
74 0           $self->{logger}->info("Send Scan results failed...");
75             }
76             }
77              
78             1;
79              
80             __END__
81              
82             =head1 NAME
83              
84             Armadito::Agent::Task::Scan - Scan Task base class
85              
86             =head1 DESCRIPTION
87              
88             This task inherits from L<Armadito::Agent::Task>. Launch a Antivirus on-demand scan and send a brief report to GPLI server Armadito 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