Commit 7fabfbfe authored by 陈子龙's avatar 陈子龙

自动化运维 fix

parent 37f16c6f
...@@ -12,6 +12,8 @@ require ( ...@@ -12,6 +12,8 @@ require (
github.com/go-playground/validator/v10 v10.13.0 github.com/go-playground/validator/v10 v10.13.0
github.com/go-redis/redis v6.15.9+incompatible github.com/go-redis/redis v6.15.9+incompatible
github.com/google/uuid v1.3.0 github.com/google/uuid v1.3.0
github.com/jinzhu/copier v0.3.5
github.com/json-iterator/go v1.1.12
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/lib/pq v1.10.9 github.com/lib/pq v1.10.9
github.com/minio/minio-go/v7 v7.0.58 github.com/minio/minio-go/v7 v7.0.58
...@@ -20,6 +22,7 @@ require ( ...@@ -20,6 +22,7 @@ require (
github.com/satori/go.uuid v1.2.0 github.com/satori/go.uuid v1.2.0
github.com/spf13/cast v1.5.0 github.com/spf13/cast v1.5.0
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
github.com/tealeg/xlsx v1.0.5
github.com/thoas/go-funk v0.9.3 github.com/thoas/go-funk v0.9.3
github.com/valyala/fasthttp v1.47.0 github.com/valyala/fasthttp v1.47.0
go.uber.org/zap v1.24.0 go.uber.org/zap v1.24.0
...@@ -41,8 +44,6 @@ require ( ...@@ -41,8 +44,6 @@ require (
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/henrylee2cn/ameda v1.5.0 // indirect github.com/henrylee2cn/ameda v1.5.0 // indirect
github.com/henrylee2cn/goutil v0.0.0-20220704075712-42f2ec55fe8d // indirect github.com/henrylee2cn/goutil v0.0.0-20220704075712-42f2ec55fe8d // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.5 // indirect github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.3 // indirect github.com/leodido/go-urn v1.2.3 // indirect
......
...@@ -436,6 +436,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ ...@@ -436,6 +436,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw= github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw=
github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
...@@ -628,8 +630,9 @@ google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175 ...@@ -628,8 +630,9 @@ google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 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 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/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/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= 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/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
......
...@@ -4,35 +4,35 @@ import "time" ...@@ -4,35 +4,35 @@ import "time"
type HostManage struct { type HostManage struct {
Id int `json:"id" xorm:"pk autoincr" ` // id Id int `json:"id" xorm:"pk autoincr" ` // id
HostName string `json:"hostName" xorm:"host_name"` // 主机分组名称 HostName string `json:"host_name" xorm:"host_name"` // 主机分组名称
IsDelete int `json:"isDelete" xorm:"is_delete" ` // 是否删除(0 未删除 1已删除) IsDelete int `json:"is_delete" xorm:"is_delete" ` // 是否删除(0 未删除 1已删除)
CreateUser string `json:"createUser" xorm:"create_user" ` // 创建人 CreateUser string `json:"create_user" xorm:"create_user" ` // 创建人
CreateTime time.Time `json:"createTime" xorm:"create_time"` // 创建时间 CreateTime time.Time `json:"create_time" xorm:"create_time"` // 创建时间
UpdateUser string `json:"updateUser" xorm:"update_user" ` // 修改人 UpdateUser string `json:"update_user" xorm:"update_user" ` // 修改人
UpdateTime time.Time `json:"updateTime" xorm:"update_time"` // 修改时间 UpdateTime time.Time `json:"update_time" xorm:"update_time"` // 修改时间
} }
type HostManageList struct { type HostManageList struct {
Id int `json:"id" xorm:"pk autoincr" ` // id Id int `json:"id" xorm:"pk autoincr" ` // id
Ip string `json:"ip" xorm:"ip"` // ip Ip string `json:"ip" xorm:"ip"` // ip
Port string `json:"port" xorm:"port"` // 端口 Port string `json:"port" xorm:"port"` // 端口
VoucherType int `json:"voucherType" xorm:"voucher_type"` // 凭证类型(0密码验证 密钥验证) VoucherType int `json:"voucher_type" xorm:"voucher_type"` // 凭证类型(0密码验证 1密钥验证)
UserName string `json:"userName" xorm:"user_name"` // 用户名 UserName string `json:"user_name" xorm:"user_name"` // 用户名
Password string `json:"password" xorm:"password"` // 密码 Password string `json:"password" xorm:"password"` // 密码
HostGroupId int `json:"hostGroupId" xorm:"host_group_id"` // 主机分组id HostGroupId int `json:"host_group_id" xorm:"host_group_id"` // 主机分组id
HostFileUrl string `json:"hostFileUrl" xorm:"host_file_url"` // 主机文件url HostFileUrl string `json:"host_file_url" xorm:"host_file_url"` // 主机文件url
IsDelete int `json:"isDelete" xorm:"is_delete" ` // 是否删除(0 未删除 1已删除) IsDelete int `json:"is_delete" xorm:"is_delete" ` // 是否删除(0 未删除 1已删除)
ConnStatus int `json:"connStatus" xorm:"conn_status" ` // 连接状态(0正常 1异常) ConnStatus int `json:"conn_status" xorm:"conn_status" ` // 连接状态(0正常 1异常)
IpGroup int `json:"ipGroup" xorm:"ip_group" ` // ip分组 IpGroup int `json:"ip_group" xorm:"ip_group" ` // ip分组
} }
type HostManageListCache struct { type HostManageListCache struct {
Id string `json:"id" xorm:"id" ` // id Id string `json:"id" xorm:"id" ` // id
Ip string `json:"ip" xorm:"ip"` // ip Ip string `json:"ip" xorm:"ip"` // ip
Port string `json:"port" xorm:"port"` // 端口 Port string `json:"port" xorm:"port"` // 端口
VoucherType int `json:"voucherType" xorm:"voucher_type"` // 凭证类型(0密码验证 密钥验证) VoucherType int `json:"voucher_type" xorm:"voucher_type"` // 凭证类型(0密码验证 密钥验证)
UserName string `json:"userName" xorm:"user_name"` // 用户名 UserName string `json:"user_name" xorm:"user_name"` // 用户名
Password string `json:"password" xorm:"password"` // 密码 Password string `json:"password" xorm:"password"` // 密码
ConnStatus int `json:"connStatus" xorm:"conn_status" ` // 连接状态(0正常 1异常) ConnStatus int `json:"conn_status" xorm:"conn_status" ` // 连接状态(0正常 1异常)
IpGroup int `json:"ipGroup" xorm:"ip_group" ` // ip分组 IpGroup int `json:"ip_group" xorm:"ip_group" ` // ip分组
} }
...@@ -4,17 +4,17 @@ import "time" ...@@ -4,17 +4,17 @@ import "time"
type TaskManage struct { type TaskManage struct {
Id int `json:"id" xorm:"pk autoincr" ` // id Id int `json:"id" xorm:"pk autoincr" ` // id
TaskName string `json:"taskName" xorm:"task_name"` // 任务名称 TaskName string `json:"task_name" xorm:"task_name"` // 任务名称
TaskDesc string `json:"taskDesc" xorm:"task_desc"` // 任务描述 TaskDesc string `json:"task_desc" xorm:"task_desc"` // 任务描述
YamlDesc string `json:"yamlDesc" xorm:"yaml_desc"` // yaml文件 YamlDesc string `json:"yaml_desc" xorm:"yaml_desc"` // yaml文件
YamlUrl string `json:"yamlUrl" xorm:"yaml_url"` // yaml文件地址 YamlUrl string `json:"yaml_url" xorm:"yaml_url"` // yaml文件地址
ExecCnt int `json:"execCnt" xorm:"exec_cnt"` // 执行次数 ExecCnt int `json:"exec_cnt" xorm:"exec_cnt"` // 执行次数
SuccessCnt int `json:"successCnt" xorm:"success_cnt"` // 执行成功次数 SuccessCnt int `json:"success_cnt" xorm:"success_cnt"` // 执行成功次数
FailCnt int `json:"failCnt" xorm:"fail_cnt"` // 执行失败次数 FailCnt int `json:"fail_cnt" xorm:"fail_cnt"` // 执行失败次数
HostGroupId int `json:"hostGroupId" xorm:"host_group_id"` // 主机分组ID HostGroupId int `json:"host_group_id" xorm:"host_group_id"` // 主机分组ID
IsDelete int `json:"isDelete" xorm:"is_delete" ` // 是否删除(0 未删除 1已删除) IsDelete int `json:"is_delete" xorm:"is_delete" ` // 是否删除(0 未删除 1已删除)
CreateUser string `json:"createUser" xorm:"create_user" ` // 创建人 CreateUser string `json:"create_user" xorm:"create_user" ` // 创建人
CreateTime time.Time `json:"createTime" xorm:"create_time"` // 创建时间 CreateTime time.Time `json:"create_time" xorm:"create_time"` // 创建时间
UpdateUser string `json:"updateUser" xorm:"update_user" ` // 修改人 UpdateUser string `json:"update_user" xorm:"update_user" ` // 修改人
UpdateTime time.Time `json:"updateTime" xorm:"update_time"` // 修改时间 UpdateTime time.Time `json:"update_time" xorm:"update_time"` // 修改时间
} }
package request package request
type AddHostManageReq struct { type AddHostManageReq struct {
HostName string `json:"hostName" binding:"required"` // 主机分组名称 HostName string `json:"host_name" binding:"required"` // 主机分组名称
HostFileUrl string `json:"hostFileUrl"` // 主机文件url HostFileUrl string `json:"host_file_url"` // 主机文件url
HostManageList []HostManageList `json:"hostManageList"` //主机列表 Uuid string `json:"uuid"` //临时缓存uuid
//HostManageList []HostManageList `json:"host_manage_list"` //主机列表
} }
type HostManageList struct { type HostManageList struct {
Ip string `json:"ip"` // ip Ip string `json:"ip"` // ip
Port string `json:"port"` // 端口 Port string `json:"port"` // 端口
VoucherType int `json:"voucherType"` // 凭证类型(0密码验证 1密钥验证) VoucherType int `json:"voucher_type"` // 凭证类型(0密码验证 1密钥验证)
UserName string `json:"userName"` // 用户名 UserName string `json:"user_name"` // 用户名
Password string `json:"password"` // 密码 Password string `json:"password"` // 密码
IpGroup int `json:"ipGroup"` // ip分组 IpGroup int `json:"ip_group"` // ip分组
} }
type EditHostManageReq struct { type EditHostManageReq struct {
Id int `json:"id" binding:"required"` // 主键ID Id int `json:"id" binding:"required"` // 主键ID
HostFileUrl string `json:"hostFileUrl"` // 主机文件url HostFileUrl string `json:"host_file_url"` // 主机文件url
HostManageList []HostManageList `json:"hostManageList"` //主机列表 Uuid string `json:"uuid"` //临时缓存uuid
//HostManageList []HostManageList `json:"host_manage_list"` //主机列表
} }
type DelHostManageReq struct { type DelHostManageReq struct {
...@@ -27,22 +29,22 @@ type DelHostManageReq struct { ...@@ -27,22 +29,22 @@ type DelHostManageReq struct {
type ListHostManageReq struct { type ListHostManageReq struct {
Search string `json:"search"` //关键词 Search string `json:"search"` //关键词
CreateDateFrom string `json:"createDateFrom"` //创建时间从 CreateDateFrom string `json:"create_date_from"` //创建时间从
CreateDateTo string `json:"createDateTo"` //创建时间至 CreateDateTo string `json:"create_date_to"` //创建时间至
Pagination Pagination
} }
// StateHostManageReq 状态检测 // StateHostManageReq 状态检测
type StateHostManageReq struct { type StateHostManageReq struct {
DetectionType int `json:"detectionType" form:"detectionType" binding:"oneof=1 2 3"` //1主页列表手动检测 2输入ip列表保存时检测 3上传ip列表文件保存时检测 DetectionType int `json:"detection_type" form:"detection_type" binding:"oneof=1 2 3"` //1主页列表手动检测 2输入ip列表保存时检测 3上传ip列表文件保存时检测
Id int `json:"id" form:"id"` //主机分组ID Id int `json:"id" form:"id"` //主机分组ID
//HostFile string `form:"hostFile"` // 主机文件 //HostFile file `form:"host_file"` // 主机文件
HostManageList string `json:"hostManageList" form:"hostManageList"` //主机ip列表 HostManageList string `json:"host_manage_list" form:"host_manage_list"` //主机ip列表
} }
// HostIpExceptionListReq 异常列表 // HostIpExceptionListReq 异常列表
type HostIpExceptionListReq struct { type HostIpExceptionListReq struct {
DetectionType int `json:"detectionType" binding:"oneof=1 2"` //1主页异常ip列表 2保存检测时异常列表 DetectionType int `json:"detection_type" binding:"oneof=1 2"` //1主页异常ip列表 2保存检测时异常列表
Id int `json:"id"` //主机分组ID Id int `json:"id"` //主机分组ID
Uuid string `json:"uuid"` //临时缓存uuid Uuid string `json:"uuid"` //临时缓存uuid
Pagination Pagination
......
package request package request
type AddTaskManageReq struct { type AddTaskManageReq struct {
TaskName string `json:"taskName" vd:"len($)>0;msg:'请输入任务名称'"` // 任务名称 TaskName string `json:"task_name" vd:"len($)>0;msg:'请输入任务名称'"` // 任务名称
TaskDesc string `json:"taskDesc"` // 任务描述 TaskDesc string `json:"task_desc"` // 任务描述
YamlDesc string `json:"yamlDesc"` // yaml内容 YamlDesc string `json:"yaml_desc"` // yaml内容
YamlUrl string `json:"yamlUrl"` // yaml文件url YamlUrl string `json:"yaml_url"` // yaml文件url
HostGroupId int `json:"hostGroupId" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID HostGroupId int `json:"host_group_id" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID
} }
type EditTaskManageReq struct { type EditTaskManageReq struct {
Id int `json:"id" vd:"$>0;msg:'请输入id'"` // 主键ID Id int `json:"id" vd:"$>0;msg:'请输入id'"` // 主键ID
TaskDesc string `json:"taskDesc"` // 任务描述 TaskDesc string `json:"task_desc"` // 任务描述
YamlDesc string `json:"yamlDesc"` // yaml内容 YamlDesc string `json:"yaml_desc"` // yaml内容
YamlUrl string `json:"yamlUrl"` // yaml文件url YamlUrl string `json:"yaml_url"` // yaml文件url
HostGroupId int `json:"hostGroupId" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID HostGroupId int `json:"host_group_id" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID
} }
type DelTaskManageReq struct { type DelTaskManageReq struct {
...@@ -26,8 +26,8 @@ type DetailsTaskManageReq struct { ...@@ -26,8 +26,8 @@ type DetailsTaskManageReq struct {
type ListTaskManageReq struct { type ListTaskManageReq struct {
Search string `json:"search" form:"search"` //关键词 Search string `json:"search" form:"search"` //关键词
CreateDateFrom string `json:"createDateFrom" form:"createDateFrom"` //创建时间从 CreateDateFrom string `json:"create_date_from" form:"createDateFrom"` //创建时间从
CreateDateTo string `json:"createDateTo" form:"createDateTo"` //创建时间至 CreateDateTo string `json:"create_date_to" form:"createDateTo"` //创建时间至
Pagination Pagination
} }
......
...@@ -4,70 +4,70 @@ import "time" ...@@ -4,70 +4,70 @@ import "time"
type HostManageRes struct { type HostManageRes struct {
Id int `json:"id"` // id Id int `json:"id"` // id
HostName string `json:"hostName"` // 主机分组名称 HostName string `json:"host_name"` // 主机分组名称
TaskCnt int `json:"taskCnt"` // 任务数量 TaskCnt int `json:"task_cnt"` // 任务数量
IpCnt int `json:"ipCnt"` // ip数量 IpCnt int `json:"ip_cnt"` // ip数量
CreateUser string `json:"createUser"` // 创建人 CreateUser string `json:"create_user"` // 创建人
CreateTime time.Time `json:"createTime"` // 创建时间 CreateTime time.Time `json:"create_time"` // 创建时间
UpdateUser string `json:"updateUser"` // 修改人 UpdateUser string `json:"update_user"` // 修改人
UpdateTime time.Time `json:"updateTime"` // 修改时间 UpdateTime time.Time `json:"update_time"` // 修改时间
HostFileUrl string `json:"hostFileUrl"` // 主机文件url HostFileUrl string `json:"host_file_url"` // 主机文件url
HostList []HostList `json:"hostList"` // 主机列表 HostList []HostList `json:"host_list"` // 主机列表
TaskList []TaskList `json:"taskList"` // 主机列表 TaskList []TaskList `json:"task_list"` // 任务列表
} }
type HostManage struct { type HostManage struct {
Id int `json:"id"` // id Id int `json:"id"` // id
HostName string `json:"hostName"` // 主机分组名称 HostName string `json:"host_name"` // 主机分组名称
CreateUser string `json:"createUser"` // 创建人 CreateUser string `json:"create_user"` // 创建人
CreateTime time.Time `json:"createTime"` // 创建时间 CreateTime time.Time `json:"create_time"` // 创建时间
UpdateUser string `json:"updateUser"` // 修改人 UpdateUser string `json:"update_user"` // 修改人
UpdateTime time.Time `json:"updateTime"` // 修改时间 UpdateTime time.Time `json:"update_time"` // 修改时间
} }
type HostList struct { type HostList struct {
Id int `json:"id"` // id Id int `json:"id"` // id
Ip string `json:"ip"` // ip Ip string `json:"ip"` // ip
Port string `json:"port"` // 端口 Port string `json:"port"` // 端口
HostFileUrl string `json:"hostFileUrl"` // 主机文件url HostFileUrl string `json:"host_file_url"` // 主机文件url
} }
type TaskList struct { type TaskList struct {
Id int `json:"id"` // id Id int `json:"id"` // id
TaskName string `json:"taskName"` // 任务名称 TaskName string `json:"task_name"` // 任务名称
TaskDesc string `json:"taskDesc"` // 任务描述 TaskDesc string `json:"task_desc"` // 任务描述
ExecCnt int `json:"execCnt"` // 执行次数 ExecCnt int `json:"exec_cnt"` // 执行次数
} }
type HostManagesRes struct { type HostManagesRes struct {
Id int `json:"id"` // id Id int `json:"id"` // id
HostName string `json:"hostName"` // 主机分组名称 HostName string `json:"host_name"` // 主机分组名称
CreateUser string `json:"createUser"` // 创建人 CreateUser string `json:"create_user"` // 创建人
CreateTime time.Time `json:"createTime"` // 创建时间 CreateTime time.Time `json:"create_time"` // 创建时间
TaskCnt int `json:"taskCnt"` // 任务数量 TaskCnt int `json:"task_cnt"` // 任务数量
IpCntErr int `json:"ipCntErr"` // ip数量(异常) IpCntErr int `json:"ip_cnt_err"` // ip数量(异常)
IpCnt int `json:"ipCnt"` // ip数量(全部) IpCnt int `json:"ip_cnt"` // ip数量(全部)
} }
type HostManageListRes struct { type HostManageListRes struct {
Id int `json:"id"` // id Id int `json:"id"` // id
Ip string `json:"ip"` // ip Ip string `json:"ip"` // ip
Port string `json:"port"` // 端口 Port string `json:"port"` // 端口
VoucherType int `json:"voucherType"` // 凭证类型(0密码验证 密钥验证) VoucherType int `json:"voucher_type"` // 凭证类型(0密码验证 密钥验证)
UserName string `json:"userName"` // 用户名 UserName string `json:"user_name"` // 用户名
Password string `json:"password"` // 密码 Password string `json:"password"` // 密码
} }
type HostManageListCacheRes struct { //type HostManageListCacheRes struct {
AormalHost []HostManageListCache `json:"normalHost"` // 正常ip // AormalHost []HostManageListCache `json:"normal_host"` // 正常ip
AbnormalHost []HostManageListCache `json:"abnormalHost"` // 异常ip // AbnormalHost []HostManageListCache `json:"abnormal_host"` // 异常ip
} //}
type HostManageListCache struct { type HostManageListCache struct {
Ip string `json:"ip"` // ip Ip string `json:"ip"` // ip
Port string `json:"port"` // 端口 Port string `json:"port"` // 端口
VoucherType int `json:"voucherType"` // 凭证类型(0密码验证 密钥验证) VoucherType int `json:"voucher_type"` // 凭证类型(0密码验证 1密钥验证)
UserName string `json:"userName"` // 用户名 UserName string `json:"user_name"` // 用户名
Password string `json:"password"` // 密码 Password string `json:"password"` // 密码
IpGroup int `json:"ipGroup"` // ip分组 IpGroup int `json:"ip_group"` // ip分组
} }
...@@ -4,16 +4,16 @@ import "time" ...@@ -4,16 +4,16 @@ import "time"
type TaskManageRes struct { type TaskManageRes struct {
Id int `json:"id" xorm:"pk autoincr" ` // id Id int `json:"id" xorm:"pk autoincr" ` // id
TaskName string `json:"taskName" xorm:"task_name"` // 任务名称 TaskName string `json:"task_name" xorm:"task_name"` // 任务名称
TaskDesc string `json:"taskDesc" xorm:"task_desc"` // 任务描述 TaskDesc string `json:"task_desc" xorm:"task_desc"` // 任务描述
YamlDesc string `json:"yamlDesc" xorm:"yaml_desc"` // yaml文件 YamlDesc string `json:"yaml_desc" xorm:"yaml_desc"` // yaml文件
YamlUrl string `json:"yamlUrl" xorm:"yaml_url"` // yaml文件地址 YamlUrl string `json:"yaml_url" xorm:"yaml_url"` // yaml文件地址
ExecCnt int `json:"execCnt" xorm:"exec_cnt"` // 执行次数 ExecCnt int `json:"exec_cnt" xorm:"exec_cnt"` // 执行次数
SuccessCnt int `json:"successCnt" xorm:"success_cnt"` // 执行成功次数 SuccessCnt int `json:"success_cnt" xorm:"success_cnt"` // 执行成功次数
FailCnt int `json:"failCnt" xorm:"fail_cnt"` // 执行失败次数 FailCnt int `json:"fail_cnt" xorm:"fail_cnt"` // 执行失败次数
HostGroupId int `json:"hostGroupId" xorm:"host_group_id"` // 主机分组ID HostGroupId int `json:"host_group_id" xorm:"host_group_id"` // 主机分组ID
CreateUser string `json:"createUser" xorm:"create_user" ` // 创建人 CreateUser string `json:"create_user" xorm:"create_user" ` // 创建人
CreateTime time.Time `json:"createTime" xorm:"create_time"` // 创建时间 CreateTime time.Time `json:"create_time" xorm:"create_time"` // 创建时间
UpdateUser string `json:"updateUser" xorm:"update_user" ` // 修改人 UpdateUser string `json:"update_user" xorm:"update_user" ` // 修改人
UpdateTime time.Time `json:"updateTime" xorm:"update_time"` // 修改时间 UpdateTime time.Time `json:"update_time" xorm:"update_time"` // 修改时间
} }
...@@ -30,6 +30,7 @@ type Config struct { ...@@ -30,6 +30,7 @@ type Config struct {
MinioAccessKey string MinioAccessKey string
MinioSecretKey string MinioSecretKey string
MinioBucket string MinioBucket string
TempDirPrefix string
} }
const ( const (
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
json "github.com/json-iterator/go" json "github.com/json-iterator/go"
"github.com/spf13/cast" "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/bean/vo/request"
"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/service" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
...@@ -15,7 +16,7 @@ import ( ...@@ -15,7 +16,7 @@ import (
// ParsingHostFiles 解析主机文件 // ParsingHostFiles 解析主机文件
func ParsingHostFiles(c *gin.Context) (hostManageList []request.HostManageList, err error) { func ParsingHostFiles(c *gin.Context) (hostManageList []request.HostManageList, err error) {
//获取文件流 //获取文件流
metaData, _, err := c.Request.FormFile("hostFile") metaData, _, err := c.Request.FormFile("host_file")
if err != nil { if err != nil {
err = resp.GetFileStreamError.WithError(err) err = resp.GetFileStreamError.WithError(err)
return return
...@@ -72,20 +73,20 @@ func AddHostManage(c *gin.Context) { ...@@ -72,20 +73,20 @@ func AddHostManage(c *gin.Context) {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组名称为空")), nil) SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组名称为空")), nil)
return return
} }
if len(req.HostManageList) == 0 { //if len(req.HostManageList) == 0 {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil) // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil)
return // return
} //}
for _, v := range req.HostManageList { //for _, v := range req.HostManageList {
if v.Ip == "" || v.UserName == "" { // if v.Ip == "" || v.UserName == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil) // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil)
return // return
} // }
if v.VoucherType == 0 && v.Password == "" { // if v.VoucherType == 0 && v.Password == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil) // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil)
return // return
} // }
} //}
hostManageSvc := service.HostManageSvc{} hostManageSvc := service.HostManageSvc{}
err = hostManageSvc.AddHostManage(req) err = hostManageSvc.AddHostManage(req)
...@@ -108,20 +109,20 @@ func EditHostManage(c *gin.Context) { ...@@ -108,20 +109,20 @@ func EditHostManage(c *gin.Context) {
} }
//参数校验 //参数校验
if len(req.HostManageList) == 0 { //if len(req.HostManageList) == 0 {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil) // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil)
return // return
} //}
for _, v := range req.HostManageList { //for _, v := range req.HostManageList {
if v.Ip == "" || v.UserName == "" { // if v.Ip == "" || v.UserName == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil) // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil)
return // return
} // }
if v.VoucherType == 0 && v.Password == "" { // if v.VoucherType == 0 && v.Password == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil) // SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil)
return // return
} // }
} //}
hostManageSvc := service.HostManageSvc{} hostManageSvc := service.HostManageSvc{}
err = hostManageSvc.EditHostManage(req) err = hostManageSvc.EditHostManage(req)
...@@ -211,6 +212,10 @@ func StateHostManage(c *gin.Context) { ...@@ -211,6 +212,10 @@ func StateHostManage(c *gin.Context) {
switch req.DetectionType { switch req.DetectionType {
case 1: case 1:
if req.Id == 0 {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("id为空")), nil)
return
}
//列表点击状态检测 //列表点击状态检测
err = hostManageSvc.ListStateHostManage(req) err = hostManageSvc.ListStateHostManage(req)
if err != nil { if err != nil {
...@@ -221,6 +226,10 @@ func StateHostManage(c *gin.Context) { ...@@ -221,6 +226,10 @@ func StateHostManage(c *gin.Context) {
return return
case 2: case 2:
//解析主机列表 //解析主机列表
if req.HostManageList == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机IP列表为空")), nil)
return
}
err = json.Unmarshal([]byte(req.HostManageList), &hostManageList) err = json.Unmarshal([]byte(req.HostManageList), &hostManageList)
if err != nil { if err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
...@@ -303,3 +312,35 @@ func HostIpExceptionList(c *gin.Context) { ...@@ -303,3 +312,35 @@ func HostIpExceptionList(c *gin.Context) {
SendJsonPageResponse(c, err, list, total) SendJsonPageResponse(c, err, list, total)
} }
} }
// 导出
func ExportIp(c *gin.Context) {
detectionType := c.Query("detection_type")
id := c.Query("id")
uuid := c.Query("uuid")
if cast.ToInt(detectionType) != 0 && cast.ToInt(detectionType) != 1 {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("导出类型解析错误")), nil)
return
}
if id == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("id为空")), nil)
return
}
if uuid == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("uuid为空")), nil)
return
}
hostManageSvc := service.HostManageSvc{}
fileName, err := hostManageSvc.ExportIp(id, uuid, cast.ToInt(detectionType))
if err != nil {
SendJsonResponse(c, err, nil)
return
}
c.Writer.Header().Add("Content-Type", "application/octet-stream")
c.Writer.Header().Add("Content-Transfer-Encoding", "binary")
c.Writer.Header().Add("Content-Disposition", "filename="+fileName)
c.File(conf.Options.TempDirPrefix + fileName)
}
...@@ -51,7 +51,7 @@ func initConfig() { ...@@ -51,7 +51,7 @@ func initConfig() {
Prefix: *prefix, Prefix: *prefix,
DbURL: util.SetEnvStr("DB_URL", "host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"), DbURL: util.SetEnvStr("DB_URL", "host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"),
DbDriver: util.SetEnvStr("DB_DRIVER", "postgres"), DbDriver: util.SetEnvStr("DB_DRIVER", "postgres"),
RedisURL: util.SetEnvStr("REDIS_URL", "localhost:6379"), RedisURL: util.SetEnvStr("REDIS_URL", "localhost:7001"),
RedisDB: 0, RedisDB: 0,
RedisTag: "bg", RedisTag: "bg",
LogDirPrefix: util.SetEnvStr("LOG_DIR_PREFIX", "/app/log"), // 日志目录 LogDirPrefix: util.SetEnvStr("LOG_DIR_PREFIX", "/app/log"), // 日志目录
...@@ -60,10 +60,11 @@ func initConfig() { ...@@ -60,10 +60,11 @@ func initConfig() {
LogMode: util.SetEnvInt("LOG_MODE", 1), // 1.标准打印 2.输出文件 LogMode: util.SetEnvInt("LOG_MODE", 1), // 1.标准打印 2.输出文件
ArgBool: util.SetEnvBool("ARG_BOOL", false), // 示例参数 ArgBool: util.SetEnvBool("ARG_BOOL", false), // 示例参数
ArgInt: util.SetEnvInt("ARG_INT", 10), // 示例参数 ArgInt: util.SetEnvInt("ARG_INT", 10), // 示例参数
MinioServer: util.SetEnvStr("MINIO_SERVER", "https://cache.wodcloud.com"), // Minio 服务地址 MinioServer: util.SetEnvStr("MINIO_SERVER", "cache.wodcloud.com"), // Minio 服务地址
MinioAccessKey: util.SetEnvStr("MINIO_ACCESS_KEY", "beagleadmin"), // Minio Access Key MinioAccessKey: util.SetEnvStr("MINIO_ACCESS_KEY", "beagleadmin"), // Minio Access Key
MinioSecretKey: util.SetEnvStr("MINIO_SECRET_KEY", "H76cPmwvH7vJ"), // Minio Secret MinioSecretKey: util.SetEnvStr("MINIO_SECRET_KEY", "H76cPmwvH7vJ"), // Minio Secret
MinioBucket: util.SetEnvStr("MINIO_BUCKET", "so-operation"), // Minio Bucket MinioBucket: util.SetEnvStr("MINIO_BUCKET", "so-operation"), // Minio Bucket
TempDirPrefix: util.SetEnvStr("TEMP_DIR_PREFIX", "/app/xlsx/"), //模板目录前缀
} }
} }
......
...@@ -9,9 +9,9 @@ import ( ...@@ -9,9 +9,9 @@ import (
// InitAutomatedMaintenRouter 初始化自动化运维路由 // InitAutomatedMaintenRouter 初始化自动化运维路由
func InitAutomatedMaintenRouter(e *gin.Engine) { func InitAutomatedMaintenRouter(e *gin.Engine) {
so := e.Group(fmt.Sprintf("%s/automatedMainten", conf.Options.Prefix)) so := e.Group(fmt.Sprintf("%s/automated_mainten", conf.Options.Prefix))
//任务管理 //任务管理
task := so.Group("/taskManage") task := so.Group("/task_manage")
{ {
task.POST("/add", controller.AddTaskManage) // 新增 task.POST("/add", controller.AddTaskManage) // 新增
task.PUT("/edit", controller.EditTaskManage) // 编辑 task.PUT("/edit", controller.EditTaskManage) // 编辑
...@@ -21,7 +21,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) { ...@@ -21,7 +21,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) {
task.POST("/exec/script", controller.ExecScript) // 立即执行 task.POST("/exec/script", controller.ExecScript) // 立即执行
} }
//主机管理 //主机管理
host := so.Group("/hostManage") host := so.Group("/host_manage")
{ {
host.POST("/add", controller.AddHostManage) // 新增 host.POST("/add", controller.AddHostManage) // 新增
host.PUT("/edit", controller.EditHostManage) // 编辑 host.PUT("/edit", controller.EditHostManage) // 编辑
...@@ -29,6 +29,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) { ...@@ -29,6 +29,7 @@ func InitAutomatedMaintenRouter(e *gin.Engine) {
host.GET("/details", controller.DetailsHostManage) // 详情 host.GET("/details", controller.DetailsHostManage) // 详情
host.GET("/list", controller.ListHostManage) // 列表 host.GET("/list", controller.ListHostManage) // 列表
host.POST("/state", controller.StateHostManage) // 状态检测 host.POST("/state", controller.StateHostManage) // 状态检测
host.GET("/ipExceptionList", controller.HostIpExceptionList) // 主机ip异常列表 host.GET("/ip_exception_list", controller.HostIpExceptionList) // 主机ip异常列表
host.GET("/export", controller.ExportIp) // 导出ip列表
} }
} }
...@@ -28,7 +28,7 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) { ...@@ -28,7 +28,7 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
base.GET("/example/list", controller.GetExampleList) // 示例获取列表 base.GET("/example/list", controller.GetExampleList) // 示例获取列表
} }
base.POST("addFile", controller.AddFile) //文件上传 base.POST("add_file", controller.AddFile) //文件上传
// 初始化自动化运维路由 // 初始化自动化运维路由
InitAutomatedMaintenRouter(r) InitAutomatedMaintenRouter(r)
......
...@@ -35,7 +35,7 @@ func (d *DocLibSvc) AddFile(c *gin.Context) (fileUrl string, err error) { ...@@ -35,7 +35,7 @@ func (d *DocLibSvc) AddFile(c *gin.Context) (fileUrl string, err error) {
ext string ext string
contentType string contentType string
) )
uploadFile, err = c.FormFile("uploadFile") uploadFile, err = c.FormFile("upload_file")
if err != nil { if err != nil {
err = errors.Wrap(err, "上传的文件不存在") err = errors.Wrap(err, "上传的文件不存在")
return return
......
...@@ -4,10 +4,13 @@ import ( ...@@ -4,10 +4,13 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/spf13/cast"
"github.com/tealeg/xlsx"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" "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/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/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"os" "os"
"os/exec" "os/exec"
...@@ -60,8 +63,27 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error) ...@@ -60,8 +63,27 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error)
return return
} }
//查询临时表中的ip列表
hostManageLists := make([]request.HostManageList, 0)
finder1 := session.Table("host_manage_list_cache").Where("conn_status = 0 AND id = ?", req.Uuid)
//查询
err = finder1.OrderBy("ip_group").Find(&hostManageLists)
if err != nil {
err = resp.DbSelectError.WithError(err)
session.Rollback()
return
}
//删除临时表数据
_, err = session.Table("host_manage_list_cache").Where("id = ?", req.Uuid).Delete()
if err != nil {
err = resp.DbDeleteError.WithError(err)
session.Rollback()
return
}
//新增主机分组列表 //新增主机分组列表
for _, v := range req.HostManageList { for _, v := range hostManageLists {
port := "22" port := "22"
if v.Port != "" { if v.Port != "" {
port = v.Port port = v.Port
...@@ -114,6 +136,24 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error ...@@ -114,6 +136,24 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
return return
} }
//正常ip列表
hostManageLists := make([]request.HostManageList, 0)
finder1 := session.Table("host_manage_list_cache").Where("conn_status = 0 AND id = ?", req.Uuid)
//查询
err = finder1.OrderBy("ip_group").Find(&hostManageLists)
if err != nil {
err = resp.DbSelectError.WithError(err)
session.Rollback()
return
}
//删除临时数据
_, err = session.Table("host_manage_list_cache").Where("id = ?", req.Uuid).Delete()
if err != nil {
err = resp.DbDeleteError.WithError(err)
session.Rollback()
return
}
//删除主机列表数据 //删除主机列表数据
_, err = session.Table("host_manage_list").Where("host_group_id = ?", req.Id).Cols("is_delete").Update(&entity.TaskManage{ _, err = session.Table("host_manage_list").Where("host_group_id = ?", req.Id).Cols("is_delete").Update(&entity.TaskManage{
IsDelete: 1, IsDelete: 1,
...@@ -125,7 +165,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error ...@@ -125,7 +165,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
} }
//新增主机分组列表 //新增主机分组列表
for _, v := range req.HostManageList { for _, v := range hostManageLists {
port := "22" port := "22"
if v.Port != "" { if v.Port != "" {
port = v.Port port = v.Port
...@@ -276,7 +316,7 @@ func (h *HostManageSvc) ListHostManage(req request.ListHostManageReq) (total int ...@@ -276,7 +316,7 @@ func (h *HostManageSvc) ListHostManage(req request.ListHostManageReq) (total int
//查询任务 //查询任务
total, err = finder.Select("hm.id,hm.host_name,hm.create_user,hm.create_time,(SELECT COUNT(*) FROM "+ total, err = finder.Select("hm.id,hm.host_name,hm.create_user,hm.create_time,(SELECT COUNT(*) FROM "+
"task_manage tm WHERE tm.is_delete = 0 AND tm.host_group_id = hm.ID) AS task_cnt,(SELECT COUNT(*) FROM "+ "task_manage tm WHERE tm.is_delete = 0 AND tm.host_group_id = hm.ID) AS task_cnt,(SELECT COUNT(*) FROM "+
"host_manage_list hml WHERE hml.is_delete = 0 AND hml.conn_status = 0 AND hml.host_group_id = hm.ID) AS "+ "host_manage_list hml WHERE hml.is_delete = 0 AND hml.conn_status = 1 AND hml.host_group_id = hm.ID) AS "+
"ip_cnt_err,(SELECT COUNT(*) FROM host_manage_list hml WHERE hml.is_delete = 0 AND hml.host_group_id = hm.ID) AS ip_cnt"). "ip_cnt_err,(SELECT COUNT(*) FROM host_manage_list hml WHERE hml.is_delete = 0 AND hml.host_group_id = hm.ID) AS ip_cnt").
Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&hostManageListRes) Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&hostManageListRes)
if err != nil { if err != nil {
...@@ -325,7 +365,6 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err ...@@ -325,7 +365,6 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
for _, v := range hostManageList { for _, v := range hostManageList {
//状态检测 //状态检测
ipConn := StatusDetection(v.Ip) ipConn := StatusDetection(v.Ip)
var state int var state int
if ipConn { if ipConn {
//连接正常 //连接正常
...@@ -382,23 +421,38 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL ...@@ -382,23 +421,38 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL
ipGroup += 1 ipGroup += 1
} }
//往hosts文件中写入主机组ip
f, err := os.OpenFile("/etc/ansible/hosts", os.O_APPEND|os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
if err != nil {
err = resp.FileExecError.WithError(err)
return
}
defer f.Close()
for _, v := range hostManageList {
_, err = f.Write([]byte(fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_pass=\"%s\"\n", v.Ip, v.Ip, v.Port, v.UserName, v.Password)))
if err != nil {
err = resp.FileExecError.WithError(err)
return
}
}
//状态检测 //状态检测
id = uuid.New().String() id = uuid.New().String()
if err != nil { if err != nil {
err = resp.FAIL.WithError(err) err = resp.FAIL.WithError(err)
return return
} }
for k, _ := range HostManageListCaches { for k, v := range HostManageListCaches {
//调用状态检测函数 //调用状态检测函数
cc := true ipConn := StatusDetection(v.Ip)
if ipConn {
if cc { //连接正常
//正常
HostManageListCaches[k].ConnStatus = 0 HostManageListCaches[k].ConnStatus = 0
} else { } else {
//异常 //连接异常
HostManageListCaches[k].ConnStatus = 1 HostManageListCaches[k].ConnStatus = 1
} }
HostManageListCaches[k].Id = id HostManageListCaches[k].Id = id
} }
...@@ -431,7 +485,7 @@ func (h *HostManageSvc) HostIpExceptionList(req request.HostIpExceptionListReq) ...@@ -431,7 +485,7 @@ func (h *HostManageSvc) HostIpExceptionList(req request.HostIpExceptionListReq)
} }
// SaveIpExceptionList 保存时状态检测异常列表 // SaveIpExceptionList 保存时状态检测异常列表
func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq) (total int64, hostManageListCacheRes response.HostManageListCacheRes, err error) { func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq) (total int64, hostManageListCacheRes []response.HostManageListCache, err error) {
db, err := client.GetDbClient() db, err := client.GetDbClient()
if err != nil { if err != nil {
err = resp.DbConnectError.WithError(err) err = resp.DbConnectError.WithError(err)
...@@ -441,27 +495,27 @@ func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq) ...@@ -441,27 +495,27 @@ func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq)
//异常ip列表-分页 //异常ip列表-分页
finder := db.Table("host_manage_list_cache").Where("conn_status = 1 AND id = ?", req.Uuid) finder := db.Table("host_manage_list_cache").Where("conn_status = 1 AND id = ?", req.Uuid)
//查询 //查询
total, err = finder.OrderBy("ip_group").Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&hostManageListCacheRes.AbnormalHost) total, err = finder.OrderBy("ip_group").Limit(req.PageSize, (req.Page-1)*req.PageSize).FindAndCount(&hostManageListCacheRes)
if err != nil { if err != nil {
err = resp.DbSelectError.WithError(err) err = resp.DbSelectError.WithError(err)
return return
} }
//正常ip列表 ////正常ip列表
finder1 := db.Table("host_manage_list_cache").Where("conn_status = 0 AND id = ?", req.Uuid) //finder1 := db.Table("host_manage_list_cache").Where("conn_status = 0 AND id = ?", req.Uuid)
//查询 ////查询
err = finder1.OrderBy("ip_group").Find(&hostManageListCacheRes.AormalHost) //err = finder1.OrderBy("ip_group").Find(&hostManageListCacheRes.AormalHost)
if err != nil { //if err != nil {
err = resp.DbSelectError.WithError(err) // err = resp.DbSelectError.WithError(err)
return // return
} //}
//
//删除临时数据 ////删除临时数据
_, err = db.Table("host_manage_list_cache").Where("id = ?", req.Uuid).Delete() //_, err = db.Table("host_manage_list_cache").Where("id = ?", req.Uuid).Delete()
if err != nil { //if err != nil {
err = resp.DbDeleteError.WithError(err) // err = resp.DbDeleteError.WithError(err)
return // return
} //}
return return
} }
...@@ -483,3 +537,100 @@ func StatusDetection(ip string) (ipConn bool) { ...@@ -483,3 +537,100 @@ func StatusDetection(ip string) (ipConn bool) {
return true return true
} }
// ExportIpStr 结果导出
type ExportIpStr struct {
Ip string `json:"ip" index:"0"` // ip
Port string `json:"port" index:"1"` // 端口
VoucherType string `json:"voucher_type" index:"2"` // 凭证类型
UserName string `json:"user_name" index:"3"` // 用户名
Password string `json:"password" index:"4"` // 密码
ConnStatus string `json:"conn_status" index:"5" ` // 连接状态
}
// ExportIp 结果导出
func (h *HostManageSvc) ExportIp(id, uuid string, detectionType int) (fileName string, err error) {
var (
push = make([]ExportIpStr, 0)
hostManageList = make([]entity.HostManageList, 0)
)
db, err := client.GetDbClient()
if err != nil {
err = resp.DbConnectError.WithError(err)
return
}
if detectionType == 1 {
//列表检测导出
finder := db.Table("host_manage_list").Where("is_delete = 0 AND host_group_id = ?", cast.ToInt(id))
err = finder.Select("").Find(&hostManageList)
if err != nil {
err = resp.DbSelectError.WithError(err)
return
}
} else {
//新增/编辑检测导出
finder := db.Table("host_manage_list_cache").Where("id = ?", uuid)
err = finder.Select("").Find(&hostManageList)
if err != nil {
err = resp.DbSelectError.WithError(err)
return
}
}
for _, v := range hostManageList {
voucherType := ""
switch v.VoucherType {
case 0:
voucherType = "密码验证"
case 1:
voucherType = "密钥验证"
}
connStatus := ""
switch v.ConnStatus {
case 0:
connStatus = "正常"
case 1:
connStatus = "异常"
}
staff := ExportIpStr{
Ip: v.Ip,
Port: v.Port,
VoucherType: voucherType,
UserName: v.UserName,
Password: v.Password,
ConnStatus: connStatus,
}
push = append(push, staff)
}
saveFileName, err := generatePushExportXlsx(push)
if err != nil {
err = resp.FileExecError.WithError(err)
return
}
return saveFileName, nil
}
func generatePushExportXlsx(push []ExportIpStr) (string, error) {
file := xlsx.NewFile()
sheet, _ := file.AddSheet("Sheet1")
titles := []string{"IP", "端口", "凭证类型", "用户名", "密码", "状态"}
row := sheet.AddRow()
var cell *xlsx.Cell
for _, title := range titles {
cell = row.AddCell()
cell.Value = title
}
for _, v := range push {
row = sheet.AddRow()
row.WriteStruct(&v, -1)
}
saveFileName := "IP列表导出数据.xlsx"
err := file.Save(conf.Options.TempDirPrefix + saveFileName)
return saveFileName, err
}
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