Skip to content

Commit

Permalink
feat(hostinfo/routes): fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kaustavha committed Aug 4, 2015
1 parent 221147f commit 2c68ef0
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hostinfo/all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ return {
require('./deleted_libs'),
require('./cve'),
require('./last_logins'),
require('./remote_services')
require('./remote_services'),
require('./ip4routes'),
require('./ip6routes')
}
82 changes: 82 additions & 0 deletions hostinfo/ip4routes.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
--[[
Copyright 2015 Rackspace
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.
--]]
local HostInfo = require('./base').HostInfo

local fmt = require('string').format
local los = require('los')
local sigar = require('sigar')
local table = require('table')
local execFileToBuffers = require('./misc').execFileToBuffers

--[[ IP v4 routes check]]--
local Info = HostInfo:extend()
function Info:initialize()
HostInfo.initialize(self)
end

function Info:run(callback)
if los.type() ~= 'linux' then
self._error = 'Unsupported OS for routs'
return callback()
end

local vendor, cmd, args, method, opts
vendor = sigar:new():sysinfo().vendor:lower()
opts = {}
cmd = 'netstat'

if vendor == 'ubuntu' or vendor == 'debian' then
args = {'-nr4'}
elseif vendor == 'rhel' or vendor == 'centos' then
args = {'-nr'}
else
self._error = 'Could not determine linux distro for ipv4 routes check'
return callback()
end

local function execCB(err, exitcode, stdout_data, stderr_data)
if exitcode ~= 0 then
self._error = fmt("netstat exited with a %d exitcode", exitcode)
return callback()
end
for line in stdout_data:gmatch("[^\r\n]+") do
local iter = line:gmatch("%S+")
local firstw = iter()
if firstw == 'Destination' or firstw == 'Kernel' then
-- Do nothing
else
table.insert(self._params, {
destination = firstw,
gateway = iter(),
genmask = iter(),
flags = iter(),
mss = iter(),
window = iter(),
irtt = iter(),
iface = iter()
})
end
end
return callback()
end
return execFileToBuffers(cmd, args, opts, execCB)
end

function Info:getType()
return 'IP4ROUTES'
end

return Info
81 changes: 81 additions & 0 deletions hostinfo/ip6routes.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
--[[
Copyright 2015 Rackspace
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.
--]]
local HostInfo = require('./base').HostInfo

local fmt = require('string').format
local los = require('los')
local sigar = require('sigar')
local table = require('table')
local execFileToBuffers = require('./misc').execFileToBuffers

--[[ IP v4 routes check]]--
local Info = HostInfo:extend()
function Info:initialize()
HostInfo.initialize(self)
end

function Info:run(callback)
if los.type() ~= 'linux' then
self._error = 'Unsupported OS for routs'
return callback()
end

local vendor, cmd, args, method, opts
vendor = sigar:new():sysinfo().vendor:lower()
opts = {}
cmd = 'netstat'

if vendor == 'ubuntu' or vendor == 'debian' then
args = {'-nr6'}
elseif vendor == 'rhel' or vendor == 'centos' then
args = {'--inet6', '-nr'}
else
self._error = 'Could not determine linux distro for ipv4 routes check'
return callback()
end

local function execCB(err, exitcode, stdout_data, stderr_data)
if exitcode ~= 0 then
self._error = fmt("netstat exited with a %d exitcode", exitcode)
return callback()
end
for line in stdout_data:gmatch("[^\r\n]+") do
local iter = line:gmatch("%S+")
local firstw = iter()
if firstw == 'Destination' or firstw == 'Kernel' then
-- Do nothing
else
table.insert(self._params, {
destination = firstw,
next_hop = iter(),
flags = iter(),
metric = iter(),
ref = iter(),
use = iter(),
iface = iter()
})
end
end
return callback()
end
return execFileToBuffers(cmd, args, opts, execCB)
end

function Info:getType()
return 'IP6ROUTES'
end

return Info

0 comments on commit 2c68ef0

Please sign in to comment.