Commit ba349856 authored by 李科's avatar 李科

feat: 添加OpenSearch

parent 537008ee
......@@ -20,7 +20,9 @@ require (
github.com/lib/pq v1.10.9
github.com/minio/minio-go/v7 v7.0.58
github.com/mojocn/base64Captcha v1.3.5
github.com/opensearch-project/opensearch-go v1.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.66.0
github.com/robfig/cron v1.2.0
github.com/satori/go.uuid v1.2.0
github.com/spf13/cast v1.5.0
......@@ -51,7 +53,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/henrylee2cn/ameda v1.5.0 // indirect
github.com/henrylee2cn/goutil v0.0.0-20220704075712-42f2ec55fe8d // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.3 // indirect
......@@ -65,7 +67,6 @@ require (
github.com/nyaruka/phonenumbers v1.1.7 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.66.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/sirupsen/logrus v1.9.2 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
......
......@@ -32,6 +32,7 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
......@@ -241,8 +242,11 @@ github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
......@@ -352,6 +356,8 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opensearch-project/opensearch-go v1.1.0 h1:eG5sh3843bbU1itPRjA9QXbxcg8LaZ+DjEzQH9aLN3M=
github.com/opensearch-project/opensearch-go v1.1.0/go.mod h1:+6/XHCuTH+fwsMJikZEWsucZ4eZMma3zNSeLrTtVGbo=
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
......@@ -403,7 +409,7 @@ github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
......@@ -558,6 +564,7 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
......@@ -593,6 +600,7 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
......@@ -608,8 +616,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
......@@ -665,8 +671,8 @@ google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
......@@ -821,6 +827,7 @@ sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h6
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 h1:bvLlAPW1ZMTWA32LuZMBEGHAUOcATZjzHcotf3SWweM=
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
......
......@@ -35,6 +35,7 @@ type ListAlertList struct {
Keyword string `json:"keyword" form:"keyword"` // 预警点/分类/指标
StartTime string `json:"start_time" form:"start_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
EndTime string `json:"end_time" form:"end_time" binding:"omitempty,datetime=2006-01-02 15:04:05"`
Pagination
}
type DisposeAlertList struct {
......
......@@ -14,3 +14,47 @@ type AlertListList struct {
TotalCount int64 `json:"total_count"`
List []AlertListItem `json:"list"`
}
type CatIndices struct {
Health string `json:"health"`
Status string `json:"status"`
Index string `json:"index"`
Uuid string `json:"uuid"`
Pri string `json:"pri"`
Rep string `json:"rep"`
DocsCount string `json:"docs.count"`
DocsDeleted string `json:"docs.deleted"`
StoreSize string `json:"store.size"`
PriStoreSize string `json:"pri.store.size"`
}
type OpenSearchSource struct {
Took int `json:"took"`
TimedOut bool `json:"timed_out"`
Shards Shards `json:"_shards"`
Hits Hits `json:"hits"`
}
type Shards struct {
Total int `json:"total"`
Successful int `json:"successful"`
Skipped int `json:"skipped"`
Failed int `json:"failed"`
}
type Total struct {
Value int `json:"value"`
Relation string `json:"relation"`
}
type SubHits struct {
Index string `json:"_index"`
Type string `json:"_type"`
ID string `json:"_id"`
Score float64 `json:"_score"`
Ignored []string `json:"_ignored"`
Source AlertListItem `json:"_source"`
}
type Hits struct {
Total Total `json:"total"`
MaxScore float64 `json:"max_score"`
Hits []SubHits `json:"hits"`
}
package client
import (
"crypto/tls"
"github.com/opensearch-project/opensearch-go"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"net/http"
)
var openSearchClient *opensearch.Client
func GetOpenSearch() (client *opensearch.Client, err error) {
if openSearchClient != nil {
return openSearchClient, nil
}
client, err = opensearch.NewClient(opensearch.Config{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Addresses: []string{conf.Options.OpenSearchAddresses},
Username: conf.Options.OpenSearchUserName,
Password: conf.Options.OpenSearchPassword,
})
if err != nil {
return
}
openSearchClient = client
return
}
......@@ -46,6 +46,10 @@ type Config struct {
AweRestURL string
KubernetesToken string
OpenSearchAddresses string
OpenSearchUserName string
OpenSearchPassword string
}
const (
......
......@@ -86,6 +86,9 @@ func initConfig() {
SmsSignName: util.SetEnvStr("SMS_SIGN_NAME", "比格数据"), // 签名
AweRestURL: util.SetEnvStr("AWE_REST_URL", "http://awecloud-rest/awecloud/rest"), // awecloud-rest
KubernetesToken: util.SetEnvStr("AWE_REST_K8S_TOKEN", "eyJhbGciOiJSUzI1NiIsImtpZCI6InJ1alJzNEVGamN5UC0wRU1rS1BKQ0JZVUtNNWpzR0t2bmlrSlJhY2Q3R00ifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJiZWFnbGUtc3lzdGVtIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6InJvb3QiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoicm9vdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjRlMDM0OTI3LTc0ZTMtNDQ5Yy1hN2RlLWExMGE3MjU1NGYyMCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpiZWFnbGUtc3lzdGVtOnJvb3QifQ.YPLE_E2kIeo-YFQtKScBt5p4KhnniJF9n3iWN2i9UMYS06lIsq2-2wBrgON-YsJihWJupYyDQRiZ9h8bUWTrQzhnpsnuJ_aUclKyAw3QOT9rjvZhJp7qP--27dmdspSHncKtvIiprWE7UTUKzvF33WsMB0fSYFqYXOggNFMoT-fXmWwUXjgar3op0iOl3c3deJ_GeBzFyLSHEuGM7OVdjU8032aUmTen0Kji_P1yB4-O3Iqd0OdVs33BQy_tycjbxhQ8TDEpqrqhLnXjAwJCprLDEpFMx7ODZbjB9Wmuns8yJhaRDxTO47rTME7ZIAxjZ-zLR_QybtW97rlwnUTaNw"), // k8s token
OpenSearchAddresses: util.SetEnvStr("Open_Search_Addresses", "https://so-opensearch.wodcloud.com"), // 短信验证码模板
OpenSearchUserName: util.SetEnvStr("Open_Search_User_Name", ""), // 短信验证码模板
OpenSearchPassword: util.SetEnvStr("Open_Search_Password", ""), // 短信验证码模板
}
}
......@@ -168,7 +171,7 @@ func initAnsibleSSH() {
fmt.Println(err.Error())
}
}
//f2, err := os.Create("/root/.ssh/id_rsa.pub")
//f2, err := os.CreateIndex("/root/.ssh/id_rsa.pub")
//defer f2.Close()
//if err != nil {
// fmt.Println(err.Error())
......
package service
import (
"context"
"errors"
"fmt"
"github.com/jinzhu/copier"
json "github.com/json-iterator/go"
"github.com/opensearch-project/opensearch-go/opensearchapi"
"github.com/thoas/go-funk"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"go.uber.org/zap"
"io"
"net/http"
"strings"
"xorm.io/xorm"
)
......@@ -15,6 +25,264 @@ type AlertListSvc struct {
User entity.SystemUserInfo
}
var (
OpenSearchIndex = "so_alert"
Mapping = strings.NewReader(`{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"index.max_result_window": "1000000"
},
"mappings": {
"properties": {
"id": {
"type": "integer"
},
"alert_point": {
"type": "keyword"
},
"alert_rules_id": {
"type": "keyword"
},
"risk_level": {
"type": "integer"
},
"alert_time": {
"type": "date",
"ignore_malformed": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"class_id": {
"type": "integer"
},
"class_parent_name": {
"type": "keyword"
},
"class_name": {
"type": "keyword"
},
"metric_config_id": {
"type": "keyword"
},
"metric_config_name": {
"type": "keyword"
},
"alert_rule_type": {
"type": "keyword"
},
"alert_rule_type_name": {
"type": "keyword"
},
"current_value": {
"type": "integer"
},
"notification_count": {
"type": "integer"
},
"push_count": {
"type": "integer"
},
"last_push_time": {
"type": "date",
"ignore_malformed": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"status": {
"type": "integer"
},
"disposed_list": {
"type": "nested",
"properties": {
"is_disposed": {
"type": "integer"
},
"disposal_content": {
"type": "keyword"
},
"disposal_user": {
"type": "keyword"
},
"disposal_time": {
"type": "date",
"ignore_malformed": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
},
"is_disposed": {
"type": "integer"
},
"close_remark": {
"type": "keyword"
},
"close_user": {
"type": "keyword"
},
"close_time": {
"type": "date",
"ignore_malformed": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"defer_push": {
"type": "integer"
},
"created_by": {
"type": "keyword"
},
"created_at": {
"type": "date",
"ignore_malformed": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"updated_by": {
"type": "keyword"
},
"updated_at": {
"type": "date",
"ignore_malformed": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"alert_condition": {
"properties": {
"thresholds_min": {
"type": "integer"
},
"thresholds_max": {
"type": "integer"
},
"risk_level": {
"type": "integer"
}
}
}
}
}
}`)
)
func (a *AlertListSvc) CreateIndex() error {
cli, err := client.GetOpenSearch()
if err != nil {
return err
}
res := opensearchapi.IndicesCreateRequest{
Index: OpenSearchIndex,
Body: Mapping,
}
do, err := res.Do(context.Background(), cli)
if err != nil {
return err
}
defer do.Body.Close()
if do.StatusCode != http.StatusOK {
return errors.New(do.String())
}
return nil
}
func (a *AlertListSvc) DeleteIndex() error {
cli, err := client.GetOpenSearch()
if err != nil {
return err
}
res := opensearchapi.IndicesDeleteRequest{
Index: []string{OpenSearchIndex},
}
do, err := res.Do(context.Background(), cli)
if err != nil {
return err
}
defer do.Body.Close()
if do.StatusCode != http.StatusOK {
return errors.New(do.String())
}
return nil
}
func (a *AlertListSvc) Indices() (indices []string, err error) {
var (
catIndicesList []response.CatIndices
)
cli, err := client.GetOpenSearch()
if err != nil {
return
}
res := opensearchapi.CatIndicesRequest{Format: "json"}
do, err := res.Do(context.Background(), cli)
if err != nil {
return
}
defer do.Body.Close()
if do.StatusCode != http.StatusOK {
err = errors.New(do.String())
return
}
body, err := io.ReadAll(do.Body)
if err != nil {
return
}
err = json.Unmarshal(body, &catIndicesList)
if err != nil {
return
}
funkGet := funk.Get(catIndicesList, "Index") //取一层
indices, ok := funkGet.([]string)
if !ok {
err = errors.New("funk.Get failed")
return
}
return
}
func (a *AlertListSvc) IndexSearch(req request.ListAlertList) (resp response.AlertListList, err error) {
var (
sources response.OpenSearchSource
)
cli, err := client.GetOpenSearch()
if err != nil {
return
}
content := strings.NewReader(fmt.Sprintf(`{
"query": {
"match_all": {}
},
"from": %d,
"size": %d
}`, req.GetPageSize()*(req.GetPage()-1), req.GetPageSize()))
res := opensearchapi.SearchRequest{
Index: []string{OpenSearchIndex},
Body: content,
}
do, err := res.Do(context.Background(), cli)
if err != nil {
return
}
defer do.Body.Close()
if do.StatusCode != http.StatusOK {
err = errors.New(do.String())
return
}
body, err := io.ReadAll(do.Body)
if err != nil {
return
}
err = json.Unmarshal(body, &sources)
if err != nil {
return
}
for _, hit := range sources.Hits.Hits {
resp.List = append(resp.List, hit.Source)
}
return
}
func (a *AlertListSvc) Update(session *xorm.Session, req request.UpdateAlertList) error {
now := jsontime.Now()
data := entity.AlertList{
......@@ -131,7 +399,7 @@ func (a *AlertListSvc) GetDataById(req request.DetailAlertList) (resp response.A
}
func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListList, err error) {
now := jsontime.Now()
/*now := jsontime.Now()
data1 := response.AlertListItem{
AlertList: entity.AlertList{
Id: 123,
......@@ -298,6 +566,9 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL
},
}
resp.List = append(resp.List, data1, data2)
resp.TotalCount = int64(len(resp.List))*/
resp, err = a.IndexSearch(req)
resp.TotalCount = int64(len(resp.List))
return
}
......
......@@ -104,7 +104,7 @@ func (d DocLibSvc) GetFile(fileName string) (obj io.Reader, err error) {
}
obj = io.Reader(object)
return obj, nil
//localFile, err := os.Create("C:/Users/25238/Desktop/123456.xlsx")
//localFile, err := os.CreateIndex("C:/Users/25238/Desktop/123456.xlsx")
//if err != nil {
// log.Fatalf("create local object error " + err.Error())
//}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment