Merge branch 'main' of ssh://github.com/OliveTin/OliveTin
This commit is contained in:
commit
8ed3db0170
|
|
@ -93,6 +93,12 @@ message WhoAmIResponse {
|
||||||
string authenticatedUser = 1;
|
string authenticatedUser = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message SosReportRequest {}
|
||||||
|
|
||||||
|
message SosReportResponse {
|
||||||
|
string alert = 1;
|
||||||
|
}
|
||||||
|
|
||||||
service OliveTinApi {
|
service OliveTinApi {
|
||||||
rpc GetDashboardComponents(GetDashboardComponentsRequest) returns (GetDashboardComponentsResponse) {
|
rpc GetDashboardComponents(GetDashboardComponentsRequest) returns (GetDashboardComponentsResponse) {
|
||||||
option (google.api.http) = {
|
option (google.api.http) = {
|
||||||
|
|
@ -125,4 +131,10 @@ service OliveTinApi {
|
||||||
get: "/api/WhoAmI"
|
get: "/api/WhoAmI"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpc SosReport(SosReportRequest) returns (SosReportResponse) {
|
||||||
|
option (google.api.http) = {
|
||||||
|
get: "/api/sosreport"
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/OliveTin/OliveTin/internal/executor"
|
"github.com/OliveTin/OliveTin/internal/executor"
|
||||||
grpcapi "github.com/OliveTin/OliveTin/internal/grpcapi"
|
grpcapi "github.com/OliveTin/OliveTin/internal/grpcapi"
|
||||||
|
"github.com/OliveTin/OliveTin/internal/installationinfo"
|
||||||
"github.com/OliveTin/OliveTin/internal/oncron"
|
"github.com/OliveTin/OliveTin/internal/oncron"
|
||||||
"github.com/OliveTin/OliveTin/internal/onstartup"
|
"github.com/OliveTin/OliveTin/internal/onstartup"
|
||||||
updatecheck "github.com/OliveTin/OliveTin/internal/updatecheck"
|
updatecheck "github.com/OliveTin/OliveTin/internal/updatecheck"
|
||||||
|
|
@ -76,6 +77,11 @@ func init() {
|
||||||
|
|
||||||
warnIfPuidGuid()
|
warnIfPuidGuid()
|
||||||
|
|
||||||
|
installationinfo.Config = cfg
|
||||||
|
installationinfo.Build.Version = version
|
||||||
|
installationinfo.Build.Commit = commit
|
||||||
|
installationinfo.Build.Date = date
|
||||||
|
|
||||||
log.Info("Init complete")
|
log.Info("Init complete")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import (
|
||||||
acl "github.com/OliveTin/OliveTin/internal/acl"
|
acl "github.com/OliveTin/OliveTin/internal/acl"
|
||||||
config "github.com/OliveTin/OliveTin/internal/config"
|
config "github.com/OliveTin/OliveTin/internal/config"
|
||||||
executor "github.com/OliveTin/OliveTin/internal/executor"
|
executor "github.com/OliveTin/OliveTin/internal/executor"
|
||||||
|
installationinfo "github.com/OliveTin/OliveTin/internal/installationinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -108,6 +109,16 @@ func (api *oliveTinAPI) WhoAmI(ctx ctx.Context, req *pb.WhoAmIRequest) (*pb.WhoA
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *oliveTinAPI) SosReport(ctx ctx.Context, req *pb.SosReportRequest) (*pb.SosReportResponse, error) {
|
||||||
|
res := &pb.SosReportResponse{
|
||||||
|
Alert: "Your SOS Report has been logged to OliveTin logs.",
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("\n" + installationinfo.GetSosReport())
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Start will start the GRPC API.
|
// Start will start the GRPC API.
|
||||||
func Start(globalConfig *config.Config, ex *executor.Executor) {
|
func Start(globalConfig *config.Config, ex *executor.Executor) {
|
||||||
cfg = globalConfig
|
cfg = globalConfig
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package installationinfo
|
||||||
|
|
||||||
|
type buildInfo struct {
|
||||||
|
Commit string
|
||||||
|
Version string
|
||||||
|
Date string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Build = &buildInfo{}
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package installationinfo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type runtimeInfo struct {
|
||||||
|
OS string
|
||||||
|
OSReleasePrettyName string
|
||||||
|
Arch string
|
||||||
|
InContainer bool
|
||||||
|
LastBrowserUserAgent string
|
||||||
|
}
|
||||||
|
|
||||||
|
func isInContainer() bool {
|
||||||
|
if _, err := os.Stat("/.dockerenv"); errors.Is(err, os.ErrNotExist) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOsReleasePrettyName() string {
|
||||||
|
handle, err := os.Open("/etc/os-release")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(handle)
|
||||||
|
scanner.Split(bufio.ScanLines)
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
|
||||||
|
if strings.Contains(line, "PRETTY_NAME") {
|
||||||
|
return line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.Close()
|
||||||
|
|
||||||
|
return "notfound"
|
||||||
|
}
|
||||||
|
|
||||||
|
var Runtime = &runtimeInfo{
|
||||||
|
OS: runtime.GOOS,
|
||||||
|
Arch: runtime.GOARCH,
|
||||||
|
InContainer: isInContainer(),
|
||||||
|
OSReleasePrettyName: getOsReleasePrettyName(),
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package installationinfo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
config "github.com/OliveTin/OliveTin/internal/config"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Config *config.Config
|
||||||
|
|
||||||
|
type sosReportConfig struct {
|
||||||
|
CountOfActions int
|
||||||
|
LogLevel string
|
||||||
|
}
|
||||||
|
|
||||||
|
func configToSosreport(cfg *config.Config) *sosReportConfig {
|
||||||
|
return &sosReportConfig{
|
||||||
|
CountOfActions: len(cfg.Actions),
|
||||||
|
LogLevel: cfg.LogLevel,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSosReport() string {
|
||||||
|
ret := ""
|
||||||
|
|
||||||
|
ret += "### SOSREPORT START (copy all text to SOSREPORT END)\n"
|
||||||
|
|
||||||
|
out, _ := yaml.Marshal(Build)
|
||||||
|
ret += fmt.Sprintf("# Build: \n%+v\n", string(out))
|
||||||
|
|
||||||
|
out, _ = yaml.Marshal(Runtime)
|
||||||
|
ret += fmt.Sprintf("# Runtime:\n%+v\n", string(out))
|
||||||
|
|
||||||
|
out, _ = yaml.Marshal(configToSosreport(Config))
|
||||||
|
ret += fmt.Sprintf("# Config:\n%+v\n", string(out))
|
||||||
|
ret += "### SOSREPORT END (copy all text from SOSREPORT START)\n"
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
@ -3,15 +3,14 @@ package updatecheck
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
config "github.com/OliveTin/OliveTin/internal/config"
|
config "github.com/OliveTin/OliveTin/internal/config"
|
||||||
|
installationinfo "github.com/OliveTin/OliveTin/internal/installationinfo"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type updateRequest struct {
|
type updateRequest struct {
|
||||||
|
|
@ -63,14 +62,6 @@ func installationID(filename string) string {
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
func isInContainer() bool {
|
|
||||||
if _, err := os.Stat("/.dockerenv"); errors.Is(err, os.ErrNotExist) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// StartUpdateChecker will start a job that runs periodically, checking
|
// StartUpdateChecker will start a job that runs periodically, checking
|
||||||
// for updates.
|
// for updates.
|
||||||
func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config.Config, configDir string) {
|
func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config.Config, configDir string) {
|
||||||
|
|
@ -84,10 +75,10 @@ func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config
|
||||||
payload := updateRequest{
|
payload := updateRequest{
|
||||||
CurrentVersion: currentVersion,
|
CurrentVersion: currentVersion,
|
||||||
CurrentCommit: currentCommit,
|
CurrentCommit: currentCommit,
|
||||||
OS: runtime.GOOS,
|
OS: installationinfo.Runtime.OS,
|
||||||
Arch: runtime.GOARCH,
|
Arch: installationinfo.Runtime.Arch,
|
||||||
InstallationID: installationID(configDir + "/installation-id.txt"),
|
InstallationID: installationID(configDir + "/installation-id.txt"),
|
||||||
InContainer: isInContainer(),
|
InContainer: installationinfo.Runtime.InContainer,
|
||||||
}
|
}
|
||||||
|
|
||||||
s := cron.New(cron.WithSeconds())
|
s := cron.New(cron.WithSeconds())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue