-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c1888c
commit 0299b5d
Showing
7 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/Go-Lift-TV/discordnotifier-client | ||
|
||
go 1.15 | ||
go 1.16 | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.3.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package snapshot | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const synologyConf = "/etc/synoinfo.conf" | ||
|
||
type Synology struct { | ||
Build string `json:"last_admin_login_build"` // 254263 | ||
Manager string `json:"manager"` // Synology DiskStation | ||
Vendor string `json:"vender"` // Synology Inc. | ||
Model string `json:"upnpmodelname"` // DS1517+ | ||
Version string `json:"udc_check_state"` // 6.2.3 | ||
} | ||
|
||
/* | ||
"platform": "Synology Inc.", | ||
"platformFamily": "Synology DiskStation DS1517+", | ||
"platformVersion": "6.2.3-254263", | ||
*/ | ||
|
||
func (s *Snapshot) GetSynology(run bool) error { //nolint:cyclop | ||
if !run || !s.synology { | ||
return nil | ||
} | ||
|
||
file, err := os.Open(synologyConf) | ||
if err != nil { | ||
return fmt.Errorf("opening synology conf: %w", err) | ||
} | ||
defer file.Close() | ||
|
||
// Start reading from the file with a reader. | ||
var ( | ||
reader = bufio.NewReader(file) | ||
syn = &Synology{} | ||
) | ||
|
||
for { | ||
line, err := reader.ReadString('\n') | ||
if errors.Is(err, io.EOF) { | ||
break | ||
} else if err != nil { | ||
return fmt.Errorf("reading synology conf: %w", err) | ||
} | ||
|
||
lsplit := strings.Split(line, "=") | ||
if len(lsplit) < 2 { //nolint:gomnd | ||
continue | ||
} | ||
|
||
switch lsplit[0] { | ||
case "last_admin_login_build": | ||
syn.Build = strings.Trim(lsplit[1], "\n\"") | ||
case "manager": | ||
syn.Manager = strings.Trim(lsplit[1], "\n\"") | ||
case "vender": | ||
syn.Vendor = strings.Trim(lsplit[1], "\n\"") | ||
case "upnpmodelname": | ||
syn.Model = strings.Trim(lsplit[1], "\n\"") | ||
case "udc_check_state": | ||
syn.Version = strings.Trim(lsplit[1], "\n\"") | ||
} | ||
} | ||
|
||
s.setSynology(syn) | ||
|
||
return nil | ||
} | ||
|
||
func (s *Snapshot) setSynology(syn *Synology) { | ||
if s.System.InfoStat.Platform == "" && syn.Vendor != "" { | ||
s.System.InfoStat.Platform = syn.Vendor | ||
} | ||
|
||
if s.System.InfoStat.PlatformFamily == "" && syn.Manager != "" { | ||
s.System.InfoStat.PlatformFamily = syn.Manager + " " + syn.Model | ||
} | ||
|
||
if s.System.InfoStat.PlatformVersion == "" && syn.Version != "" { | ||
s.System.InfoStat.PlatformVersion = syn.Version + "-" + syn.Build | ||
} | ||
} |