Merge branch '8-fail-on-startup-if-database-file-does-not-exist' into 'main'
Resolve "Fail on startup if database file does not exist" Closes #8 See merge request hectorjsmith/fail2ban-prometheus-exporter!4
This commit is contained in:
commit
98c6da4796
4
db/db.go
4
db/db.go
@ -3,6 +3,7 @@ package db
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
const queryBadIpsPerJail = "SELECT j.name, (SELECT COUNT(1) FROM bips b WHERE j.name = b.jail) FROM jails j"
|
const queryBadIpsPerJail = "SELECT j.name, (SELECT COUNT(1) FROM bips b WHERE j.name = b.jail) FROM jails j"
|
||||||
@ -14,6 +15,9 @@ type Fail2BanDB struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MustConnectToDb(databasePath string) *Fail2BanDB {
|
func MustConnectToDb(databasePath string) *Fail2BanDB {
|
||||||
|
if _, err := os.Stat(databasePath); os.IsNotExist(err) {
|
||||||
|
log.Fatalf("database path does not exist: %v", err)
|
||||||
|
}
|
||||||
db, err := sql.Open("sqlite3", databasePath)
|
db, err := sql.Open("sqlite3", databasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user