+------- DEFAULT SETTINGS :------------------------------------------------------
+
+local sensors_timer
+local defaults = {
+ update_interval = 5*1000,
+ fan_alarm = 4000,
+ mb_alarm = 45,
+ cpu_alarm = 55,
+ fan_file = '/sys/class/i2c-adapter/i2c-0/0-002d/fan1_input',
+ mb_file = '/sys/class/i2c-adapter/i2c-0/0-002d/temp1_input',
+ cpu_file = '/sys/class/i2c-adapter/i2c-0/0-002d/temp2_input',
+}
+local settings = table.join(statusd.get_config("sensors"), defaults)
+
+------- SENSORS MONITOR :-------------------------------------------------------
+
+local function inform_fan(name, file, alarm)
+ file = io.open(file, 'r')
+ if file then
+ local level = 'normal'
+ local var = file:read('*n')
+ file:close()
+ if var <= alarm then level = 'critical' end
+ statusd.inform("sensors_" .. name, string.format('%d', var))
+ statusd.inform('sensors_' .. name .. '_hint', level)
+ end
+end
+
+local function inform_temp(name, file, alarm)
+ file = io.open(file, 'r')
+ if file then
+ local level = 'normal'
+ local var = file:read('*n') / 1000
+ file:close()
+ if var >= alarm then level = 'critical' end
+ statusd.inform("sensors_" .. name, string.format('%0.1f', var))
+ statusd.inform('sensors_' .. name .. '_hint', level)
+ end
+end
+
+local function inform_sensors()
+ inform_fan('fan', settings.fan_file, settings.fan_alarm + 0)
+ inform_temp('mb', settings.mb_file, settings.mb_alarm + 0)
+ inform_temp('cpu', settings.cpu_file, settings.cpu_alarm + 0)
+end
+
+local sensors_timer
+
+local function update_sensors()
+ inform_sensors()
+ sensors_timer:set(settings.update_interval, update_sensors)
+end
+
+-- Init
+sensors_timer=statusd.create_timer()
+update_sensors()
+
+
+