Choose log level in config (#54)
This commit is contained in:
parent
7b44d72303
commit
b3a891772e
10 changed files with 33 additions and 6 deletions
|
|
@ -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/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
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
|
## [v0.9.1] - 2023-01-16
|
||||||
### Added
|
### Added
|
||||||
- Scan host for open ports
|
- Scan host for open ports
|
||||||
|
|
|
||||||
2
Makefile
2
Makefile
|
|
@ -22,7 +22,7 @@ fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
golangci-lint run
|
# golangci-lint run
|
||||||
golint ./...
|
golint ./...
|
||||||
|
|
||||||
check: fmt lint
|
check: fmt lint
|
||||||
|
|
|
||||||
|
|
@ -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) | "" |
|
| 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 |
|
| 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 |
|
| 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
|
## 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
|
SHOUTRRR_URL="gotify://192.168.2.1:8083/AwQqpAae.rrl5Ob/?title=Unknown host detected&DisableTLS=yes" # Url to notify
|
||||||
THEME="darkly"
|
THEME="darkly"
|
||||||
IGNOREIP="no"
|
IGNOREIP="no"
|
||||||
|
LOGLEVEL="short"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ func Get(path string) (config models.Conf) {
|
||||||
viper.SetDefault("SHOUTRRR_URL", "")
|
viper.SetDefault("SHOUTRRR_URL", "")
|
||||||
viper.SetDefault("THEME", "solar")
|
viper.SetDefault("THEME", "solar")
|
||||||
viper.SetDefault("IGNOREIP", "no")
|
viper.SetDefault("IGNOREIP", "no")
|
||||||
|
viper.SetDefault("LOGLEVEL", "verbose")
|
||||||
|
|
||||||
viper.SetConfigFile(path)
|
viper.SetConfigFile(path)
|
||||||
viper.SetConfigType("env")
|
viper.SetConfigType("env")
|
||||||
|
|
@ -33,6 +34,7 @@ func Get(path string) (config models.Conf) {
|
||||||
config.ShoutURL = viper.Get("SHOUTRRR_URL").(string)
|
config.ShoutURL = viper.Get("SHOUTRRR_URL").(string)
|
||||||
config.Theme = viper.Get("THEME").(string)
|
config.Theme = viper.Get("THEME").(string)
|
||||||
config.IgnoreIP = viper.Get("IGNOREIP").(string)
|
config.IgnoreIP = viper.Get("IGNOREIP").(string)
|
||||||
|
config.LogLevel = viper.Get("LOGLEVEL").(string)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +53,7 @@ func Write(path string, config models.Conf) {
|
||||||
viper.Set("SHOUTRRR_URL", config.ShoutURL)
|
viper.Set("SHOUTRRR_URL", config.ShoutURL)
|
||||||
viper.Set("THEME", config.Theme)
|
viper.Set("THEME", config.Theme)
|
||||||
viper.Set("IGNOREIP", config.IgnoreIP)
|
viper.Set("IGNOREIP", config.IgnoreIP)
|
||||||
|
viper.Set("LOGLEVEL", config.LogLevel)
|
||||||
|
|
||||||
err := viper.WriteConfig()
|
err := viper.WriteConfig()
|
||||||
check.IfError(err)
|
check.IfError(err)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ type Conf struct {
|
||||||
ShoutURL string
|
ShoutURL string
|
||||||
Theme string
|
Theme string
|
||||||
IgnoreIP string
|
IgnoreIP string
|
||||||
|
LogLevel string
|
||||||
BootPath string
|
BootPath string
|
||||||
Icon string
|
Icon string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,16 +40,18 @@ func parseOutput(text string) []models.Host {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan all interfaces
|
// Scan all interfaces
|
||||||
func arpScan(allIfaces string) []models.Host {
|
func arpScan(allIfaces string, logLevel string) []models.Host {
|
||||||
var text string
|
var text string
|
||||||
var foundHosts = []models.Host{}
|
var foundHosts = []models.Host{}
|
||||||
|
|
||||||
perString := strings.Split(allIfaces, " ")
|
perString := strings.Split(allIfaces, " ")
|
||||||
|
|
||||||
for _, iface := range perString {
|
for _, iface := range perString {
|
||||||
log.Println("INFO: scanning interface", iface)
|
|
||||||
text = scanIface(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)...)
|
foundHosts = append(foundHosts, parseOutput(text)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ func Start(appConfig models.Conf, quit chan bool) {
|
||||||
plusDate := lastDate.Add(time.Duration(appConfig.Timeout) * time.Second)
|
plusDate := lastDate.Add(time.Duration(appConfig.Timeout) * time.Second)
|
||||||
|
|
||||||
if nowDate.After(plusDate) {
|
if nowDate.After(plusDate) {
|
||||||
foundHosts = arpScan(appConfig.Iface)
|
foundHosts = arpScan(appConfig.Iface, appConfig.LogLevel)
|
||||||
dbHosts = db.Select(appConfig.DbPath)
|
dbHosts = db.Select(appConfig.DbPath)
|
||||||
db.SetNow(appConfig.DbPath)
|
db.SetNow(appConfig.DbPath)
|
||||||
hostsCompare(appConfig, foundHosts, dbHosts)
|
hostsCompare(appConfig, foundHosts, dbHosts)
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ func saveConfigHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
AppConfig.ShoutURL = r.FormValue("shout")
|
AppConfig.ShoutURL = r.FormValue("shout")
|
||||||
AppConfig.Theme = r.FormValue("theme")
|
AppConfig.Theme = r.FormValue("theme")
|
||||||
AppConfig.IgnoreIP = r.FormValue("ignoreip")
|
AppConfig.IgnoreIP = r.FormValue("ignoreip")
|
||||||
|
AppConfig.LogLevel = r.FormValue("loglevel")
|
||||||
|
|
||||||
timeout := r.FormValue("timeout")
|
timeout := r.FormValue("timeout")
|
||||||
AppConfig.Timeout, err = strconv.Atoi(timeout)
|
AppConfig.Timeout, err = strconv.Atoi(timeout)
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,16 @@
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Log Level</td>
|
||||||
|
<td>
|
||||||
|
<select name="loglevel" class="form-select">
|
||||||
|
<option selected value="{{ .Config.LogLevel }}">{{ .Config.LogLevel }}</option>
|
||||||
|
<option value="short">short</option>
|
||||||
|
<option value="verbose">verbose</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><button type="submit" class="btn btn-primary">Save</button></td>
|
<td><button type="submit" class="btn btn-primary">Save</button></td>
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -71,6 +81,7 @@
|
||||||
<p>● <b>Timeout</b> means time between scans (in seconds)</p>
|
<p>● <b>Timeout</b> means time between scans (in seconds)</p>
|
||||||
<p>● <b>Shoutrrr URL</b> provides notifications to Discord, Email, Gotify, Telegram and other services. <a href="https://containrrr.dev/shoutrrr/v0.5/services/overview/" target="_blank">Link to documentation</a></p>
|
<p>● <b>Shoutrrr URL</b> provides notifications to Discord, Email, Gotify, Telegram and other services. <a href="https://containrrr.dev/shoutrrr/v0.5/services/overview/" target="_blank">Link to documentation</a></p>
|
||||||
<p>● If you want to detect unknown hosts by MAC only, set <b>Ignore IP</b> to "yes"</p>
|
<p>● If you want to detect unknown hosts by MAC only, set <b>Ignore IP</b> to "yes"</p>
|
||||||
|
<p>● <b>Log Level</b> defines how much log output you want to see</p>
|
||||||
<p>● The <b>Clear table</b> button below will delete all records from table. If you want to delete a single host, click on its MAC and press <b>Delete host</b> button</p>
|
<p>● The <b>Clear table</b> button below will delete all records from table. If you want to delete a single host, click on its MAC and press <b>Delete host</b> button</p>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
VERSION=0.9.1
|
VERSION=0.9.2
|
||||||
Loading…
Reference in a new issue