Hooks

Hook Methods

onDHCPRequestBefore(request)

Called before the DHCP response is generated.

onDHCPRequestAfter(request, response)

Called after the DHCP response is generated.

Environment

gravity Object

log(msg)

Logs a message to the stdout of the Gravity node this hook is run on.

node

The identifier of the node this hook is run on.

version

The version of Gravity on the node this hook is run on.

role

A reference to the Role instance this hook was triggered by.

dhcp Object

Opt(code, data)

Create a DHCP option with the code and data given.

Examples

Set Option 43 for UniFi Adoption

const UniFiPrefix = [0x01, 0x04];
// IP of the UniFi Network Controller, converted to Hex. Each octet of the IP is converted individually.
const UniFiIP = [0xC0, 0xA8, 0x01, 0x64];
function onDHCPRequestAfter(req, res) {
    res.UpdateOption(dhcp.Opt(43, [...UniFiPrefix, ...UniFiIP]))
}