Skip to content
Merged
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
31 changes: 26 additions & 5 deletions snmp/freebsd_entity
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ history. The ifindex is read via ifmib(4), so it matches IF-MIB.
to IF-MIB::ifIndex.$ifindex. entPhysicalAlias is the interface
description, as set via C<ifconfig $interface description ...>.

- $ifindex * 1000 + 1 :: The transceiver. Vendor name, part number, and
serial go in entPhysicalMfgName, ModelName, and SerialNum.
- $ifindex * 1000 + 1 :: The transceiver. Vendor name, part number,
serial, and date go in entPhysicalMfgName, ModelName, SerialNum, and
MfgDate.

- $ifindex * 1000 + 10 :: Transceiver temperature, celsius.

Expand Down Expand Up @@ -187,7 +188,8 @@ With B<--state>, the entStateTable has a row for each transceiver, and
with B<--power> each battery and the AC adapter.

- Transceivers :: entStateAdmin is unlocked if the interface is up and
locked if down. entStateOper is enabled.
locked if down. entStateOper is enabled. entStateAlarm is always clear,
as ifconfig does not report the alarm, loss of signal, or Tx fault flags.

- Batteries :: entStateAlarm has critical set if acpiconf reports the
state as critical.
Expand Down Expand Up @@ -388,6 +390,7 @@ sub read_smbios_dump {
# Returns a hash ref. up is true if the interface has the UP flag. description is
# the interface description. plugged is what ifconfig says is plugged in, '' if there
# is no module. vendor_name, vendor_pn, and vendor_sn are strings, '' if not printed.
# mfg_date is the module date as YYYY-MM-DD, '' if missing or invalid.
# readings is a array ref of hash refs, one per reading found, each with the kind of
# reading, the lane, 0 if it is not per lane, and the value. Kind is one of temperature
# in C, voltage in V, bias in mA, tx_power in dBm, or rx_power in dBm. -inf dBm becomes -40.
Expand All @@ -399,6 +402,7 @@ sub read_smbios_dump {
# vendor_name => 'FINISAR CORP.',
# vendor_pn => 'FTLX8571D3BCL',
# vendor_sn => 'AAA0B1C',
# mfg_date => '2011-05-20',
# readings => [
# { kind => 'temperature', lane => 0, value => 32.45 },
# { kind => 'rx_power', lane => 0, value => -2.81 },
Expand All @@ -420,6 +424,7 @@ sub parse_ifconfig {
vendor_name => '',
vendor_pn => '',
vendor_sn => '',
mfg_date => '',
readings => [],
);

Expand All @@ -434,8 +439,12 @@ sub parse_ifconfig {
} elsif ( $line =~ /^\s+plugged:\s*(.*?)\s*$/ ) {
# the connector, such as '(LC)', is left off
$interface_info{plugged} = $1 =~ s/\s*\([^)]*\)$//r;
} elsif ( $line =~ /^\s+vendor:\s*(.*?)\s+PN:\s*(.*?)\s+SN:\s*(.*?)(?:\s+DATE:.*)?\s*$/ ) {
} elsif ( $line =~ /^\s+vendor:\s*(.*?)\s+PN:\s*(.*?)\s+SN:\s*(.*?)(?:\s+DATE:\s*(\S*))?\s*$/ ) {
@interface_info{ 'vendor_name', 'vendor_pn', 'vendor_sn' } = ( $1, $2, $3 );
my $date = $4 // '';
if ( $date =~ /^(\d{4})-(\d{2})-(\d{2})$/ && $2 >= 1 && $2 <= 12 && $3 >= 1 && $3 <= 31 ) {
$interface_info{mfg_date} = $date;
}
} elsif ( $line =~ /^\s+module temperature:/i ) {
if ( $line =~ /temperature:\s*(-?[\d.]+)\s*C\b/i ) {
push( @{ $interface_info{readings} }, { kind => 'temperature', lane => 0, value => $1 + 0 } );
Expand Down Expand Up @@ -597,7 +606,7 @@ if ( $opts{u} ) {
# Each is [ OID, pass_persist type, value ]. The entPhysicalTable columns
# are, in order, Descr, VendorType, ContainedIn, Class, ParentRelPos, Name,
# HardwareRev, FirmwareRev, SoftwareRev, SerialNum, MfgName, ModelName,
# Alias, AssetID, and IsFRU, which are 2 to 16.
# Alias, AssetID, and IsFRU, which are 2 to 16, with MfgDate as 17.
my @oids;
my $add_entity = sub {
my (%entity) = @_;
Expand Down Expand Up @@ -625,6 +634,17 @@ if ( $opts{u} ) {
push( @oids,
[ '.1.3.6.1.2.1.47.1.1.1.1.' . ( $column_index + 2 ) . '.' . $entity{index}, $type, $value ] );
}

# entPhysicalMfgDate is a DateAndTime, the year as two bytes, then a byte each for
# month, day, hour, minutes, seconds, and deciseconds. mfg_date is YYYY-MM-DD, with
# the time left 0. All zeros means unknown, per the RFC. Sent as hex for the octet type.
my @date_parts = ( 0, 0, 0 );
if ( ( $entity{mfg_date} // '' ) =~ /^(\d{4})-(\d{2})-(\d{2})$/ ) {
@date_parts = ( $1, $2, $3 );
}
my $mfg_date_hex
= join( ' ', map { sprintf( '%02X', $_ ) } unpack( 'C*', pack( 'nC6', @date_parts, 0, 0, 0, 0 ) ) );
push( @oids, [ '.1.3.6.1.2.1.47.1.1.1.1.17.' . $entity{index}, 'octet', $mfg_date_hex ] );
}; ## end $add_entity = sub

# Adds a sensor entity and its entPhySensorTable row. Takes index, name,
Expand Down Expand Up @@ -793,6 +813,7 @@ if ( $opts{u} ) {
mfg_name => $interface_info->{vendor_name},
model_name => $interface_info->{vendor_pn},
is_fru => 1,
mfg_date => $interface_info->{mfg_date},
);

$add_state->(
Expand Down
64 changes: 54 additions & 10 deletions snmp/linux_entity
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ history.
description, as set via C<ip link set $interface alias ...>.

- $ifindex * 1000 + 1 :: The transceiver. Vendor name, part number,
revision, and serial go in entPhysicalMfgName, ModelName, HardwareRev,
and SerialNum.
revision, serial, and date code go in entPhysicalMfgName, ModelName,
HardwareRev, SerialNum, and MfgDate.

- $ifindex * 1000 + 10 :: Transceiver temperature, celsius.

Expand Down Expand Up @@ -244,8 +244,10 @@ each power supply.

- Transceivers :: entStateAdmin is unlocked if the interface is up and
locked if down. entStateOper is enabled. entStateAlarm has critical set
if any of the alarm flags are on and warning if any of the warning flags
are on.
if any of the alarm flags are on or there is a Tx fault, major if there
is a Rx or Tx loss of signal, and warning if any of the warning flags
are on. ethtool only reports loss of signal and Tx fault for QSFP and
CMIS modules.

- Power supplies :: entStateOper is enabled or disabled going by online,
for those that have it. entStateAlarm has critical set for a battery
Expand Down Expand Up @@ -419,7 +421,9 @@ sub read_smbios_structures {
# the kind of reading, the lane, 0 if it is not per channel, and the value. Kind is
# one of temperature in C, voltage in V, bias in mA, tx_power in dBm, or rx_power
# in dBm. -inf dBm becomes -40. alarms and warnings are how many of the alarm and
# warning flags are on.
# warning flags are on. signal_loss is true if Rx or Tx loss of signal is reported
# on any lane and tx_fault if Tx fault is. ethtool prints those for QSFP and CMIS,
# but not for SFP. mfg_date is the date code as YYYY-MM-DD, '' if missing or invalid.
#
# {
# identifier => 'SFP',
Expand All @@ -428,12 +432,15 @@ sub read_smbios_structures {
# vendor_pn => 'FTLX8571D3BCL',
# vendor_rev => 'A',
# vendor_sn => 'AAA0B1C',
# mfg_date => '2011-05-20',
# readings => [
# { kind => 'bias', lane => 0, value => 6.162 },
# { kind => 'tx_power', lane => 0, value => -2.05 },
# ],
# alarms => 0,
# warnings => 1,
# alarms => 0,
# warnings => 1,
# signal_loss => 0,
# tx_fault => 0,
# }
#
# Example:
Expand All @@ -450,6 +457,7 @@ sub parse_ethtool_module {
'vendor pn' => 'vendor_pn',
'vendor rev' => 'vendor_rev',
'vendor sn' => 'vendor_sn',
'date code' => 'date_code',
);

# The labels differ between ethtool versions and between the SFP and QSFP layouts.
Expand All @@ -476,9 +484,13 @@ sub parse_ethtool_module {
vendor_pn => '',
vendor_rev => '',
vendor_sn => '',
date_code => '',
mfg_date => '',
readings => [],
alarms => 0,
warnings => 0,
signal_loss => 0,
tx_fault => 0,
);

foreach my $line ( split( /\n/, $ethtool_output ) ) {
Expand Down Expand Up @@ -506,6 +518,15 @@ sub parse_ethtool_module {
}
}

# 'Yes' or 'No' per lane, such as '[ Yes, No, No, No ]', or 'None' if not supported
if ( $value =~ /\byes\b/i ) {
if ( $label =~ /^[rt]x loss of signal$/ ) {
$module_info{signal_loss} = 1;
} elsif ( $label eq 'tx fault' ) {
$module_info{tx_fault} = 1;
}
}

foreach my $reading_pattern (@reading_patterns) {
my ( $kind, $label_regexp, $value_regexp ) = @{$reading_pattern};
next if $label !~ $label_regexp;
Expand All @@ -525,6 +546,12 @@ sub parse_ethtool_module {
$module_info{identifier} = $1;
}

# The date code is YYMMDD, with a lot code after it on some modules. All modules
# post date the year 2000, so the century is assumed.
if ( $module_info{date_code} =~ /^(\d{2})(\d{2})(\d{2})/ && $2 >= 1 && $2 <= 12 && $3 >= 1 && $3 <= 31 ) {
$module_info{mfg_date} = sprintf( '20%02d-%02d-%02d', $1, $2, $3 );
}

return \%module_info;
} ## end sub parse_ethtool_module

Expand Down Expand Up @@ -661,7 +688,7 @@ if ( $opts{u} ) {
# Each is [ OID, pass_persist type, value ]. The entPhysicalTable columns
# are, in order, Descr, VendorType, ContainedIn, Class, ParentRelPos, Name,
# HardwareRev, FirmwareRev, SoftwareRev, SerialNum, MfgName, ModelName,
# Alias, AssetID, and IsFRU, which are 2 to 16.
# Alias, AssetID, and IsFRU, which are 2 to 16, with MfgDate as 17.
my @oids;
my $add_entity = sub {
my (%entity) = @_;
Expand Down Expand Up @@ -689,6 +716,17 @@ if ( $opts{u} ) {
push( @oids,
[ '.1.3.6.1.2.1.47.1.1.1.1.' . ( $column_index + 2 ) . '.' . $entity{index}, $type, $value ] );
}

# entPhysicalMfgDate is a DateAndTime, the year as two bytes, then a byte each for
# month, day, hour, minutes, seconds, and deciseconds. mfg_date is YYYY-MM-DD, with
# the time left 0. All zeros means unknown, per the RFC. Sent as hex for the octet type.
my @date_parts = ( 0, 0, 0 );
if ( ( $entity{mfg_date} // '' ) =~ /^(\d{4})-(\d{2})-(\d{2})$/ ) {
@date_parts = ( $1, $2, $3 );
}
my $mfg_date_hex
= join( ' ', map { sprintf( '%02X', $_ ) } unpack( 'C*', pack( 'nC6', @date_parts, 0, 0, 0, 0 ) ) );
push( @oids, [ '.1.3.6.1.2.1.47.1.1.1.1.17.' . $entity{index}, 'octet', $mfg_date_hex ] );
}; ## end $add_entity = sub

# Adds a sensor entity and its entPhySensorTable row. Takes index, name,
Expand Down Expand Up @@ -859,15 +897,21 @@ if ( $opts{u} ) {
mfg_name => $module_info->{vendor_name},
model_name => $module_info->{vendor_pn},
is_fru => 1,
mfg_date => $module_info->{mfg_date},
);

# IFF_UP is the lowest bit of the interface flags
# IFF_UP is the lowest bit of the interface flags. A Tx fault is the module failing,
# so critical, while a loss of signal may just be the far end down, so major.
my $interface_flags = read_sysfs( '/sys/class/net/' . $interface . '/flags' ) // '0';
$add_state->(
index => $module_index,
admin => hex($interface_flags) & 1 ? 4 : 2,
oper => 3,
alarms => { critical => $module_info->{alarms}, warning => $module_info->{warnings} },
alarms => {
critical => $module_info->{alarms} || $module_info->{tx_fault},
major => $module_info->{signal_loss},
warning => $module_info->{warnings},
},
);

my $sensor_position = 1;
Expand Down
Loading