Skip to content

Instantly share code, notes, and snippets.

@rphillips
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rphillips/8e5ba84263d58527f636 to your computer and use it in GitHub Desktop.
Save rphillips/8e5ba84263d58527f636 to your computer and use it in GitHub Desktop.
--[[
Copyright 2014 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 streamingSpawn = require('./misc').streamingSpawn
local sigar = require('sigar')
local Handler = MetricsHandler:extend()
function Handler:initialize()
MetricsHandler.initialize(self)
self.vendor = sigar:new():sysinfo().vendor:lower()
end
function Handler:_transform(line, callback)
local status, value, method
if self.vendor == 'rhel' or self.vender == 'centos' then
status = 'enabled'
method = 'yum_cron'
elseif self.vendor == 'ubuntu' or self.vendor == 'debian' then
local _, _, key, value = line:find("(.*)%s(.*)")
value, _ = value:gsub('"', ''):gsub(';', '')
if key == 'APT::Periodic::Unattended-Upgrade' and value ~= 0 then
status = 'enabled'
end
method = 'unattended_upgrades'
end
self:push({ update_method = method, status = status })
callback()
end
--[[ Are autoupdates enabled? ]]--
local Info = HostInfoStdoutSubProc:extend()
function Info:initialize()
local vendor = sigar:new():sysinfo().vendor:lower()
local command, args
if vendor == 'ubuntu' or vendor == 'debian' then
command = 'apt-config'
args = {'dump' }
elseif vendor == 'rhel' or vendor == 'centos' then
command = 'service'
args = {'yum-cron', 'status' }
end
HostInfoStdoutSubProc.initialize(self, command, args, Handler)
end
function Info:getRestrictedPlatforms()
return {'win32'}
end
function Info:getType()
return 'AUTOUPDATES'
end
return Info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment