Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions src/hardware/sensors/hwgste/snmp/mode/components/co2.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package hardware::sensors::hwgste::snmp::mode::components::co2;

use strict;
use warnings;

use hardware::sensors::hwgste::snmp::mode::components::resources qw($mapping);

sub load {}

sub check {
my ($self) = @_;

$self->{output}->output_add(long_msg => "Checking co2");
$self->{components}->{co2} = {
name => 'co2',
total => 0,
skip => 0
};

return if ($self->check_filter(section => 'co2'));

foreach my $oid (
$self->{snmp}->oid_lex_sort(
keys %{
$self->{results}->{
$mapping->{branch_sensors}->{$self->{branch}}
}
}
)
) {
next if (
$oid !~
/^$mapping->{$self->{branch}}->{sensState}->{oid}\.(.*)$/
);

my $instance = $1;

my $result = $self->{snmp}->map_instance(
mapping => $mapping->{$self->{branch}},
results => $self->{results}->{
$mapping->{branch_sensors}->{$self->{branch}}
},
instance => $instance
);

#
# STE2 Plus:
# CO2 sensors have:
# unit = 0 => ''
# name contains CO2
#
next if (
!defined($result->{sensUnit})
|| $result->{sensUnit} ne ''
);

next if (
!defined($result->{sensName})
|| $result->{sensName} !~ /CO2/i
);

next if (
$self->check_filter(
section => 'co2',
instance => $instance
)
);

$self->{components}->{co2}->{total}++;

#
# STE2 returns value * 10
#
if (
defined($result->{sensValue})
&& $result->{sensValue} =~ /^-?\d+(?:\.\d+)?$/
) {
$result->{sensValue} /= 10;
}

$self->{output}->output_add(
long_msg => sprintf(
"co2 '%s' state is '%s' [instance: %s, value: %s ppm]",
$result->{sensName},
$result->{sensState},
$instance,
$result->{sensValue}
)
);

my $exit = $self->get_severity(
section => 'co2',
label => 'default',
instance => $instance,
value => $result->{sensState}
);

if (
!$self->{output}->is_status(
value => $exit,
compare => 'ok',
litteral => 1
)
) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"co2 '%s' state is '%s'",
$result->{sensName},
$result->{sensState}
)
);
}

if (
defined($result->{sensValue})
&& $result->{sensValue} =~ /^-?\d+(?:\.\d+)?$/
) {
my ($exit2, $warn, $crit, $checked) =
$self->get_severity_numeric(
section => 'co2',
instance => $instance,
value => $result->{sensValue}
);

if (
!$self->{output}->is_status(
value => $exit2,
compare => 'ok',
litteral => 1
)
) {
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf(
"co2 '%s' value is %s ppm",
$result->{sensName},
$result->{sensValue}
)
);
}

$self->{output}->perfdata_add(
label => 'sensor',
unit => 'ppm',
nlabel => 'hardware.sensor.co2.ppm',
instances => $result->{sensName},
value => $result->{sensValue},
warning => $warn,
critical => $crit,
min => 0
);
}
}
}

1;
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ our @EXPORT_OK = qw($mapping);
2 => 'F',
3 => 'K',
4 => '%',
5 => 'water',
);

$mapping = {
Expand Down
94 changes: 94 additions & 0 deletions src/hardware/sensors/hwgste/snmp/mode/components/water.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package hardware::sensors::hwgste::snmp::mode::components::water;

use strict;
use warnings;

use hardware::sensors::hwgste::snmp::mode::components::resources qw($mapping);

sub load {}

sub check {
my ($self) = @_;

$self->{output}->output_add(long_msg => "Checking water");

$self->{components}->{water} = {
name => 'water',
total => 0,
skip => 0
};

return if ($self->check_filter(section => 'water'));

foreach my $oid (
$self->{snmp}->oid_lex_sort(
keys %{
$self->{results}->{
$mapping->{branch_sensors}->{$self->{branch}}
}
}
)
) {
next if (
$oid !~
/^$mapping->{$self->{branch}}->{sensState}->{oid}\.(.*)$/
);

my $instance = $1;

my $result = $self->{snmp}->map_instance(
mapping => $mapping->{$self->{branch}},
results => $self->{results}->{
$mapping->{branch_sensors}->{$self->{branch}}
},
instance => $instance
);

#
# STE2 Plus water leak sensor:
# unit = 5 => water
#
next if (
!defined($result->{sensUnit})
|| $result->{sensUnit} ne 'water'
);

#
# Accept common naming conventions
#
next if (
!defined($result->{sensName})
|| $result->{sensName} !~ /(?:WATER|FLOOD|LEAK)/i
);

next if (
$self->check_filter(
section => 'water',
instance => $instance
)
);

$self->{components}->{water}->{total}++;

my $value = defined($result->{sensValue})
? $result->{sensValue}
: 'unknown';

$self->{output}->output_add(
long_msg => sprintf(
"water sensor '%s' state is '%s' [instance: %s, value: %s]",
$result->{sensName},
$result->{sensState},
$instance,
$value
)
);

#
# Water leak detector is binary:
# normal => OK
# anything else => CRITICAL
#
my $exit = 'OK';

if ($result->{sensState}
Loading