diff --git a/CHANGELOG.md b/CHANGELOG.md index b3a0f2f..011b3cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [v0.9.2] - 2023-05-05 +### Added +- Choose log level in config + +### Changed +- Move to go-1.20 + ## [v0.9.1] - 2023-01-16 ### Added - Scan host for open ports diff --git a/Makefile b/Makefile index 1c9efd1..06dd5ee 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ fmt: go fmt ./... lint: - golangci-lint run + # golangci-lint run golint ./... check: fmt lint diff --git a/README.md b/README.md index 1ab5522..cd7631d 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Configuration can be done through config file or environment variables | SHOUTRRR_URL | Url to any notification service supported by [Shoutrrr](https://github.com/containrrr/shoutrrr) (gotify, email, telegram and others) or [Generic Webhook](https://github.com/containrrr/shoutrrr/blob/main/docs/services/generic.md) | "" | | THEME | Any theme name from https://bootswatch.com in lowcase | solar | | IGNOREIP | If you want to detect unknown hosts by MAC only, set this wariable to "yes" | no | +| LOGLEVEL | How much log output you want to see ("short" or "verbose") | verbose | ## Config file @@ -62,6 +63,7 @@ TIMEOUT="300" # 5 minutes SHOUTRRR_URL="gotify://192.168.2.1:8083/AwQqpAae.rrl5Ob/?title=Unknown host detected&DisableTLS=yes" # Url to notify THEME="darkly" IGNOREIP="no" +LOGLEVEL="short" ``` ## Options diff --git a/internal/conf/get-config.go b/internal/conf/get-config.go index 89e1ae9..ddfc049 100644 --- a/internal/conf/get-config.go +++ b/internal/conf/get-config.go @@ -17,6 +17,7 @@ func Get(path string) (config models.Conf) { viper.SetDefault("SHOUTRRR_URL", "") viper.SetDefault("THEME", "solar") viper.SetDefault("IGNOREIP", "no") + viper.SetDefault("LOGLEVEL", "verbose") viper.SetConfigFile(path) viper.SetConfigType("env") @@ -33,6 +34,7 @@ func Get(path string) (config models.Conf) { config.ShoutURL = viper.Get("SHOUTRRR_URL").(string) config.Theme = viper.Get("THEME").(string) config.IgnoreIP = viper.Get("IGNOREIP").(string) + config.LogLevel = viper.Get("LOGLEVEL").(string) return config } @@ -51,6 +53,7 @@ func Write(path string, config models.Conf) { viper.Set("SHOUTRRR_URL", config.ShoutURL) viper.Set("THEME", config.Theme) viper.Set("IGNOREIP", config.IgnoreIP) + viper.Set("LOGLEVEL", config.LogLevel) err := viper.WriteConfig() check.IfError(err) diff --git a/internal/models/models.go b/internal/models/models.go index 234b633..0cea6dc 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -22,6 +22,7 @@ type Conf struct { ShoutURL string Theme string IgnoreIP string + LogLevel string BootPath string Icon string } diff --git a/internal/scan/arpscan.go b/internal/scan/arpscan.go index 49b0261..6f1f974 100644 --- a/internal/scan/arpscan.go +++ b/internal/scan/arpscan.go @@ -40,16 +40,18 @@ func parseOutput(text string) []models.Host { } // Scan all interfaces -func arpScan(allIfaces string) []models.Host { +func arpScan(allIfaces string, logLevel string) []models.Host { var text string var foundHosts = []models.Host{} perString := strings.Split(allIfaces, " ") for _, iface := range perString { - log.Println("INFO: scanning interface", iface) text = scanIface(iface) - log.Println("INFO: found IPs:", text) + if logLevel != "short" { + log.Println("INFO: scanning interface", iface) + log.Println("INFO: found IPs:", text) + } foundHosts = append(foundHosts, parseOutput(text)...) } diff --git a/internal/scan/start.go b/internal/scan/start.go index ada0efa..875c1a8 100644 --- a/internal/scan/start.go +++ b/internal/scan/start.go @@ -22,7 +22,7 @@ func Start(appConfig models.Conf, quit chan bool) { plusDate := lastDate.Add(time.Duration(appConfig.Timeout) * time.Second) if nowDate.After(plusDate) { - foundHosts = arpScan(appConfig.Iface) + foundHosts = arpScan(appConfig.Iface, appConfig.LogLevel) dbHosts = db.Select(appConfig.DbPath) db.SetNow(appConfig.DbPath) hostsCompare(appConfig, foundHosts, dbHosts) diff --git a/internal/web/config.go b/internal/web/config.go index 935bb04..1f58a7d 100644 --- a/internal/web/config.go +++ b/internal/web/config.go @@ -55,6 +55,7 @@ func saveConfigHandler(w http.ResponseWriter, r *http.Request) { AppConfig.ShoutURL = r.FormValue("shout") AppConfig.Theme = r.FormValue("theme") AppConfig.IgnoreIP = r.FormValue("ignoreip") + AppConfig.LogLevel = r.FormValue("loglevel") timeout := r.FormValue("timeout") AppConfig.Timeout, err = strconv.Atoi(timeout) diff --git a/internal/web/templates/config.html b/internal/web/templates/config.html index 66d30af..6ad818a 100644 --- a/internal/web/templates/config.html +++ b/internal/web/templates/config.html @@ -51,6 +51,16 @@ + + Log Level + + + + @@ -71,6 +81,7 @@

Timeout means time between scans (in seconds)

Shoutrrr URL provides notifications to Discord, Email, Gotify, Telegram and other services. Link to documentation

● If you want to detect unknown hosts by MAC only, set Ignore IP to "yes"

+

Log Level defines how much log output you want to see

● The Clear table button below will delete all records from table. If you want to delete a single host, click on its MAC and press Delete host button


diff --git a/internal/web/templates/version b/internal/web/templates/version index 06d1998..9bc5d8f 100644 --- a/internal/web/templates/version +++ b/internal/web/templates/version @@ -1 +1 @@ -VERSION=0.9.1 \ No newline at end of file +VERSION=0.9.2 \ No newline at end of file