Skip to content

Instantly share code, notes, and snippets.

@bish0polis
Created February 25, 2022 18:12
Show Gist options
  • Save bish0polis/f703fe3b5c879647bef26f6ede78f4a9 to your computer and use it in GitHub Desktop.
Save bish0polis/f703fe3b5c879647bef26f6ede78f4a9 to your computer and use it in GitHub Desktop.
# Cookbook Name:: ohai
# Plugin:: llpd
#
# "THE BEER-WARE LICENSE" (Revision 42):
# <john@dewey.ws> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return John-B Dewey Jr.
#
# renovated a bit by bishopolis@gmail.com, who also enjoys certain beers.
#
cookbook_name = 'all-base'
recipe_name = 'ohai/lldp'
Ohai.plugin(:Lldp) do
provides "llpd"
def hashify h, list
if list.size == 1
return list.shift
end
key = list.shift
h[key] ||= {}
h[key] = hashify h[key], list
h
end
collect_data(:default) do
lldp Mash.new
so = `lldpctl -f keyvalue 2>/dev/null`
if (res = $?.exitstatus) == 0
so
.split("\n")
.each do |element|
(key, value) = element.split('=')
elements = key
.split('.')[1..-1]
.push(value)
hashify(lldp, elements)
end # each
else
Chef::Log.warn "#{cookbook_name}==#{recipe_name} - bad result from lldpctl run: #{res}"
end # if res
end # def
end # plugin-do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment