sector-f / failoverd

Scriptable daemon for updating routes based on packet loss to endpoints
MIT License
1 stars 0 forks source link

failoverd

A scriptable daemon for updating routes based on packet loss to endpoints.

Configuration

failoverd is configured using a Lua script that specifies a number of variables and functions.

Example

-- Number of seconds to wait before sending each packet
ping_frequency = 1

-- Number of seconds to wait before calling on_update function
update_frequency = 5

-- Use ICMP pings if true, UDP pings if false
privileged = true 

-- The global_probe_stats that are passed to functions are the statistics for the last num_seconds seconds
num_seconds = 10

-- List of endpoints to ping
probes = {
    probe.new("192.168.0.1"),         -- Pings 192.168.0.1
    probe.new("192.168.0.2", "eth0"), -- Pings 192.168.0.2 using eth0's address
}

-- Gets called whenever a response is received
function on_recv(gps, ps)
   io.write(string.format("%s: %.2f\n", ps:dst(), ps:loss()))
end

-- Gets called every update_frequency seconds
function on_update(gps)
    ps = gps:lowest_loss()
    io.write(string.format("%s: %.2f\n", ps:dst(), ps:loss()))
end

-- Gets called on program shutdown (SIGINT)
function on_quit(gps)
    print("Shutting down")
end

Variables

Note that if privileged is true, then you will need to give failoverd the CAP_NET_RAW capability to allow it to send ICMP ping requests, unless you are running it as the superuser.

Types

The following types are implemented for use in the configuration file:

probe

The probe type is used to specify endpoints that should be pinged. It is created via the probe.new function, which can be called in two ways:

Additionally, probes can be started/stopped during runtime:

global_probe_stats

The global_probe_stats type stores information about the statistics of all running probes. It has the following methods:

probe_stats

The probe_stats type stores information about the statistics about one running probe. It has the following methods:

Functions

The following functions can be specified in the configuration file; they will be called by failoverd when indicated. Note that all functions are optional.

Modules

The following modules are provided:

dns

The dns module allows for DNS lookups using the system DNS resolver. It provides the following functions:

Example
local dns = require("dns")

addresses = dns.lookup_v4("google.com")
for i,addr in ipairs(addresses) do
    table.insert(probes, probe.new(addr))
end