Created
February 25, 2022 18:12
-
-
Save bish0polis/f703fe3b5c879647bef26f6ede78f4a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cookbook Name:: ohai | |
# Plugin:: llpd | |
# | |
# "THE BEER-WARE LICENSE" (Revision 42): | |
# <[email protected]> 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 [email protected], 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