Author: Paolo Lulli <paolo@lulli.net>
Timestamps WIP
client/main.go | 63 +++++++++++++++++++++++++++++++++++++--------------
diff --git a/client/main.go b/client/main.go index 17486917c344f6e7e284799131a3860b37aac484..d5cee29a754bf282c5b3394d58033c331e5c5ebc 100644 --- a/client/main.go +++ b/client/main.go @@ -12,6 +12,7 @@ import ( "fmt" "os" + "time" "yats/config" flag "github.com/spf13/pflag" @@ -34,31 +35,56 @@ cfg := config.GetClientConfig(configPath) var yatsClient = YatsClient{config: cfg} - generatePki := flag.BoolP("csr", "c", false, "Create Certificate Signing Request") + generatePki := flag.BoolP("csr", "c", false, "create CSR") - sourceOption := flag.StringP("source", "s", "", "Source Application") + sourceOption := flag.StringP("source", "s", "", "source application") - isShowPermsOption := flag.BoolP("show-permissions", "S", false, "Show User Permissions") + isShowPermsOption := flag.BoolP("show-permissions", "S", false, "show user permissions") - fromOption := flag.Int64("from", 0, "From tstamp") - toOption := flag.Int64("to", 0, "To tstamp") + fromOption := flag.Int64("from", 0, "from tstamp") + toOption := flag.Int64("to", 0, "to tstamp") - timestampOption := flag.Int64("timestamp", 0, "Metric/Event TimeStamp") + timestampOption := flag.Int64("timestamp", 0, "timeStamp") - writeEvent := flag.StringP("write-event", "E", "", "Write Event Name") - writeMetric := flag.StringP("write-metric", "M", "", "Write Metric Name") - metricValue := flag.StringP("metric-value", "v", "", "Metric Value") - writePosition := flag.StringP("write-position", "P", "", "Write Position Name") + writeEvent := flag.StringP("write-event", "E", "", "write event with name") + writeMetric := flag.StringP("write-metric", "M", "", "write metric with name") + metricValue := flag.StringP("metric-value", "v", "", "metric value") + writePosition := flag.StringP("write-position", "P", "", "write position name") - listEvents := flag.BoolP("list-events", "e", false, "List Events") - listMetrics := flag.StringP("list-metrics", "m", "", "List Metrics with Name") - listPositions := flag.StringP("list-positions", "p", "", "List Positions with Name") + listEvents := flag.BoolP("list-events", "e", false, "list events") + listMetrics := flag.StringP("list-metrics", "m", "", "list metrics with name") + listPositions := flag.StringP("list-positions", "p", "", "list positions with name") - longitudeOption := flag.Float64P("longitude", "o", 0, "Longitude") - latitudeOption := flag.Float64P("latitude", "a", 0, "Latitude") + longitudeOption := flag.Float64P("longitude", "o", 0, "longitude") + latitudeOption := flag.Float64P("latitude", "a", 0, "latitude") + + sinceSeconds := flag.BoolP("sec", "", false, "seconds ago") + sinceMinutes := flag.BoolP("min", "", false, "minutes ago") + sinceHours := flag.BoolP("hour", "", false, "hours ago") + sinceDays := flag.BoolP("day", "", false, "days ago") + sinceYears := flag.BoolP("year", "", false, "years ago") flag.Parse() + var actualTimestamp int64 + if 0 != *timestampOption { + if *sinceSeconds { + actualTimestamp = time.Now().Unix() - *timestampOption + } + if *sinceMinutes { + actualTimestamp = time.Now().Unix() - *timestampOption*60 + } + if *sinceHours { + actualTimestamp = time.Now().Unix() - *timestampOption*60*60 + } + if *sinceDays { + actualTimestamp = time.Now().Unix() - *timestampOption*60*60*24 + } + if *sinceYears { + actualTimestamp = time.Now().Unix() - *timestampOption*60*60*24*365 + } + } + if *isShowPermsOption { listResponse, err := yatsClient.PermissionsList() if err == nil { @@ -75,7 +101,7 @@ os.Exit(0) } if "" != *writeEvent { - saveEventResponse, err := yatsClient.EventSave(*writeEvent, *timestampOption) + saveEventResponse, err := yatsClient.EventSave(*writeEvent, actualTimestamp) if err == nil { fmt.Printf("%s", saveEventResponse) } else { @@ -85,7 +111,7 @@ os.Exit(0) } if "" != *writeMetric { - listResponse, err := yatsClient.MetricSave(*writeMetric, *metricValue, *timestampOption) + listResponse, err := yatsClient.MetricSave(*writeMetric, *metricValue, actualTimestamp) if err == nil { fmt.Printf("%s", listResponse) } else { @@ -93,8 +119,9 @@ fmt.Println(err) } os.Exit(0) } + if "" != *writePosition { - savePositionResponse, err := yatsClient.PositionSave(*writePosition, *latitudeOption, *longitudeOption, *timestampOption) + savePositionResponse, err := yatsClient.PositionSave(*writePosition, *latitudeOption, *longitudeOption, actualTimestamp) if err == nil { fmt.Printf("%s", savePositionResponse) } else {