indent + add battery last replace date

This commit is contained in:
garnier-quentin 2020-01-28 14:53:59 +01:00
parent 7a2046eb29
commit 0ab1fa151b
5 changed files with 136 additions and 111 deletions

View File

@ -28,26 +28,31 @@ use centreon::plugins::templates::catalog_functions;
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Battery status is '%s' [battery needs replace: %s]", $self->{result_values}->{status}, $self->{result_values}->{replace}); return sprintf(
return $msg; "battery status is '%s' [battery needs replace: %s] [last replace date: %s]",
$self->{result_values}->{status},
$self->{result_values}->{replace},
$self->{result_values}->{last_replace_date}
);
} }
sub custom_status_calc { sub custom_status_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_upsBasicBatteryStatus'}; $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_upsBasicBatteryStatus'};
$self->{result_values}->{replace} = $options{new_datas}->{$self->{instance} . '_upsAdvBatteryReplaceIndicator'}; $self->{result_values}->{replace} = $options{new_datas}->{$self->{instance} . '_upsAdvBatteryReplaceIndicator'};
$self->{result_values}->{last_replace_date} = $options{new_datas}->{$self->{instance} . '_upsBasicBatteryLastReplaceDate'};
return 0; return 0;
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0, skipped_code => { -10 => 1 } },
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'upsBasicBatteryStatus' }, { name => 'upsAdvBatteryReplaceIndicator' } ], key_values => [ { name => 'upsBasicBatteryStatus' }, { name => 'upsAdvBatteryReplaceIndicator' } ],
@ -59,7 +64,7 @@ sub set_counters {
}, },
{ label => 'load', set => { { label => 'load', set => {
key_values => [ { name => 'upsAdvBatteryCapacity' } ], key_values => [ { name => 'upsAdvBatteryCapacity' } ],
output_template => 'Remaining capacity : %s %%', output_template => 'remaining capacity: %s %%',
perfdatas => [ perfdatas => [
{ label => 'load', value => 'upsAdvBatteryCapacity_absolute', template => '%s', { label => 'load', value => 'upsAdvBatteryCapacity_absolute', template => '%s',
min => 0, max => 100, unit => '%' }, min => 0, max => 100, unit => '%' },
@ -68,7 +73,7 @@ sub set_counters {
}, },
{ label => 'time', set => { { label => 'time', set => {
key_values => [ { name => 'upsAdvBatteryRunTimeRemaining' } ], key_values => [ { name => 'upsAdvBatteryRunTimeRemaining' } ],
output_template => 'Remaining time : %.2f minutes', output_template => 'remaining time: %.2f minutes',
perfdatas => [ perfdatas => [
{ label => 'load_time', value => 'upsAdvBatteryRunTimeRemaining_absolute', template => '%.2f', { label => 'load_time', value => 'upsAdvBatteryRunTimeRemaining_absolute', template => '%.2f',
min => 0, unit => 'm' }, min => 0, unit => 'm' },
@ -77,7 +82,7 @@ sub set_counters {
}, },
{ label => 'current', set => { { label => 'current', set => {
key_values => [ { name => 'upsAdvBatteryCurrent' } ], key_values => [ { name => 'upsAdvBatteryCurrent' } ],
output_template => 'Current : %s A', output_template => 'current: %s A',
perfdatas => [ perfdatas => [
{ label => 'current', value => 'upsAdvBatteryCurrent_absolute', template => '%s', { label => 'current', value => 'upsAdvBatteryCurrent_absolute', template => '%s',
min => 0, unit => 'A' }, min => 0, unit => 'A' },
@ -86,7 +91,7 @@ sub set_counters {
}, },
{ label => 'voltage', set => { { label => 'voltage', set => {
key_values => [ { name => 'upsAdvBatteryActualVoltage' } ], key_values => [ { name => 'upsAdvBatteryActualVoltage' } ],
output_template => 'Voltage : %s V', output_template => 'voltage: %s V',
perfdatas => [ perfdatas => [
{ label => 'voltage', value => 'upsAdvBatteryActualVoltage_absolute', template => '%s', { label => 'voltage', value => 'upsAdvBatteryActualVoltage_absolute', template => '%s',
unit => 'V' }, unit => 'V' },
@ -95,7 +100,7 @@ sub set_counters {
}, },
{ label => 'temperature', set => { { label => 'temperature', set => {
key_values => [ { name => 'upsAdvBatteryTemperature' } ], key_values => [ { name => 'upsAdvBatteryTemperature' } ],
output_template => 'Temperature : %s C', output_template => 'temperature: %s C',
perfdatas => [ perfdatas => [
{ label => 'temperature', value => 'upsAdvBatteryTemperature_absolute', template => '%s', { label => 'temperature', value => 'upsAdvBatteryTemperature_absolute', template => '%s',
unit => 'C'}, unit => 'C'},
@ -126,25 +131,25 @@ sub check_options {
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
} }
my %map_battery_status = ( my $map_battery_status = {
1 => 'unknown', 1 => 'unknown',
2 => 'batteryNormal', 2 => 'batteryNormal',
3 => 'batteryLow', 3 => 'batteryLow',
); };
my %map_replace_status = ( my $map_replace_status = {
1 => 'no', 1 => 'no', 2 => 'yes'
2 => 'yes', };
);
my $mapping = { my $mapping = {
upsBasicBatteryStatus => { oid => '.1.3.6.1.4.1.318.1.1.1.2.1.1', map => \%map_battery_status }, upsBasicBatteryStatus => { oid => '.1.3.6.1.4.1.318.1.1.1.2.1.1', map => $map_battery_status },
upsBasicBatteryTimeOnBattery => { oid => '.1.3.6.1.4.1.318.1.1.1.2.1.2' }, upsBasicBatteryTimeOnBattery => { oid => '.1.3.6.1.4.1.318.1.1.1.2.1.2' },
upsBasicBatteryLastReplaceDate => { oid => '.1.3.6.1.4.1.318.1.1.1.2.1.3' },
}; };
my $mapping2 = { my $mapping2 = {
upsAdvBatteryCapacity => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.1' }, upsAdvBatteryCapacity => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.1' },
upsAdvBatteryTemperature => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.2' }, upsAdvBatteryTemperature => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.2' },
upsAdvBatteryRunTimeRemaining => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.3' }, upsAdvBatteryRunTimeRemaining => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.3' },
upsAdvBatteryReplaceIndicator => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.4', map => \%map_replace_status }, upsAdvBatteryReplaceIndicator => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.4', map => $map_replace_status },
upsAdvBatteryActualVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.8' }, upsAdvBatteryActualVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.8' },
upsAdvBatteryCurrent => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.9' }, upsAdvBatteryCurrent => { oid => '.1.3.6.1.4.1.318.1.1.1.2.2.9' },
}; };
@ -154,23 +159,21 @@ my $oid_upsAdvBattery = '.1.3.6.1.4.1.318.1.1.1.2.2';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{global} = {}; my $snmp_result = $options{snmp}->get_multiple_table(
$self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_upsBasicBattery }, oids => [
{ oid => $oid_upsAdvBattery }, { oid => $oid_upsBasicBattery },
], { oid => $oid_upsAdvBattery },
nothing_quit => 1); ],
nothing_quit => 1
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_upsBasicBattery}, instance => '0'); );
my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_upsAdvBattery}, instance => '0');
$result2->{upsAdvBatteryRunTimeRemaining} = sprintf("%.0f", $result2->{upsAdvBatteryRunTimeRemaining} / 100 / 60) if (defined($result2->{upsAdvBatteryRunTimeRemaining})); $self->{global} = {};
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_upsBasicBattery}, instance => '0');
foreach my $name (keys %{$mapping}) { my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_upsAdvBattery}, instance => '0');
$self->{global}->{$name} = $result->{$name};
} $result2->{upsAdvBatteryRunTimeRemaining} = sprintf("%.0f", $result2->{upsAdvBatteryRunTimeRemaining} / 100 / 60)
foreach my $name (keys %{$mapping2}) { if (defined($result2->{upsAdvBatteryRunTimeRemaining}));
$self->{global}->{$name} = $result2->{$name}; $self->{global} = { %$result, %$result2 };
}
} }
1; 1;
@ -179,7 +182,7 @@ __END__
=head1 MODE =head1 MODE
Check Battery Status and battery charge remaining. Check battery status and battery charge remaining.
=over 8 =over 8

View File

@ -29,12 +29,11 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
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:s' => { name => 'warning' },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical' },
"critical:s" => { name => 'critical', }, });
});
return $self; return $self;
} }
@ -60,17 +59,25 @@ sub run {
my $oid_iveCpuUtil = '.1.3.6.1.4.1.12532.10.0'; my $oid_iveCpuUtil = '.1.3.6.1.4.1.12532.10.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_iveCpuUtil], nothing_quit => 1); my $result = $self->{snmp}->get_leef(oids => [$oid_iveCpuUtil], nothing_quit => 1);
my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_iveCpuUtil}, my $exit_code = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); value => $result->{$oid_iveCpuUtil},
$self->{output}->output_add(severity => $exit_code, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
short_msg => sprintf("CPU Usage is %.2f%%", );
$result->{$oid_iveCpuUtil})); $self->{output}->output_add(
$self->{output}->perfdata_add(label => 'cpu', unit => '%', severity => $exit_code,
value => sprintf("%.2f", $result->{$oid_iveCpuUtil}), short_msg => sprintf(
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), 'CPU Usage is %.2f%%',
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), $result->{$oid_iveCpuUtil}
min => 0, max => 100); )
);
$self->{output}->perfdata_add(
label => 'cpu', unit => '%',
value => sprintf("%.2f", $result->{$oid_iveCpuUtil}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0, max => 100
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }

View File

@ -29,12 +29,11 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
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:s' => { name => 'warning', },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical', },
"critical:s" => { name => 'critical', }, });
});
return $self; return $self;
} }
@ -56,21 +55,29 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{snmp} = $options{snmp}; $self->{snmp} = $options{snmp};
my $oid_diskFullPercent = '.1.3.6.1.4.1.12532.25.0'; my $oid_diskFullPercent = '.1.3.6.1.4.1.12532.25.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_diskFullPercent], nothing_quit => 1); my $result = $self->{snmp}->get_leef(oids => [$oid_diskFullPercent], nothing_quit => 1);
my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_diskFullPercent}, my $exit_code = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); value => $result->{$oid_diskFullPercent},
$self->{output}->output_add(severity => $exit_code, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
short_msg => sprintf("Disk Usage is %.2f%%", );
$result->{$oid_diskFullPercent})); $self->{output}->output_add(
$self->{output}->perfdata_add(label => 'used', unit => '%', severity => $exit_code,
value => sprintf("%.2f", $result->{$oid_diskFullPercent}), short_msg => sprintf(
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), 'Disk Usage is %.2f%%',
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), $result->{$oid_diskFullPercent}
min => 0, max => 100); )
);
$self->{output}->perfdata_add(
label => 'used', unit => '%',
value => sprintf("%.2f", $result->{$oid_diskFullPercent}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0, max => 100
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }

View File

@ -29,12 +29,11 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
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:s' => { name => 'warning', },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical', },
"critical:s" => { name => 'critical', }, });
});
return $self; return $self;
} }
@ -56,21 +55,29 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{snmp} = $options{snmp}; $self->{snmp} = $options{snmp};
my $oid_logFullPercent = '.1.3.6.1.4.1.12532.1.0'; my $oid_logFullPercent = '.1.3.6.1.4.1.12532.1.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_logFullPercent], nothing_quit => 1); my $result = $self->{snmp}->get_leef(oids => [$oid_logFullPercent], nothing_quit => 1);
my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_logFullPercent}, my $exit_code = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); value => $result->{$oid_logFullPercent},
$self->{output}->output_add(severity => $exit_code, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
short_msg => sprintf("Log File Usage is %.2f%%", );
$result->{$oid_logFullPercent})); $self->{output}->output_add(
$self->{output}->perfdata_add(label => 'used', unit => '%', severity => $exit_code,
value => sprintf("%.2f", $result->{$oid_logFullPercent}), short_msg => sprintf(
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), 'Log File Usage is %.2f%%',
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), $result->{$oid_logFullPercent}
min => 0, max => 100); )
);
$self->{output}->perfdata_add(
label => 'used', unit => '%',
value => sprintf("%.2f", $result->{$oid_logFullPercent}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0, max => 100
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }

View File

@ -27,10 +27,11 @@ use warnings;
sub set_counters { 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} = [
{ label => 'web', set => { { label => 'web', set => {
key_values => [ { name => 'web' } ], key_values => [ { name => 'web' } ],
@ -71,10 +72,9 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
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 => {
{ });
});
return $self; return $self;
} }
@ -86,12 +86,19 @@ sub manage_selection {
my $oid_meetingUserCount = '.1.3.6.1.4.1.12532.9.0'; my $oid_meetingUserCount = '.1.3.6.1.4.1.12532.9.0';
my $oid_iveConcurrentUsers = '.1.3.6.1.4.1.12532.12.0'; my $oid_iveConcurrentUsers = '.1.3.6.1.4.1.12532.12.0';
my $oid_clusterConcurrentUsers = '.1.3.6.1.4.1.12532.13.0'; my $oid_clusterConcurrentUsers = '.1.3.6.1.4.1.12532.13.0';
my $result = $options{snmp}->get_leef(oids => [$oid_signedInWebUsers, $oid_meetingUserCount, my $result = $options{snmp}->get_leef(
$oid_iveConcurrentUsers, $oid_clusterConcurrentUsers], nothing_quit => 1); oids => [
$self->{global} = { web => $result->{$oid_signedInWebUsers}, $oid_signedInWebUsers, $oid_meetingUserCount,
meeting => $result->{$oid_meetingUserCount}, $oid_iveConcurrentUsers, $oid_clusterConcurrentUsers
node => $result->{$oid_iveConcurrentUsers}, ],
cluster => $result->{$oid_clusterConcurrentUsers} }; nothing_quit => 1
);
$self->{global} = {
web => $result->{$oid_signedInWebUsers},
meeting => $result->{$oid_meetingUserCount},
node => $result->{$oid_iveConcurrentUsers},
cluster => $result->{$oid_clusterConcurrentUsers}
};
} }
1; 1;
@ -109,17 +116,11 @@ Check users connections (web users, cluster users, node users, meeting users) (J
Only display some counters (regexp can be used). Only display some counters (regexp can be used).
Example: --filter-counters='^web|meeting$' Example: --filter-counters='^web|meeting$'
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'web', 'meeting', 'node', 'cluster'.
=item B<--critical-*>
Threshold critical.
Can be: 'web', 'meeting', 'node', 'cluster'. Can be: 'web', 'meeting', 'node', 'cluster'.
=back =back
=cut =cut