Fix #1984
This commit is contained in:
parent
4582350dfc
commit
e28b55b3d1
|
@ -31,8 +31,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
|
||||||
sub custom_status_output {
|
sub custom_status_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $msg = sprintf("Updates status is '%s'", $self->{result_values}->{status});
|
return sprintf("Updates status is '%s'", $self->{result_values}->{status});
|
||||||
return $msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_status_calc {
|
sub custom_status_calc {
|
||||||
|
@ -45,26 +44,34 @@ sub custom_status_calc {
|
||||||
sub custom_last_perfdata {
|
sub custom_last_perfdata {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => 'last_server_update',
|
$self->{output}->perfdata_add(
|
||||||
value => $self->{result_values}->{diff},
|
label => 'last_server_update',
|
||||||
unit => 's',
|
value => $self->{result_values}->{diff},
|
||||||
min => 0);
|
unit => 's',
|
||||||
|
min => 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_last_threshold {
|
sub custom_last_threshold {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{diff},
|
my $exit = $self->{perfdata}->threshold_check(
|
||||||
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
value => $self->{result_values}->{diff},
|
||||||
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
|
threshold => [
|
||||||
|
{ label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
||||||
|
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' }
|
||||||
|
]
|
||||||
|
);
|
||||||
return $exit;
|
return $exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_last_output {
|
sub custom_last_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $msg = sprintf("Last server update: %s [%s]", centreon::plugins::misc::change_seconds(value => $self->{result_values}->{diff}), $self->{result_values}->{date_time});
|
return sprintf(
|
||||||
return $msg;
|
'Last server update: %s [%s]',
|
||||||
|
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{diff}), $self->{result_values}->{date_time}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_last_calc {
|
sub custom_last_calc {
|
||||||
|
@ -80,7 +87,7 @@ sub custom_last_calc {
|
||||||
hour => $4,
|
hour => $4,
|
||||||
minute => $5,
|
minute => $5,
|
||||||
second => $6,
|
second => $6,
|
||||||
%{$self->{tz}}
|
%{$self->{instance_mode}->{tz}}
|
||||||
);
|
);
|
||||||
$self->{result_values}->{diff} = time() - $dt->epoch;
|
$self->{result_values}->{diff} = time() - $dt->epoch;
|
||||||
$self->{result_values}->{date_time} = $dt->datetime();
|
$self->{result_values}->{date_time} = $dt->datetime();
|
||||||
|
@ -93,7 +100,7 @@ sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'global', type => 0, message_separator => ' - ' },
|
{ name => 'global', type => 0, message_separator => ' - ' }
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{global} = [
|
$self->{maps_counters}->{global} = [
|
||||||
|
@ -102,7 +109,7 @@ sub set_counters {
|
||||||
closure_custom_calc => $self->can('custom_status_calc'),
|
closure_custom_calc => $self->can('custom_status_calc'),
|
||||||
closure_custom_output => $self->can('custom_status_output'),
|
closure_custom_output => $self->can('custom_status_output'),
|
||||||
closure_custom_perfdata => sub { return 0; },
|
closure_custom_perfdata => sub { return 0; },
|
||||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
closure_custom_threshold_check => \&catalog_status_threshold
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'last-server-update', set => {
|
{ label => 'last-server-update', set => {
|
||||||
|
@ -110,17 +117,17 @@ sub set_counters {
|
||||||
closure_custom_calc => $self->can('custom_last_calc'),
|
closure_custom_calc => $self->can('custom_last_calc'),
|
||||||
closure_custom_output => $self->can('custom_last_output'),
|
closure_custom_output => $self->can('custom_last_output'),
|
||||||
closure_custom_threshold_check => $self->can('custom_last_threshold'),
|
closure_custom_threshold_check => $self->can('custom_last_threshold'),
|
||||||
closure_custom_perfdata => $self->can('custom_last_perfdata'),
|
closure_custom_perfdata => $self->can('custom_last_perfdata')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'not-updated', set => {
|
{ label => 'not-updated', set => {
|
||||||
key_values => [ { name => 'hostsNotUpdated' } ],
|
key_values => [ { name => 'hostsNotUpdated' } ],
|
||||||
output_template => '%d host(s) not up to date',
|
output_template => '%d host(s) not up to date',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'not_updated', value => 'hostsNotUpdated_absolute', template => '%d', min => 0 },
|
{ label => 'not_updated', value => 'hostsNotUpdated_absolute', template => '%d', min => 0 }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +136,12 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /Warning/i' },
|
||||||
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /Warning/i' },
|
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /Critical/i' },
|
||||||
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Critical/i' },
|
'timezone:s' => { name => 'timezone', default => 'GMT' }
|
||||||
"timezone:s" => { name => 'timezone', default => 'GMT' },
|
});
|
||||||
});
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,12 +153,12 @@ sub check_options {
|
||||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||||
}
|
}
|
||||||
|
|
||||||
my %map_status = (
|
my $map_status = {
|
||||||
0 => 'OK',
|
0 => 'OK',
|
||||||
1 => 'Info',
|
1 => 'Info',
|
||||||
2 => 'Warning',
|
2 => 'Warning',
|
||||||
3 => 'Critical',
|
3 => 'Critical'
|
||||||
);
|
};
|
||||||
|
|
||||||
my $oid_updatesStatus = '.1.3.6.1.4.1.23668.1093.1.2.1';
|
my $oid_updatesStatus = '.1.3.6.1.4.1.23668.1093.1.2.1';
|
||||||
my $oid_lastServerUpdateTime = '.1.3.6.1.4.1.23668.1093.1.2.3';
|
my $oid_lastServerUpdateTime = '.1.3.6.1.4.1.23668.1093.1.2.3';
|
||||||
|
@ -160,14 +167,16 @@ my $oid_hostsNotUpdated = '.1.3.6.1.4.1.23668.1093.1.2.4';
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_updatesStatus, $oid_lastServerUpdateTime,
|
my $snmp_result = $options{snmp}->get_leef(
|
||||||
$oid_hostsNotUpdated ],
|
oids => [
|
||||||
nothing_quit => 1);
|
$oid_updatesStatus, $oid_lastServerUpdateTime,
|
||||||
|
$oid_hostsNotUpdated
|
||||||
$self->{global} = {};
|
],
|
||||||
|
nothing_quit => 1
|
||||||
|
);
|
||||||
|
|
||||||
$self->{global} = {
|
$self->{global} = {
|
||||||
updatesStatus => $map_status{$snmp_result->{$oid_updatesStatus}},
|
updatesStatus => $map_status->{$snmp_result->{$oid_updatesStatus}},
|
||||||
lastServerUpdateTime => $snmp_result->{$oid_lastServerUpdateTime},
|
lastServerUpdateTime => $snmp_result->{$oid_lastServerUpdateTime},
|
||||||
hostsNotUpdated => $snmp_result->{$oid_hostsNotUpdated},
|
hostsNotUpdated => $snmp_result->{$oid_hostsNotUpdated},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue