enh juniper junos hardware

This commit is contained in:
Colin Gagnaire 2019-08-01 13:35:40 +02:00
parent 24a0ab3643
commit d278dbbbf1
3 changed files with 166 additions and 39 deletions

View File

@ -74,45 +74,54 @@ sub check {
my $mapping = { my $mapping = {
jnxFruState => { oid => '.1.3.6.1.4.1.2636.3.1.15.1.8', map => \%map_fru_states }, jnxFruState => { oid => '.1.3.6.1.4.1.2636.3.1.15.1.8', map => \%map_fru_states },
jnxFruTemp => { oid => '.1.3.6.1.4.1.2636.3.1.15.1.9' },
jnxFruOfflineReason => { oid => '.1.3.6.1.4.1.2636.3.1.15.1.10', map => \%map_fru_offline }, jnxFruOfflineReason => { oid => '.1.3.6.1.4.1.2636.3.1.15.1.10', map => \%map_fru_offline },
}; };
my $results = $self->{snmp}->get_table(oid => $self->{oids_fru}->{jnxFruEntry}, start => $mapping->{jnxFruState}->{oid}, end => $mapping->{jnxFruOfflineReason}->{oid}); my $results = $self->{snmp}->get_table(
oid => $self->{oids_fru}->{jnxFruEntry},
start => $mapping->{jnxFruState}->{oid},
end => $mapping->{jnxFruOfflineReason}->{oid}
);
foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruName})) { foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_fru}->{jnxFruEntry},
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); oid_name => $self->{oids_fru}->{jnxFruName})) {
my $name = $self->get_cache(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruName}, instance => $instance); my $result = $self->{snmp}->map_instance(
mapping => $mapping,
results => $results,
instance => $instance
);
my $name = $self->get_cache(
oid_entry => $self->{oids_fru}->{jnxFruEntry},
oid_name => $self->{oids_fru}->{jnxFruName},
instance => $instance
);
next if ($self->check_filter(section => 'fru', instance => $instance, name => $name)); next if ($self->check_filter(section => 'fru', instance => $instance, name => $name));
next if ($result->{jnxFruState} =~ /empty/i && next if ($result->{jnxFruState} =~ /empty/i &&
$self->absent_problem(section => 'fru', instance => $instance, name => $name)); $self->absent_problem(section => 'fru', instance => $instance, name => $name));
$self->{components}->{fru}->{total}++; $self->{components}->{fru}->{total}++;
my $type = $self->get_cache(oid_entry => $self->{oids_fru}->{jnxFruEntry}, oid_name => $self->{oids_fru}->{jnxFruType}, instance => $instance); my $type = $self->get_cache(
$self->{output}->output_add(long_msg => sprintf("fru '%s' state is %s [instance: %s, type: %s, offline reason: %s]", oid_entry => $self->{oids_fru}->{jnxFruEntry},
$name, $result->{jnxFruState}, oid_name => $self->{oids_fru}->{jnxFruType},
$instance, $map_fru_type{$type}, $result->{jnxFruOfflineReason})); instance => $instance
);
$self->{output}->output_add(
long_msg => sprintf("fru '%s' state is %s [instance: %s, type: %s, offline reason: %s]",
$name,
$result->{jnxFruState},
$instance,
$map_fru_type{$type},
$result->{jnxFruOfflineReason})
);
my $exit = $self->get_severity(section => 'fru', instance => $instance, value => $result->{jnxFruState}); my $exit = $self->get_severity(section => 'fru', instance => $instance, value => $result->{jnxFruState});
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(
short_msg => sprintf("Fru '%s' state is %s [offline reason: %s]", $name, $result->{jnxFruState}, severity => $exit,
$result->{jnxFruOfflineReason})); short_msg => sprintf("Fru '%s' state is %s [offline reason: %s]",
} $name,
$result->{jnxFruState},
if (defined($result->{jnxFruTemp}) && $result->{jnxFruTemp} != 0) { $result->{jnxFruOfflineReason})
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fru-temperature', instance => $instance, name => $name, value => $result->{jnxFruTemp});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2,
short_msg => sprintf("Fru '%s' temperature is %s degree centigrade", $name, $result->{jnxFruTemp}));
}
$self->{output}->perfdata_add(
label => "temp", unit => 'C',
nlabel => 'hardware.temperature.celsius',
instances => $name,
value => $result->{jnxFruTemp},
warning => $warn,
critical => $crit
); );
} }
} }

View File

