Skip to content
This repository has been archived by the owner. It is now read-only.

LLDP Module add #78

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -8,3 +8,4 @@ ruby.tcz
lshw.tcz
libssl-0.9.8.tcz
firmware-bnx2.tcz
lldpad.tcz
@@ -250,6 +250,10 @@ cp -p opt/gems/gem.list tmp-build-dir/tmp/gem-mirror/gems/gem.list
mkdir -p tmp-build-dir/root
cp rz_mk_gemrc.yaml tmp-build-dir/root/.gemrc

# Copy openlldp facterplugin to tmp
mkdir -p tmp-build-dir/tmp
cp tmp/openlldp.rb tmp-build-dir/tmp/

# create a copy of the local TCL Extension mirror that we will be running within
# our Microkernel instances
mkdir -p tmp-build-dir/tmp/tinycorelinux/4.x/x86/tcz
@@ -15,6 +15,9 @@ sudo ruby setup.rb
cd $prev_wd
sudo rm -rf /opt/tmp-install-rubygems

sudo mkdir -p /var/lib/lldpad
sudo lldpad -d
for i in `cat /proc/net/dev|cut -d : -f 1 |grep eth`; do sudo lldptool set-ssdp -i $i adminStatus=rx; done
# then, initialize the Microkernel and start a few key services
/usr/bin/sethostname box
if [ -f /usr/local/etc/init.d/openssh ]
@@ -40,6 +40,11 @@
# /usr/local/bin directory then we need construct a link to the executable in
# the #{gem_root}/bin subdirectory...

#facter's plugin directoy
facter_lib_dir = File.join(facter_lib, 'facter')
#add open lldp plugin to facter
%x[sudo cp /tmp/openlldp.rb #{facter_lib_dir}]

if !File.exists?("/usr/local/bin/facter") then
facter_exec = File.join(File.join(gem_root,"bin"),"facter")
%x[sudo ln -s #{facter_exec} /usr/local/bin/facter]
@@ -0,0 +1,92 @@
# Fact:
# lldp_neighbor_chassisid_<interface>
# lldp_neighbor_mngaddr_ipv4_<interface>
# lldp_neighbor_mngaddr_ipv6_<interface>
# lldp_neighbor_mtu_<interface>
# lldp_neighbor_portid_<interface>
# lldp_neighbor_sysname_<interface>
# lldp_neighbor_pvid_<interface>
#
# Purpose:
# Return information about the host's LLDP neighbors.
#
# Resolution:
# On hosts with the lldptool binary, send queries to the lldpad for each of
# the host's Ethernet interfaces and parse the output.
#
# Caveats:
# Assumes that the connected Ethernet switch is sending LLDPDUs, Open-LLDP
# (lldpad) is running, and lldpad is configured to receive LLDPDUs on each
# Ethernet interface.
#

require 'facter/util/macaddress'

# http://www.ruby-forum.com/topic/3418285#1040695
module Enumerable
def grep_v(cond)
select {|x| not cond === x}
end
end

if Facter::Util::Resolution.which('lldptool')
lldp = {
# LLDP Name Numeric value
'chassisID' => '1',
'portID' => '2',
'sysName' => '5',
'mngAddr_ipv4' => '8',
'mngAddr_ipv6' => '8',
'PVID' => '0x0080c201',
'MTU' => '0x00120f04',
}

# Remove interfaces that pollute the list (like lo and bond0).
Facter.value('interfaces').split(/,/).grep_v(/^lo$|^bond[0-9]/).each do |interface|
# Loop through the list of LLDP TLVs that we want to present as facts.
lldp.each_pair do |key, value|
Facter.add("lldp_neighbor_#{key}_#{interface}") do
setcode do
result = ""
output = Facter::Util::Resolution.exec("sudo lldptool get-tlv -n -i #{interface} -V #{value} 2>/dev/null")
if not output.nil?
case key
when 'sysName', 'MTU'
output.split("\n").each do |line|
result = $1 if line.match(/^\s+(.*)/)
end
when 'chassisID'
output.split("\n").each do |line|
ether = $1 if line.match(/MAC:\s+(.*)/)
result = Facter::Util::Macaddress.standardize(ether)
end
when 'portID'
output.split("\n").each do |line|
result = $1 if line.match(/Ifname:\s+(.*)/)
end
when 'mngAddr_ipv4'
output.split("\n").each do |line|
result = $1 if line.match(/IPv4:\s+(.*)/)
end
when 'mngAddr_ipv6'
output.split("\n").each do |line|
result = $1 if line.match(/IPv6:\s+(.*)/)
end
when 'PVID'
output.split("\n").each do |line|
result = $1.to_i if line.match(/Info:\s+(.*)/)
end
else
# case default
result = nil
end
else
# No output from lldptool
result = nil
end
result
end
end
end
end
end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.