|
|
@@ -6,6 +6,8 @@ import ( |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
) |
|
|
|
|
|
|
|
//输入elk的json结构begin |
|
|
@@ -98,7 +100,7 @@ type ResultInfo struct { |
|
|
|
|
|
|
|
//发送post请求到elk |
|
|
|
func SendReqToElk(jsonStr []byte) (content string) { |
|
|
|
url := "http://192.168.207.35:5601/internal/bsearch" |
|
|
|
url := setting.ElkUrl |
|
|
|
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) |
|
|
|
req.Header.Set("Content-Type", "application/json") |
|
|
|
req.Header.Set("kbn-version", "7.13.2") |
|
|
@@ -126,17 +128,16 @@ func GetResultFromElk(resultinfo ResultInfo, jobResult string) (loaded int, tota |
|
|
|
func ProjectViewInit(User string, Project string, Gte string, Lte string) (projectViewInit InputInfo) { |
|
|
|
var inputStruct InputInfo |
|
|
|
inputStruct.Batch = make([]Batch, 1) |
|
|
|
inputStruct.Batch[0].Request.Params.Index = "filebeat-7.3.2*" |
|
|
|
inputStruct.Batch[0].Request.Params.Index = setting.Index |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Size = 0 |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields = make([]Fields, 1) |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Field = "@timestamptest" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Format = "date_time" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Field = setting.TimeField |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Format = setting.ElkTimeFormat |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Query.BoolIn.Filter = make([]Filter, 3) |
|
|
|
//限定查询时间 |
|
|
|
var timeRange Range |
|
|
|
timeRange.Timestamptest.Gte = Gte |
|
|
|
timeRange.Timestamptest.Lte = Lte |
|
|
|
timeRange.Timestamptest.Format = "strict_date_optional_time" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Query.BoolIn.Filter[0].Range = &timeRange |
|
|
|
//限定用户 |
|
|
|
var userName FilterMatchPhrase |
|
|
@@ -153,11 +154,11 @@ func ProjectViewInit(User string, Project string, Gte string, Lte string) (proje |
|
|
|
func AllProjectViewInit(MessageInfo string, NotProject string, Gte string, Lte string) (allProjectViewInit InputInfo) { |
|
|
|
var inputStruct InputInfo |
|
|
|
inputStruct.Batch = make([]Batch, 1) |
|
|
|
inputStruct.Batch[0].Request.Params.Index = "filebeat-7.3.2*" |
|
|
|
inputStruct.Batch[0].Request.Params.Index = setting.Index |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Size = 0 |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields = make([]Fields, 1) |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Field = "@timestamptest" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Format = "date_time" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Field = setting.TimeField |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Format = setting.ElkTimeFormat |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Query.BoolIn.Filter = make([]Filter, 2) |
|
|
|
//限定message |
|
|
|
var bool Bool |
|
|
@@ -169,7 +170,6 @@ func AllProjectViewInit(MessageInfo string, NotProject string, Gte string, Lte s |
|
|
|
var timeRange Range |
|
|
|
timeRange.Timestamptest.Gte = Gte |
|
|
|
timeRange.Timestamptest.Lte = Lte |
|
|
|
timeRange.Timestamptest.Format = "strict_date_optional_time" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Query.BoolIn.Filter[1].Range = &timeRange |
|
|
|
//限定非项目 |
|
|
|
// var boolIn BoolIn |
|
|
@@ -182,11 +182,11 @@ func AllProjectViewInit(MessageInfo string, NotProject string, Gte string, Lte s |
|
|
|
func TagNameInit(MessageInfo string, Tagname string, Gte string, Lte string) (projectViewInit InputInfo) { |
|
|
|
var inputStruct InputInfo |
|
|
|
inputStruct.Batch = make([]Batch, 1) |
|
|
|
inputStruct.Batch[0].Request.Params.Index = "filebeat-7.3.2*" |
|
|
|
inputStruct.Batch[0].Request.Params.Index = setting.Index |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Size = 0 |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields = make([]Fields, 1) |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Field = "@timestamptest" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Format = "date_time" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Field = setting.TimeField |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Fields[0].Format = setting.ElkTimeFormat |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Query.BoolIn.Filter = make([]Filter, 3) |
|
|
|
//限定message |
|
|
|
var bool Bool |
|
|
@@ -202,7 +202,6 @@ func TagNameInit(MessageInfo string, Tagname string, Gte string, Lte string) (pr |
|
|
|
var timeRange Range |
|
|
|
timeRange.Timestamptest.Gte = Gte |
|
|
|
timeRange.Timestamptest.Lte = Lte |
|
|
|
timeRange.Timestamptest.Format = "strict_date_optional_time" |
|
|
|
inputStruct.Batch[0].Request.Params.Body.Query.BoolIn.Filter[2].Range = &timeRange |
|
|
|
return inputStruct |
|
|
|
} |
|
|
@@ -242,7 +241,7 @@ func ViewInfo(viewInfo InputInfo) (totalView int) { |
|
|
|
// @param User string "用户名" |
|
|
|
// @param Project string "项目名" |
|
|
|
// @param Gte string "起始时间" 如time.Now().AddDate(0, 0, -1).Format(time.RFC3339) |
|
|
|
// @param Lte string "结束时间" |
|
|
|
// @param Lte string "结束时间" 如time.Now().Format(time.RFC3339) |
|
|
|
// @return totalView int "访问量" |
|
|
|
func AppointProjectView(User string, Project string, Gte string, Lte string) (totalView int) { |
|
|
|
InitInfo := ProjectViewInit(User, Project, Gte, Lte) |
|
|
|