enh(snmp_standard): mode storage - simple access thresolds (#3101)
This commit is contained in:
parent
424b8a8bdb
commit
5057741870
|
@ -155,55 +155,38 @@ sub custom_usage_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub custom_access_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(
|
||||
nlabel => $self->{nlabel},
|
||||
instances => $self->{result_values}->{display},
|
||||
value => $self->{result_values}->{access},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-access'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-access'),
|
||||
min => 1, max => 2
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_access_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{perfdata}->threshold_check(
|
||||
value => $self->{result_values}->{access},
|
||||
threshold => [
|
||||
{ label => 'critical-access', exit_litteral => 'critical' },
|
||||
{ label => 'warning-access', exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_access_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf(
|
||||
'Access : %s',
|
||||
return sprintf(
|
||||
'Access: %s',
|
||||
$self->{result_values}->{access} == 1 ? 'readWrite' : 'readOnly'
|
||||
);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
{ name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok', skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'count', nlabel => 'storage.partitions.count', display_ok => 0, set => {
|
||||
key_values => [ { name => 'count' } ],
|
||||
output_template => 'Partitions count : %d',
|
||||
perfdatas => [
|
||||
{ label => 'count', value => 'count', template => '%d', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{storage} = [
|
||||
{ label => 'usage', nlabel => 'storage.space.usage.bytes', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'size' }, { name => 'allocation_units' } ],
|
||||
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'access', nlabel => 'storage.access', set => {
|
||||
key_values => [ { name => 'access' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_access_output'),
|
||||
perfdatas => [
|
||||
{ label => 'access', value => 'access', template => '%d', min => 1, max => 2,
|
||||
label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_storage_output {
|
||||
|
@ -218,6 +201,44 @@ sub default_storage_type {
|
|||
return '^(hrStorageFixedDisk|hrStorageNetworkDisk|hrFSBerkeleyFFS)$';
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
{ name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok', skipped_code => { -10 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'count', nlabel => 'storage.partitions.count', display_ok => 0, set => {
|
||||
key_values => [ { name => 'count' } ],
|
||||
output_template => 'Partitions count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'count', template => '%d', min => 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{storage} = [
|
||||
{ label => 'usage', nlabel => 'storage.space.usage.bytes', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'size' }, { name => 'allocation_units' } ],
|
||||
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'access', nlabel => 'storage.access.count', threshold => 0, set => {
|
||||
key_values => [ { name => 'access' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_access_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_access_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_access_perfdata')
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
|
@ -240,7 +261,9 @@ sub new {
|
|||
'filter-duplicate' => { name => 'filter_duplicate' },
|
||||
'filter-storage-type:s' => { name => 'filter_storage_type', default => $self->default_storage_type() },
|
||||
'add-access' => { name => 'add_access' },
|
||||
'counters-overflow' => { name => 'counters_overflow' }
|
||||
'counters-overflow' => { name => 'counters_overflow' },
|
||||
'warning-access:s' => { name => 'warning_access' },
|
||||
'critical-access:s' => { name => 'critical_access' }
|
||||
});
|
||||
|
||||
$self->{storage_id_selected} = [];
|
||||
|
@ -253,6 +276,16 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
foreach (('warning', 'critical')) {
|
||||
next if (!defined($self->{option_results}->{$_ . '_access'}));
|
||||
$self->{option_results}->{$_ . '_access'} = '@2:2' if ($self->{option_results}->{$_ . '_access'} =~ /readOnly/i);
|
||||
$self->{option_results}->{$_ . '_access'} = '@1:1' if ($self->{option_results}->{$_ . '_access'} =~ /readWrite/i);
|
||||
if (($self->{perfdata}->threshold_validate(label => $_ . '-access', value => $self->{option_results}->{$_ . '_access'})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong $_-access threshold '" . $self->{option_results}->{$_ . '_access'} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{space_reservation}) &&
|
||||
($self->{option_results}->{space_reservation} < 0 || $self->{option_results}->{space_reservation} > 100)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Space reservation argument must be between 0 and 100 percent.");
|
||||
|
@ -544,7 +577,7 @@ Threshold warning.
|
|||
=item B<--critical-access>
|
||||
|
||||
Threshold critical.
|
||||
Check if storage is readOnly: --critical-access=@2:2
|
||||
Check if storage is readOnly: --critical-access=readOnly
|
||||
|
||||
=item B<--add-access>
|
||||
|
||||
|
|
Loading…
Reference in New Issue