diff options
author | Hleb Valoshka <375gnu@gmail.com> | 2015-09-04 19:28:18 +0300 |
---|---|---|
committer | Hleb Valoshka <375gnu@gmail.com> | 2015-09-25 17:37:08 +0300 |
commit | 07f276512edc30bcffe5e66091a46ea0885e8d4f (patch) | |
tree | 3ab0b998b169298df555a4a1da0cd85b600dfcb1 | |
parent | 0e6456ca3e56ae4e84feabff87f3c538bf38964a (diff) | |
download | ohai-07f276512edc30bcffe5e66091a46ea0885e8d4f.tar.gz |
Initial support for DragonFly BSD
-rw-r--r-- | lib/ohai/mixin/os.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/dragonflybsd/cpu.rb | 58 | ||||
-rw-r--r-- | lib/ohai/plugins/dragonflybsd/filesystem.rb | 57 | ||||
-rw-r--r-- | lib/ohai/plugins/dragonflybsd/memory.rb | 60 | ||||
-rw-r--r-- | lib/ohai/plugins/dragonflybsd/network.rb | 126 | ||||
-rw-r--r-- | lib/ohai/plugins/dragonflybsd/os.rb | 32 | ||||
-rw-r--r-- | lib/ohai/plugins/dragonflybsd/platform.rb | 29 | ||||
-rw-r--r-- | lib/ohai/plugins/hostname.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/kernel.rb | 12 | ||||
-rw-r--r-- | lib/ohai/plugins/ps.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/uptime.rb | 2 |
11 files changed, 379 insertions, 3 deletions
diff --git a/lib/ohai/mixin/os.rb b/lib/ohai/mixin/os.rb index d42b1943..2fe8ca73 100644 --- a/lib/ohai/mixin/os.rb +++ b/lib/ohai/mixin/os.rb @@ -39,6 +39,8 @@ module Ohai return "openbsd" when /netbsd(.*)$/ return "netbsd" + when /dragonfly(.*)$/ + return "dragonflybsd" when /solaris2/ return "solaris2" when /mswin|mingw32|windows/ diff --git a/lib/ohai/plugins/dragonflybsd/cpu.rb b/lib/ohai/plugins/dragonflybsd/cpu.rb new file mode 100644 index 00000000..feccd249 --- /dev/null +++ b/lib/ohai/plugins/dragonflybsd/cpu.rb @@ -0,0 +1,58 @@ +# +# Author:: Bryan McLellan (btm@loftninjas.org) +# Copyright:: Copyright (c) 2008 Bryan McLellan +# 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. +# + +Ohai.plugin(:CPU) do + provides "cpu" + + collect_data(:dragonflybsd) do + # all dmesg output for smp I can find only provides info about a single processor + # identical processors is probably a hardware requirement so we'll duplicate data for each cpu + # old examples: http://www.bnv-bamberg.de/home/ba3294/smp/rbuild/index.htm + cpuinfo = Mash.new + cpuinfo["flags"] = [] + + # /var/run/dmesg.boot + # CPU: Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz (3516.61-MHz K8-class CPU) + # Origin = "GenuineIntel" Id = 0x306a9 Family = 6 Model = 3a Stepping = 9 + # Features=0x783fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE,SSE2> + # Features2=0x209<SSE3,MON,SSSE3> + # AMD Features=0x28100800<SYSCALL,NX,RDTSCP,LM> + # AMD Features2=0x1<LAHF> + + File.open("/var/run/dmesg.boot").each do |line| + case line + when /CPU:\s+(.+) \(([\d.]+).+\)/ + cpuinfo["model_name"] = $1 + cpuinfo["mhz"] = $2 + when /Origin = "(.+)"\s+Id = (.+)\s+Stepping = (.+)/ + cpuinfo["vendor_id"] = $1 + cpuinfo["stepping"] = $3 + # These _should_ match /AMD Features2?/ lines as well + when /Features=.+<(.+)>/ + cpuinfo["flags"].concat($1.downcase.split(',')) + # Features2=0x80000001<SSE3,<b31>> + when /Features2=[a-f\dx]+<(.+)>/ + cpuinfo["flags"].concat($1.downcase.split(',')) + end + end + + cpu cpuinfo + so = shell_out("sysctl -n hw.ncpu") + cpu[:total] = so.stdout.split($/)[0].to_i + end +end diff --git a/lib/ohai/plugins/dragonflybsd/filesystem.rb b/lib/ohai/plugins/dragonflybsd/filesystem.rb new file mode 100644 index 00000000..558efb00 --- /dev/null +++ b/lib/ohai/plugins/dragonflybsd/filesystem.rb @@ -0,0 +1,57 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2008 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. +# + +Ohai.plugin(:Filesystem) do + provides "filesystem" + + collect_data(:dragonflybsd) do + fs = Mash.new + + # Grab filesystem data from df + so = shell_out("df") + so.stdout.lines do |line| + case line + when /^Filesystem/ + next + when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ + filesystem = $1 + fs[filesystem] = Mash.new + fs[filesystem][:kb_size] = $2 + fs[filesystem][:kb_used] = $3 + fs[filesystem][:kb_available] = $4 + fs[filesystem][:percent_used] = $5 + fs[filesystem][:mount] = $6 + end + end + + # Grab mount information from mount + so = shell_out("mount") + so.stdout.lines do |line| + if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/ + filesystem = $1 + fs[filesystem] = Mash.new unless fs.has_key?(filesystem) + fs[filesystem][:mount] = $2 + fs[filesystem][:fs_type] = $3 + fs[filesystem][:mount_options] = $4.split(/,\s*/) + end + end + + # Set the filesystem data + filesystem fs + end +end diff --git a/lib/ohai/plugins/dragonflybsd/memory.rb b/lib/ohai/plugins/dragonflybsd/memory.rb new file mode 100644 index 00000000..47618698 --- /dev/null +++ b/lib/ohai/plugins/dragonflybsd/memory.rb @@ -0,0 +1,60 @@ +# +# Author:: Bryan McLellan (btm@loftninjas.org) +# Copyright:: Copyright (c) 2009 Bryan McLellan +# 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. +# + +Ohai.plugin(:Memory) do + provides "memory", "memory/swap" + + collect_data(:dragonflybsd) do + memory Mash.new + memory[:swap] = Mash.new + + # /usr/src/sys/sys/vmmeter.h + so = shell_out("sysctl -n vm.stats.vm.v_page_size") + memory[:page_size] = so.stdout.split($/)[0] + so = shell_out("sysctl -n vm.stats.vm.v_page_count") + memory[:page_count] = so.stdout.split($/)[0] + memory[:total] = memory[:page_size].to_i * memory[:page_count].to_i + so = shell_out("sysctl -n vm.stats.vm.v_free_count") + memory[:free] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i + so = shell_out("sysctl -n vm.status.vm.v_active_count") + memory[:active] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i + so = shell_out("sysctl -n vm.status.vm.v_inactive_count") + memory[:inactive] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i + so = shell_out("sysctl -n vm.stats.vm.v_cache_count") + memory[:cache] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i + so = shell_out("sysctl -n vm.stats.vm.v_wire_count") + memory[:wired] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i + so = shell_out("sysctl -n vfs.bufspace") + memory[:buffers] = so.stdout.split($/)[0] + + so = shell_out("swapinfo") + so.stdout.lines do |line| + # Device 1K-blocks Used Avail Capacity + # /dev/ad0s1b 253648 0 253648 0% + if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/ + mdev = $1 + memory[:swap][mdev] = Mash.new + memory[:swap][mdev][:total] = $2 + memory[:swap][mdev][:used] = $3 + memory[:swap][mdev][:free] = $4 + memory[:swap][mdev][:percent_free] = $5 + end + end + end +end + diff --git a/lib/ohai/plugins/dragonflybsd/network.rb b/lib/ohai/plugins/dragonflybsd/network.rb new file mode 100644 index 00000000..cc80903a --- /dev/null +++ b/lib/ohai/plugins/dragonflybsd/network.rb @@ -0,0 +1,126 @@ +# +# Author:: Bryan McLellan (btm@loftninjas.org) +# Copyright:: Copyright (c) 2009 Bryan McLellan +# 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. +# + +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" + + collect_data(:dragonflybsd) do + network Mash.new unless network + network[:interfaces] = Mash.new unless network[:interfaces] + counters Mash.new unless counters + counters[:network] = Mash.new unless counters[:network] + + so = shell_out("route -n get default") + so.stdout.lines do |line| + if line =~ /(\w+): ([\w\.]+)/ + case $1 + when "gateway" + network[:default_gateway] = $2 + when "interface" + network[:default_interface] = $2 + end + end + end + + iface = Mash.new + so = shell_out("#{ Ohai.abs_path( "/sbin/ifconfig" )} -a") + cint = nil + so.stdout.lines do |line| + if line =~ /^([0-9a-zA-Z\.]+):\s+/ + cint = $1 + iface[cint] = Mash.new + if cint =~ /^(\w+)(\d+.*)/ + iface[cint][:type] = $1 + iface[cint][:number] = $2 + end + end + # call the family lladdr to match linux for consistency + if line =~ /\s+ether (.+?)\s/ + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] + iface[cint][:addresses][$1] = { "family" => "lladdr" } + end + if line =~ /\s+inet ([\d.]+) netmask ([\da-fx]+)\s*\w*\s*([\d.]*)/ + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] + # convert the netmask to decimal for consistency + netmask = "#{$2[2,2].hex}.#{$2[4,2].hex}.#{$2[6,2].hex}.#{$2[8,2].hex}" + if $3.empty? + iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask } + else + # found a broadcast address + iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask, "broadcast" => $3 } + end + end + if line =~ /\s+inet6 ([a-f0-9\:]+)%?(\w*)\s+prefixlen\s+(\d+)\s*\w*\s*([\da-fx]*)/ + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses] + if $4.empty? + iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $3 } + else + # found a zone_id / scope + iface[cint][:addresses][$1] = { "family" => "inet6", "zoneid" => $2, "prefixlen" => $3, "scopeid" => $4 } + end + end + if line =~ /flags=\d+<(.+)>/ + flags = $1.split(',') + iface[cint][:flags] = flags if flags.length > 0 + end + if line =~ /metric: (\d+) mtu: (\d+)/ + iface[cint][:metric] = $1 + iface[cint][:mtu] = $2 + end + end + + so = shell_out("arp -an") + so.stdout.lines do |line| + if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/ + next unless iface[$3] # this should never happen + iface[$3][:arp] = Mash.new unless iface[$3][:arp] + iface[$3][:arp][$1] = $2.downcase + end + end + + network["interfaces"] = iface + + net_counters = Mash.new + # From netstat(1), not sure of the implications: + # Show the state of all network interfaces or a single interface + # which have been auto-configured (interfaces statically configured + # into a system, but not located at boot time are not shown). + so = shell_out("netstat -ibdn") + so.stdout.lines do |line| + # Name Mtu Network Address Ipkts Ierrs Ibytes Opkts Oerrs Obytes Coll Drop + # ed0 1500 <Link#1> 54:52:00:68:92:85 333604 26 151905886 175472 0 24897542 0 905 + # $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 + if line =~ /^([\w\.\*]+)\s+\d+\s+<Link#\d+>\s+([\w:]*)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ + net_counters[$1] = Mash.new unless net_counters[$1] + net_counters[$1]["rx"] = Mash.new unless net_counters[$1]["rx"] + net_counters[$1]["tx"] = Mash.new unless net_counters[$1]["tx"] + net_counters[$1]["rx"]["packets"] = $3 + net_counters[$1]["rx"]["errors"] = $4 + net_counters[$1]["rx"]["bytes"] = $5 + net_counters[$1]["tx"]["packets"] = $6 + net_counters[$1]["tx"]["errors"] = $7 + net_counters[$1]["tx"]["bytes"] = $8 + net_counters[$1]["tx"]["collisions"] = $9 + net_counters[$1]["tx"]["dropped"] = $10 + end + end + + counters[:network][:interfaces] = net_counters + end +end diff --git a/lib/ohai/plugins/dragonflybsd/os.rb b/lib/ohai/plugins/dragonflybsd/os.rb new file mode 100644 index 00000000..39b05540 --- /dev/null +++ b/lib/ohai/plugins/dragonflybsd/os.rb @@ -0,0 +1,32 @@ +# +# Authors:: Adam Jacob (<adam@opscode.com>) +# Richard Manyanza (<liseki@nyikacraftsmen.com>) +# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Copyright:: Copyright (c) 2014 Richard Manyanza. +# 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 'ohai/mixin/os' + +Ohai.plugin(:OS) do + provides "os", "os_version" + + collect_data(:dragonflybsd) do + os collect_os + + # This is __DragonFly_version. See sys/param.h + os_version shell_out("sysctl -n kern.osreldate").stdout.split($/)[0] + end +end diff --git a/lib/ohai/plugins/dragonflybsd/platform.rb b/lib/ohai/plugins/dragonflybsd/platform.rb new file mode 100644 index 00000000..169488e2 --- /dev/null +++ b/lib/ohai/plugins/dragonflybsd/platform.rb @@ -0,0 +1,29 @@ +# +# Author:: Bryan McLellan (btm@loftninjas.org) +# Copyright:: Copyright (c) 2009 Bryan McLellan +# 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. +# + +Ohai.plugin(:Platform) do + provides "platform", "platform_version", "platform_family" + + collect_data(:dragonflybsd) do + so = shell_out("uname -s") + platform so.stdout.split($/)[0].downcase + so = shell_out("uname -r") + platform_version so.stdout.split($/)[0] + platform_family "dragonflybsd" + end +end diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb index c65b7706..834aee8d 100644 --- a/lib/ohai/plugins/hostname.rb +++ b/lib/ohai/plugins/hostname.rb @@ -97,7 +97,7 @@ Ohai.plugin(:Hostname) do collect_domain end - collect_data(:darwin, :netbsd, :openbsd) do + collect_data(:darwin, :netbsd, :openbsd, :dragonflybsd) do hostname from_cmd("hostname -s") fqdn resolve_fqdn machinename from_cmd("hostname") diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb index c038aa03..17c98314 100644 --- a/lib/ohai/plugins/kernel.rb +++ b/lib/ohai/plugins/kernel.rb @@ -132,6 +132,18 @@ Ohai.plugin(:Kernel) do kernel[:modules] = bsd_modules("/usr/bin/modstat") end + collect_data(:dragonflybsd) do + kernel init_kernel + kernel[:os] = kernel[:name] + + so = shell_out("uname -i") + kernel[:ident] = so.stdout.split($/)[0] + so = shell_out("sysctl kern.securelevel") + kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ } + + kernel[:modules] = bsd_modules("/sbin/kldstat") + end + collect_data(:solaris2) do kernel init_kernel diff --git a/lib/ohai/plugins/ps.rb b/lib/ohai/plugins/ps.rb index ac0ee07d..19890ea0 100644 --- a/lib/ohai/plugins/ps.rb +++ b/lib/ohai/plugins/ps.rb @@ -27,7 +27,7 @@ Ohai.plugin(:PS) do command[:ps] = 'ps -ef' end - collect_data(:freebsd, :netbsd, :openbsd) do + collect_data(:freebsd, :netbsd, :openbsd, :dragonflybsd) do # ps -e requires procfs command[:ps] = 'ps -ax' end diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb index 8f879d35..51f01614 100644 --- a/lib/ohai/plugins/uptime.rb +++ b/lib/ohai/plugins/uptime.rb @@ -57,7 +57,7 @@ Ohai.plugin(:Uptime) do uptime data.last end - collect_data(:freebsd, :netbsd) do + collect_data(:freebsd, :netbsd, :dragonflybsd) do data = collect_uptime("/sbin/sysctl") uptime_seconds data.first uptime data.last |