diff options
author | Tim Smith <tsmith84@gmail.com> | 2016-02-10 22:53:34 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2016-02-14 21:14:23 -0800 |
commit | 2724ecc4628ca45f745c19da332a060d97e13bb4 (patch) | |
tree | 20b9dfae1ffd5fd8717c7535bcdefbbf7efca0c5 | |
parent | ac9f5a2ae4ada9f2e6e821418ed3a9039bda9a91 (diff) | |
download | ohai-2724ecc4628ca45f745c19da332a060d97e13bb4.tar.gz |
Log sigar gem load failures
These two plugins run on every system and spam debug logs. There are other plugins that use sigar, but they're confined to HPUX where you need sigar for ohai to operate.
-rw-r--r-- | lib/ohai/plugins/network_listeners.rb | 56 | ||||
-rw-r--r-- | lib/ohai/plugins/sigar/network_route.rb | 61 |
2 files changed, 63 insertions, 54 deletions
diff --git a/lib/ohai/plugins/network_listeners.rb b/lib/ohai/plugins/network_listeners.rb index 7ecfef72..62661c77 100644 --- a/lib/ohai/plugins/network_listeners.rb +++ b/lib/ohai/plugins/network_listeners.rb @@ -22,35 +22,39 @@ Ohai.plugin(:NetworkListeners) do depends "network", "counters/network" collect_data do - require "sigar" - flags = Sigar::NETCONN_TCP | Sigar::NETCONN_SERVER + begin + require 'sigar' + flags = Sigar::NETCONN_TCP | Sigar::NETCONN_SERVER - network Mash.new unless network - listeners = Mash.new + network Mash.new unless network + listeners = Mash.new - sigar = Sigar.new - sigar.net_connection_list(flags).each do |conn| - port = conn.local_port - addr = conn.local_address.to_s - if addr == "0.0.0.0" || addr == "::" - addr = "*" + sigar = Sigar.new + sigar.net_connection_list(flags).each do |conn| + port = conn.local_port + addr = conn.local_address.to_s + if addr == "0.0.0.0" || addr == "::" + addr = "*" + end + listeners[port] = Mash.new + listeners[port][:address] = addr + begin + pid = sigar.proc_port(conn.type, port) + # workaround for a failure of proc_state to throw + # after the first 0 has been supplied to it + # + # no longer required when hyperic/sigar#48 is fixed + throw ArgumentError.new("No such process") if pid == 0 + listeners[port][:pid] = pid + listeners[port][:name] = sigar.proc_state(pid).name + rescue + end end - listeners[port] = Mash.new - listeners[port][:address] = addr - begin - pid = sigar.proc_port(conn.type, port) - # workaround for a failure of proc_state to throw - # after the first 0 has been supplied to it - # - # no longer required when hyperic/sigar#48 is fixed - throw ArgumentError.new("No such process") if pid == 0 - listeners[port][:pid] = pid - listeners[port][:name] = sigar.proc_state(pid).name - rescue - end - end - network[:listeners] = Mash.new - network[:listeners][:tcp] = listeners + network[:listeners] = Mash.new + network[:listeners][:tcp] = listeners + rescue LoadError + Ohai::Log.debug('Could not load sigar gem. Skipping NetworkListeners plugin') + end end end diff --git a/lib/ohai/plugins/sigar/network_route.rb b/lib/ohai/plugins/sigar/network_route.rb index eaed4052..f4d3161f 100644 --- a/lib/ohai/plugins/sigar/network_route.rb +++ b/lib/ohai/plugins/sigar/network_route.rb @@ -19,41 +19,46 @@ require "ohai/mixin/network_constants" Ohai.plugin(:NetworkRoutes) do - include Ohai::Mixin::NetworkConstants + begin + require "sigar" - provides "network/interfaces/adapters/route" - depends "network/interfaces" + include Ohai::Mixin::NetworkConstants - def flags(flags) - f = "" - if (flags & Sigar::RTF_UP) != 0 - f += "U" - end - if (flags & Sigar::RTF_GATEWAY) != 0 - f += "G" - end - if (flags & Sigar::RTF_HOST) != 0 - f += "H" + provides "network/interfaces/adapters/route" + depends "network/interfaces" + + def flags(flags) + f = "" + if (flags & Sigar::RTF_UP) != 0 + f += "U" + end + if (flags & Sigar::RTF_GATEWAY) != 0 + f += "G" + end + if (flags & Sigar::RTF_HOST) != 0 + f += "H" + end + f end - f - end - collect_data(:default) do - require "sigar" - sigar = Sigar.new + collect_data(:default) do + sigar = Sigar.new - sigar.net_route_list.each do |route| - next unless network[:interfaces][route.ifname] # this should never happen - network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route] - route_data = {} - Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m| - if(m == :flags) - route_data[m] = flags(route.send(m)) - else - route_data[m] = route.send(m) + sigar.net_route_list.each do |route| + next unless network[:interfaces][route.ifname] # this should never happen + network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route] + route_data = {} + Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m| + if(m == :flags) + route_data[m] = flags(route.send(m)) + else + route_data[m] = route.send(m) + end end + network[:interfaces][route.ifname][:route][route.destination] = route_data end - network[:interfaces][route.ifname][:route][route.destination] = route_data end + rescue LoadError + Ohai::Log.debug('Could not load sigar gem. Skipping NetworkRoutes plugin') end end |