Skip to content

gentlemanautomaton/nettrigger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nettrigger

GoDoc

A swiss army knife of triggerable network actions. Intended to capture callbacks from other programs. Originally written as a DNS registration handler for ISC DHCP.

The nettrigger library provides a rudimentary rules engine. The included nettrigger program performs one-time evaluation of a set of rules upon its execution.

This package is experimental and subject to breaking changes.

Rules

Each rule defines zero or more triggers and one or more actions.

Triggers and actions can contain environment variables in their arguments.

Rule Syntax (Text)

Triggers

pattern subject glob
regex   subject expression

Actions

dns.a      host zone ip [ttl]
dns.cname  host zone target [ttl]
https.post url
http.post  url

Rules

[trigger [,trigger ...] :] action [,action ...]

Example Rule

pattern $HOST *-server : dns.a $HOST.example.com $IP

This example relies upon the definition of HOST and IP environment variables. It matches host names ending in -server and attempts to register A records for them.

Environment

Rules can be defined via environment variables:

RULE1='[rule syntax]'
RULE2='[rule syntax]'

Arguments can be mapped to environment variables, using environment variables:

ARG1='Host'
ARG2='IP'
ARG2='MAC'

Functions

When expanding environment variables, a small set of built-in functions are provided:

concat(value[, value ...])

sha2_256(value)
sha2_64(value)

Providers

Some actions rely on providers to perform their work. For example, DNS actions require configuration of a DNS provider that has control of the zone.

Currently supported:

  • DNS: Digital Ocean

ISC DHCP

The nettrigger program was originally written to register DNS records on lease commits. The dhcpd daemon can be configured to call nettrigger on commit like so:

on commit {
    set clip = binary-to-ascii(10, 8, ".", leased-address);
    set clhw = binary-to-ascii(16, 8, "", substring(hardware, 1, 6));
    execute("/nettrigger", host-decl-name, clip, clhw);
}

Note that this assumes the existence of nettrigger in the / root driectory.

Such an invocation of nettrigger would also require its arguments to be mapped:

ARG1='HOST'
ARG2='IP'
ARG3='MAC'

See this helpful blog post by Jan-Piet Mens for additional information about the on commit handler.

About

A swiss army knife of triggerable network actions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published