Skip to content

Commit

Permalink
add: individual asset tag (location, inventory, ...) tags for each op…
Browse files Browse the repository at this point in the history
…n appliance
  • Loading branch information
paepckehh committed Dec 20, 2024
1 parent 45e7888 commit 72d4229
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 20 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ see opnborg-prometheus-grafana.nix
# Required
- OPN_APIKEY - OPNsense Backup User APIKEY [string, base64 encoded]
- OPN_APISECRET - OPNsense Backup User APISECRET [string, base64 encoded]
- OPN_TARGETS - list of OPNSense Target Server to Backup [string, hostnames, comma separated]
- OPN_TARGETS - list of OPNSense Target Server to Backup [string, hostnames, comma separated] [optional: add asset-tag, via # as seprator for each host]
- OPN_TARGETS_* - alternative: custom groups for OPNSense Target server [example: OPN_TARGETS_INTRANET="opn-int-01.lan:8443,..."]
- OPN_TARGETS_IMGURL_* - alternative: custom image url for customs groups within WebUI [example: OPN_TARGETS_IMGURL_INTRANET="https://paepcke.de/img/intra.png"]
# Optional
- OPN_PATH - specify a target path (absolut or releative) to store backups [string: defaults to '.']
- OPN_TLSKEYPIN - OPNsense TLS MitM proof Certificate Keypin [string]
Expand Down
10 changes: 5 additions & 5 deletions actionOPN.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// actionOPN, perform individual server backup
func actionOPN(server string, config *OPNCall, id int, wg *sync.WaitGroup) {
func actionOPN(server, tag string, config *OPNCall, id int, wg *sync.WaitGroup) {

// setup
defer wg.Done()
Expand Down Expand Up @@ -51,7 +51,7 @@ func actionOPN(server string, config *OPNCall, id int, wg *sync.WaitGroup) {
serverXML, err := fetchXML(server, config)
if err != nil {
displayChan <- []byte("[BACKUP][ERROR][FAIL:UNABLE-TO-FETCH-XML] " + server + err.Error())
setOPNStatus(config, server, id, ts, notice, degraded, false)
setOPNStatus(config, server, tag, id, ts, notice, degraded, false)
return
}

Expand All @@ -62,7 +62,7 @@ func actionOPN(server string, config *OPNCall, id int, wg *sync.WaitGroup) {
if config.Debug {
displayChan <- []byte("[BACKUP][SERVER][NO-CHANGE] " + server)
}
setOPNStatus(config, server, id, ts, notice, degraded, true)
setOPNStatus(config, server, tag, id, ts, notice, degraded, true)
return
}

Expand All @@ -74,9 +74,9 @@ func actionOPN(server string, config *OPNCall, id int, wg *sync.WaitGroup) {
// check xml file into storage
if err = checkIntoStore(config, server, "xml", serverXML, ts, sum); err != nil {
displayChan <- []byte("[BACKUP][ERROR][FAIL:XML-STORE-CHECKIN] " + err.Error())
setOPNStatus(config, server, id, ts, notice, degraded, false)
setOPNStatus(config, server, tag, id, ts, notice, degraded, false)
return
}
displayChan <- []byte("[BACKUP][OK][SUCCESS:XML-STORE-CHECKIN-OF-MODIFIED-XML]")
setOPNStatus(config, server, id, ts, notice, degraded, true)
setOPNStatus(config, server, tag, id, ts, notice, degraded, true)
}
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// global exported consts
const SemVer = "v0.1.50"
const SemVer = "v0.1.51"

// global var
var (
Expand Down
5 changes: 3 additions & 2 deletions example-env-config-unifi.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh
export OPN_TARGETS_STANDBY='opn00.lan:8443'
export OPN_TARGETS_INTRANET='opn01.lan:8443,opn02.lan:8443'
# export OPN_TARGETS='opn00.lan:8443,opn01.lan:8443#RACK-PROD01,opn02.lan:8443#RACK-PROD02'
export OPN_TARGETS_STANDBY='opn00.lan:8443#RACK-LAB'
export OPN_TARGETS_INTRANET='opn01.lan:8443#RACK-PROD01,opn02.lan:8443#RACK-PROD02'
export OPN_TARGETS_EXTERNAL='opn03.lan:8443,opn04.lan:8443'
export OPN_TARGETS_IMGURL_STANDBY='https://paepcke.de/res/hot.png'
export OPN_TARGETS_IMGURL_INTRANET='https://paepcke.de/res/int.png'
Expand Down
6 changes: 3 additions & 3 deletions httpd-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func getHive() string {
s.WriteString(" <tr><td>")
if grp.OPN {
for _, line := range hive {
if strings.Contains(line, srv) {
target := strings.Split(srv, "#")
if strings.Contains(line, target[0]) {
s.WriteString(line)
break
}
Expand Down Expand Up @@ -187,8 +188,7 @@ func getNavi() string {
s.WriteString(_nwin)
s.WriteString("><button><b>[ Unifi Dashboard ]</b></button></a> ")
}
if unifiWebUI != nil {
// if unifiWebUI != nil && !unifiEnable.Load() {
if unifiWebUI != nil && !unifiEnable.Load() {
s.WriteString(" <a href=\"")
s.WriteString(unifiWebUI.String())
s.WriteString("/")
Expand Down
2 changes: 1 addition & 1 deletion setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func checkSetRequiredOPN() bool {
}

if isEnv("OPN_TARGETS") {
tg = append(tg, OPNGroup{Name: "", Member: strings.Split(os.Getenv("OPN_TARGETS"), ",")})
tg = append(tg, OPNGroup{Name: "", Img: false, OPN: true, Member: strings.Split(os.Getenv("OPN_TARGETS"), ",")})
return true
}

Expand Down
26 changes: 22 additions & 4 deletions srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,19 @@ func srv(config *OPNCall) error {
// setup hive
servers = strings.Split(config.Targets, ",")
for _, server := range servers {
status := _na + " <b>Member: </b> " + server + " <b>Version: </b>n/a <b>Last Seen: </b>n/a<br>"
hive = append(hive, status)
s := strings.Split(server, "#")
switch len(s) {
case 1:
if len(s[0]) > 0 {
status := _na + " <b>Member: </b> " + s[0] + " <b>Version: </b>n/a <b>Last Seen: </b>n/a<br>"
hive = append(hive, status)
}
case 2:
if len(s[0]) > 0 && len(s[1]) > 0 {
status := _na + " <b>Member: </b> " + s[0] + " <b>Version: </b>n/a <b>Last Seen: </b>n/a <b>AssetTag: </b>" + s[1] + "<br>"
hive = append(hive, status)
}
}
}
}
displayChan <- []byte("[SERVICE][OPN-BACKUP-AND-MONITORING]" + state)
Expand Down Expand Up @@ -96,8 +107,15 @@ func srv(config *OPNCall) error {
displayChan <- []byte("[STARTING][BACKUP]")
}
for id, server := range servers {
wg.Add(1)
go actionOPN(server, config, id, &wg)
s := strings.Split(server, "#")
switch len(s) {
case 1:
wg.Add(1)
go actionOPN(s[0], "", config, id, &wg)
case 2:
wg.Add(1)
go actionOPN(s[0], s[1], config, id, &wg)
}
}

// wait till all worker done
Expand Down
10 changes: 7 additions & 3 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
)

// setOPNStatus sets the hive member server status
func setOPNStatus(config *OPNCall, server string, id int, ts time.Time, notice string, degraded, ok bool) {
func setOPNStatus(config *OPNCall, server, tag string, id int, ts time.Time, notice string, degraded, ok bool) {
year, month, _ := ts.Date()
archive := filepath.Join(_archive, strconv.Itoa(year), padMonth(strconv.Itoa(int(month))))
if ok {
Expand All @@ -35,8 +35,12 @@ func setOPNStatus(config *OPNCall, server string, id int, ts time.Time, notice s
linkVS := "<a href=\"https://" + server + _fwup + "\" " + _nwin + "><button><b>[" + ver + "]</b></button></a>"
linkCurrent := "<a href=\"./files/" + server + "/current.xml\"" + _nwin + "><button><b>[current.xml]</b></button></a>"
linkArchive := "<a href=\"./files/" + server + "/" + archive + "\" " + _nwin + "><button><b>[archive]</b></button></a>"
links := linkCurrent + " " + linkArchive
status := state + _b + linkUI + _b + linkVS + " <button><b>Last Seen:" + seen + "</b></button> " + links + "<br>"
links := " " + linkCurrent + " " + linkArchive
tags := ""
if tag != "" {
tags = " <button><b>[" + tag + "]</b></button>"
}
status := state + _b + linkUI + _b + linkVS + " <button><b>Last Seen:" + seen + "</b></button>" + tags + links + "<br>"
hiveMutex.Lock()
hive[id] = status
hiveMutex.Unlock()
Expand Down

0 comments on commit 72d4229

Please sign in to comment.