#!/usr/bin/perl ### ### Copyright (C) 2016 Alexander Gall ### ### This program is free software: you can redistribute it and/or ### modify it under the terms of the GNU General Public License as ### published by the Free Software Foundation, either version 3 of the ### License, or (at your option) any later version. ### ### This program is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ### General Public License for more details. ### ### You should have received a copy of the GNU General Public License ### along with this program. If not, see . use strict; use warnings; use Getopt::Long; use Snabb::SNMP::Agent qw(%persistent_ifIndex %compound_scalar_handlers $sysUpTime); my %opt = ( 'check-interval' => 5, 'shmem-dir' => '/var/lib/snabb/shmem', ); sub usage() { print <<"EOF"; usage: $0 --ifindex= EOF exit(1); } sub ifTable_indexer($$$) { ## Force persistent ifIndex based on ifDescr my ($oid, $table_oid, $segment) = @_; my $ifDescr_obj = $segment->{objs}{ifDescr}; defined $ifDescr_obj or die "ifTable IID indexer: no ifDescr present for $segment->{name}"; tie my $ifDescr, 'Snabb::SNMP::Tie::OCTETSTR', $segment, 'ifDescr'; my $ifIndex = $persistent_ifIndex{$ifDescr}; defined $ifIndex or die "ifTable IID indexer: unknown interface $ifDescr"; return($oid.".".$ifIndex); } my %subtrees = ( interfaces => { tables => { scalars => { handlers => { ifNumber => { compound_handler => sub { return scalar(keys(%persistent_ifIndex)); } }, }, }, ifTable => { indexer => \&ifTable_indexer }, }, }, ifMIB => { tables => { scalars => { handlers => { ifTableLastChange => { compound_handler => sub { return $sysUpTime; } }, }, }, ifXTable => { indexer => \&ifTable_indexer }, }, }, ); GetOptions(\%opt, "check-interval=i", "ifindex=s", "shmem-dir=s") or usage(); defined $opt{ifindex} or usage(); Snabb::SNMP::Agent::start({ name => "interface", subtrees => \%subtrees, check_interval => $opt{'check-interval'}, if_index => $opt{ifindex}, mibs_dirs => '', mibs => '', shmem_dir => $opt{'shmem-dir'}, }); ## Not reached ## Local Variables: ## mode: CPerl ## End: