Skip to content

Commit

Permalink
Merge upstream (#3)
Browse files Browse the repository at this point in the history
* add and fix some metrics + refactor login (#1)

* update docker build workflow

* change name

* take all changed from upstream
  • Loading branch information
michelheusschen authored Oct 12, 2023
1 parent f4265e8 commit 9f90a16
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 199 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,32 @@ on:
pull_request:

jobs:
build:
runs-on: ubuntu-20.04
check:
runs-on: ubuntu-22.04
steps:
- name: Checkout the code
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.19'

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Lint with golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Run Go tests
run: go test -v ./...

- name: Run GoReleaser check
uses: goreleaser/goreleaser-action@v2.8.1
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: build --skip-validate
32 changes: 13 additions & 19 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,34 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout the code
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.19'

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: "charlie-haley"
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2.8.1
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88 changes: 25 additions & 63 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ builds:

dockers:
- image_templates:
- "docker.io/chhaley/omada_exporter:latest-amd64"
- "docker.io/chhaley/omada_exporter:{{ .Version }}-amd64"
- "docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
- "docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}-amd64"
- "docker.io/chhaley/omada_exporter:{{ .Major }}-amd64"

- "ghcr.io/charlie-haley/omada_exporter:latest-amd64"
- "ghcr.io/charlie-haley/omada_exporter:{{ .Version }}-amd64"
- "ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
- "ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}-amd64"
- "ghcr.io/charlie-haley/omada_exporter:{{ .Major }}-amd64"
- "ghcr.io/michelheusschen/omada_exporter:latest-amd64"
- "ghcr.io/michelheusschen/omada_exporter:{{ .Version }}-amd64"
- "ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
- "ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}-amd64"
- "ghcr.io/michelheusschen/omada_exporter:{{ .Major }}-amd64"
use: buildx
dockerfile: Dockerfile
goarch: amd64
Expand All @@ -48,17 +42,11 @@ dockers:
- "--build-arg=VCS_REF={{.FullCommit}}"
- "--platform=linux/amd64"
- image_templates:
- "docker.io/chhaley/omada_exporter:latest-arm64v8"
- "docker.io/chhaley/omada_exporter:{{ .Version }}-arm64v8"
- "docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64v8"
- "docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}-arm64v8"
- "docker.io/chhaley/omada_exporter:{{ .Major }}-arm64v8"

- "ghcr.io/charlie-haley/omada_exporter:latest-arm64v8"
- "ghcr.io/charlie-haley/omada_exporter:{{ .Version }}-arm64v8"
- "ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64v8"
- "ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}-arm64v8"
- "ghcr.io/charlie-haley/omada_exporter:{{ .Major }}-arm64v8"
- "ghcr.io/michelheusschen/omada_exporter:latest-arm64v8"
- "ghcr.io/michelheusschen/omada_exporter:{{ .Version }}-arm64v8"
- "ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64v8"
- "ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}-arm64v8"
- "ghcr.io/michelheusschen/omada_exporter:{{ .Major }}-arm64v8"
use: buildx
dockerfile: Dockerfile
goarch: arm64
Expand All @@ -74,57 +62,31 @@ dockers:
- "--platform=linux/arm64/v8"

docker_manifests:
## Docker Hub
- name_template: docker.io/chhaley/omada_exporter:latest
image_templates:
- docker.io/chhaley/omada_exporter:latest-amd64
- docker.io/chhaley/omada_exporter:latest-arm64v8

- name_template: docker.io/chhaley/omada_exporter:{{ .Version }}
image_templates:
- docker.io/chhaley/omada_exporter:{{ .Version }}-amd64
- docker.io/chhaley/omada_exporter:{{ .Version }}-arm64v8

- name_template: docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}
image_templates:
- docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64
- docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64v8

- name_template: docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}
image_templates:
- docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}-amd64
- docker.io/chhaley/omada_exporter:{{ .Major }}.{{ .Minor }}-arm64v8

- name_template: docker.io/chhaley/omada_exporter:{{ .Major }}
image_templates:
- docker.io/chhaley/omada_exporter:{{ .Major }}-amd64
- docker.io/chhaley/omada_exporter:{{ .Major }}-arm64v8

## GHCR
- name_template: ghcr.io/charlie-haley/omada_exporter:latest
- name_template: ghcr.io/michelheusschen/omada_exporter:latest
image_templates:
- ghcr.io/charlie-haley/omada_exporter:latest-amd64
- ghcr.io/charlie-haley/omada_exporter:latest-arm64v8
- ghcr.io/michelheusschen/omada_exporter:latest-amd64
- ghcr.io/michelheusschen/omada_exporter:latest-arm64v8

- name_template: ghcr.io/charlie-haley/omada_exporter:{{ .Version }}
- name_template: ghcr.io/michelheusschen/omada_exporter:{{ .Version }}
image_templates:
- ghcr.io/charlie-haley/omada_exporter:{{ .Version }}-amd64
- ghcr.io/charlie-haley/omada_exporter:{{ .Version }}-arm64v8
- ghcr.io/michelheusschen/omada_exporter:{{ .Version }}-amd64
- ghcr.io/michelheusschen/omada_exporter:{{ .Version }}-arm64v8

- name_template: ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}
- name_template: ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}
image_templates:
- ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64
- ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64v8
- ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64
- ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64v8

