mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
Merge pull request #12 from JohnsonRan/os-syno
feat: add Synology support
This commit is contained in:
@@ -10,6 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func OSName() string {
|
func OSName() string {
|
||||||
|
if synologyName := detectSynology(); synologyName != "" {
|
||||||
|
return synologyName
|
||||||
|
}
|
||||||
|
|
||||||
file, err := os.Open("/etc/os-release")
|
file, err := os.Open("/etc/os-release")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "Linux"
|
return "Linux"
|
||||||
@@ -30,3 +34,64 @@ func OSName() string {
|
|||||||
|
|
||||||
return "Linux"
|
return "Linux"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func detectSynology() string {
|
||||||
|
synologyFiles := []string{
|
||||||
|
"/etc/synoinfo.conf",
|
||||||
|
"/etc.defaults/synoinfo.conf",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range synologyFiles {
|
||||||
|
if info, err := os.Stat(file); err == nil && !info.IsDir() {
|
||||||
|
if synologyInfo := readSynologyInfo(file); synologyInfo != "" {
|
||||||
|
return synologyInfo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if info, err := os.Stat("/usr/syno"); err == nil && info.IsDir() {
|
||||||
|
return "Synology DSM"
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func readSynologyInfo(filename string) string {
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
var unique, udcCheckState string
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := strings.TrimSpace(scanner.Text())
|
||||||
|
|
||||||
|
if strings.HasPrefix(line, "unique=") {
|
||||||
|
unique = strings.Trim(strings.TrimPrefix(line, "unique="), `"`)
|
||||||
|
} else if strings.HasPrefix(line, "udc_check_state=") {
|
||||||
|
udcCheckState = strings.Trim(strings.TrimPrefix(line, "udc_check_state="), `"`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if unique != "" && strings.Contains(unique, "synology_") {
|
||||||
|
parts := strings.Split(unique, "_")
|
||||||
|
if len(parts) >= 3 {
|
||||||
|
model := strings.ToUpper(parts[len(parts)-1])
|
||||||
|
|
||||||
|
result := "Synology " + model
|
||||||
|
|
||||||
|
if udcCheckState != "" {
|
||||||
|
result += " DSM " + udcCheckState
|
||||||
|
} else {
|
||||||
|
result += " DSM"
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user