Skip to content

Commit

Permalink
Merge pull request #20 from kisbogdan-kolos/homeserver-type
Browse files Browse the repository at this point in the history
Add option to set homeserver type
  • Loading branch information
gen2brain authored Sep 19, 2024
2 parents 83d5922 + 68d9ee9 commit 512f07e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Name | Description
radius.address | Address of [FreeRADIUS status server](https://wiki.freeradius.org/config/Status), defaults to `127.0.0.1:18121`.
radius.secret | FreeRADIUS client secret, defaults to `adminsecret`.
radius.timeout | Timeout, in milliseconds, defaults to `5000`.
radius.homeservers | Addresses of home servers separated by comma, e.g. "172.28.1.2:1812,172.28.1.3:1812"
radius.homeservers | Addresses of home servers separated by comma, e.g. "172.28.1.2:1812:auth,172.28.1.3:1813:acct", auth/acct is optional and defaults to all
web.listen-address | Address to listen on for web interface and telemetry, defaults to `:9812`.
web.telemetry-path | Path under which to expose metrics, defaults to `/metrics`.
version | Display version information
Expand All @@ -34,7 +34,7 @@ Name | Description
RADIUS_ADDRESS | Address of [FreeRADIUS status server](https://wiki.freeradius.org/config/Status).
RADIUS_SECRET | FreeRADIUS client secret.
RADIUS_TIMEOUT | Timeout, in milliseconds.
RADIUS_HOMESERVERS | Addresses of home servers separated by comma, e.g. "172.28.1.2:1812,172.28.1.3:1812"
RADIUS_HOMESERVERS | Addresses of home servers separated by comma, e.g. "172.28.1.2:1812:auth,172.28.1.3:1813:acct", auth/acct is optional and defaults to all

### Metrics

Expand Down
35 changes: 30 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,37 @@ func NewFreeRADIUSClient(addr string, homeServers []string, secret string, timeo
if hs == "" {
continue
}
packet, err := newPacket([]byte(secret), hs, radius.NewInteger(uint32(

statAttr := radius.NewInteger(uint32(
freeradius.StatisticsTypeAuthentication| // will give "Home server is not auth" stats error when server is acct (but won't fail and give the available metrics)
freeradius.StatisticsTypeAccounting| // will give "Home server is not acct" stats error when server is auth (but won't fail and give the available metrics)
freeradius.StatisticsTypeInternal|
freeradius.StatisticsTypeHomeServer,
)))
freeradius.StatisticsTypeAccounting| // will give "Home server is not acct" stats error when server is auth (but won't fail and give the available metrics)
freeradius.StatisticsTypeInternal|
freeradius.StatisticsTypeHomeServer,
))

if strings.Count(hs, ":") == 2 { // has third parameter
index := strings.LastIndex(hs, ":")
hsType := hs[index+1:]
hs = hs[:index]

if hsType == "auth" {
statAttr = radius.NewInteger(uint32(
freeradius.StatisticsTypeAuthentication|
freeradius.StatisticsTypeInternal|
freeradius.StatisticsTypeHomeServer,
))
} else if hsType == "acct" {
statAttr = radius.NewInteger(uint32(
freeradius.StatisticsTypeAccounting|
freeradius.StatisticsTypeInternal|
freeradius.StatisticsTypeHomeServer,
))
} else {
log.Fatalf("unknown server type: '%v'", hsType)
}
}

packet, err := newPacket([]byte(secret), hs, statAttr)
if err != nil {
log.Fatalf("failed creating new packet for address '%v': %v\n", addr, err)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
metricsPath := fs.String("web.telemetry-path", "/metrics", "A path under which to expose metrics.")
radiusTimeout := fs.Int("radius.timeout", 5000, "Timeout, in milliseconds [RADIUS_TIMEOUT].")
radiusAddr := fs.String("radius.address", "127.0.0.1:18121", "Address of FreeRADIUS status server [RADIUS_ADDRESS].")
homeServers := fs.String("radius.homeservers", "", "List of FreeRADIUS home servers to check, e.g. '172.28.1.2:1812,172.28.1.3:1812' [RADIUS_HOMESERVERS].")
homeServers := fs.String("radius.homeservers", "", "List of FreeRADIUS home servers to check, e.g. '172.28.1.2:1812:auth,172.28.1.3:1813:acct' [RADIUS_HOMESERVERS].")
radiusSecret := fs.String("radius.secret", "adminsecret", "FreeRADIUS client secret [RADIUS_SECRET].")

err := ff.Parse(fs, os.Args[1:], ff.WithEnvVarNoPrefix(), ff.WithConfigFileFlag("config"), ff.WithConfigFileParser(ff.JSONParser))
Expand Down

0 comments on commit 512f07e

Please sign in to comment.