Skip to content

Commit

Permalink
Filter information returned by iwinfo before logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed Oct 14, 2023
1 parent 160769e commit 45bebc4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion network/access_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
accessPointConfigBackoffSec = 5
)

var accessPointInfoLines = []string{"ESSID: ", "Mode: ", "Tx-Power: ", "Signal: ", "Bit Rate: "}

type AccessPoint struct {
isVividType bool
address string
Expand Down Expand Up @@ -204,7 +206,7 @@ func (ap *AccessPoint) updateTeamWifiStatuses() error {

output, err := ap.runCommand("iwinfo")
if err == nil {
log.Printf("Access point status: %s\n", output)
logWifiInfo(output)
err = decodeWifiInfo(output, ap.TeamWifiStatuses[:])
}

Expand Down Expand Up @@ -285,6 +287,21 @@ func (ap *AccessPoint) generateTeamAccessPointConfig(team *model.Team, position
return strings.Join(commands, "\n"), nil
}

// Filters the given output from the "iwiinfo" command on the AP and logs the relevant parts.
func logWifiInfo(wifiInfo string) {
lines := strings.Split(wifiInfo, "\n")
var filteredLines []string
for _, line := range lines {
for _, infoLine := range accessPointInfoLines {
if strings.Contains(line, infoLine) {
filteredLines = append(filteredLines, line)
break
}
}
}
log.Printf("Access point status:\n%s\n", strings.Join(filteredLines, "\n"))
}

// Parses the given output from the "iwinfo" command on the AP and updates the given status structure with the result.
func decodeWifiInfo(wifiInfo string, statuses []TeamWifiStatus) error {
ssidRe := regexp.MustCompile("ESSID: \"([-\\w ]*)\"")
Expand Down

0 comments on commit 45bebc4

Please sign in to comment.