- name_template: ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}
- name_template: ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}
image_templates:
- ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}-amd64
- ghcr.io/charlie-haley/omada_exporter:{{ .Major }}.{{ .Minor }}-arm64v8
- ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}-amd64
- ghcr.io/michelheusschen/omada_exporter:{{ .Major }}.{{ .Minor }}-arm64v8

- name_template: ghcr.io/charlie-haley/omada_exporter:{{ .Major }}
- name_template: ghcr.io/michelheusschen/omada_exporter:{{ .Major }}
image_templates:
- ghcr.io/charlie-haley/omada_exporter:{{ .Major }}-amd64
- ghcr.io/charlie-haley/omada_exporter:{{ .Major }}-arm64v8
- ghcr.io/michelheusschen/omada_exporter:{{ .Major }}-amd64
- ghcr.io/michelheusschen/omada_exporter:{{ .Major }}-arm64v8

release:
prerelease: auto
Expand Down
6 changes: 3 additions & 3 deletions cmd/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"
"strings"

"github.com/charlie-haley/omada_exporter/pkg/api"
"github.com/charlie-haley/omada_exporter/pkg/collector"
"github.com/charlie-haley/omada_exporter/pkg/config"
"github.com/michelheusschen/omada_exporter/pkg/api"
"github.com/michelheusschen/omada_exporter/pkg/collector"
"github.com/michelheusschen/omada_exporter/pkg/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
zerolog "github.com/rs/zerolog"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/charlie-haley/omada_exporter
module github.com/michelheusschen/omada_exporter

go 1.19

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/charlie-haley/omada_exporter/cmd"
"github.com/michelheusschen/omada_exporter/cmd"
)

func main() {
Expand Down
21 changes: 20 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"net/http/cookiejar"
"time"

"github.com/charlie-haley/omada_exporter/pkg/config"
"github.com/michelheusschen/omada_exporter/pkg/config"
log "github.com/rs/zerolog/log"
)

type Client struct {
Expand All @@ -18,6 +19,24 @@ type Client struct {
SiteId string
}

func (c *Client) makeLoggedInRequest(req *http.Request) (*http.Response, error) {
loggedIn, err := c.IsLoggedIn()
if err != nil {
return nil, err
}
if !loggedIn {
log.Info().Msg(fmt.Sprintf("not logged in, logging in with user: %s", c.Config.Username))
err := c.Login()
if err != nil || c.token == "" {
log.Error().Err(err).Msg("failed to login")
return nil, err
}
}

setHeaders(req, c.token)
return c.httpClient.Do(req)
}

func setuphttpClient(insecure bool, timeout int) (*http.Client, error) {
jar, err := cookiejar.New(nil)
if err != nil {
Expand Down
26 changes: 6 additions & 20 deletions pkg/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ func (c *Client) GetClients() ([]NetworkClient, error) {

// gets clients by filters in omada - currentl supports SwitchMac
func (c *Client) getClientsWithFilters(filtersEnabled bool, mac string) ([]NetworkClient, error) {
loggedIn, err := c.IsLoggedIn()
if err != nil {
return nil, err
}
if !loggedIn {
log.Info().Msg(fmt.Sprintf("not logged in, logging in with user: %s", c.Config.Username))
err := c.Login()
if err != nil || c.token == "" {
log.Error().Err(err).Msg("Failed to login")
return nil, err
}
}

url := fmt.Sprintf("%s/%s/api/v2/sites/%s/clients", c.Config.Host, c.omadaCID, c.SiteId)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
Expand All @@ -64,8 +51,7 @@ func (c *Client) getClientsWithFilters(filtersEnabled bool, mac string) ([]Netwo

req.URL.RawQuery = q.Encode()

setHeaders(req, c.token)
resp, err := c.httpClient.Do(req)
resp, err := c.makeLoggedInRequest(req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -104,9 +90,9 @@ type NetworkClient struct {
SignalLevel float64 `json:"signalLevel"`
WifiMode float64 `json:"wifiMode"`
Ssid string `json:"ssid"`
Rssi float64 `json:"rssi"`
TrafficDown float64 `json:"trafficDown"`
TrafficUp float64 `json:"trafficUp"`
RxRate float64 `json:"rxRate"`
TxRate float64 `json:"txRate"`
Rssi float64 `json:"rssi"`
TrafficDown float64 `json:"trafficDown"`
TrafficUp float64 `json:"trafficUp"`
RxRate float64 `json:"rxRate"`
TxRate float64 `json:"txRate"`
}
16 changes: 1 addition & 15 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,13 @@ import (
)

func (c *Client) GetController() (*Controller, error) {
loggedIn, err := c.IsLoggedIn()
if err != nil {
return nil, err
}
if !loggedIn {
log.Info().Msg(fmt.Sprintf("not logged in, logging in with user: %s", c.Config.Username))
err := c.Login()
if err != nil || c.token == "" {
log.Error().Err(err).Msg("failed to login")
return nil, err
}
}

url := fmt.Sprintf("%s/%s/api/v2/maintenance/controllerStatus?", c.Config.Host, c.omadaCID)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}

setHeaders(req, c.token)
resp, err := c.httpClient.Do(req)
resp, err := c.makeLoggedInRequest(req)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 9f90a16

Please sign in to comment.