@ -42,28 +42,146 @@ sub check {
my $mapping = { my $mapping = {
jnxOperatingState => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.6', map => \%map_operating_states }, jnxOperatingState => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.6', map => \%map_operating_states },
jnxOperatingTemp => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.7' },
jnxOperatingCPU => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.8' },
jnxOperatingBuffer => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.11' },
jnxOperatingHeap => { oid => '.1.3.6.1.4.1.2636.3.1.13.1.12' },
}; };
my $results = $self->{snmp}->get_table(oid => $self->{oids_operating}->{jnxOperatingEntry}, my $results = $self->{snmp}->get_table(
start => $mapping->{jnxOperatingState}->{oid}, end => $mapping->{jnxOperatingState}->{oid}); oid => $self->{oids_operating}->{jnxOperatingEntry},
start => $mapping->{jnxOperatingState}->{oid},
end => $mapping->{jnxOperatingHeap}->{oid}
);
foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, foreach my $instance (sort $self->get_instances(oid_entry => $self->{oids_operating}->{jnxOperatingEntry},
oid_name => $self->{oids_operating}->{jnxOperatingDescr})) { oid_name => $self->{oids_operating}->{jnxOperatingDescr})) {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); my $result = $self->{snmp}->map_instance(
my $desc = $self->get_cache(oid_entry => $self->{oids_operating}->{jnxOperatingEntry}, mapping => $mapping,
oid_name => $self->{oids_operating}->{jnxOperatingDescr}, instance => $instance); results => $results,
instance => $instance
);
my $description = $self->get_cache(
oid_entry => $self->{oids_operating}->{jnxOperatingEntry},
oid_name => $self->{oids_operating}->{jnxOperatingDescr},
instance => $instance
);
next if ($self->check_filter(section => 'operating', instance => $instance, name => $desc)); next if ($self->check_filter(section => 'operating', instance => $instance, name => $description));
$self->{components}->{operating}->{total}++; $self->{components}->{operating}->{total}++;
$self->{output}->output_add(long_msg => sprintf("operating '%s' state is %s [instance: %s]", $self->{output}->output_add(
$desc, $result->{jnxOperatingState}, $instance)); long_msg => sprintf("operating '%s' state is %s [instance: %s]",
$description,
$result->{jnxOperatingState},
$instance)
);
my $exit = $self->get_severity(section => 'operating', instance => $instance, my $exit = $self->get_severity(section => 'operating', instance => $instance,
value => $result->{jnxOperatingState}); value => $result->{jnxOperatingState});
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("Operating '%s' state is %s", short_msg => sprintf("Operating '%s' state is %s",
$desc, $result->{jnxOperatingState})); $description,
$result->{jnxOperatingState})
);
}
if (defined($result->{jnxOperatingTemp}) && $result->{jnxOperatingTemp} != 0) {
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(
section => 'operating-temperature',
instance => $instance,
name => $description,
value => $result->{jnxOperatingTemp}
);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf("Operating '%s' temperature is %s degree centigrade",
$description,
$result->{jnxOperatingTemp})
);
}
$self->{output}->perfdata_add(
label => "temp", unit => 'C',
nlabel => 'hardware.temperature.celsius',
instances => $description,
value => $result->{jnxOperatingTemp},
warning => $warn,
critical => $crit
);
}
if (defined($result->{jnxOperatingCPU}) && $result->{jnxOperatingCPU} != 0) {
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(
section => 'operating-cpu',
instance => $instance,
name => $description,
value => $result->{jnxOperatingCPU}
);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf("Operating '%s' CPU utilization is %s%%",
$description,
$result->{jnxOperatingCPU})
);
}
$self->{output}->perfdata_add(
label => "cpu_utilization", unit => '%',
nlabel => 'hardware.cpu.utilization.percentage',
instances => $description,
value => $result->{jnxOperatingCPU},
warning => $warn,
critical => $crit
);
}
if (defined($result->{jnxOperatingBuffer}) && $result->{jnxOperatingBuffer} != 0) {
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(
section => 'operating-buffer',
instance => $instance,
name => $description,
value => $result->{jnxOperatingBuffer}
);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf("Operating '%s' buffer usage is %s%%",
$description,
$result->{jnxOperatingBuffer})
);
}
$self->{output}->perfdata_add(
label => "buffer_usage", unit => '%',
nlabel => 'hardware.buffer.usage.percentage',
instances => $description,
value => $result->{jnxOperatingBuffer},
warning => $warn,
critical => $crit
);
}
if (defined($result->{jnxOperatingHeap}) && $result->{jnxOperatingHeap} != 0) {
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(
section => 'operating-heap',
instance => $instance,
name => $description,
value => $result->{jnxOperatingHeap}
);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf("Operating '%s' heap usage is %s%%",
$description,
$result->{jnxOperatingHeap})
);
}
$self->{output}->perfdata_add(
label => "heap_usage", unit => '%',
nlabel => 'hardware.heap.usage.percentage',
instances => $description,
value => $result->{jnxOperatingHeap},
warning => $warn,
critical => $crit
);
} }
} }
} }

View File

@ -30,7 +30,7 @@ sub set_system {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fru|operating|alarm)$'; $self->{regexp_threshold_overload_check_section_option} = '^(fru|operating|alarm)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(fru-temperature)$'; $self->{regexp_threshold_numeric_check_section_option} = '^(operating-temperature|operating-cpu|operating-buffer|operating-heap)$';
$self->{cb_hook1} = 'init_cache'; $self->{cb_hook1} = 'init_cache';
$self->{cb_hook2} = 'snmp_execute'; $self->{cb_hook2} = 'snmp_execute';