|
@@ -0,0 +1,61 @@
|
|
|
|
+package datacenter_client
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "encoding/json"
|
|
|
|
+ "errors"
|
|
|
|
+ "fmt"
|
|
|
|
+ "log"
|
|
|
|
+ "metawant.greentech.com.cn/gaoyagang/gt-common/httplib"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type ItemHistoryReq struct {
|
|
|
|
+ ServerIp string
|
|
|
|
+ ProjectId string
|
|
|
|
+ ItemName string
|
|
|
|
+ Stime string
|
|
|
|
+ Etime string
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type ItemHistoryResp struct {
|
|
|
|
+ ProjectId int `json:"project_id"`
|
|
|
|
+ ItemName string `json:"item_name"`
|
|
|
|
+ Val float64 `json:"val"`
|
|
|
|
+ HTime string `json:"h_time"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type ItemHistoryRespList struct {
|
|
|
|
+ List []ItemHistoryResp
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type ItemHistoryBody struct {
|
|
|
|
+ Code int `json:"code"`
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
+ Data ItemHistoryRespList `json:"data"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetItemHistory (req ItemHistoryReq) (resp []ItemHistoryResp, err error) {
|
|
|
|
+ url := fmt.Sprintf("http://%s/api/dtgateway/v1/item-history/info", req.ServerIp)
|
|
|
|
+ h := httplib.Get(url)
|
|
|
|
+ h.Header("X-Forwarded-For", "127.0.0.1")
|
|
|
|
+ h.Param("project_id", req.ProjectId)
|
|
|
|
+ h.Param("item_name", req.ItemName)
|
|
|
|
+ h.Param("stime", req.Stime)
|
|
|
|
+ h.Param("etime", req.Etime)
|
|
|
|
+ body, err := h.Bytes()
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("GetItemHistory Error:", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ result := &ItemHistoryBody{}
|
|
|
|
+ err = json.Unmarshal(body, &result)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("GetItemHistory Error:", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if result.Code != 200 {
|
|
|
|
+ err = errors.New(result.Msg)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ resp = result.Data.List
|
|
|
|
+ return
|
|
|
|
+}
|