From 8c3f278914a37d7b9f9e1c261356a73e37a2e86b Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 4 Sep 2021 09:53:21 +0200 Subject: add backup widget --- config/awesome/backup_status_widget.lua | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 config/awesome/backup_status_widget.lua (limited to 'config/awesome/backup_status_widget.lua') diff --git a/config/awesome/backup_status_widget.lua b/config/awesome/backup_status_widget.lua new file mode 100644 index 0000000..577b082 --- /dev/null +++ b/config/awesome/backup_status_widget.lua @@ -0,0 +1,69 @@ +-- from https://awesomewm.org/recipes/countdown/ +-- on 2018-04-10 +-- slightly modified + +local gears = require("gears") +local awful = require("awful") +local wibox = require("wibox") +local naughty = require("naughty") +local beautiful = require("beautiful") + +local backup_state_file = '/var/cache/dsa/nagios/borgmatic.stamp' +local max_age_s = 3600*24 + + +function backup_status_get_mtime() + local f = io.popen("stat -c %Y " .. backup_state_file) + local last_modified = f:read() + if last_modified == nil then + return 0 + else + return last_modified + end +end + +function backup_status_age() + local mtime = backup_status_get_mtime() + local current_time = os.time(os.date("*t")) + return current_time - mtime +end + +function backup_status_update(widget) + local age = backup_status_age() + widget.checked = (age > max_age_s) +end + +backup_status_widget = wibox.widget { + checked = false, + check_color = "#ff0000", + border_color = "#499644", + border_width = 2, + shape = gears.shape.circle, + widget = wibox.widget.checkbox +} + +local backup_status_tooltip = awful.tooltip { } +backup_status_tooltip:add_to_object(backup_status_widget) + +backup_status_widget:connect_signal('mouse::enter', function() + -- local mtime = backup_status_get_mtime() + -- backup_status_tooltip.text = os.date('state file last touched %c', mtime) + if backup_status_widget.checked then + backup_status_tooltip.text = 'Backup state file too old.' + else + backup_status_tooltip.text = 'Backup state file is recent.' + end +end) + + +backup_status_timer = gears.timer({timeout = 900, + call_now = true, + autostart = true, + callback = function() + backup_status_update(backup_status_widget) + end, + }) + +backup_status_widget:buttons(awful.util.table.join( + awful.button({}, 1, function() backup_status_update(backup_status_widget) end) +)) -- cgit v1.2.3