Skip to content

Instantly share code, notes, and snippets.

@binarybucks
Last active June 15, 2016 12:45
Show Gist options
  • Save binarybucks/4ba7e299a011b52ae738725eb92842fc to your computer and use it in GitHub Desktop.
Save binarybucks/4ba7e299a011b52ae738725eb92842fc to your computer and use it in GitHub Desktop.
object Host "me.owntracks.alr.st" {
import "owntracks-host"
}
object Host "5s.owntracks.alr.st" {
import "owntracks-host"
}
object Host "sm.owntracks.alr.st" {
import "owntracks-host"
}
local icinga2Cmd
function otr_init()
otr.log("recorder lua hooks starting")
icinga2Cmd = io.open("/var/run/icinga2/cmd/icinga2.cmd", "a")
end
function otr_hook(topic, _type, data)
if _type == "location" then
local batt = data['batt']
local status = 0;
local code = "OK"
if batt < 20 then
status = 1
code = "WARNING"
end
if batt < 10 then
status = 2
code ="CRITICAL"
end
local locationOut = "[" .. data['tst'] .. "] PROCESS_SERVICE_CHECK_RESULT;" .. data['tid'] .. ".owntracks.alr.st;location;0;" .. data['addr'] .. "\n"
local batteryOut = "[" .. data['tst'] .. "] PROCESS_SERVICE_CHECK_RESULT;" .. data['tid'] .. ".owntracks.alr.st;battery;" .. status .. ";BATTERY " .. code .. " - " .. batt .. "%\n"
icinga2Cmd:write(locationOut)
icinga2Cmd:write(batteryOut)
icinga2Cmd:flush()
end
end
function otr_exit()
end
apply Service "location" {
import "generic-service"
check_command = "dummy"
vars.dummy_state = 3
vars.dummy_text = "No Passive Check Result Received."
assign where host.vars.os == "owntracks"
enable_active_checks = false
max_check_attempts = 3
retry_interval = 1m
check_interval = 12h
}
apply Service "battery" {
import "generic-service"
check_command = "dummy"
vars.dummy_state = 3
vars.dummy_text = "No Passive Check Result Received."
assign where host.vars.os == "owntracks"
enable_active_checks = false
max_check_attempts = 3
retry_interval = 1m
check_interval = 12h
}
template Host "owntracks-host" {
check_command = "dummy"
max_check_attempts = 3
vars.os = "owntracks"
vars.dummy_state = 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment