update veeam backup

This commit is contained in:
garnier-quentin 2020-03-02 13:46:08 +01:00
parent 49ab6839d2
commit a904a8275a
7 changed files with 162 additions and 71 deletions

View File

@ -25,54 +25,17 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::powershell::veeam::jobstatus;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use apps::backup::veeam::local::mode::resources::types qw($job_type $job_result);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::misc;
use JSON::XS;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
# To exclude some OK
if (defined($self->{instance_mode}->{option_results}->{ok_status}) && $self->{instance_mode}->{option_results}->{ok_status} ne '' &&
eval "$self->{instance_mode}->{option_results}->{ok_status}") {
$status = 'ok';
} elsif (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' &&
eval "$self->{instance_mode}->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' &&
eval "$self->{instance_mode}->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
return 'status : ' . $self->{result_values}->{status} . ' [type: ' . $self->{result_values}->{type} . ']';
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
$self->{result_values}->{is_running} = $options{new_datas}->{$self->{instance} . '_is_running'};
return 0;
}
sub custom_long_output {
my ($self, %options) = @_;
@ -98,7 +61,7 @@ sub set_counters {
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'job', type => 1, cb_prefix_output => 'prefix_job_output', message_multiple => 'All jobs are ok', skipped_code => { -11 => 1, -10 => 1 } },
{ name => 'job', type => 1, cb_prefix_output => 'prefix_job_output', message_multiple => 'All jobs are ok', skipped_code => { -11 => 1, -10 => 1 } }
];
$self->{maps_counters}->{global} = [
@ -106,19 +69,19 @@ sub set_counters {
key_values => [ { name => 'total' } ],
output_template => 'Total Jobs : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s', min => 0 },
],
{ label => 'total', value => 'total_absolute', template => '%s', min => 0 }
]
}
},
}
];
$self->{maps_counters}->{job} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' }, { name => 'type' }, { name => 'is_running' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'long', threshold => 0, set => {
@ -126,9 +89,9 @@ sub set_counters {
closure_custom_calc => $self->can('custom_long_calc'),
closure_custom_output => $self->can('custom_long_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold
}
},
}
];
}
@ -153,7 +116,7 @@ sub new {
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{is_running} == 0 and not %{status} =~ /Success/i' },
'warning-long:s' => { name => 'warning_long' },
'critical-long:s' => { name => 'critical_long' },
'critical-long:s' => { name => 'critical_long' }
});
return $self;
@ -215,9 +178,9 @@ sub manage_selection {
}
#[
# { name: 'xxxx', type: 'Backup', isRunning: False, result: 'Success', creationTimeUTC: 1512875246.2, endTimeUTC: 1512883615.377 },
# { name: 'xxxx', type: 'Backup', isRunning: False, result: '', creationTimeUTC: '', endTimeUTC: '' },
# { name: 'xxxx', type: 'BackupSync', isRunning: True, result: 'None', creationTimeUTC: 1513060425.027, endTimeUTC: -2208992400 }
# { name: 'xxxx', type: 0, isRunning: False, result: 0, creationTimeUTC: 1512875246.2, endTimeUTC: 1512883615.377 },
# { name: 'xxxx', type: 0, isRunning: False, result: 1, creationTimeUTC: '', endTimeUTC: '' },
# { name: 'xxxx', type: 1, isRunning: True, result: 0, creationTimeUTC: 1513060425.027, endTimeUTC: -2208992400 }
#]
$self->{global} = { total => 0 };
@ -233,7 +196,7 @@ sub manage_selection {
next;
}
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$job->{type} !~ /$self->{option_results}->{filter_type}/) {
$job_type->{ $job->{type} } !~ /$self->{option_results}->{filter_type}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $job->{name} . "': no matching filter type.", debug => 1);
next;
}
@ -250,14 +213,15 @@ sub manage_selection {
my $elapsed_time;
$elapsed_time = $current_time - $job->{creationTimeUTC} if ($job->{creationTimeUTC} =~ /[0-9]/);
#is_running = 2 (never running)
$self->{job}->{ $job->{name} } = {
display => $job->{name},
elapsed => $elapsed_time,
type => $job->{type},
type => $job_type->{ $job->{type} },
is_running => $job->{isRunning} =~ /True|1/ ? 1 : ($job->{creationTimeUTC} !~ /[0-9]/ ? 2 : 0),
status => $job->{result} ne '' ? $job->{result} : '-'
status => defined($job_result->{ $job->{result} }) && $job_result->{ $job->{result} } ne '' ?
$job_result->{ $job->{result} } : '-'
};
$self->{global}->{total}++;
}

View File

