Page MenuHomePhabricator

Inventorize network equipment in Netbox
Closed, ResolvedPublic0 Estimated Story Points

Description

Netbox has an "inventory" system for devices, where one can add parts to a device, with a manufacturer, part ID, asset tag, serial number etc.

We haven't used it so far -- for servers it's too much trouble for little gain.

I think the situation for network equipment is a bit different; routers like the MX480 have parts such as linecards that cost potentially hundreds of thousands, which we add or replace throughout their lifetime.

These are also blindspots in our CapEx planning, as they're not separate line items with purchase dates, asset tags, tasks etc. and easy to miss when we plan for our 5-year refresh cycle.

I propose that we start populating these with the "big" items, starting with MX480 parts (REs, linecards, PSUs, fantrays). We should probably also do the same for uplink modules and redundant PSUs for switches?

(To be clear, I'm not suggesting that we should track SFPs :)

BTW I don't think Netbox supports custom fields for inventory items; we should file a bug once we decide this is something we need to explore indeed.

Event Timeline

faidon triaged this task as Medium priority.Apr 20 2019, 9:18 PM
faidon created this task.
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I do think it's something useful to track. And overall quite easy for a one time import.

Running the following against LibreNMS DB:

SELECT sysName, entPhysicalName, entPhysicalSerialNum, entPhysicalModelName
FROM entPhysical
INNER JOIN devices
ON entPhysical.device_id = devices.device_id
WHERE entPhysicalSerialNum != 'BUILTIN'
AND entPhysicalSerialNum != ''
AND entPhysicalVendorType = 'Juniper'
AND hardware = 'Juniper MX480'  # Not to forget the other routers
AND entPhysicalIsFRU != 'frontPan'
AND entPhysicalIsFRU != '';

Exports 55 rows similar to:
're0.cr2-codfw', 'FPC: MPCE Type 3 3D @ 0/*/*', 'S/N XXX000', '750-045372'
A quick cleanup: remove re0., remove @.*, remove S/N
And it can be mass imported through https://netbox.wikimedia.org/dcim/inventory-items/import/

The data doesn't change often, so manually updating it is not an issue.

Some devices only expose the strict minimum about their fan tray, for example an MX480 show chassis hardware:
Fan Tray Enhanced Left Fan Tray
Some a bit more (eg. MX104):
Fan Tray 0 REV 03 711-049570 XXX000 Fan Tray

VCF are a bit more tricky:

SELECT sysName, entPhysicalName, entPhysicalSerialNum, entPhysicalModelName
FROM entPhysical
INNER JOIN devices
ON entPhysical.device_id = devices.device_id
WHERE entPhysicalSerialNum != 'BUILTIN'
AND entPhysicalSerialNum != ''
AND entPhysicalVendorType = 'Juniper'
AND sysName like "asw%"
AND entPhysicalIsFRU != 'frontPan'
AND entPhysicalIsFRU != ''
AND entPhysicalIsFRU != 'flexible';

Returns:

'asw-d-codfw', 'PIC: 4x 1G/10G SFP/SFP+ @ 8/2/*', 'XXX000', '611-063980'
'asw-a-codfw', 'Power Supply 0 @ 1/0/*', 'XXX000', '740-046876'

So we can derive the exact Netbox parent name from the @ X part.

BTW I don't think Netbox supports custom fields for inventory items; we should file a bug once we decide this is something we need to explore indeed.

Indeed, in the meantime, we can record that data in the description field.

Apparently Netbox allows for a CSV import even for inventory items.

So,
ssh cr1-eqiad.wikimedia.org show chassis hardware models | tail -n +2 sed -nr 's/ *(.*[^ ]) +R(ev|EV) +[0-9]+ +[0-9-]+ +([^ ]+) +([^ ]+)/cr3-esams,"\1",Juniper,\3,\4,false/p' seems to have done the trick, with a CSV header of:
device,name,manufacturer,serial,part_id,discovered

Note that the above doesn't emit output for e.g. fan trays (as they don't have a serial number), or air filters (since show chassis hardware doesn't show them). These needed to be added manually.

This is now done with FRUs imported in Netbox for:

  • cr1-eqiad
  • cr2-eqiad
  • cr1-codfw
  • cr2-codfw
  • cr2-esams
  • cr3-esams
  • cr1-eqsin

These are all missing asset tags, because to my knowledge we never tagged them. We should start doing so from now onwards at least for linecards and REs.

Unfortunately, someone else filed an upstream bug (#3083) for custom fields in inventory items, and that's now declined :(

OK for switches, this did the trick:

#!/usr/bin/perl
use strict;
use warnings;
my $template = $ARGV[0];
my $device;
while (<STDIN>) {
        chomp;
        if (/FPC (\d)/) {
                my $fpc = $1;
                $device = $template;
                $device =~ s/%/$fpc/;
        } elsif (/BUILTIN/) {
                next;
        } elsif (/((?:Power Supply|PIC) \d) +R(?:EV|ev) \d\d + [\d-]+ +([^ ]+) +([^ ]+)$/) {
                my ($fru, $serial, $model) = ($1, $2, $3);
                $model =~ s/-A$//;
                print "$device,\"$fru\",Juniper,$model,$serial\n";
        }
}
#!/bin/sh
echo "device,name,manufacturer,part_id,serial"
for row in a b c d; do ssh asw-${row}-codfw.mgmt.codfw.wmnet "show chassis hardware" | perl parse-jnpr.pl asw-${row}%-codfw; done
for row in a b c d; do ssh asw2-${row}-eqiad.mgmt.eqiad.wmnet "show chassis hardware" | perl parse-jnpr.pl asw2-${row}%-eqiad; done
# manually s/asw2-a5/asw3-a5/
for row in a c ; do ssh asw-${row}-eqiad.mgmt.eqiad.wmnet "show chassis hardware models" | perl parse-jnpr.pl asw-${row}%-eqiad; done
ssh asw2-a5-eqiad.mgmt.eqiad.wmnet "show chassis hardware models" | perl parse-jnpr.pl asw2-a5-eqiad; done
ssh asw2-ulsfo.mgmt.ulsfo.wmnet "show chassis hardware" | perl parse-jnpr.pl asw%-ulsfo
ssh asw1-eqsin.mgmt.eqsin.wmnet "show chassis hardware" | perl parse-jnpr.pl asw060%-eqsin
# manually fix their hostnames to match 0603/0604
ssh asw-esams.mgmt.esams.wmnet "show chassis hardware" | perl parse-jnpr.pl asw-oe1%-esams
ssh msw1-eqiad.mgmt.eqiad.wmnet "show chassis hardware models" | perl parse-jnpr.pl msw1-eqiad
ssh msw1-codfw.mgmt.codfw.wmnet "show chassis hardware models" | perl parse-jnpr.pl msw1-codfw

csw2-esams I skipped because I think the serials in Netbox are not representing reality, and it's pointless at this point anyway.

For asw-a/b/d-codfw, I had to add the PIC2 manually, as JunOS for QFX can either show the model (with show chassis hardware clei-models) or the serial (show chassis hardware) but not both.

pfw and fasw devices added.

I think everything that can be done here is done.