You've already forked prometheus-fail2ban-exporter
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
08157eda73 | |||
8c38a10245 | |||
04b84cc840 | |||
efa02e3c28 | |||
6818f034c0 | |||
77b69da93c | |||
fd58b20162 | |||
951ceccf67 | |||
24ee5d96bd | |||
7c2bcecf7a |
14
CHANGELOG.md
14
CHANGELOG.md
@ -7,6 +7,16 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
*Nothing yet*
|
*Nothing yet*
|
||||||
|
|
||||||
|
## [0.7.1] - 2022-09-18
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- (04b84cc) fix: report failure when server fails to start ([#23](https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/issues/23))
|
||||||
|
|
||||||
|
## [0.7.0] - 2022-06-19
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- (fd58b20) feat: option to exit on socket conn error ([#21](https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/issues/21))
|
||||||
|
|
||||||
## [0.6.0] - 2022-02-20
|
## [0.6.0] - 2022-02-20
|
||||||
*Rewrite CLI flags and environment variables*
|
*Rewrite CLI flags and environment variables*
|
||||||
|
|
||||||
@ -105,10 +115,12 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
|
|||||||
|
|
||||||
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
|
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
|
||||||
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
|
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
|
||||||
[Unreleased]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.1.0...main
|
[Unreleased]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.7.1...main
|
||||||
[0.1.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.0.0...0.1.0
|
[0.1.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.0.0...0.1.0
|
||||||
[0.2.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.1.0...0.2.0
|
[0.2.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.1.0...0.2.0
|
||||||
[0.3.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.2.0...0.3.0
|
[0.3.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.2.0...0.3.0
|
||||||
[0.4.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.3.0...0.4.0
|
[0.4.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.3.0...0.4.0
|
||||||
[0.5.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.4.0...0.5.0
|
[0.5.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.4.0...0.5.0
|
||||||
[0.6.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.5.0...0.6.0
|
[0.6.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.5.0...0.6.0
|
||||||
|
[0.7.0]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.6.0...0.7.0
|
||||||
|
[0.7.1]: https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/compare/0.7.0...0.7.1
|
||||||
|
@ -112,7 +112,7 @@ There are no configuration files.
|
|||||||
|
|
||||||
**CLI flags**
|
**CLI flags**
|
||||||
```
|
```
|
||||||
usage: fail2ban_exporter [<flags>]
|
usage: exporter [<flags>]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help Show context-sensitive help (also try --help-long and --help-man).
|
-h, --help Show context-sensitive help (also try --help-long and --help-man).
|
||||||
@ -127,6 +127,8 @@ Flags:
|
|||||||
username to use to protect endpoints with basic auth
|
username to use to protect endpoints with basic auth
|
||||||
--web.basic-auth.password=""
|
--web.basic-auth.password=""
|
||||||
password to use to protect endpoints with basic auth
|
password to use to protect endpoints with basic auth
|
||||||
|
--collector.f2b.exit-on-socket-connection-error
|
||||||
|
when set to true the exporter will immediately exit on a fail2ban socket connection error
|
||||||
```
|
```
|
||||||
|
|
||||||
**Environment variables**
|
**Environment variables**
|
||||||
@ -135,12 +137,13 @@ Each environment variable corresponds to a CLI flag.
|
|||||||
If both are specified, the CLI flag takes precedence.
|
If both are specified, the CLI flag takes precedence.
|
||||||
|
|
||||||
| Environment variable | Corresponding CLI flag |
|
| Environment variable | Corresponding CLI flag |
|
||||||
|---------------------------|----------------------------------|
|
|---------------------------------|---------------------------------------------------|
|
||||||
| `F2B_COLLECTOR_SOCKET` | `--collector.f2b.socket` |
|
| `F2B_COLLECTOR_SOCKET` | `--collector.f2b.socket` |
|
||||||
| `F2B_COLLECTOR_TEXT_PATH` | `--collector.textfile.directory` |
|
| `F2B_COLLECTOR_TEXT_PATH` | `--collector.textfile.directory` |
|
||||||
| `F2B_WEB_LISTEN_ADDRESS` | `--web.listen-address` |
|
| `F2B_WEB_LISTEN_ADDRESS` | `--web.listen-address` |
|
||||||
| `F2B_WEB_BASICAUTH_USER` | `--web.basic-auth.username` |
|
| `F2B_WEB_BASICAUTH_USER` | `--web.basic-auth.username` |
|
||||||
| `F2B_WEB_BASICAUTH_PASS` | `--web.basic-auth.password` |
|
| `F2B_WEB_BASICAUTH_PASS` | `--web.basic-auth.password` |
|
||||||
|
| `F2B_EXIT_ON_SOCKET_CONN_ERROR` | `--collector.f2b.exit-on-socket-connection-error` |
|
||||||
|
|
||||||
## 4. Building from source
|
## 4. Building from source
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import "fail2ban-prometheus-exporter/auth"
|
import "gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth"
|
||||||
|
|
||||||
type hashedBasicAuth struct {
|
type hashedBasicAuth struct {
|
||||||
username string
|
username string
|
||||||
|
@ -12,6 +12,7 @@ const (
|
|||||||
addressEnvName = "F2B_WEB_LISTEN_ADDRESS"
|
addressEnvName = "F2B_WEB_LISTEN_ADDRESS"
|
||||||
basicAuthUserEnvName = "F2B_WEB_BASICAUTH_USER"
|
basicAuthUserEnvName = "F2B_WEB_BASICAUTH_USER"
|
||||||
basicAuthPassEnvName = "F2B_WEB_BASICAUTH_PASS"
|
basicAuthPassEnvName = "F2B_WEB_BASICAUTH_PASS"
|
||||||
|
exitOnSocketConnErrorEnvName = "F2B_EXIT_ON_SOCKET_CONN_ERROR"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppSettings struct {
|
type AppSettings struct {
|
||||||
@ -20,6 +21,7 @@ type AppSettings struct {
|
|||||||
Fail2BanSocketPath string
|
Fail2BanSocketPath string
|
||||||
FileCollectorPath string
|
FileCollectorPath string
|
||||||
BasicAuthProvider *hashedBasicAuth
|
BasicAuthProvider *hashedBasicAuth
|
||||||
|
ExitOnSocketConnError bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -64,6 +66,11 @@ func readParamsFromCli(settings *AppSettings) {
|
|||||||
Default("").
|
Default("").
|
||||||
Envar(basicAuthPassEnvName).
|
Envar(basicAuthPassEnvName).
|
||||||
String()
|
String()
|
||||||
|
rawExitOnSocketConnError := kingpin.
|
||||||
|
Flag("collector.f2b.exit-on-socket-connection-error", "when set to true the exporter will immediately exit on a fail2ban socket connection error").
|
||||||
|
Default("false").
|
||||||
|
Envar(exitOnSocketConnErrorEnvName).
|
||||||
|
Bool()
|
||||||
|
|
||||||
kingpin.Parse()
|
kingpin.Parse()
|
||||||
|
|
||||||
@ -72,6 +79,7 @@ func readParamsFromCli(settings *AppSettings) {
|
|||||||
settings.Fail2BanSocketPath = *socketPath
|
settings.Fail2BanSocketPath = *socketPath
|
||||||
settings.FileCollectorPath = *fileCollectorPath
|
settings.FileCollectorPath = *fileCollectorPath
|
||||||
settings.setBasicAuthValues(*rawBasicAuthUsername, *rawBasicAuthPassword)
|
settings.setBasicAuthValues(*rawBasicAuthUsername, *rawBasicAuthPassword)
|
||||||
|
settings.ExitOnSocketConnError = *rawExitOnSocketConnError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (settings *AppSettings) setBasicAuthValues(rawUsername, rawPassword string) {
|
func (settings *AppSettings) setBasicAuthValues(rawUsername, rawPassword string) {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package f2b
|
package f2b
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fail2ban-prometheus-exporter/cfg"
|
|
||||||
"fail2ban-prometheus-exporter/socket"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/cfg"
|
||||||
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
@ -13,6 +14,7 @@ type Collector struct {
|
|||||||
lastError error
|
lastError error
|
||||||
socketConnectionErrorCount int
|
socketConnectionErrorCount int
|
||||||
socketRequestErrorCount int
|
socketRequestErrorCount int
|
||||||
|
exitOnSocketConnError bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExporter(appSettings *cfg.AppSettings, exporterVersion string) *Collector {
|
func NewExporter(appSettings *cfg.AppSettings, exporterVersion string) *Collector {
|
||||||
@ -23,6 +25,7 @@ func NewExporter(appSettings *cfg.AppSettings, exporterVersion string) *Collecto
|
|||||||
lastError: nil,
|
lastError: nil,
|
||||||
socketConnectionErrorCount: 0,
|
socketConnectionErrorCount: 0,
|
||||||
socketRequestErrorCount: 0,
|
socketRequestErrorCount: 0,
|
||||||
|
exitOnSocketConnError: appSettings.ExitOnSocketConnError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +44,9 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error opening socket: %v", err)
|
log.Printf("error opening socket: %v", err)
|
||||||
c.socketConnectionErrorCount++
|
c.socketConnectionErrorCount++
|
||||||
|
if c.exitOnSocketConnError {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package f2b
|
package f2b
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fail2ban-prometheus-exporter/socket"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package textfile
|
package textfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fail2ban-prometheus-exporter/cfg"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/cfg"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fail2ban-prometheus-exporter/auth"
|
|
||||||
"fail2ban-prometheus-exporter/cfg"
|
|
||||||
"fail2ban-prometheus-exporter/collector/f2b"
|
|
||||||
"fail2ban-prometheus-exporter/collector/textfile"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth"
|
||||||
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/cfg"
|
||||||
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/collector/f2b"
|
||||||
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/collector/textfile"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -85,7 +85,7 @@ func main() {
|
|||||||
log.Print("ready")
|
log.Print("ready")
|
||||||
|
|
||||||
err := <-svrErr
|
err := <-svrErr
|
||||||
log.Print(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module fail2ban-prometheus-exporter
|
module gitlab.com/hectorjsmith/fail2ban-prometheus-exporter
|
||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user