@ -24,8 +24,10 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use apps::backup::veeam::local::mode::resources::types qw($job_type);
use centreon::common::powershell::veeam::listjobs;
use centreon::plugins::misc;
use JSON::XS;
sub new {
my ($class, %options) = @_;
@ -40,7 +42,7 @@ sub new {
'no-ps' => { name => 'no_ps' },
'ps-exec-only' => { name => 'ps_exec_only' },
'ps-display' => { name => 'ps_display' },
'filter-name:s' => { name => 'filter_name' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
@ -128,14 +130,14 @@ sub manage_selection {
}
$self->{jobs} = {};
foreach my $job (@$decoded) {
foreach my $job (@$decoded) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$job->{name} !~ /$self->{option_results}->{filter_name}/i) {
$self->{output}->output_add(long_msg => "skipping job '" . $job->{name} . "': no type or no matching filter type", debug => 1);
$self->{output}->output_add(long_msg => "skipping job '" . $job->{name} . "': no matching filter name", debug => 1);
next;
}
$self->{jobs}->{ $job->{name} } = { type => $job->{type} };
$self->{jobs}->{ $job->{name} } = { type => $job_type->{ $job->{type} } };
}
}

View File

@ -0,0 +1,124 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::backup::veeam::local::mode::resources::types;
use strict;
use warnings;
use Exporter;
our $job_type;
our $job_result;
our $job_tape_type;
our $job_tape_result;
our $job_tape_state;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(
$job_type $job_result $job_tape_type $job_tape_result $job_tape_state
);
$job_type = {
0 => 'Backup', 1 => 'Replica', 2 => 'Copy',
3 => 'DRV', 4 => 'RestoreVm', 5 => 'RestoreVmFiles',
6 => 'RestoreFiles', 7 => 'Failover', 8 => 'QuickMigration',
9 => 'UndoFailover', 10 => 'FileLevelRestore',
11 => 'LinuxFileLevelRestore', 12 => 'InstantRecovery',
13 => 'RestoreHdd', 14 => 'Failback', 15 => 'PermanentFailover',
16 => 'UndoFailback', 17 => 'CommitFailback', 18 => 'ShellRun',
19 => 'VolumesDiscover', 20 => 'HvCtpRescan',
21 => 'CatCleanup', 22 => 'SanRescan', 23 => 'CreateSanSnapshot',
24 => 'FileTapeBackup', 25 => 'FileTapeRestore',
26 => 'TapeValidate', 27 => 'TapeInventory', 28 => 'VmTapeBackup',
29 => 'VmTapeRestore', 30 => 'SanMonitor', 31 => 'DeleteSanSnapshot',
32 => 'TapeErase', 33 => 'TapeEject', 34 => 'TapeExport',
35 => 'TapeImport', 36 => 'TapeCatalog', 37 => 'TapeLibrariesDiscover',
38 => 'PowerShellScript', 39 => 'VmReconfig', 40 => 'VmStart',
41 => 'VcdVAppRestore', 42 => 'VcdVmRestore', 46 => 'HierarchyScan',
47 => 'ViVmConsolidation', 48 => 'ApplicationLevelRestore',
50 => 'RemoteReplica', 51 => 'BackupSync', 52 => 'SqlLogBackup',
53 => 'LicenseAutoUpdate', 54 => 'OracleLogBackup',
55 => 'TapeMarkAsFree', 56 => 'TapeDeleteFromLibrary',
57 => 'TapeMoveToMediaPool', 58 => 'TapeCatalogueDecrypted',
63 => 'SimpleBackupCopyWorker', 64 => 'QuickMigrationCheck',
100 => 'ConfBackup', 101 => 'ConfRestore', 102 => 'ConfResynchronize',
103 => 'WaGlobalDedupFill', 104 => 'DatabaseMaintenance',
105 => 'RepositoryMaintenance', 106 => 'InfrastructureRescan',
200 => 'HvLabDeploy', 201 => 'HvLabDelete', 202 => 'FailoverPlan',
203 => 'UndoFailoverPlan', 204 => 'FailoverPlanTask',
205 => 'UndoFailoverPlanTask', 206 => 'PlannedFailover',
207 => 'ViLabDeploy', 208 => 'ViLabDelete', 209 => 'ViLabStart',
300 => 'Cloud', 301 => 'CloudApplDeploy',
302 => 'HardwareQuotasProcessing', 303 => 'ReconnectVpn',
304 => 'DisconnectVpn', 305 => 'OrchestratedTask',
306 => 'ViReplicaRescan', 307 => 'ExternalRepositoryMaintenance',
308 => 'DeleteBackup', 309 => 'CloudProviderRescan',
401 => 'AzureApplDeploy', 500 => 'TapeTenantRestore',
666 => 'Unknown', 4000 => 'EndpointBackup',
4005 => 'EndpointRestore', 4010 => 'BackupCacheSync',
4020 => 'EndpointSqlLogBackup', 4021 => 'EndpointOracleLogBackup',
4030 => 'OracleRMANBackup', 4031 => 'SapBackintBackup',
5000 => 'CloudBackup', 6000 => 'RestoreVirtualDisks',
6001 => 'RestoreAgentVolumes', 7000 => 'InfraItemSave',
7001 => 'InfraItemUpgrade', 7002 => 'InfraItemDelete',
7003 => 'AzureWinProxySave', 8000 => 'FileLevelRestoreByEnterprise',
9000 => 'RepositoryEvacuate', 10000 => 'LogsExport',
10001 => 'InfraStatistic', 11000 => 'AzureVmRestore',
12000 => 'EpAgentManagement', 12001 => 'EpAgentDiscoveryObsolete',
12002 => 'EpAgentPolicy', 12003 => 'EpAgentBackup',
12004 => 'EpAgentTestCreds', 12005 => 'EpAgentDiscovery',
12006 => 'EpAgentDeletedRetention', 13000 => 'NasBackup',
13001 => 'NasBackupBrowse', 13002 => 'NasRestore',
14000 => 'VmbApiPolicyTempJob', 15000 => 'ExternalInfrastructureRescan',
16000 => 'AmazonRestore', 17000 => 'StagedRestore',
18000 => 'ArchiveBackup', 18001 => 'ArchiveRehydration',
18002 => 'ArchiveDownload', 19000 => 'HvStagedRestore',
20000 => 'VbkExport', 21000 => 'GuestScriptingConnect'
};
$job_result = {
0 => 'Success',
1 => 'Warning',
2 => 'Failed',
-1 => 'None'
};
$job_tape_type = {
0 => 'BackupToTape', 1 => 'FileToTape',
2 => 'TapeCatalog', 3 => 'TapeEject',
4 => 'TapeErase', 5 => 'TapeExport',
6 => 'TapeImport', 7 => 'TapeInventory',
8 => 'TapeRescan', 9 => 'Backup',
10 => 'BackupSync', 11 => 'EndpointBackup',
12 => 'ConfigurationBackup'
};
$job_tape_result = {
0 => 'None', 1 => 'Success', 2 => 'Warning', 3 => 'Failed'
};
$job_tape_state = {
0 => 'Stopped', 1 => 'Starting', 2 => 'Stopping',
3 => 'Working', 4 => 'Pausing', 5 => 'Resuming',
6 => 'WaitingTape', 7 => 'Idle', 8 => 'Postprocessing',
9 => 'WaitingRepository', 10 => 'Pending'
};
1;

View File

@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::powershell::veeam::tapejobs;
use apps::backup::veeam::local::mode::resources::types qw($job_tape_type $job_tape_result $job_tape_state);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::misc;
use JSON::XS;
@ -154,8 +155,8 @@ sub manage_selection {
}
#[
# { name: 'xxxx', type: 'BackupToTape', Enabled: True, lastResult: 'Success', lastState: 'Stopped' },
# { name: 'xxxx', type: 'FileToTape', Enabled: True, lastResult: 'None', lastState: 'Working' }
# { name: 'xxxx', type: 0, Enabled: True, lastResult: 0, lastState: 0 },
# { name: 'xxxx', type: 1, Enabled: True, lastResult: 1, lastState: 1 }
#]
$self->{global} = { total => 0 };
@ -174,10 +175,10 @@ sub manage_selection {
$self->{job}->{ $job->{name} } = {
display => $job->{name},
type => $job->{type},
type => $job_tape_type->{ $job->{type} },
enabled => $job->{enabled} =~ /True|1/ ? 1 : 0,
last_result => $job->{lastResult},
last_state => $job->{lastState}
last_result => $job_tape_result->{ $job->{lastResult} },
last_state => $job_tape_state->{ $job->{lastState} }
};
$self->{global}->{total}++;
}

View File

@ -61,15 +61,15 @@ Try {
foreach ($job in $jobs) {
$item = @{}
$item.name = $job.Name
$item.type = $job.JobType
$item.type = $job.JobType.value__
$item.isRunning = $job.isRunning
$item.result = ""
$item.result = -10
$item.creationTimeUTC = ""
$item.endTimeUTC = ""
$lastsession = $job.findlastsession()
if ($lastsession) {
$item.result = $lastsession.Result
$item.result = $lastsession.Result.value__
$item.creationTimeUTC = (get-date -date $lastsession.creationTime.ToUniversalTime() -Uformat ' . "'%s'" . ')
$item.endTimeUTC = (get-date -date $lastsession.EndTime.ToUniversalTime() -Uformat ' . "'%s'" . ')
}

View File

@ -61,7 +61,7 @@ Try {
foreach ($job in $jobs) {
$item = @{
name = $job.Name;
type = $job.JobType
type = $job.JobType.value__
}
$items.Add($item)

View File

@ -62,9 +62,9 @@ Try {
$item = @{
name = $job.Name;
enabled = $job.Enabled;
type = $job.Type;
lastResult = $job.LastResult;
lastState = $job.LastState
type = $job.Type.value__;
lastResult = $job.LastResult.value__;
lastState = $job.LastState.value__
}
$items.Add($item)