Skip to content

Commit

Permalink
Update go to 1.22; README
Browse files Browse the repository at this point in the history
  • Loading branch information
ihatemodels committed Feb 24, 2024
1 parent 395aca9 commit 63b103b
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 38 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21'
go-version: '1.22'
- name: Check out code
uses: actions/checkout@v2
- name: "Run Linters"
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
uses: docker/metadata-action@v4
with:
images: |
st3ga/opnsense-exporter
ghcr.io/AthennaMind/opnsense-exporter
tags: |
type=semver,pattern={{version}}
Expand All @@ -60,12 +60,13 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Release build
id: release_build
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21 as build
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.22 as build

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG Version

WORKDIR /go/src/github.com/st3ga/opnsense-exporter
WORKDIR /go/src/github.com/AthennaMind/opnsense-exporter
COPY . .

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 \
Expand All @@ -17,11 +17,11 @@ RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 \

FROM --platform=${BUILDPLATFORM:-linux/amd64} gcr.io/distroless/static-debian12:latest

LABEL org.opencontainers.image.source=https://github.com/st3ga/opnsense-exporter
LABEL org.opencontainers.image.source=https://github.com/AthennaMind/opnsense-exporter
LABEL org.opencontainers.image.version=${Version}
LABEL org.opencontainers.image.authors="the st3ga Authors admins@st3ga.com"
LABEL org.opencontainers.image.authors="the AthennaMind Authors admins@AthennaMind.com"
LABEL org.opencontainers.image.title="opnsense-exporter"
LABEL org.opencontainers.image.description="Prometheus exporter for OPNsense metrics"
LABEL org.opencontainers.image.description="Prometheus exporter for OPNsense"

