diff --git a/elk/kibanaClient/gjsonProcess.go b/elk/kibanaClient/gjsonProcess.go index 8bc8788579fafd1e830669158675289a19e40432..7c396eb3ac4060b0088cd9186e106641a19ae6cc 100644 --- a/elk/kibanaClient/gjsonProcess.go +++ b/elk/kibanaClient/gjsonProcess.go @@ -1,6 +1,7 @@ package kibanaClient import ( + "gitee.com/openeuler/PilotGo-plugin-elk/kibanaClient/meta" "github.com/tidwall/gjson" ) @@ -31,3 +32,54 @@ func VarsProcess(varssrc gjson.Result) []map[string]interface{} { }) return varsdst } + +func Gjson_GetPackageInfo(pkginfobytes []byte, searchitems ...string) *meta.PackageInfo_p { + pinfo := &meta.PackageInfo_p{ + Name: "", + PolicyTemplates: []meta.PolicyTemplate_p{}, + DataStreams: []meta.DataStream_p{}, + } + results := gjson.GetManyBytes(pkginfobytes, searchitems...) + pinfo.Name = results[0].String() + policy_templates_raw_arr := results[1].Array() + policy_template := meta.PolicyTemplate_p{ + Name: policy_templates_raw_arr[0].Get("name").String(), + Inputs: []meta.PolicyTemplateInput_p{}, + Multiple: policy_templates_raw_arr[0].Get("multiple").Bool(), + } + policy_templates_inputs_raw_arr := policy_templates_raw_arr[0].Get("inputs").Array() + for _, policy_templates_input_raw := range policy_templates_inputs_raw_arr { + policy_template_input := meta.PolicyTemplateInput_p{ + Type: policy_templates_input_raw.Get("type").String(), + Vars: []map[string]interface{}{}, + } + _vars := VarsProcess(policy_templates_input_raw.Get("vars")) + policy_template_input.Vars = _vars + policy_template.Inputs = append(policy_template.Inputs, policy_template_input) + } + pinfo.PolicyTemplates = append(pinfo.PolicyTemplates, policy_template) + + data_streams_raw_arr := results[2].Array() + for _, data_stream_raw := range data_streams_raw_arr { + data_stream := meta.DataStream_p{ + Type: data_stream_raw.Get("type").String(), + Dataset: data_stream_raw.Get("dataset").String(), + Streams: []meta.DataStreamStream_p{}, + Package: data_stream_raw.Get("package").String(), + Path: data_stream_raw.Get("path").String(), + } + data_stream_streams_raw_arr := data_stream_raw.Get("streams").Array() + for _, data_stream_stream_raw := range data_stream_streams_raw_arr { + data_stream_stream := meta.DataStreamStream_p{ + Input: data_stream_stream_raw.Get("input").String(), + Vars: []map[string]interface{}{}, + Enabled: data_stream_stream_raw.Get("enabled").Bool(), + } + _vars := VarsProcess(data_stream_stream_raw.Get("vars")) + data_stream_stream.Vars = _vars + data_stream.Streams = append(data_stream.Streams, data_stream_stream) + } + pinfo.DataStreams = append(pinfo.DataStreams, data_stream) + } + return pinfo +} diff --git a/elk/kibanaClient/meta/packagePolicy.go b/elk/kibanaClient/meta/packagePolicy.go new file mode 100644 index 0000000000000000000000000000000000000000..bfc43342cdaf47e71bc9ff674c4808d01f4b7fc5 --- /dev/null +++ b/elk/kibanaClient/meta/packagePolicy.go @@ -0,0 +1,26 @@ +package meta + +import "github.com/elastic/elastic-agent-libs/kibana" + +type PackagePolicyInput_p struct { + Enabled bool `json:"enabled"` + Vars map[string]interface{} `json:"vars"` + Streams map[string]PackagePolicyInputStream_p `json:"streams"` +} + +type PackagePolicyInputStream_p struct { + Enabled bool `json:"enabled"` + Vars map[string]interface{} `json:"vars"` +} + +type PackagePolicyRequest_p struct { + ID string `json:"id,omitempty"` + Name string `json:"name"` + Description string `json:"description"` + Namespace string `json:"namespace"` + PolicyID string `json:"policy_id"` + Package kibana.PackagePolicyRequestPackage `json:"package"` + Vars map[string]interface{} `json:"vars"` + Inputs map[string]PackagePolicyInput_p `json:"inputs"` + Force bool `json:"force"` +} \ No newline at end of file