Skip to content

Commit

Permalink
improve: unifi webui, add asset tag, update docu
Browse files Browse the repository at this point in the history
  • Loading branch information
paepckehh committed Jan 11, 2025
1 parent 5e5e672 commit 2db3b98
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ see opnborg-prometheus-grafana.nix
- OPN_PROMETHEUS_WEBUI - Promometheus Web Console target & port [example: http://localhost:8443]
# Unifi
- OPN_UNIFI_WEBUI - Unifi Web Console target & port [example: http://localhost:8444]
- OPN_UNIFI_WEBUI - Unifi Web Console target & port [example: http://localhost:8444], use '#' to add asset tag
- OPN_UNIFI_BACKUP_USER - Unifi Backup User Account
- OPN_UNIFI_BACKUP_SECRET - Unifi Backup User Account Password
- OPN_UNIFI_BACKUP_IMGURL - Unifi Backup Group Image URL [example: export OPN_UNIFI_BACKUP_IMGURL="https://paepcke.de/img/unifi.png"]
Expand Down
8 changes: 4 additions & 4 deletions actionOPN.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func actionOPN(server, tag 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, tag, id, ts, notice, degraded, false)
setOPNStatus(config, server, tag, notice, id, ts, degraded, false)
return
}

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

Expand All @@ -74,9 +74,9 @@ func actionOPN(server, tag 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, tag, id, ts, notice, degraded, false)
setOPNStatus(config, server, tag, notice, id, ts, degraded, false)
return
}
displayChan <- []byte("[BACKUP][OK][SUCCESS:XML-STORE-CHECKIN-OF-MODIFIED-XML]")
setOPNStatus(config, server, tag, id, ts, notice, degraded, true)
setOPNStatus(config, server, tag, notice, id, ts, degraded, true)
}
3 changes: 2 additions & 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.60"
const SemVer = "v0.1.61"

