yats.git

commit 7a02e6e5c41d1addc2b3479fb0b678ea30d80fd6

Author: Paolo Lulli <paolo@lulli.net>

Always return maxpage

 client/apiclient.go | 2 --
 client/main.go | 4 ++--
 server/rest/rest-event.go | 7 +++++--
 server/rest/rest-metric.go | 16 ++++++++++------
 server/rest/rest-position.go | 18 +++++++++++-------


diff --git a/client/apiclient.go b/client/apiclient.go
index 32a7d23f1eae795c491d27fa747f8ef2399b6b49..c972411b7eb00a3c327a7979c9c68bd0e5cd6af9 100644
--- a/client/apiclient.go
+++ b/client/apiclient.go
@@ -48,8 +48,6 @@ func (c *YatsClient) ApiGet(endpoint string) string {
 	certKey := path.Join(c.config.ClientCertDir, c.config.ClientCn+".key")
 	cert := path.Join(c.config.ClientCertDir, c.config.ClientCn+".crt")
 
-	//fmt.Printf("cert: %s\nkey: %sendpoint:%s\n", cert, certKey, endpoint)
-
 	client := c.httpClient(certKey, cert)
 
 	req, err := http.NewRequest("GET", endpoint, nil)




diff --git a/client/main.go b/client/main.go
index 428119a29182ea1e90240540d824915c221e2fe5..bf1d6a8de418282082ae3500713031f5ebe343ad 100644
--- a/client/main.go
+++ b/client/main.go
@@ -7,6 +7,7 @@  *
  * @author Paolo Lulli <kevwe.com>
  * @copyright Paolo Lulli 2024
  */
+
 package main
 
 import (
@@ -40,8 +41,7 @@
 	cfg := config.GetClientConfig(configPath)
 	var yatsClient = YatsClient{config: cfg}
 
-	generatePki := flag.BoolP("csr", "c", false, "create CSR")
-
+	generatePki := flag.BoolP("pki-init", "", false, "create CSR")
 	sourceOption := flag.StringP("source", "s", "", "source application")
 
 	isShowPermsOption := flag.BoolP("show-permissions", "S", false, "show user permissions")




diff --git a/server/rest/rest-event.go b/server/rest/rest-event.go
index bd7e0049d2d4d7036df328809b547450daa83ef4..6185e491ff0765d4bc8d7316272117282c5d6582 100644
--- a/server/rest/rest-event.go
+++ b/server/rest/rest-event.go
@@ -92,7 +92,9 @@ 			eventsPack = db.EventsFrom(db.Session, clientCN, util.Int64ToTimeUTC(event.From), 100)
 		} else if event.From != 0 {
 			eventsPack = db.EventsBetween(db.Session, clientCN, util.Int64ToTimeUTC(event.From), util.Int64ToTimeUTC(event.To), 100)
 		}
-		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"ret": "OK", "data": eventsPack})
+
+		maxpage := eventsPack[len(eventsPack)-1].Etime
+		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"maxpage": maxpage, "data": eventsPack})
 	}
 }
 
@@ -123,6 +125,7 @@
 		var eventsPack []model.EventModel
 		eventsPack = db.EventsFrom(db.Session, clientCN, util.Int64ToTimeUTC(fromParamInt64), 100)
 
-		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"ret": "OK", "data": eventsPack})
+		maxpage := eventsPack[len(eventsPack)-1].Etime
+		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"maxpage": maxpage, "data": eventsPack})
 	}
 }




diff --git a/server/rest/rest-metric.go b/server/rest/rest-metric.go
index 2acfa37e3cb70c50910b68ab5ec3b71a55efeb0a..adf3a8bb509e93877f190b0fc7df03c8c338d110 100644
--- a/server/rest/rest-metric.go
+++ b/server/rest/rest-metric.go
@@ -27,6 +27,7 @@
 var (
 	//outfile, _ = os.Create(configuration.LogFile)
 	LOG = log.New(os.Stdout, "[YATS] ", log.Ldate|log.Ltime)
+	var MaxPageSize int32 = 100
 )
 
 // @BasePath /
