mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-24 05:41:43 +02:00
Added utils.getIP function, set to run as a 60 tick scheduled task
This commit is contained in:
@@ -250,6 +250,9 @@ func ExecuteSchedules(tick int) {
|
||||
|
||||
if tick == 1 {
|
||||
|
||||
ip := taskGetSystemIP()
|
||||
log.Println("System IP is: " + ip)
|
||||
|
||||
release := taskSetReleaseVersion()
|
||||
log.Println("Setting api option flag for Edgeboxctl (" + release + " version)")
|
||||
|
||||
@@ -274,6 +277,11 @@ func ExecuteSchedules(tick int) {
|
||||
|
||||
}
|
||||
|
||||
if tick%60 == 0 {
|
||||
ip := taskGetSystemIP()
|
||||
log.Println("System IP is: " + ip)
|
||||
}
|
||||
|
||||
// Just add a schedule here if you need a custom one (every "tick hour", every "tick day", etc...)
|
||||
|
||||
}
|
||||
@@ -498,3 +506,31 @@ func taskGetStorageDevices() string {
|
||||
return string(devicesJSON)
|
||||
|
||||
}
|
||||
|
||||
func taskGetSystemIP() string {
|
||||
fmt.Println("Executing taskGetStorageDevices")
|
||||
|
||||
ip := system.GetIP()
|
||||
|
||||
db, err := sql.Open("sqlite3", utils.GetSQLiteDbConnectionDetails())
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
statement, err := db.Prepare("REPLACE into option (name, value, created, updated) VALUES (?, ?, ?, ?);") // Prepare SQL Statement
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
formatedDatetime := utils.GetSQLiteFormattedDateTime(time.Now())
|
||||
|
||||
_, err = statement.Exec("IP_ADDRESS", ip, formatedDatetime, formatedDatetime) // Execute SQL Statement
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
db.Close()
|
||||
|
||||
return ip
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user