+ Ref #122 (WIP)

This commit is contained in:
garnier-quentin 2015-08-10 13:42:00 +02:00
parent bd69e9184a
commit b3b5957a5d
4 changed files with 78 additions and 38 deletions

View File

@ -85,6 +85,20 @@ $mapping = {
State => { oid => '.1.3.6.1.4.1.13742.6.5.2.3.1.3', map => \%map_state }, # measurementsInletSensorState 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 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 = ( %raritan_type = (

View File

@ -47,7 +47,7 @@ sub check {
my $long_msg = 0; my $long_msg = 0;
next if ($component !~ /$options{component}/); next if ($component !~ /$options{component}/);
$self->{components}->{$component} = {name => $component, total => 0, skip => 0}; $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 $instance_type = $raritan_type{$component};
my $value_type = $map_type{$instance_type}; 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 $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); 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) { if ($long_msg == 0) {
$self->{output}->output_add(long_msg => "Checking " . $component); $self->{output}->output_add(long_msg => "Checking " . $component);
@ -70,15 +72,15 @@ sub check {
if ($value =~ /[0-9]/) { if ($value =~ /[0-9]/) {
$value *= 10 ** -int($result->{Decimal}); $value *= 10 ** -int($result->{Decimal});
} }
$self->{output}->output_add(long_msg => sprintf("'%s' %s state is '%s' [instance: %s, value: %s, unit: %s]", $self->{output}->output_add(long_msg => sprintf("'%s' %s state is '%s' [instance: %s, value: %s, unit: %s, label: %s]",
$result2->{Label}, $component, $result->{State}, $instance, $component, $result->{State},
$instance, $value, $result->{Unit})); $instance, $value, $result->{Unit}, $result2->{Label}));
my $exit = $self->get_severity(section => $component, label => $value_type, my $exit = $self->get_severity(section => $component, label => $value_type,
instance => $instance, value => $result->{State}); instance => $instance, value => $result->{State});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf("'%s' %s state is '%s'", short_msg => sprintf("'%s' %s state is '%s'",
$result2->{Label}, $component, $result->{State})); $instance, $component, $result->{State}));
} }
if ($value->{value} =~ /[0-9]/) { if ($value->{value} =~ /[0-9]/) {
@ -98,9 +100,9 @@ sub check {
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2, $self->{output}->output_add(severity => $exit2,
short_msg => sprintf("'%s' %s value is %s %s", 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, value => $value,
warning => $warn, warning => $warn,
critical => $crit); critical => $crit);

View File

@ -34,7 +34,7 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' }, "filter:s@" => { name => 'filter' },
"component:s" => { name => 'component', default => '.*' }, "component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' }, "no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' }, "threshold-overload:s@" => { name => 'threshold_overload' },
@ -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} = {}; $self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
my @values = split (/,/, $val); my @values = split (/,/, $val);
@ -152,19 +162,21 @@ sub run {
$self->{output}->exit(); $self->{output}->exit();
} }
sub check_exclude { sub check_filter {
my ($self, %options) = @_; my ($self, %options) = @_;
if (defined($options{instance})) { foreach (@{$self->{filter}}) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { if ($options{section} =~ /$_->{filter}/) {
$self->{components}->{$options{section}}->{skip}++; 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.")); $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1; 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; return 0;
} }
@ -226,10 +238,10 @@ Check inlet sensors.
Which component to check (Default: '.*'). Which component to check (Default: '.*').
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=airPressure,rmsVoltage) Exclude some parts (comma seperated list) (Example: --filter=airPressure --filter=rmsVoltage)
Can also exclude specific instance: --exclude=rmsVoltage#1.2.3#,airPressure Can also exclude specific instance: --filter=rmsVoltage,I1
=item B<--no-component> =item B<--no-component>

View File

@ -34,7 +34,7 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"exclude:s" => { name => 'exclude' }, "filter:s@" => { name => 'filter' },
"component:s" => { name => 'component', default => '.*' }, "component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' }, "no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' }, "threshold-overload:s@" => { name => 'threshold_overload' },
@ -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} = {}; $self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
my @values = split (/,/, $val); my @values = split (/,/, $val);
@ -152,19 +162,21 @@ sub run {
$self->{output}->exit(); $self->{output}->exit();
} }
sub check_exclude { sub check_filter {
my ($self, %options) = @_; my ($self, %options) = @_;
if (defined($options{instance})) { foreach (@{$self->{filter}}) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { if ($options{section} =~ /$_->{filter}/) {
$self->{components}->{$options{section}}->{skip}++; 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.")); $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1; 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; return 0;
} }
@ -226,10 +238,10 @@ Check outlet sensors.
Which component to check (Default: '.*'). Which component to check (Default: '.*').
=item B<--exclude> =item B<--filter>
Exclude some parts (comma seperated list) (Example: --exclude=airPressure,rmsVoltage) Exclude some parts (comma seperated list) (Example: --filter=airPressure --filter=rmsVoltage)
Can also exclude specific instance: --exclude=rmsVoltage#1.2.3#,airPressure Can also exclude specific instance: --filter=rmsVoltage,I1
=item B<--no-component> =item B<--no-component>