« blib/lib/Monitoring/Sneck/Checks/pkg_audit.pm
↑ Summary
blib/lib/Monitoring/Sneck/Checks/cert_file.pm »
| 1 | package Monitoring::Sneck::Checks::neighbors; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use parent 'Monitoring::Sneck::Checks::base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Monitoring::Sneck::Checks::neighbors - checks how full the ARP and NDP neighbor tables are | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Version 0.0.1 | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 12 | our $VERSION = '0.0.1'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # The tables, their stats file under /proc/net/stat, and their limit under /proc/sys/net. | ||||||||||||||||||||||||||||
| 21 | 12 | our @TABLES = ( | |||||||||||||||||||||||||||
| 22 | [ 'arp', 'arp_cache', 'ipv4/neigh/default/gc_thresh3' ], | ||||||||||||||||||||||||||||
| 23 | [ 'ndp', 'ndisc_cache', 'ipv6/neigh/default/gc_thresh3' ] | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | neighbors|perl:neighbors | ||||||||||||||||||||||||||||
| 29 | neighbors_big_l2|perl:neighbors -w 60 -c 80 | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Checks the ARP table, for IPv4, and the NDP one, for IPv6, against | ||||||||||||||||||||||||||||
| 34 | gc_thresh3, past which the kernel will not add entries, so traffic to | ||||||||||||||||||||||||||||
| 35 | new neighbors is dropped with only a kernel log line saying so. This | ||||||||||||||||||||||||||||
| 36 | bites on big layer 2 networks. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | The kernel also counts each time a table was full. That count is kept | ||||||||||||||||||||||||||||
| 39 | in a state file, see L<Monitoring::Sneck::Checks::base/read_state>, and | ||||||||||||||||||||||||||||
| 40 | any rise since the last run is CRITICAL, as packets were dropped. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | The sizes come from /proc/net/stat. Only Linux has this, others are | ||||||||||||||||||||||||||||
| 43 | UNKNOWN. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | - -w, --warning :: Range of percent of gc_thresh3 used. | ||||||||||||||||||||||||||||
| 48 | Default :: 80 | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | - -c, --critical :: Range of percent of gc_thresh3 used. | ||||||||||||||||||||||||||||
| 51 | Default :: 90 | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =cut | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 30 | ▶ | sub option_spec { return ( 'warning|w=s', 'critical|c=s' ) } | ||||||||||||||||||||||||||
|
Subroutine
option_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 30 | ▶ | sub defaults { return { warning => '80', critical => '90' } } | ||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 30 | ▶ | sub ranges { return ( 'warning', 'critical' ) } | ||||||||||||||||||||||||||
|
Subroutine
ranges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 METHODS | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head2 check | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Does the check. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =cut | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 30 | ▶ | sub check { | ||||||||||||||||||||||||||
|
Subroutine
check: called CC=16 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 30 | my ($self) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 30 | ▶ | die( 'not supported on ' . $self->os . "\n" ) if $self->os ne 'linux'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 30 | my $file = $Monitoring::Sneck::Checks::base::STATE_DIR . '/neighbors.json'; | |||||||||||||||||||||||||||
| 74 | 30 | my $state = $self->read_state($file); | |||||||||||||||||||||||||||
| 75 | 30 | ▶ | return $self->finish( $self->UNKNOWN, 'can not read the state in ' . $file ) if !defined($state); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 30 | my @codes; | |||||||||||||||||||||||||||
| 78 | my @parts; | ||||||||||||||||||||||||||||
| 79 | 30 | my %new_state; | |||||||||||||||||||||||||||
| 80 | 30 | foreach my $table (@TABLES) { | |||||||||||||||||||||||||||
| 81 | 60 | my ( $name, $stats_file, $limit_file ) = @{$table}; | |||||||||||||||||||||||||||
| 82 | 60 | ▶ | my $stats = eval { $self->proc_file( 'net/stat/' . $stats_file ) } // next; | ||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$self->proc_file('net/stat/' . $stats_file)
}
} // (next)
MC/DC0%0/1
eval {
do {
$self->proc_file('net/stat/' . $stats_file)
}
} // (next)
eval {
do {
$self->proc_file('net/stat/' . $stats_file)
}
}
Truth table50%1/2
A
A= eval {
do {
$self->proc_file('net/stat/' . $stats_file)
}
}
| |||||||||||||||||||||||||||||
| 83 | 60 | ▶ | my $limit = eval { $self->proc_file( 'sys/net/' . $limit_file ) } // next; | ||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$self->proc_file('sys/net/' . $limit_file)
}
} // (next)
MC/DC0%0/1
eval {
do {
$self->proc_file('sys/net/' . $limit_file)
}
} // (next)
eval {
do {
$self->proc_file('sys/net/' . $limit_file)
}
}
Truth table50%1/2
A
A= eval {
do {
$self->proc_file('sys/net/' . $limit_file)
}
}
| |||||||||||||||||||||||||||||
| 84 | 60 | $limit =~ s/\s+//g; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # a header, then a line per CPU in hex, entries being for the whole table and the rest for that CPU | ||||||||||||||||||||||||||||
| 87 | 60 | my ( $header, @rows ) = split( /\n/, $stats ); | |||||||||||||||||||||||||||
| 88 | 60 | my @columns = split( /\s+/, $header ); | |||||||||||||||||||||||||||
| 89 | 60 | my ( $entries, $fulls ); | |||||||||||||||||||||||||||
| 90 | 60 | foreach my $row (@rows) { | |||||||||||||||||||||||||||
| 91 | 90 | my %row; | |||||||||||||||||||||||||||
| 92 | 90 | @row{@columns} = map { hex($_) } split( /\s+/, $row ); | |||||||||||||||||||||||||||
| 93 | 90 | ▶ | $entries //= $row{entries}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$entries //= $row{"entries"}
MC/DC0%0/2
$entries //= $row{"entries"}
$entries
$row{"entries"}
Truth table66%2/3
A //= B
A= $entriesB= $row{"entries"}
| |||||||||||||||||||||||||||||
| 94 | 90 | ▶ | $fulls = ( $fulls // 0 ) + ( $row{table_fulls} // 0 ); | ||||||||||||||||||||||||||
|
Condition75%3/4
$fulls // 0
$row{"table_fulls"} // 0
MC/DC100%1/1
$fulls // 0
$fulls
MC/DC0%0/1
$row{"table_fulls"} // 0
$row{"table_fulls"}
Truth table100%2/2
A
A= $fulls
Truth table50%1/2
A
A= $row{"table_fulls"}
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 60 | ▶ | next if !defined($entries) || !$limit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $entries and $limit
MC/DC0%0/2
defined $entries and $limit
defined $entries
$limit
Truth table33%1/3
A and B
A= defined $entriesB= $limit
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 60 | my $percent = sprintf( '%.1f', $entries / $limit * 100 ); | |||||||||||||||||||||||||||
| 99 | 60 | my $code = $self->threshold_status( $percent, $self->opt('warning'), $self->opt('critical') ); | |||||||||||||||||||||||||||
| 100 | 60 | my $part = $name . ' ' . $entries . ' of ' . $limit; | |||||||||||||||||||||||||||
| 101 | 60 | my $was = $state->{ $name . '_fulls' }; | |||||||||||||||||||||||||||
| 102 | 60 | ▶ | if ( defined($was) && $fulls > $was ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $was and $fulls > $was
MC/DC100%2/2
defined $was and $fulls > $was
defined $was
$fulls > $was
Truth table100%3/3
A and B
A= defined $wasB= $fulls > $was
| |||||||||||||||||||||||||||||
| 103 | 10 | $code = $self->CRITICAL; | |||||||||||||||||||||||||||
| 104 | 10 | $part = $part . ', full ' . ( $fulls - $was ) . ' times since the last check'; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 60 | $new_state{ $name . '_fulls' } = $fulls; | |||||||||||||||||||||||||||
| 107 | 60 | push( @codes, $code ); | |||||||||||||||||||||||||||
| 108 | 60 | push( @parts, $part ); | |||||||||||||||||||||||||||
| 109 | 60 | $self->perfdata( | |||||||||||||||||||||||||||
| 110 | label => $name, | ||||||||||||||||||||||||||||
| 111 | value => $percent, | ||||||||||||||||||||||||||||
| 112 | uom => '%', | ||||||||||||||||||||||||||||
| 113 | warning => $self->opt('warning'), | ||||||||||||||||||||||||||||
| 114 | critical => $self->opt('critical'), | ||||||||||||||||||||||||||||
| 115 | min => 0, | ||||||||||||||||||||||||||||
| 116 | max => 100 | ||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||
| 118 | } ## end foreach my $table (@TABLES) | ||||||||||||||||||||||||||||
| 119 | 30 | ▶ | die("no neighbor tables found\n") if !defined( $parts[0] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 30 | my $problem = $self->write_state( $file, \%new_state ); | |||||||||||||||||||||||||||
| 121 | 30 | ▶ | return $self->finish( $self->UNKNOWN, $problem ) if defined($problem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 30 | return $self->finish( $self->worst(@codes), join( ', ', @parts ) ); | |||||||||||||||||||||||||||
| 124 | } ## end sub check | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 12 | 1; | |||||||||||||||||||||||||||