Sha256: 5172d091b4fbeb13dab0bbb44f828ff027bf8306e1a8c8d0bc0bf642be5d8d3c

Contents?: true

Size: 1.57 KB

Versions: 24

Compression:

Stored size: 1.57 KB

Contents

#
# Author:: Toomas Pelberg (<toomas.pelberg@playtech.com>)
# Copyright:: Copyright (c) 2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require "sigar"
require_plugin "network"

provides "network"

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

# From sigar: include/sigar.h sigar_net_route_t
SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname]

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={}
  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

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ohai-6.24.2 lib/ohai/plugins/sigar/network_route.rb
ohai-6.24.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.24.0.rc.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.22.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.22.0.rc.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.20.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.20.0.rc.1 lib/ohai/plugins/sigar/network_route.rb
ohai-6.18.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.18.0.rc.4 lib/ohai/plugins/sigar/network_route.rb
ohai-6.18.0.rc.3 lib/ohai/plugins/sigar/network_route.rb
ohai-6.18.0.rc.1 lib/ohai/plugins/sigar/network_route.rb
ohai-6.18.0.rc.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.16.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.16.0.beta.2 lib/ohai/plugins/sigar/network_route.rb
ohai-6.16.0.beta.1 lib/ohai/plugins/sigar/network_route.rb
ohai-6.14.0 lib/ohai/plugins/sigar/network_route.rb
ohai-6.14.0.rc.1 lib/ohai/plugins/sigar/network_route.rb
ohai-0.6.14.rc.1 lib/ohai/plugins/sigar/network_route.rb
ohai-0.6.12 lib/ohai/plugins/sigar/network_route.rb
ohai-0.6.12.rc.5 lib/ohai/plugins/sigar/network_route.rb