First commit
This commit is contained in:
parent
c132e17bd4
commit
e8bd42f507
2 changed files with 55 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
# snmp-ifalias
|
||||
|
||||
Perl script feeding the ifAlias table
|
||||
|
||||
Inspirated from https://github.com/pgmillon/observium/blob/master/scripts/ifAlias_persist
|
||||
|
|
52
ifAlias_persist
Executable file
52
ifAlias_persist
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
# SNMP::Extension::PassPersist is required.
|
||||
# This is in the package libsnmp-extension-passpersist-perl on Debian and
|
||||
# Ubuntu
|
||||
# And in the package dev-perl/SNMP-Extension-PassPersist from
|
||||
# https://git.grifon.fr/alarig/SwordArMor-gentoo-overlay.git overlay
|
||||
# Usage : Copy the script to /usr/local/bin/ifAlias_persist and add to
|
||||
# /etc/snmp/snmpd.conf
|
||||
# pass_persist .1.3.6.1.2.1.31.1.1.1.18 /usr/local/bin/ifAlias_persist
|
||||
|
||||
use strict;
|
||||
use SNMP::Extension::PassPersist;
|
||||
|
||||
|
||||
# create the object
|
||||
my $extsnmp = SNMP::Extension::PassPersist->new(
|
||||
backend_collect => \&update_tree,
|
||||
idle_count => 10, # no more than 10 idle cycles
|
||||
refresh => 60, # refresh every 60 sec
|
||||
);
|
||||
|
||||
# run the program
|
||||
$extsnmp->run;
|
||||
|
||||
sub update_tree {
|
||||
my ($self) = @_;
|
||||
|
||||
|
||||
my $Base = ".1.3.6.1.2.1.31.1.1.1.18";
|
||||
# get the interfaces
|
||||
my @iface_list = `ip l | grep mtu | cut -d @ -f 1`;
|
||||
my $type = "string";
|
||||
|
||||
foreach my $row (@iface_list){
|
||||
my @split = split(": ", $row);
|
||||
# remove a possible \n
|
||||
$split[1] =~ s/\R//g;
|
||||
|
||||
# cat the file
|
||||
my $filename = "/sys/class/net/$split[1]/ifalias";
|
||||
open(my $fh, '<:encoding(UTF-8)', $filename)
|
||||
or die "Could not open file '$filename' $!";
|
||||
# fill the OID with the content
|
||||
while (my $desc = <$fh>) {
|
||||
chomp $desc;
|
||||
my ($key, $value) = ("$Base.$split[0]",$desc);
|
||||
$self->add_oid_entry($key,$type,$value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue