Commit f4dff071 authored by 陈子龙's avatar 陈子龙

主机状态检测 fix

parent 44c265e1
...@@ -243,15 +243,3 @@ func ListWorkOrderMe(c *gin.Context) { ...@@ -243,15 +243,3 @@ func ListWorkOrderMe(c *gin.Context) {
} }
SendJsonPageResponse(c, resp.OK, list, total) 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)
}
...@@ -10,8 +10,10 @@ import ( ...@@ -10,8 +10,10 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "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/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client" "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/common/tools" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/tools"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"go.uber.org/zap"
"os/exec" "os/exec"
"strings" "strings"
"sync" "sync"
...@@ -677,14 +679,25 @@ func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq) ...@@ -677,14 +679,25 @@ func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq)
func StatusDetection(ip string) (ipConn int) { func StatusDetection(ip string) (ipConn int) {
var cmd *exec.Cmd var cmd *exec.Cmd
cmd = exec.Command("ansible", fmt.Sprintf("%s", AnsibleIp+ip), "-m", "ping") cmd = exec.Command("ansible", fmt.Sprintf("%s", AnsibleIp+ip), "-m", "ping")
output, err := cmd.Output() err := cmd.Run()
if err != nil { if err != nil {
fmt.Println("ping:", string(output)) conf.Logger.Error("测试 "+ip+" 连通性失败", zap.Error(err))
fmt.Println("err:", err)
return 1 return 1
} }
fmt.Println("ping:", string(output)) if cmd.ProcessState.Success() {
return 0 return 0
} else {
return 1
}
//output, err := cmd.Output()
//if err != nil {
// fmt.Println("ping:", string(output))
// fmt.Println("err:", err)
// return 1
//}
//fmt.Println("ping:", string(output))
//return 0
} }
// ExportIpStr 结果导出 // ExportIpStr 结果导出
......
...@@ -3,7 +3,6 @@ package service ...@@ -3,7 +3,6 @@ package service
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
json "github.com/json-iterator/go" json "github.com/json-iterator/go"
"github.com/wanghuiyt/ding" "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/entity"
...@@ -12,8 +11,6 @@ import ( ...@@ -12,8 +11,6 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client" "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/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "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" "time"
) )
...@@ -301,11 +298,13 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) ( ...@@ -301,11 +298,13 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) (
session := db.NewSession() session := db.NewSession()
defer session.Close() defer session.Close()
session.Begin() session.Begin()
var workOrder entity.WorkOrder
_, err = session.Table("work_order_manage").Where("id = ?", req.Id).Get(&workOrder)
if err != nil {
err = resp.FAIL.WithError(err)
return
}
//pushObj := req.PushObj.UserObj[0].UserName
//for i := 1; i < len(req.PushObj.UserObj); i++ {
// pushObj = pushObj + "、" + req.PushObj.UserObj[i].UserName
//}
pushObj, err := json.Marshal(req.PushObj) pushObj, err := json.Marshal(req.PushObj)
if err != nil { if err != nil {
err = resp.FAIL.WithError(err) err = resp.FAIL.WithError(err)
...@@ -342,8 +341,6 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) ( ...@@ -342,8 +341,6 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) (
} }
} }
//发消息通知 czl..
//修改库表实例工单数 //修改库表实例工单数
_, err = session.Table("work_order_manage").Where("id = ?", req.Id).Incr("order_cnt").Update(&entity.WorkOrder{}) _, err = session.Table("work_order_manage").Where("id = ?", req.Id).Incr("order_cnt").Update(&entity.WorkOrder{})
if err != nil { if err != nil {
...@@ -351,6 +348,37 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) ( ...@@ -351,6 +348,37 @@ func (w *WorkOrderManageSvc) PushWorkOrderManage(req request.PushWorkOrderReq) (
session.Rollback() session.Rollback()
return return
} }
var phones []string
for _, v := range req.PushObj.UserObj {
phones = append(phones, v.Phone)
}
switch req.PushObj.PushMethod {
case 1:
//发送钉钉消息
err = WorkOrderPushDingTalkMsg(workOrder.OrderName, workOrder.OrderLevel, phones)
if err != nil {
return
}
case 2:
//发送短信
err = WorkOrderPushNoteMsg(workOrder.OrderName, workOrder.OrderLevel, phones)
if err != nil {
return
}
case 3:
//发送钉钉消息
err = WorkOrderPushDingTalkMsg(workOrder.OrderName, workOrder.OrderLevel, phones)
if err != nil {
return
}
//发送短信
err = WorkOrderPushNoteMsg(workOrder.OrderName, workOrder.OrderLevel, phones)
if err != nil {
return
}
}
session.Commit() session.Commit()
return return
} }
...@@ -613,7 +641,7 @@ func (w *WorkOrderManageSvc) ListWorkOrderMe(req request.ListWorkOrderReq) (tota ...@@ -613,7 +641,7 @@ func (w *WorkOrderManageSvc) ListWorkOrderMe(req request.ListWorkOrderReq) (tota
} }
// WorkOrderPushDingTalkMsg 推送钉钉消息 // WorkOrderPushDingTalkMsg 推送钉钉消息
func WorkOrderPushDingTalkMsg(orderName, phone string, orderLevel int) (err error) { func WorkOrderPushDingTalkMsg(orderName string, orderLevel int, phones []string) (err error) {
d := ding.Webhook{ d := ding.Webhook{
AccessToken: conf.Options.OrderDingTalkAccessToken, //"203fe1644b446bba0a34e6e622c523d39ee9916fdad94b9c64224449f659e20b", AccessToken: conf.Options.OrderDingTalkAccessToken, //"203fe1644b446bba0a34e6e622c523d39ee9916fdad94b9c64224449f659e20b",
Secret: conf.Options.OrderDingTalkSecret, //"SECa73d8372e336451c9daf29a99f750ee1bdd170c1dab910eab9cd06d729a831b7", Secret: conf.Options.OrderDingTalkSecret, //"SECa73d8372e336451c9daf29a99f750ee1bdd170c1dab910eab9cd06d729a831b7",
...@@ -630,34 +658,16 @@ func WorkOrderPushDingTalkMsg(orderName, phone string, orderLevel int) (err erro ...@@ -630,34 +658,16 @@ func WorkOrderPushDingTalkMsg(orderName, phone string, orderLevel int) (err erro
} }
//有一条工单需要您处理:工单类型:【业务工单】 工单名称:【$工单名称】 工单等级:【$工单等级】 //有一条工单需要您处理:工单类型:【业务工单】 工单名称:【$工单名称】 工单等级:【$工单等级】
err = d.SendMessageText("有一条工单需要您处理:\n工单类型:【业务工单】\n工单名称:【"+orderName+"】\n工单等级:【"+orderLevels+"】", phone) err = d.SendMessageText("有一条工单需要您处理:\n工单类型:【业务工单】\n工单名称:【"+orderName+"】\n工单等级:【"+orderLevels+"】", phones...)
if err != nil {
return
}
return return
} }
// WorkOrderPushNoteMsg 推送短信消息 // WorkOrderPushNoteMsg 推送短信消息
func WorkOrderPushNoteMsg(phone string) (err error) { func WorkOrderPushNoteMsg(orderName string, orderLevel int, 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 return nil
} }
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