Created
July 25, 2018 18:32
-
-
Save dlopes7/73cd845f30618c3e96d547f9a38a8184 to your computer and use it in GitHub Desktop.
Controller TimeRanges
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"github.com/dlopes7/go-appdynamics-rest-api/appdrest" | |
"github.com/jinzhu/now" | |
"github.com/robfig/cron" | |
) | |
var client, err = appdrest.NewClient("https", "customer.saas.appdynamics.com", 443, "user", "password", "customer") | |
func updateTimeRange(name string, startTime time.Time, endTime time.Time) { | |
timeRange, err := client.TimeRange.GetTimeRangeByName(name) | |
if err != nil { | |
fmt.Printf("Não foi possível obter o Time Range: %s\n", err.Error()) | |
} | |
timeRange.ModifiedOn = time.Now().UnixNano() / 1000000 | |
timeRange.TimeRange.StartTime = startTime.UnixNano() / 1000000 | |
timeRange.TimeRange.EndTime = endTime.UnixNano() / 1000000 | |
_, err = client.TimeRange.UpdateTimeRange(*timeRange) | |
if err != nil { | |
fmt.Printf("Não foi possível alterar o Time Range %s: %s\n", name, err.Error()) | |
} | |
fmt.Printf("Time Range '%s' atualizado\n", name) | |
} | |
func main() { | |
c := cron.New() | |
c.AddFunc("@every 1m", func() { updateTimeRange("Auto - Mes Atual", now.BeginningOfMonth(), time.Now()) }) | |
c.AddFunc("@every 1m", func() { updateTimeRange("Auto - Semana Atual", now.BeginningOfWeek(), time.Now()) }) | |
c.AddFunc("@every 30m", func() { | |
updateTimeRange("Auto - Mes Passado", now.BeginningOfMonth().AddDate(0, -1, 0), now.BeginningOfMonth()) | |
}) | |
c.AddFunc("@every 30m", func() { | |
updateTimeRange("Auto - Semana Passada", now.BeginningOfWeek().AddDate(0, 0, -7), now.BeginningOfWeek()) | |
}) | |
c.Start() | |
select {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment