statusd_nut

Olleg Samoylov <[email protected]>
Newsgroups gmane.comp.window-managers.ion.general
Organization Moscow Institute of Physics and Technology
Message-ID <[email protected]>
Hi,
Here is my contribution. This plugin check ups with the aid of
http://www.networkupstools.org and show status of ups in statusbar.
-- 
Olleg Samoylov
statusd_nut.lua (text/x-lua, 1.2 KB)
-- statusd_nut.lua
--
-- Show ups status and battery capacity when on battery
-- Depends on Network UPS Tools (upsc)
--
-- Written by Olleg Samoylov
--
-- You are free to distribute this software under the terms of the GNU
-- General Public License Version 2 or later

if not statusd_nut then
  statusd_nut={
      interval=15*1000,
      ups='myups',
  }
end

local settings = table.join (statusd.get_config("nut"), statusd_nut)

local nut_timer

local function update_nut()
      local f = io.popen("upsc '"..settings.ups.."' ups.status")
      local status = f:read()
      f:close()
      f = io.popen("upsc '"..settings.ups.."' battery.charge")
      local battery = tonumber(f:read())
      f:close()
      if battery<100 then
	 statusd.inform("nut", status.." "..battery.."%")
	 if status:match("OB %a+") then
	    statusd.inform("nut_hint", "critical")
	    nut_timer:set(1000, update_nut)
	 else
	    statusd.inform("nut_hint", "important")
	    nut_timer:set(settings.interval, update_nut)
	 end
      else
	 statusd.inform("nut", status)
	 statusd.inform("nut_hint", "normal")
	 nut_timer:set(settings.interval, update_nut)
      end
end

nut_timer = statusd.create_timer()
update_nut()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.