COPY --from=build /usr/bin/opnsense-exporter /
CMD ["/opnsense-exporter"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2023 the st3ga Authors
Copyright 2023 the AthennaMind Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ local-run:
--web.telemetry-path="/metrics" \
--web.listen-address=":8080" \
--runtime.gomaxprocs=4 \
--exporter.instance-label="opnsense-eu1" \
--exporter.instance-label="opnsense-local1" \
--exporter.disable-arp-table \
--exporter.disable-cron-table \
--opnsense.protocol="https" \
--opnsense.address="ops.domain.com" \
--opnsense.api-key="XXX" \
--opnsense.api-secret="XXX" \
--opnsense.address="${OPS_ADDRESS}" \
--opnsense.api-key="${OPS_API_KEY}" \
--opnsense.api-secret="${OPS_API_SECRET}" \
--web.disable-exporter-metrics \

test:
Expand Down
84 changes: 75 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
# OPNsense Prometheus Exporter

The OPNsense exporter enables you to monitor your OPNsense firewall from the API.
The missing OPNsense exporter for Prometheus

`Still under heavy development. The full metrics list is not yet implemented.`

## Table of Contents

**[About](#about)**
**[OPNsense User Permissions](#opnsense-user-permissions)**
**[Usage](#usage)**
**[Configuration](#configuration)**
- **[SSL/TLS](#ssltls)**
**[Grafana Dashboard](#grafana-dashboard)**
- **[About](#about)**
- **[OPNsense User Permissions](#opnsense-user-permissions)**
- **[Development](#development)**
- **[Usage](#usage)**
- **[Docker](#docker)**
- **[Docker Compose](#docker-compose)**
- **[Systemd](#systemd)**
- **[K8s](#k8s)**
- **[Configuration](#configuration)**
- **[SSL/TLS](#ssltls)**
- **[All Options](#all-options)**
- **[Grafana Dashboard](#grafana-dashboard)**

## About

This exporter delivers an extensive range of OPNsense-specific metrics, sourced directly from the OPNsense API. Focusing specifically on OPNsense, this exporter provides metrics about OPNsense, the plugin ecosystem and the services running on the firewall. However, it's recommended to use it with `node_exporter`. You can combine the metrics from both exporters in Grafana and in your Alert System to create a dashboard that displays the full picture of your system.
Focusing specifically on OPNsense, this exporter provides metrics about OPNsense, the plugin ecosystem and the services running on the firewall. However, it's recommended to use it with `node_exporter`. You can combine the metrics from both exporters in Grafana and in your Alert System to create a dashboard that displays the full picture of your system.

While the `node_exporter` must be installed on the firewall itself, this exporter can be installed on any machine that has network access to the OPNsense API.

## Development

This guide is for osx and Linux.

### Create API key and secret in OPNsense

`SYSTEM>ACCESS>USERS>[user]>API KEYS`

[OPNsense Documentation](https://docs.opnsense.org/development/how-tos/api.html#creating-keys)

### Run the exporter locally

```bash
OPS_ADDRESS="ops.example.com" OPS_API_KEY=your-api-key OPS_API_SECRET=your-api-secret make local-run
curl http://localhost:8080/metrics
```

### Before PR

- Make sure to sync the vendor if the dependencies have changed.

```bash
make sync-vendor
```

- Make sure to run the tests and linters.

```bash
make test
make lint
```

## OPNsense user permissions

**TODO**
Expand All @@ -27,6 +65,34 @@ While the `node_exporter` must be installed on the firewall itself, this exporte

**TODO**

### Docker

To run the exporter using Docker, you can use the following command:

```bash
docker run -p 8080:8080 ghcr.io/AthennaMind/opnsense-exporter:latest \
/opnsense-exporter \
--log.level=debug \
--log.format=json \
--opnsense.protocol=https \
--opnsense.address=ops.example.com \
--opnsense.api-key=your-api-key \
--opnsense.api-secret=your-api-secret \
--exporter.instance-label=opnsense-eu1 \
--web.listen-address=:8080
```
### Docker Compose

**TODO**

### Systemd

**TODO**

### K8s

**TODO**

## Configuration

To configure where your OPNsense API is located, you can use the following flags:
Expand Down Expand Up @@ -54,7 +120,7 @@ You can disable the exporter metrics using the following flag:

- `--web.disable-exporter-metrics` - Exclude metrics about the exporter itself (promhttp_*, process_*, go_*). Defaults to `false`.

Full list
### All Options

```bash
Flags:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/st3ga/opnsense-exporter
module github.com/AthennaMind/opnsense-exporter

go 1.21
go 1.22

require (
github.com/alecthomas/kingpin/v2 v2.3.2
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/arp_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package collector
import (
"fmt"

"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

type arpTableCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"

"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

const namespace = "opnsense"
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package collector
import (
"testing"

"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/st3ga/opnsense-exporter/opnsense"
)

func TestWithoutArpCollector(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/cron.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package collector

import (
"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

type cronCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/gateways.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package collector

import (
"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

type gatewaysCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package collector

import (
"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

type interfacesCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/openvpn.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package collector

import (
"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

type openVPNCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/protocol.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package collector

import (
"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

type protocolCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/services.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package collector

import (
"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

type servicesCollector struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/unbound_dns.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package collector

import (
"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/st3ga/opnsense-exporter/opnsense"
)

type unboundDNSCollector struct {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"runtime"
"syscall"

"github.com/AthennaMind/opnsense-exporter/internal/collector"
"github.com/AthennaMind/opnsense-exporter/opnsense"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -16,8 +18,6 @@ import (
"github.com/prometheus/common/promlog"
"github.com/prometheus/exporter-toolkit/web"
"github.com/prometheus/exporter-toolkit/web/kingpinflag"
"github.com/st3ga/opnsense-exporter/internal/collector"
"github.com/st3ga/opnsense-exporter/opnsense"
)

var version = ""
Expand Down
7 changes: 7 additions & 0 deletions opnsense/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ func (c *Client) do(method string, path EndpointPath, body io.Reader, responseSt
switch resp.Header.Get("Content-Encoding") {
case "gzip":
reader, err = gzip.NewReader(resp.Body)
if err != nil {
return &APICallError{
Endpoint: string(path),
Message: fmt.Sprintf("failed to decompress gzip response body: %s", err.Error()),
StatusCode: resp.StatusCode,
}
}
default:
reader = resp.Body
}
Expand Down

0 comments on commit 63b103b

Please sign in to comment.