// global var
var (
Expand Down Expand Up @@ -58,6 +58,7 @@ type OPNCall struct {
}
Unifi struct {
WebUI *url.URL
Tag string
Version string
Backup struct {
Enable bool
Expand Down
2 changes: 1 addition & 1 deletion example-env-config-unifi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export OPN_GRAFANA_DASHBOARD_HAPROXY='rEqu1u5ue/haproxy-2-full'
export OPN_GRAFANA_DASHBOARD_UNIFI='rEqu1u5ue/haproxy-2-full'
export OPN_WAZUH_WEBUI='http://localhost:9292'
export OPN_PROMETHEUS_WEBUI='http://localhost:9191'
export OPN_UNIFI_WEBUI='https://localhost:8443'
export OPN_UNIFI_WEBUI='https://localhost:8443#RACK-PROD03'
export OPN_UNIFI_VERSION='8.5.6'
export OPN_UNIFI_BACKUP_USER='admin'
export OPN_UNIFI_BACKUP_SECRET='start'
Expand Down
4 changes: 3 additions & 1 deletion littlehelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"net/url"
"os"
"strings"
"sync"
)

Expand Down Expand Up @@ -38,7 +39,8 @@ func startLog(config *OPNCall) {

// checkURL
func checkURL(env string) (*url.URL, error) {
if _, ok := os.LookupEnv(env); ok {
s := strings.Split(env, "#")
if _, ok := os.LookupEnv(s[0]); ok {
out, err := url.Parse(os.Getenv(env))
if err != nil {
return nil, errors.New("[SETUP][" + env + "][INVALID-URL] " + err.Error())
Expand Down
Binary file modified resources/screenshot02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func Setup() (*OPNCall, error) {
if config.Unifi.WebUI, err = checkURL("OPN_UNIFI_WEBUI"); err != nil {
return config, err
}
s := strings.Split(os.Getenv("OPN_UNIFI_WEBUI"), "#")
if len(s) > 1 {
config.Unifi.Tag = s[1]
}
unifiBackupEnable.Store(false)
unifiExportEnable.Store(false)
if config.Unifi.WebUI != nil {
Expand Down
7 changes: 4 additions & 3 deletions srvUnifiBackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
// perform unifi backup
func srvUnifiBackup(config *OPNCall) {

// info
displayChan <- []byte("[UNIFI][BACKUP][START][CONTROLLER] " + config.Unifi.WebUI.Hostname())
// setup
server, notice := config.Unifi.WebUI.Hostname(), ""
displayChan <- []byte("[UNIFI][BACKUP][START][CONTROLLER] " + server)

// setup session
jar, err := cookiejar.New(nil)
Expand Down Expand Up @@ -176,7 +177,7 @@ func srvUnifiBackup(config *OPNCall) {
}

// set unifi status
setUnifiStatus(config, time.Now(), notice, isReachable, backupOK)
setUnifiStatus(config, server, config.Unifi.Tag, notice, time.Now(), isReachable, backupOK)

// wait for next round trigger
<-updateUnifiBackup
Expand Down
12 changes: 7 additions & 5 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, tag string, id int, ts time.Time, notice string, degraded, ok bool) {
func setOPNStatus(config *OPNCall, server, tag, notice string, id int, ts time.Time, degraded, ok bool) {
year, month, _ := ts.Date()
archive := filepath.Join(_archive, strconv.Itoa(year), padMonth(strconv.Itoa(int(month))))
if ok {
Expand Down Expand Up @@ -54,7 +54,7 @@ func setOPNStatus(config *OPNCall, server, tag string, id int, ts time.Time, not
}

// setUnifiStatus
func setUnifiStatus(config *OPNCall, ts time.Time, notice string, responsive, backup bool) {
func setUnifiStatus(config *OPNCall, server, tag, notice string, ts time.Time, responsive, backup bool) {
// lock
unifiMutex.Lock()
defer unifiMutex.Unlock()
Expand All @@ -63,7 +63,6 @@ func setUnifiStatus(config *OPNCall, ts time.Time, notice string, responsive, ba
unifiStatus = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(unifiStatus, _unifi, ""), _na, ""), _fail, ""), _degraded, "")

// setup
server := config.Unifi.WebUI.Hostname()
year, month, _ := ts.Date()
archive := filepath.Join(_archive, strconv.Itoa(year), padMonth(strconv.Itoa(int(month))))

Expand All @@ -73,7 +72,7 @@ func setUnifiStatus(config *OPNCall, ts time.Time, notice string, responsive, ba
linkUI := "<a href=\"" + config.Unifi.WebUI.String() + "\" " + _nwin + "><button><b>[" + server + "]</b></button></a> "
linkCurrent := "<a href=\"./files/" + server + "/current.unf\"" + _nwin + "><button><b>[current.unf]</b></button></a>"
linkArchive := "<a href=\"./files/" + server + "/" + archive + "\" " + _nwin + "><button><b>[archive]</b></button></a>"
links := " <td><b>Backup: </b>" + linkCurrent + " " + linkArchive + "</td>"
links := " <td>" + linkCurrent + " " + linkArchive + "</td>"
if !backup {
state = _degraded
}
Expand All @@ -84,7 +83,10 @@ func setUnifiStatus(config *OPNCall, ts time.Time, notice string, responsive, ba
exportArchive := "<a href=\"./files/" + _uniEx + "/" + archive + "\" " + _nwin + "><button><b>[archive]</b></button></a>"
export = " <td><b>Export: </b>" + exportCurrent + " " + exportArchive + "</td>"
}
unifiStatus = state + " </td><td>" + linkUI + _b + seen + links + export + "<br>"
if tag != "" {
tag = "</td><td><b>" + tag + "</b>"
}
unifiStatus = state + " </td><td>" + linkUI + _b + links + export + seen + tag + "<br>"
return
}
unifiStatus = _fail + unifiStatus
Expand Down

0 comments on commit 2db3b98

Please sign in to comment.