Include notionflux in the main repo instead of its own submodule
[notion/jeffpc.git] / contrib / statusd / statusd_drives.lua
blobad82efb7a8c3307d07d3826baedd2368c9b62af8
1 -- Authors: Voker57 <voker57@gmail.com>
2 -- License: Public domain
3 -- Last Changed: Unknown
4 --
5 -- Disk drives monitor
7 -- %drives - list of currently connected drives
9 -- by Voker57 <voker57@gmail.com>
10 -- Public domain
12 local defaults={
13 update_interval=500
16 local settings=table.join(statusd.get_config("drives"), defaults)
18 local drives_timer
20 local function get_drives()
21 local lsres = io.popen("ls /dev/sd* | sort")
22 return lsres:lines()
23 end
25 local function update_drives()
26 local drives_list = get_drives()
27 local drive_table = {}
28 for drive in drives_list do
29 if drive:match("/([^/]+)$") then
30 local drive_name = drive:match("/([^/]+)$")
31 local drive_base = drive_name:sub(1,3)
32 local drive_partition = drive_name:sub(4,-1)
33 if drive_table[drive_base] then
34 table.insert(drive_table[drive_base], drive_partition)
35 else
36 drive_table[drive_base] = {drive_partition}
37 end
38 end
39 end
40 local result_table = {}
41 for drive, partitions in pairs(drive_table) do
42 local result = drive
43 local parts = ""
44 for k,i in pairs(partitions) do
45 if i ~= "" then
46 parts = parts..i.." "
47 end
48 end
49 if parts ~= "" then
50 result = result.."["..parts:sub(1,-2).."]"
51 end
52 table.insert(result_table, result)
53 end
54 table.sort(result_table)
55 statusd.inform("drives", table.concat(result_table, " "))
56 drives_timer:set(settings.update_interval, update_drives)
57 end
59 -- Init
60 drives_timer=statusd.create_timer()
61 update_drives()