mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 15:44:21 +02:00
+ Ref #122 (WIP)
This commit is contained in:
parent
bd69e9184a
commit
b3b5957a5d
@ -85,6 +85,20 @@ $mapping = {
|
||||
State => { oid => '.1.3.6.1.4.1.13742.6.5.2.3.1.3', map => \%map_state }, # measurementsInletSensorState
|
||||
Value => { oid => '.1.3.6.1.4.1.13742.6.5.2.3.1.4' }, # measurementsInletSensorValue
|
||||
},
|
||||
outlet_label => {
|
||||
Label => { oid => '.1.3.6.1.4.1.13742.6.3.5.3.1.2' }, # outletLabel
|
||||
},
|
||||
outlet => {
|
||||
Unit => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.6', map => \%map_units }, # outletSensorUnits
|
||||
Decimal => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.7' }, # outletSensorDecimalDigits
|
||||
EnabledThresholds => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.25' }, # outletSensorEnabledThresholds
|
||||
LowerCriticalThreshold => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.21' }, # outletSensorLowerCriticalThreshold
|
||||
LowerWarningThreshold => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.22' }, # outletSensorLowerWarningThreshold
|
||||
UpperCriticalThreshold => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.23' }, # outletSensorUpperCriticalThreshold
|
||||
UpperWarningThreshold => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.24' }, # outletSensorUpperWarningThreshold
|
||||
State => { oid => '.1.3.6.1.4.1.13742.6.5.4.3.1.3', map => \%map_state }, # measurementsOutletSensorState
|
||||
Value => { oid => '.1.3.6.1.4.1.13742.6.5.4.3.1.4' }, # measurementsOutletSensorValue
|
||||
},
|
||||
};
|
||||
|
||||
%raritan_type = (
|
||||
|
@ -47,7 +47,7 @@ sub check {
|
||||
my $long_msg = 0;
|
||||
next if ($component !~ /$options{component}/);
|
||||
$self->{components}->{$component} = {name => $component, total => 0, skip => 0};
|
||||
next if ($self->check_exclude(section => $component));
|
||||
next if ($self->check_filter(section => $component));
|
||||
|
||||
my $instance_type = $raritan_type{$component};
|
||||
my $value_type = $map_type{$instance_type};
|
||||
@ -57,7 +57,9 @@ sub check {
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping->{$options{type}}, results => $self->{results}, instance => $instance);
|
||||
my $result2 = $self->{snmp}->map_instance(mapping => $mapping->{$options{type} . '_label'}, results => $self->{results}, instance => $1 . '.' . $2);
|
||||
|
||||
next if ($self->check_exclude(section => $component, instance => $instance));
|
||||
$instance = defined($result2->{Label}) && $result2->{Label} ne '' ? $result2->{Label} : $1 . '.' . $2;
|
||||
|
||||
next if ($self->check_filter(section => $component, instance => $instance));
|
||||
|
||||
if ($long_msg == 0) {
|
||||
$self->{output}->output_add(long_msg => "Checking " . $component);
|
||||
@ -70,15 +72,15 @@ sub check {
|
||||
if ($value =~ /[0-9]/) {
|
||||
$value *= 10 ** -int($result->{Decimal});
|
||||
}
|
||||
$self->{output}->output_add(long_msg => sprintf("'%s' %s state is '%s' [instance: %s, value: %s, unit: %s]",
|
||||
$result2->{Label}, $component, $result->{State},
|
||||
$instance, $value, $result->{Unit}));
|
||||
$self->{output}->output_add(long_msg => sprintf("'%s' %s state is '%s' [instance: %s, value: %s, unit: %s, label: %s]",
|
||||
$instance, $component, $result->{State},
|
||||
$instance, $value, $result->{Unit}, $result2->{Label}));
|
||||
my $exit = $self->get_severity(section => $component, label => $value_type,
|
||||
instance => $instance, value => $result->{State});
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("'%s' %s state is '%s'",
|
||||
$result2->{Label}, $component, $result->{State}));
|
||||
$instance, $component, $result->{State}));
|
||||
}
|
||||
|
||||
if ($value->{value} =~ /[0-9]/) {
|
||||
@ -98,9 +100,9 @@ sub check {
|
||||
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit2,
|
||||
short_msg => sprintf("'%s' %s value is %s %s",
|
||||
$result2->{Label}, $component, $value, $result->{Unit}));
|
||||
$instance, $component, $value, $result->{Unit}));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $result2->{label} . "_" . $component, unit => $result->{Unit},
|
||||
$self->{output}->perfdata_add(label => $instance . "_" . $component, unit => $result->{Unit},
|
||||
value => $value,
|
||||
warning => $warn,
|
||||
critical => $crit);
|
||||
|
@ -34,9 +34,9 @@ sub new {
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"exclude:s" => { name => 'exclude' },
|
||||
"component:s" => { name => 'component', default => '.*' },
|
||||
"no-component:s" => { name => 'no_component' },
|
||||
"filter:s@" => { name => 'filter' },
|
||||
"component:s" => { name => 'component', default => '.*' },
|
||||
"no-component:s" => { name => 'no_component' },
|
||||
"threshold-overload:s@" => { name => 'threshold_overload' },
|
||||
"warning:s@" => { name => 'warning' },
|
||||
"critical:s@" => { name => 'critical' },
|
||||
@ -60,6 +60,16 @@ sub check_options {
|
||||
}
|
||||
}
|
||||
|
||||
$self->{filter} = [];
|
||||
foreach my $val (@{$self->{option_results}->{filter}}) {
|
||||
my @values = split (/,/, $val);
|
||||
if (scalar(@values) < 2) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong filter option '" . $val . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
|
||||
}
|
||||
|
||||
$self->{overload_th} = {};
|
||||
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
|
||||
my @values = split (/,/, $val);
|
||||
@ -152,19 +162,21 @@ sub run {
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub check_exclude {
|
||||
sub check_filter {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{instance})) {
|
||||
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
|
||||
$self->{components}->{$options{section}}->{skip}++;
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
|
||||
return 1;
|
||||
foreach (@{$self->{filter}}) {
|
||||
if ($options{section} =~ /$_->{filter}/) {
|
||||
if (!defined($options{instance}) && !defined($_->{instance})) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
|
||||
return 1;
|
||||
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -226,10 +238,10 @@ Check inlet sensors.
|
||||
|
||||
Which component to check (Default: '.*').
|
||||
|
||||
=item B<--exclude>
|
||||
=item B<--filter>
|
||||
|
||||
Exclude some parts (comma seperated list) (Example: --exclude=airPressure,rmsVoltage)
|
||||
Can also exclude specific instance: --exclude=rmsVoltage#1.2.3#,airPressure
|
||||
Exclude some parts (comma seperated list) (Example: --filter=airPressure --filter=rmsVoltage)
|
||||
Can also exclude specific instance: --filter=rmsVoltage,I1
|
||||
|
||||
=item B<--no-component>
|
||||
|
||||
|
@ -34,9 +34,9 @@ sub new {
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"exclude:s" => { name => 'exclude' },
|
||||
"component:s" => { name => 'component', default => '.*' },
|
||||
"no-component:s" => { name => 'no_component' },
|
||||
"filter:s@" => { name => 'filter' },
|
||||
"component:s" => { name => 'component', default => '.*' },
|
||||
"no-component:s" => { name => 'no_component' },
|
||||
"threshold-overload:s@" => { name => 'threshold_overload' },
|
||||
"warning:s@" => { name => 'warning' },
|
||||
"critical:s@" => { name => 'critical' },
|
||||
@ -60,6 +60,16 @@ sub check_options {
|
||||
}
|
||||
}
|
||||
|
||||
$self->{filter} = [];
|
||||
foreach my $val (@{$self->{option_results}->{filter}}) {
|
||||
my @values = split (/,/, $val);
|
||||
if (scalar(@values) < 2) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong filter option '" . $val . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
|
||||
}
|
||||
|
||||
$self->{overload_th} = {};
|
||||
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
|
||||
my @values = split (/,/, $val);
|
||||
@ -152,19 +162,21 @@ sub run {
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub check_exclude {
|
||||
sub check_filter {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{instance})) {
|
||||
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
|
||||
$self->{components}->{$options{section}}->{skip}++;
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
|
||||
return 1;
|
||||
foreach (@{$self->{filter}}) {
|
||||
if ($options{section} =~ /$_->{filter}/) {
|
||||
if (!defined($options{instance}) && !defined($_->{instance})) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
|
||||
return 1;
|
||||
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -226,10 +238,10 @@ Check outlet sensors.
|
||||
|
||||
Which component to check (Default: '.*').
|
||||
|
||||
=item B<--exclude>
|
||||
=item B<--filter>
|
||||
|
||||
Exclude some parts (comma seperated list) (Example: --exclude=airPressure,rmsVoltage)
|
||||
Can also exclude specific instance: --exclude=rmsVoltage#1.2.3#,airPressure
|
||||
Exclude some parts (comma seperated list) (Example: --filter=airPressure --filter=rmsVoltage)
|
||||
Can also exclude specific instance: --filter=rmsVoltage,I1
|
||||
|
||||
=item B<--no-component>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user