diff --git a/.beagle.yml b/.beagle.yml index aec7d8d850d2f8a6c033f0e31aac96a67cbca346..e8a04b03d159b1c138fb6055d96741a5f5a63527 100644 --- a/.beagle.yml +++ b/.beagle.yml @@ -50,7 +50,7 @@ steps: base: registry.cn-hangzhou.aliyuncs.com/xmod/alpine:3 dockerfile: .beagle/dockerfile repo: smart-operation/so-operation-api - Version: "v1.0.0" + Version: "v3.0.0" channel: amd64 args: "TARGETOS=linux,TARGETARCH=amd64" registry: hub.wodcloud.com @@ -65,7 +65,7 @@ steps: namespace: smart-manage deployment: so-operation-api container: so-operation-api - image: hub.wodcloud.com/smart-operation/so-operation-api:v1.0.0-amd64 + image: hub.wodcloud.com/smart-operation/so-operation-api:v3.0.0-amd64 environment: KUBERNETES_SERVER: from_secret: KUBERNETES_SERVER @@ -80,7 +80,7 @@ steps: base: registry.cn-hangzhou.aliyuncs.com/xmod/alpine:3-arm64 dockerfile: .beagle/dockerfile repo: smart-operation/so-operation-api - Version: "v1.0.0" + Version: "v3.0.0" channel: arm64 args: "TARGETOS=linux,TARGETARCH=arm64" registry: hub.wodcloud.com @@ -97,8 +97,8 @@ steps: settings: insecure: true platforms: linux/amd64,linux/arm64 - template: hub.wodcloud.com/smart-operation/so-operation-api:v1.0.0-ARCH - target: hub.wodcloud.com/smart-operation/so-operation-api:v1.0.0 + template: hub.wodcloud.com/smart-operation/so-operation-api:v3.0.0-ARCH + target: hub.wodcloud.com/smart-operation/so-operation-api:v3.0.0 username: from_secret: REGISTRY_USER password: @@ -131,8 +131,8 @@ steps: REGISTRY_PASSWORD: from_secret: REGISTRY_PASSWORD settings: - source: hub.wodcloud.com/smart-operation/so-operation-api:v1.0.0-amd64 - target: hub.wodcloud.com/smart-operation/so-operation-api:v1.0-amd64 + source: hub.wodcloud.com/smart-operation/so-operation-api:v3.0.0-amd64 + target: hub.wodcloud.com/smart-operation/so-operation-api:v3.0-amd64 registry: hub.wodcloud.com - name: harbor-arm64 @@ -147,8 +147,8 @@ steps: REGISTRY_PASSWORD: from_secret: REGISTRY_PASSWORD settings: - source: hub.wodcloud.com/smart-operation/so-operation-api:v1.0.0-arm64 - target: hub.wodcloud.com/smart-operation/so-operation-api:v1.0-arm64 + source: hub.wodcloud.com/smart-operation/so-operation-api:v3.0.0-arm64 + target: hub.wodcloud.com/smart-operation/so-operation-api:v3.0-arm64 registry: hub.wodcloud.com --- diff --git a/go.mod b/go.mod index 212e98d97af729253cffe83724c0459117197dbb..551b09f35d13dd44fb9c1f53bd93d07f0b09b078 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( github.com/tealeg/xlsx v1.0.5 github.com/thoas/go-funk v0.9.3 github.com/valyala/fasthttp v1.47.0 + github.com/wanghuiyt/ding v0.0.2 go.uber.org/zap v1.24.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 k8s.io/apimachinery v0.27.3 diff --git a/go.sum b/go.sum index 4719f4b0ea4ac08d9829754db8309faa8f029c00..b857756f1fcb73d711f56f0b19963efd60b0ca6d 100644 --- a/go.sum +++ b/go.sum @@ -465,6 +465,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.47.0 h1:y7moDoxYzMooFpT5aHgNgVOQDrS3qlkfiP9mDtGGK9c= github.com/valyala/fasthttp v1.47.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= +github.com/wanghuiyt/ding v0.0.2 h1:6ZISlgCSy6MVeaFR8kAdniALMRqd56GyO9LlmYdTw/s= +github.com/wanghuiyt/ding v0.0.2/go.mod h1:T1vPz74YMmGCBVKZzVsen/YAYRZ2bvBYXldUyD7Y4vc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= diff --git a/src/bean/entity/alert_list.go b/src/bean/entity/alert_list.go index 4727e8b73600bb1b44c5b3e5ebc4638ba1d51a43..94f0ae2d5b1226c46662d0c4f54ac40f8a23cd44 100644 --- a/src/bean/entity/alert_list.go +++ b/src/bean/entity/alert_list.go @@ -24,6 +24,7 @@ type AlertList struct { LastPushTime jsontime.Time `json:"last_push_time"` // 最近推送时间 Status int `json:"status"` // 状态,1:已恢复 2:未恢复 3:已关闭 DisposedList []DisposedList `json:"disposed_list"` // 处置列表 + IsDisposed int `json:"is_disposed"` // 是否处置(工单管理),1:已处置,2:未处置 通过DisposedList逻辑处理回显 CloseRemark string `json:"close_remark"` // 关闭备注(预警关闭提醒) CloseUser string `json:"close_user"` // 关闭用户,预警关闭提醒 CloseTime jsontime.Time `json:"close_time"` // 关闭关闭时间,预警关闭提醒 diff --git a/src/bean/vo/request/alert_list.go b/src/bean/vo/request/alert_list.go index 4e10d2af6d729ffc8e4d33026e4a01c4749971bf..097e7c739e31eb1c7aeaf45078cb8e693b5ee2e0 100644 --- a/src/bean/vo/request/alert_list.go +++ b/src/bean/vo/request/alert_list.go @@ -1,6 +1,8 @@ package request -import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" +import ( + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" +) type DetailAlertList struct { Id int `json:"id" form:"id" binding:"required"` @@ -34,3 +36,9 @@ type ListAlertList struct { 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"` } + +type DisposeAlertList struct { + Id int `json:"id" form:"id" binding:"required"` + Status int `json:"status" form:"status" binding:"oneof=1 2"` // 状态,1:已恢复 2:未恢复 3:已关闭 + DisposalContent string `json:"disposal_content" binding:"required"` // 处置内容(工单管理,结果反馈) +} diff --git a/src/common/conf/options.go b/src/common/conf/options.go index 89228cba56d072f369d1d9b22cf774e6166a2a7b..7891ae49590cbfd9376e4b14a0546e7b167febe2 100644 --- a/src/common/conf/options.go +++ b/src/common/conf/options.go @@ -36,11 +36,13 @@ type Config struct { LocationUrl string LocationKey string PrivateKeySSH string - PublicKeySSH string - SmsAccessKeyId string - SmsAccessSecret string - SmsTemplateLogin string - SmsSignName string + //PublicKeySSH string + OrderDingTalkAccessToken string + OrderDingTalkSecret string + SmsAccessKeyId string + SmsAccessSecret string + SmsTemplateLogin string + SmsSignName string } const ( diff --git a/src/controller/alert_list.go b/src/controller/alert_list.go index 770e25f95b87951408224d9dd82e438648e4ff6d..8fd8a4bf282f3271cae45cd46d3df32e0f79ede1 100644 --- a/src/controller/alert_list.go +++ b/src/controller/alert_list.go @@ -102,3 +102,24 @@ func ListAlertList(c *gin.Context) { } SendJsonResponse(c, resp.OK, data) } + +func DisposeAlertList(c *gin.Context) { + var req request.DisposeAlertList + if err := c.ShouldBind(&req); err != nil { + SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) + return + } + db, err := client.GetDbClient() + if err != nil { + SendJsonResponse(c, resp.DbConnectError.WithError(err), nil) + return + } + + svc := service.AlertListSvc{User: header.GetUser(c)} + err = svc.DisposeAlertList(db.NewSession(), req) + if err != nil { + SendJsonResponse(c, resp.FAIL.WithError(err), nil) + return + } + SendJsonResponse(c, resp.OK, nil) +} diff --git a/src/controller/host_manage.go b/src/controller/host_manage.go index 070363b0d59d2285cc6830f93753ebeb4f210f27..4ae2ceb1b596c9cc1c9ffd0687bf6a75fe395787 100644 --- a/src/controller/host_manage.go +++ b/src/controller/host_manage.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cast" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" ) @@ -133,7 +134,7 @@ func AddHostManage(c *gin.Context) { // } //} - hostManageSvc := service.HostManageSvc{} + hostManageSvc := service.HostManageSvc{User: header.GetUser(c)} err = hostManageSvc.AddHostManage(req) if err != nil { SendJsonResponse(c, err, nil) @@ -169,7 +170,7 @@ func EditHostManage(c *gin.Context) { // } //} - hostManageSvc := service.HostManageSvc{} + hostManageSvc := service.HostManageSvc{User: header.GetUser(c)} err = hostManageSvc.EditHostManage(req) if err != nil { SendJsonResponse(c, err, nil) diff --git a/src/controller/task_manage.go b/src/controller/task_manage.go index a26eed585d530c3a30650cd51cef5f3c5ea4bcfc..3e6b3d1d6a297287f63de6ad2d9fc15f11d079bd 100644 --- a/src/controller/task_manage.go +++ b/src/controller/task_manage.go @@ -12,6 +12,7 @@ import ( "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/resp" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" "io" @@ -31,7 +32,7 @@ func AddTaskManage(c *gin.Context) { return } - taskManageSvc := service.TaskManageSvc{} + taskManageSvc := service.TaskManageSvc{User: header.GetUser(c)} id, err := taskManageSvc.AddTaskManage(req) if err != nil { SendJsonResponse(c, err, nil) @@ -53,7 +54,7 @@ func EditTaskManage(c *gin.Context) { return } - taskManageSvc := service.TaskManageSvc{} + taskManageSvc := service.TaskManageSvc{User: header.GetUser(c)} id, err := taskManageSvc.EditTaskManage(req) if err != nil { SendJsonResponse(c, err, nil) @@ -135,7 +136,7 @@ func ExecScript(c *gin.Context) { return } - taskManageSvc := service.TaskManageSvc{} + taskManageSvc := service.TaskManageSvc{User: header.GetUser(c)} taskManage, err := taskManageSvc.GetTaskManage(req.TaskId) if err != nil { SendJsonResponse(c, err, nil) diff --git a/src/controller/work_order_manage.go b/src/controller/work_order_manage.go index 9139253be708cf705690bbfbf1077083ecdbb3d1..9e9f4136f7fefcab5ea1f681d13bc7f7360bd87e 100644 --- a/src/controller/work_order_manage.go +++ b/src/controller/work_order_manage.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cast" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" ) @@ -18,7 +19,7 @@ func AddWorkOrderManage(c *gin.Context) { return } - workOrderManageSvc := service.WorkOrderManageSvc{} + workOrderManageSvc := service.WorkOrderManageSvc{User: header.GetUser(c)} err := workOrderManageSvc.AddWorkOrderManage(req) if err != nil { SendJsonResponse(c, err, nil) @@ -40,7 +41,7 @@ func EditWorkOrderManage(c *gin.Context) { return } - workOrderManageSvc := service.WorkOrderManageSvc{} + workOrderManageSvc := service.WorkOrderManageSvc{User: header.GetUser(c)} err := workOrderManageSvc.EditWorkOrderManage(req) if err != nil { SendJsonResponse(c, err, nil) @@ -142,7 +143,7 @@ func PushWorkOrderManage(c *gin.Context) { return } - workOrderManageSvc := service.WorkOrderManageSvc{} + workOrderManageSvc := service.WorkOrderManageSvc{User: header.GetUser(c)} err := workOrderManageSvc.PushWorkOrderManage(req) if err != nil { SendJsonResponse(c, err, nil) @@ -234,7 +235,7 @@ func ListWorkOrderMe(c *gin.Context) { return } - workOrderManageSvc := service.WorkOrderManageSvc{} + workOrderManageSvc := service.WorkOrderManageSvc{User: header.GetUser(c)} total, list, err := workOrderManageSvc.ListWorkOrderMe(req) if err != nil { SendJsonPageResponse(c, err, nil, 0) @@ -242,3 +243,15 @@ func ListWorkOrderMe(c *gin.Context) { } SendJsonPageResponse(c, resp.OK, list, total) } + +// WorkOrderPushNoteMsg 我的业务工单列表 +func WorkOrderPushNoteMsg(c *gin.Context) { + phone := c.Query("phone") + + err := service.WorkOrderPushNoteMsg(phone) + if err != nil { + SendJsonResponse(c, err, nil) + return + } + SendJsonResponse(c, resp.OK, nil) +} diff --git a/src/main.go b/src/main.go index 16830ea05a3843dd7d0244ebca4d16d7ad86c48c..089bb80e04e34c291bf0f4f555cbbba2a6f26dc6 100644 --- a/src/main.go +++ b/src/main.go @@ -56,33 +56,34 @@ func initConfig() { conf.LoggerLevel = util.SetEnvStr("LOG_LEVEL", "info") conf.RunMode = util.SetEnvStr("GIN_MODE", "debug") // project run mode, available parameters: debug、release conf.Options = &conf.Config{ - Prefix: *prefix, - DbURL: util.SetEnvStr("DB_URL", "host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"), - DbDriver: util.SetEnvStr("DB_DRIVER", "postgres"), - RedisURL: util.SetEnvStr("REDIS_URL", "localhost:7001"), - RedisDB: 0, - RedisTag: "bg", - LogDirPrefix: util.SetEnvStr("LOG_DIR_PREFIX", "/app/log"), // 日志目录 - LogDirName: util.SetEnvStr("LOG_NAME", "syslog"), // 日志名称 - LogSaveDays: util.SetEnvInt("LOG_SAVE_DAYS", 7), // 日志最大存储天数 - LogMode: util.SetEnvInt("LOG_MODE", 1), // 1.标准打印 2.输出文件 - ArgBool: util.SetEnvBool("ARG_BOOL", false), // 示例参数 - ArgInt: util.SetEnvInt("ARG_INT", 10), // 示例参数 - MinioServer: util.SetEnvStr("MINIO_SERVER", "https://cache.wodcloud.com"), // Minio 服务地址 - MinioAccessKey: util.SetEnvStr("MINIO_ACCESS_KEY", "beagleadmin"), // Minio Access Key - MinioSecretKey: util.SetEnvStr("MINIO_SECRET_KEY", "H76cPmwvH7vJ"), // Minio Secret - MinioBucket: util.SetEnvStr("MINIO_BUCKET", "so-operation"), // Minio Bucket - //TempDirPrefix: util.SetEnvStr("TEMP_DIR_PREFIX", "/app/xlsx/"), //模板目录前缀 + Prefix: *prefix, + DbURL: util.SetEnvStr("DB_URL", "host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"), + DbDriver: util.SetEnvStr("DB_DRIVER", "postgres"), + RedisURL: util.SetEnvStr("REDIS_URL", "localhost:7001"), + RedisDB: 0, + RedisTag: "bg", + LogDirPrefix: util.SetEnvStr("LOG_DIR_PREFIX", "/app/log"), // 日志目录 + LogDirName: util.SetEnvStr("LOG_NAME", "syslog"), // 日志名称 + LogSaveDays: util.SetEnvInt("LOG_SAVE_DAYS", 7), // 日志最大存储天数 + LogMode: util.SetEnvInt("LOG_MODE", 1), // 1.标准打印 2.输出文件 + ArgBool: util.SetEnvBool("ARG_BOOL", false), // 示例参数 + ArgInt: util.SetEnvInt("ARG_INT", 10), // 示例参数 + MinioServer: util.SetEnvStr("MINIO_SERVER", "https://cache.wodcloud.com"), // Minio 服务地址 + MinioAccessKey: util.SetEnvStr("MINIO_ACCESS_KEY", "beagleadmin"), // Minio Access Key + MinioSecretKey: util.SetEnvStr("MINIO_SECRET_KEY", "H76cPmwvH7vJ"), // Minio Secret + MinioBucket: util.SetEnvStr("MINIO_BUCKET", "so-operation"), // Minio Bucket PrometheusHost: util.SetEnvStr("PROMETHEUS_HOST", "https://prometheus.wodcloud.com"), // Prometheus Host AccessRuleModeKey: "accessRuleMode", LocationUrl: util.SetEnvStr("LOCATION_URL", "https://apis.map.qq.com/ws/location/v1/ip"), LocationKey: util.SetEnvStr("LOCATION_KEY", "QKFBZ-PGGWJ-VZQFF-FHPA7-QWT5H-YHF4T"), - PrivateKeySSH: util.SetEnvStr("PRIVATE_KEY_SSH", "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAlwAAAAdzc2gtcn\nNhAAAAAwEAAQAAAIEAsOFk9OUB8wg9fd+PDHyX8nEtTSPSZY+tjxq2da1Pf5FkIn+U1da6\nh2eqowF9lnyvlt7uEledTIWQZDGWToGYCZnRommSZEpo/vII+l1P28bJVHfgWFCqmxNfIB\nZFQ4KrOp9rXKidmrd8flhK/NTLJNqryrhhIiDs3CTyAliscIsAAAIQTuM2gU7jNoEAAAAH\nc3NoLXJzYQAAAIEAsOFk9OUB8wg9fd+PDHyX8nEtTSPSZY+tjxq2da1Pf5FkIn+U1da6h2\neqowF9lnyvlt7uEledTIWQZDGWToGYCZnRommSZEpo/vII+l1P28bJVHfgWFCqmxNfIBZF\nQ4KrOp9rXKidmrd8flhK/NTLJNqryrhhIiDs3CTyAliscIsAAAADAQABAAAAgDjcfGPtqq\n7CG2J3l7jf5MjfcTy3I0/a3GSApd82k7PivVoJwYLswJH+1XAJbqIN+zR4/fePitWqqjxL\nZJJgPstuXpBZuJDvGwMqfl7wHRL2Qx34sRG02hG5e3uIfMxe5lHcPba0qsVQt+vOhu9MUb\nsYF/mfuQJKt/Oi8nA1BbrBAAAAQFQPrap7AtYWEoCIY7gtpFMW51iDTAv5GN99DsKNuBby\nwQX2S0Wg/da75m/emJn/2IbmaKApvrx8LbenpyywfBkAAABBAN6xiYQ2j7eRjLV4h4Hbie\nVwlPYP4otKHdF5meObr+2ifYiMktdv/44V1XWKhgavjGFNWx2sHgj7byb51e/bi3MAAABB\nAMtVxa55G0wS9Yw1WK2F4JdYZ65ZAnUuo2rbA2dMDQxsOQxgel5Ox2XmC7e0GKrO9BJKPo\nR2fHEOdm9KOmoB8IkAAAAWY2hlbnppbG9uZ0BleGFtcGxlLmNvbQECAwQF\n-----END OPENSSH PRIVATE KEY-----\n"), - PublicKeySSH: util.SetEnvStr("PUBLIC_KEY_SSH", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCw4WT05QHzCD19348MfJfycS1NI9Jlj62PGrZ1rU9/kWQif5TV1rqHZ6qjAX2WfK+W3u4SV51MhZBkMZZOgZgJmdGiaZJkSmj+8gj6XU/bxslUd+BYUKqbE18gFkVDgqs6n2tcqJ2at3x+WEr81Msk2qvKuGEiIOzcJPICWKxwiw== chenzilong@example.com\n"), - SmsAccessKeyId: util.SetEnvStr("SMS_ACCESS_KEY", "LTAI4GBcVubRjzX7ABPcHnhB"), // 短信key - SmsAccessSecret: util.SetEnvStr("SMS_ACCESS_SECRET", "dYE2dtABFOqYtK1ijcrits0yedHkw7"), // 短信secret - SmsTemplateLogin: util.SetEnvStr("SMS_TEMPLATE_LOGIN", "SMS_212925130"), // 短信验证码模板 - SmsSignName: util.SetEnvStr("SMS_SIGN_NAME", "比格数据"), // 签名 + PrivateKeySSH: util.SetEnvStr("PRIVATE_KEY_SSH", ""), + //PublicKeySSH: util.SetEnvStr("PUBLIC_KEY_SSH", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCw4WT05QHzCD19348MfJfycS1NI9Jlj62PGrZ1rU9/kWQif5TV1rqHZ6qjAX2WfK+W3u4SV51MhZBkMZZOgZgJmdGiaZJkSmj+8gj6XU/bxslUd+BYUKqbE18gFkVDgqs6n2tcqJ2at3x+WEr81Msk2qvKuGEiIOzcJPICWKxwiw== chenzilong@example.com\n"), + OrderDingTalkAccessToken: util.SetEnvStr("ORDER_DING_TALK_ACCESS_TOKEN", "203fe1644b446bba0a34e6e622c523d39ee9916fdad94b9c64224449f659e20b"), + OrderDingTalkSecret: util.SetEnvStr("ORDER_DING_TALK_SECRET", "SECa73d8372e336451c9daf29a99f750ee1bdd170c1dab910eab9cd06d729a831b7"), + SmsAccessKeyId: util.SetEnvStr("SMS_ACCESS_KEY", "LTAI4GBcVubRjzX7ABPcHnhB"), // 短信key + SmsAccessSecret: util.SetEnvStr("SMS_ACCESS_SECRET", "dYE2dtABFOqYtK1ijcrits0yedHkw7"), // 短信secret + SmsTemplateLogin: util.SetEnvStr("SMS_TEMPLATE_LOGIN", "SMS_212925130"), // 短信验证码模板 + SmsSignName: util.SetEnvStr("SMS_SIGN_NAME", "比格数据"), // 签名 } } @@ -160,19 +161,19 @@ func initAnsibleSSH() { if err != nil { fmt.Println(err.Error()) } else { - _, err := f.Write([]byte(conf.Options.PrivateKeySSH)) - if err != nil { - fmt.Println(err.Error()) - } - } - f2, err := os.Create("/root/.ssh/id_rsa.pub") - defer f2.Close() - if err != nil { - fmt.Println(err.Error()) - } else { - _, err := f.Write([]byte(conf.Options.PublicKeySSH)) + _, err = f.Write([]byte(conf.Options.PrivateKeySSH)) if err != nil { fmt.Println(err.Error()) } } + //f2, err := os.Create("/root/.ssh/id_rsa.pub") + //defer f2.Close() + //if err != nil { + // fmt.Println(err.Error()) + //} else { + // _, err := f.Write([]byte(conf.Options.PublicKeySSH)) + // if err != nil { + // fmt.Println(err.Error()) + // } + //} } diff --git a/src/router/automatedmaintenrouter.go b/src/router/automatedmaintenrouter.go index 32d3c217daa0b0783e0ad2b2dde1a0a4e18d8797..1abe0cc8cdcbafbd1a423088c0e167043612dccd 100644 --- a/src/router/automatedmaintenrouter.go +++ b/src/router/automatedmaintenrouter.go @@ -5,13 +5,14 @@ import ( "github.com/gin-gonic/gin" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" ) // InitAutomatedMaintenRouter 初始化自动化运维路由 func InitAutomatedMaintenRouter(e *gin.Engine) { so := e.Group(fmt.Sprintf("%s/automated_mainten", conf.Options.Prefix)) //任务管理 - task := so.Group("/task_manage") + task := so.Group("/task_manage", header.SetContext) { task.POST("/add", controller.AddTaskManage) // 新增 task.PUT("/edit", controller.EditTaskManage) // 编辑 @@ -22,7 +23,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) { } //任务历史 - taskHistory := so.Group("/task_history") + taskHistory := so.Group("/task_history", header.SetContext) { taskHistory.GET("/list", controller.TaskHistoryList) // 任务历史列表 taskHistory.GET("/task_info_list", controller.TaskInfoList) // 任务历史详情列表 @@ -30,7 +31,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) { } //主机管理 - host := so.Group("/host_manage") + host := so.Group("/host_manage", header.SetContext) { host.POST("/add", controller.AddHostManage) // 新增 host.PUT("/edit", controller.EditHostManage) // 编辑 diff --git a/src/router/workorderrouter.go b/src/router/workorderrouter.go index db448f59ea1f94117fa48b73abe293af8b2a001d..3cbf2833f662f53edafa8ba97676db479954b222 100644 --- a/src/router/workorderrouter.go +++ b/src/router/workorderrouter.go @@ -5,6 +5,7 @@ import ( "github.com/gin-gonic/gin" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header" ) // InitWorkOrderRouter 初始化工单路由 @@ -13,12 +14,13 @@ func InitWorkOrderRouter(e *gin.Engine) { //预警工单管理 alert := so.Group("/alert") { - alert.GET("", controller.DetailAlertList) // 详情 - alert.GET("/list", controller.ListAlertList) // 列表 + alert.GET("", controller.DetailAlertList) // 详情 + alert.GET("/list", controller.ListAlertList) // 列表 + alert.PUT("/dispose", controller.DisposeAlertList) // 处置反馈 } //业务工单管理 - manage := so.Group("/work_order_manage") + manage := so.Group("/work_order_manage", header.SetContext) { manage.POST("/add", controller.AddWorkOrderManage) // 新增 manage.PUT("/edit", controller.EditWorkOrderManage) // 编辑 @@ -30,7 +32,7 @@ func InitWorkOrderRouter(e *gin.Engine) { } //业务工单列表 - list := so.Group("/work_order_issuance") + list := so.Group("/work_order_issuance", header.SetContext) { list.PUT("/close", controller.CloseWorkOrderIssuance) // 关闭工单 list.GET("/list", controller.ListWorkOrderIssuance) // 业务工单下发列表 @@ -38,9 +40,10 @@ func InitWorkOrderRouter(e *gin.Engine) { } //我的业务工单 - me := so.Group("/work_order_me") + me := so.Group("/work_order_me", header.SetContext) { me.PUT("/feedback", controller.FeedbackWorkOrderMe) // 处置反馈 me.GET("/list", controller.ListWorkOrderMe) // 我的业务工单列表 } + //so.POST("/note_sg", controller.WorkOrderPushNoteMsg) } diff --git a/src/service/alert_list.go b/src/service/alert_list.go index 41132515c50e49a0553889b4d040c92d111e952b..b9ba3dedd72fac687772f7be6fd92ed0ae6ef501 100644 --- a/src/service/alert_list.go +++ b/src/service/alert_list.go @@ -75,6 +75,7 @@ func (a *AlertListSvc) GetDataById(req request.DetailAlertList) (resp response.A DisposalTime: now, }, }, + IsDisposed: 2, CloseRemark: "", CloseUser: "", DeferPush: 0, @@ -165,6 +166,7 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL DisposalTime: now, }, }, + IsDisposed: 2, CloseRemark: "", CloseUser: "", DeferPush: 0, @@ -235,14 +237,23 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL PushCount: 1, LastPushTime: now, Status: 3, - CloseRemark: "关闭备注", - CloseUser: "xiaowang", - CloseTime: now, - DeferPush: 1, - CreatedBy: "admin", - CreatedAt: now, - UpdatedBy: "admin", - UpdatedAt: now, + DisposedList: []entity.DisposedList{ + { + IsDisposed: 1, + DisposalContent: "已做处置", + DisposalUser: "xiaowang", + DisposalTime: now, + }, + }, + IsDisposed: 1, + CloseRemark: "关闭备注", + CloseUser: "xiaowang", + CloseTime: now, + DeferPush: 1, + CreatedBy: "admin", + CreatedAt: now, + UpdatedBy: "admin", + UpdatedAt: now, }, AlertCondition: entity.AlertCondition{ ThresholdsMax: 80, @@ -290,3 +301,11 @@ func (a *AlertListSvc) List(req request.ListAlertList) (resp response.AlertListL resp.TotalCount = int64(len(resp.List)) return } + +func (a *AlertListSvc) DisposeAlertList(session *xorm.Session, req request.DisposeAlertList) error { + now := jsontime.Now() + _ = now + // TODO 我的预警工单处置 + conf.Logger.Info("dispose alert", zap.Any("payload", req)) + return nil +} diff --git a/src/service/host_manage.go b/src/service/host_manage.go index b64b69d610f4f79e38a0ee437cbf2b9ee0b88c64..f8fe818555e6c05c4b51f75ee5d008502c73b825 100644 --- a/src/service/host_manage.go +++ b/src/service/host_manage.go @@ -18,7 +18,7 @@ import ( ) type HostManageSvc struct { - User *entity.SystemUser + User entity.SystemUserInfo } const AnsibleGroup string = "HostGroup" @@ -53,9 +53,9 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error) //新增主机分组 hostManage := entity.HostManage{ HostName: req.HostName, - CreateUser: "", + CreateUser: h.User.SystemAccount, CreateTime: time.Now(), - UpdateUser: "", + UpdateUser: h.User.SystemAccount, UpdateTime: time.Now(), } _, err = session.Table("host_manage").Insert(&hostManage) @@ -156,7 +156,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error //修改主机分组信息 hostManage := entity.HostManage{ - UpdateUser: "", + UpdateUser: h.User.SystemAccount, UpdateTime: time.Now(), } _, err = session.Table("host_manage").Where("is_delete = 0 AND id = ?", req.Id). @@ -326,7 +326,8 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa return } //查询任务列表 - err = db.Table("task_manage").Where("is_delete = 0 AND host_group_id = ?", id).Find(&taskList) + err = db.Table("task_manage").Alias("tm").Where("tm.is_delete = 0 AND tm.host_group_id = ?", id). + Select("tm.id,tm.task_name,tm.task_desc,(select count(1) from task_history th where th.task_id = tm.id) as exec_cnt").Find(&taskList) if err != nil { err = resp.DbSelectError.WithError(err) return @@ -454,10 +455,17 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err for _, v := range hostManageList { //修改状态 + connStatus, err1 := StatusDetection(v.Ip) + if err1 != nil { + session.Rollback() + return err1 + } + hostManageListConn := entity.HostManageList{ + ConnStatus: connStatus, + } + _, err = session.Table("host_manage_list").Where("is_delete = 0 AND id = ?", v.Id). - Cols("conn_status").Update(&entity.HostManageList{ - ConnStatus: StatusDetection(v.Ip), - }) + Cols("conn_status").Update(&hostManageListConn) if err != nil { err = resp.DbUpdateError.WithError(err) session.Rollback() @@ -541,7 +549,10 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL id = uuid.New().String() for k, v := range hostManageListCaches { //调用状态检测函数 - hostManageListCaches[k].ConnStatus = StatusDetection(v.Ip) + hostManageListCaches[k].ConnStatus, err = StatusDetection(v.Ip) + if err != nil { + return + } hostManageListCaches[k].Id = id } @@ -610,16 +621,25 @@ func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq) } // StatusDetection 状态检测 -func StatusDetection(ip string) (ipConn int) { +func StatusDetection(ip string) (ipConn int, err error) { var cmd *exec.Cmd cmd = exec.Command("ansible", fmt.Sprintf("%s", AnsibleIp+ip), "-m", "ping") - output, err := cmd.Output() - if err != nil { - fmt.Println("ping:", string(output)) - return 1 + //执行cmd命令 + if err = cmd.Start(); err != nil { + err = resp.CmdExecError.WithError(err) + return + } + if cmd.ProcessState.Success() { + return 0, nil } - fmt.Println("ping:", string(output)) - return 0 + return 1, nil + //output, err := cmd.Output() + //if err != nil { + // fmt.Println("ping:", string(output)) + // return 1 + //} + //fmt.Println("ping:", string(output)) + //return 0 } // ExportIpStr 结果导出 @@ -776,14 +796,17 @@ func CronStatusDetection() { // } //} for _, v := range hostManageList { + connStatus, err1 := StatusDetection(v.Ip) + if err1 != nil { + fmt.Println("CronStatusDetection err:", err1.Error()) + } //修改状态 _, err = db.Table("host_manage_list").Where("is_delete = 0 AND id = ?", v.Id). Cols("conn_status").Update(&entity.HostManageList{ - ConnStatus: StatusDetection(v.Ip), + ConnStatus: connStatus, }) if err != nil { fmt.Println("CronStatusDetection err:", err.Error()) - return } } fmt.Println("CronPersonalCardDate success!") diff --git a/src/service/task_manage.go b/src/service/task_manage.go index 25749e3a0b2f13f9763df3e686c908c88b5abbb5..95dc98716fff6ac3d83133928f9b3bac6bd0f243 100644 --- a/src/service/task_manage.go +++ b/src/service/task_manage.go @@ -17,7 +17,7 @@ import ( ) type TaskManageSvc struct { - User *entity.SystemUser + User entity.SystemUserInfo } // AddTaskManage 新增任务 @@ -45,9 +45,9 @@ func (t *TaskManageSvc) AddTaskManage(req request.AddTaskManageReq) (id int, err YamlDesc: req.YamlDesc, YamlUrl: req.YamlUrl, HostGroupId: req.HostGroupId, - CreateUser: "", + CreateUser: t.User.SystemAccount, CreateTime: time.Now(), - UpdateUser: "", + UpdateUser: t.User.SystemAccount, UpdateTime: time.Now(), } _, err = db.Table("task_manage").Insert(&taskManage) @@ -71,7 +71,7 @@ func (t *TaskManageSvc) EditTaskManage(req request.EditTaskManageReq) (id int, e YamlDesc: req.YamlDesc, YamlUrl: req.YamlUrl, HostGroupId: req.HostGroupId, - UpdateUser: "", + UpdateUser: t.User.SystemAccount, UpdateTime: time.Now(), } //编辑任务 @@ -237,13 +237,13 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id } //写入主机信息 - //hostsIp := strings.Replace(strings.Trim(fmt.Sprint(hosts), "[]"), " ", " ", -1) hostsGroup, err := os.Create("/etc/ansible/hosts_" + fmt.Sprintf("%d", req.TaskId)) if err != nil { err = resp.FileExecError.WithError(err) return } + defer hostsGroup.Close() //_, err = hostsGroup.Write([]byte(hostsIp)) _, err = hostsGroup.Write([]byte(strings.Join(hosts, "\n"))) @@ -258,6 +258,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id err = resp.FileExecError.WithError(err) return } + defer f2.Close() _, err = f2.Write([]byte(script)) if err != nil { @@ -268,7 +269,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id //新增任务历史 id, err = AddExecHistory(request.AddExecHistory{ TaskId: req.TaskId, - CreateUser: "", + CreateUser: t.User.SystemAccount, }) if err != nil { return diff --git a/src/service/work_order.go b/src/service/work_order.go index c8182b1e7ffd68e727d15bbc2d15954cbda6a40b..1d15df7697cd65958e13e63e637a326199f22d3a 100644 --- a/src/service/work_order.go +++ b/src/service/work_order.go @@ -3,17 +3,22 @@ package service import ( "errors" "fmt" + "github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi" json "github.com/json-iterator/go" + "github.com/wanghuiyt/ding" "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/resp" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" + "go.uber.org/zap" "time" ) type WorkOrderManageSvc struct { - User *entity.SystemUser + User entity.SystemUserInfo } // AddWorkOrderManage 新增业务工单 @@ -48,9 +53,9 @@ func (w *WorkOrderManageSvc) AddWorkOrderManage(req request.AddWorkOrderReq) (er OrderDesc: req.OrderDesc, PushObj: fmt.Sprintf("%s", pushObj), TimingType: req.TimingType, - CreateUser: "", + CreateUser: w.User.SystemAccount, CreateTime: time.Now(), - UpdateUser: "", + UpdateUser: w.User.SystemAccount, UpdateTime: time.Now(), } @@ -108,7 +113,7 @@ func (w *WorkOrderManageSvc) EditWorkOrderManage(req request.EditWorkOrderReq) ( OrderDesc: req.OrderDesc, PushObj: fmt.Sprintf("%s", pushObj), TimingType: req.TimingType, - UpdateUser: "", + UpdateUser: w.User.SystemAccount, UpdateTime: time.Now(), } if req.TimingType == 2 { @@ -312,7 +317,7 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) ( OrderId: req.Id, PushObj: fmt.Sprintf("%s", pushObj), OrderState: 1, - CreateUser: "admin", + CreateUser: w.User.SystemAccount, CreateTime: time.Now(), } _, err = session.Table("work_order_issuance").Insert(&workOrderIssuance) @@ -559,6 +564,8 @@ func (w *WorkOrderManageSvc) ListWorkOrderMe(req request.ListWorkOrderReq) (tota Join("INNER", "work_order_issuance woi", "wome.order_issuance_id = woi.id"). Join("INNER", "work_order_manage wom", "woi.order_id = wom.id") + finder.Where("wome.system_account = ?", w.User.SystemAccount) + if req.Search != "" { finder.Where(fmt.Sprintf("wom.order_name LIKE '%s'", "%"+req.Search+"%")) } @@ -604,3 +611,53 @@ func (w *WorkOrderManageSvc) ListWorkOrderMe(req request.ListWorkOrderReq) (tota } return } + +// WorkOrderPushDingTalkMsg 推送钉钉消息 +func WorkOrderPushDingTalkMsg(orderName, phone string, orderLevel int) (err error) { + d := ding.Webhook{ + AccessToken: conf.Options.OrderDingTalkAccessToken, //"203fe1644b446bba0a34e6e622c523d39ee9916fdad94b9c64224449f659e20b", + Secret: conf.Options.OrderDingTalkSecret, //"SECa73d8372e336451c9daf29a99f750ee1bdd170c1dab910eab9cd06d729a831b7", + } + + var orderLevels string + switch orderLevel { + case 1: + orderLevels = "紧急任务" + case 2: + orderLevels = "重要任务" + case 3: + orderLevels = "一般任务" + } + + //有一条工单需要您处理:工单类型:【业务工单】 工单名称:【$工单名称】 工单等级:【$工单等级】 + err = d.SendMessageText("有一条工单需要您处理:\n工单类型:【业务工单】\n工单名称:【"+orderName+"】\n工单等级:【"+orderLevels+"】", phone) + return +} + +// WorkOrderPushNoteMsg 推送短信消息 +func WorkOrderPushNoteMsg(phone string) (err error) { + smsClient, err := dysmsapi.NewClientWithAccessKey("cn-hangzhou", conf.Options.SmsAccessKeyId, conf.Options.SmsAccessSecret) + if err != nil { + conf.Logger.Error("dysmsapi client error", zap.Error(err)) + return resp.FAIL.ErrorDetail(err) + } + code := util.Rand6() + params := map[string]interface{}{"code": code} + templateParam, err := json.Marshal(params) + if err != nil { + conf.Logger.Error("序列化模板失败!", zap.Error(err)) + return resp.FAIL.ErrorDetail(err) + } + request := dysmsapi.CreateSendSmsRequest() + request.Scheme = "https" + request.PhoneNumbers = phone + request.TemplateCode = conf.Options.SmsTemplateLogin + request.SignName = conf.Options.SmsSignName + request.TemplateParam = string(templateParam) + req, err := smsClient.SendSms(request) + if err != nil { + return resp.FAIL.ErrorDetail(err) + } + fmt.Printf("response is %#v\n", req) + return nil +}