-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsrvUnifiExport.go
47 lines (38 loc) · 1.06 KB
/
srvUnifiExport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package opnborg
import (
"crypto/sha256"
"time"
"paepcke.de/uniex"
)
// global
const _uniEx = "unifi-export"
// unfi Asset Inventory Export Server
func srvUnifiExport(config *OPNCall) {
// info
displayChan <- []byte("[UNIFI][EXPORT][SERVER][START][MONGODB-URI] " + config.Unifi.Export.URI.String())
c := &uniex.Config{
MongoDB: config.Unifi.Export.URI.String(),
Format: config.Unifi.Export.Format,
Scope: "client",
}
// loop forever
for {
// start notice
displayChan <- []byte("[UNIFI][EXPORT][START]")
// fetch and calc checksum
data, err := c.Export()
if err != nil {
displayChan <- []byte("[UNIFI][EXPORT][FAIL] " + err.Error())
continue
}
sum := sha256.Sum256(data)
// fetch and check unifi file into storage
if err = checkIntoStore(config, _uniEx, config.Unifi.Export.Format, data, time.Now(), sum); err != nil {
displayChan <- []byte("[UNIFI][EXPORT][FAIL:DATA-STORE-CHECKIN] " + err.Error())
}
// end notice
displayChan <- []byte("[UNIFI][EXPORT][END]")
// wait for next round trigger
<-updateUnifiExport
}
}