@@ -100,11 +101,13 @@
 		var metricsPack []model.MetricModel
 
 		if metric.To == 0 {
-			metricsPack = db.MetricsFrom(db.Session, clientCN, metric.Name, util.Int64ToTimeUTC(metric.From), 100)
+			metricsPack = db.MetricsFrom(db.Session, clientCN, metric.Name, util.Int64ToTimeUTC(metric.From), MaxPageSize)
 		} else if metric.From != 0 {
-			metricsPack = db.MetricsBetween(db.Session, clientCN, metric.Name, util.Int64ToTimeUTC(metric.From), util.Int64ToTimeUTC(metric.To), 100)
+			metricsPack = db.MetricsBetween(db.Session, clientCN, metric.Name, util.Int64ToTimeUTC(metric.From), util.Int64ToTimeUTC(metric.To), MaxPageSize)
 		}
-		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"data": metricsPack})
+
+		maxpage := metricsPack[len(metricsPack)-1].Mtime
+		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"maxpage": maxpage, "data": metricsPack})
 	}
 }
 
@@ -136,8 +139,9 @@ 		clientCN := GetClientCN(c, cfg)
 		fmt.Printf("%s / %s ", clientCN, metric.Name)
 
 		var metricsPack []model.MetricModel
-		metricsPack = db.MetricsFrom(db.Session, clientCN, nameParam, util.Int64ToTimeUTC(fromParamInt64), 100)
+		metricsPack = db.MetricsFrom(db.Session, clientCN, nameParam, util.Int64ToTimeUTC(fromParamInt64), MaxPageSize)
 
-		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"data": metricsPack})
+		maxpage := metricsPack[len(metricsPack)-1].Mtime
+		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"maxpage": maxpage, "data": metricsPack})
 	}
-}
+}
\ No newline at end of file




diff --git a/server/rest/rest-position.go b/server/rest/rest-position.go
index 2bf257294c8cefa43486905f7ba15c16720a48b9..ff357283152d1d0e3884359ff88e652fe97d147a 100644
--- a/server/rest/rest-position.go
+++ b/server/rest/rest-position.go
@@ -86,13 +86,16 @@ 			}
 			clientCN = position.SourceApplication
 		}
 
-		var eventsPack []model.EventModel
+		var positionsPack []model.EventModel
 		if position.To == 0 {
-			eventsPack = db.EventsFrom(db.Session, clientCN, util.Int64ToTimeUTC(position.From), 100)
+			positionsPack = db.EventsFrom(db.Session, clientCN, util.Int64ToTimeUTC(position.From), 100)
 		} else if position.From != 0 {
-			eventsPack = db.EventsBetween(db.Session, clientCN, util.Int64ToTimeUTC(position.From), util.Int64ToTimeUTC(position.To), 100)
+			positionsPack = db.EventsBetween(db.Session, clientCN, util.Int64ToTimeUTC(position.From), util.Int64ToTimeUTC(position.To), 100)
 		}
-		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"ret": "OK", "data": eventsPack})
+
+		maxpage := positionsPack[len(positionsPack)-1].Etime
+		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"maxpage": maxpage, "data": positionsPack})
+
 	}
 }
 
@@ -120,9 +123,10 @@
 		clientCN := GetClientCN(c, cfg)
 		fmt.Printf("Client ID: %s\n ", clientCN)
 
-		var eventsPack []model.EventModel
-		eventsPack = db.EventsFrom(db.Session, clientCN, util.Int64ToTimeUTC(fromParamInt64), 100)
+		var positionsPack []model.EventModel
+		positionsPack = db.EventsFrom(db.Session, clientCN, util.Int64ToTimeUTC(fromParamInt64), 100)
 
-		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"ret": "OK", "data": eventsPack})
+		maxpage := positionsPack[len(positionsPack)-1].Etime
+		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"maxpage": maxpage, "data": positionsPack})
 	}
 }