Skip to content

Commit

Permalink
bugfix: timer thread main loop, add: unifi asset export
Browse files Browse the repository at this point in the history
  • Loading branch information
paepckehh committed Jan 10, 2025
1 parent 3a4cf89 commit c05387e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
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.55"
const SemVer = "v0.1.56"

// global var
var (
Expand Down
37 changes: 29 additions & 8 deletions srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ func srv(config *OPNCall) error {

// arm background timer
go func() {
time.Sleep(time.Duration(config.Sleep) * time.Second)
updateOPN <- true
if unifiBackupEnable.Load() {
updateUnifiBackup <- true
}
if unifiExportEnable.Load() {
updateUnifiExport <- true
// intit daily clock
last, _, _ := time.Now().Clock()
// loop forever
for {
time.Sleep(time.Duration(config.Sleep) * time.Second)
updateOPN <- true
now, _, _ := time.Now().Clock()
// check for day rollover, perform unifi backup/export
if now < last {
if unifiBackupEnable.Load() {
updateUnifiBackup <- true
}
if unifiExportEnable.Load() {
updateUnifiExport <- true
}
}
last, _, _ = time.Now().Clock()
}
}()

Expand All @@ -57,10 +67,18 @@ func srv(config *OPNCall) error {
if config.Unifi.Backup.Enable {
state = "[ENABLED]"
unifiStatus = _na + " <b>Member: </b> " + config.Unifi.WebUI.String() + " <b>Version: </b>n/a <b>Last Seen: </b>n/a<br>"
go unifiBackupServer(config)
go srvUnifiBackup(config)
}
displayChan <- []byte("[SERVICE][UNIFI-BACKUP-AND-MONITORING]" + state)

// spin up unifi asset export server
state = "[DISABLED]"
if config.Unifi.Export.Enable {
state = "[ENABLED]"
go srvUnifiExport(config)
}
displayChan <- []byte("[SERVICE][UNIFI-EXPORT-ASSET-INVENTORY]" + state)

// is opnsense hive is enabled?
state = "[DISABLED]"
if config.Enable {
Expand Down Expand Up @@ -121,7 +139,10 @@ func srv(config *OPNCall) error {
case 2:
wg.Add(1)
go actionOPN(s[0], s[1], config, id, &wg)
default:
displayChan <- []byte("[ERROR][CONFIGURATION] Line: " + server)
}

}

// wait till all worker done
Expand Down
2 changes: 1 addition & 1 deletion unifiBackup.go → srvUnifiBackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// perform unifi backup
func unifiBackupServer(config *OPNCall) {
func srvUnifiBackup(config *OPNCall) {

// info
displayChan <- []byte("[UNIFI][BACKUP][START][CONTROLLER] " + config.Unifi.WebUI.Hostname())
Expand Down
7 changes: 4 additions & 3 deletions unifiExport.go → srvUnifiExport.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package opnborg

// unfi Export Server
func unifiExportServer(config *OPNCall) {
// unfi Asset Inventory Export Server
func srvUnifiExport(config *OPNCall) {

// info
displayChan <- []byte("[UNIFI][EXPORT][START][MONGODB-URI] " + config.Unifi.Export.URI.String())
displayChan <- []byte("[UNIFI][EXPORT][SERVER][START][MONGODB-URI] " + config.Unifi.Export.URI.String())

// loop forever
for {

displayChan <- []byte("[UNIFI][EXPORT][START]")

displayChan <- []byte("[UNIFI][EXPORT][END]")

// wait for next round trigger
Expand Down

0 comments on commit c05387e

Please sign in to comment.