feature: Better sosreports (#308)

This commit is contained in:
James Read 2024-05-13 08:01:45 +01:00 committed by GitHub
parent ea1ce82ded
commit f43ece4263
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 9 deletions

View File

@ -8,8 +8,10 @@ import (
"net/http"
"os"
"path"
"path/filepath"
config "github.com/OliveTin/OliveTin/internal/config"
sv "github.com/OliveTin/OliveTin/internal/stringvariables"
updatecheck "github.com/OliveTin/OliveTin/internal/updatecheck"
)
@ -43,12 +45,15 @@ func findWebuiDir() string {
// search order must be deterministic - the order that the slice was defined in.
for i := 0; i < len(directoriesToSearch); i++ {
dir := directoriesToSearch[i]
absdir, _ := filepath.Abs(dir)
if _, err := os.Stat(dir); !os.IsNotExist(err) {
if _, err := os.Stat(absdir); !os.IsNotExist(err) {
log.WithFields(log.Fields{
"dir": dir,
"dir": absdir,
}).Infof("Found the webui directory")
sv.Set("internal.webuidir", absdir+" ("+dir+")")
return dir
}
}
@ -71,6 +76,9 @@ func setupCustomWebuiDir() {
if err != nil {
log.Warnf("Could not create themes directory: %v", err)
sv.Set("internal.themesdir", err.Error())
} else {
sv.Set("internal.themesdir", dir)
}
}

View File

@ -4,6 +4,8 @@ import (
"bufio"
"errors"
"os"
"path"
"path/filepath"
"runtime"
"strings"
)
@ -14,6 +16,32 @@ type runtimeInfo struct {
Arch string
InContainer bool
LastBrowserUserAgent string
User string
Uid string
FoundSshKey string
}
var Runtime = &runtimeInfo{
OS: runtime.GOOS,
Arch: runtime.GOARCH,
InContainer: isInContainer(),
OSReleasePrettyName: getOsReleasePrettyName(),
User: os.Getenv("USER"),
Uid: os.Getenv("UID"),
}
func refreshRuntimeInfo() {
Runtime.FoundSshKey = searchForSshKey()
}
func searchForSshKey() string {
path, _ := filepath.Abs(path.Join(os.Getenv("HOME"), ".ssh/id_rsa"))
if _, err := os.Stat(path); err == nil {
return path
}
return "none-found at " + path
}
func isInContainer() bool {
@ -46,10 +74,3 @@ func getOsReleasePrettyName() string {
return "notfound"
}
var Runtime = &runtimeInfo{
OS: runtime.GOOS,
Arch: runtime.GOARCH,
InContainer: isInContainer(),
OSReleasePrettyName: getOsReleasePrettyName(),
}

View File

@ -3,6 +3,7 @@ package installationinfo
import (
"fmt"
config "github.com/OliveTin/OliveTin/internal/config"
sv "github.com/OliveTin/OliveTin/internal/stringvariables"
"gopkg.in/yaml.v3"
"time"
)
@ -18,6 +19,10 @@ type sosReportConfig struct {
ListenAddressRestActions string
ListenAddressGrpcActions string
Timezone string
TimeNow string
ConfigDirectory string
WebuiDirectory string
ThemesDirectory string
}
func configToSosreport(cfg *config.Config) *sosReportConfig {
@ -30,10 +35,16 @@ func configToSosreport(cfg *config.Config) *sosReportConfig {
ListenAddressRestActions: cfg.ListenAddressRestActions,
ListenAddressGrpcActions: cfg.ListenAddressGrpcActions,
Timezone: time.Now().Location().String(),
TimeNow: time.Now().String(),
ConfigDirectory: cfg.GetDir(),
WebuiDirectory: sv.Get("internal.webuidir"),
ThemesDirectory: sv.Get("internal.themesdir"),
}
}
func GetSosReport() string {
refreshRuntimeInfo()
ret := ""
ret += "### SOSREPORT START (copy all text to SOSREPORT END)\n"