Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
7fabfbfe
Commit
7fabfbfe
authored
Jun 30, 2023
by
陈子龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动化运维 fix
parent
37f16c6f
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
419 additions
and
218 deletions
+419
-218
go.mod
go.mod
+3
-2
go.sum
go.sum
+4
-1
src/bean/entity/host_manage.go
src/bean/entity/host_manage.go
+26
-26
src/bean/entity/task_manage.go
src/bean/entity/task_manage.go
+14
-14
src/bean/vo/request/host_manage.go
src/bean/vo/request/host_manage.go
+24
-22
src/bean/vo/request/task_manage.go
src/bean/vo/request/task_manage.go
+13
-13
src/bean/vo/response/host_manage.go
src/bean/vo/response/host_manage.go
+48
-48
src/bean/vo/response/task_manage.go
src/bean/vo/response/task_manage.go
+13
-13
src/common/conf/options.go
src/common/conf/options.go
+1
-0
src/controller/host_manage.go
src/controller/host_manage.go
+70
-29
src/main.go
src/main.go
+12
-11
src/router/automatedmaintenrouter.go
src/router/automatedmaintenrouter.go
+11
-10
src/router/router.go
src/router/router.go
+1
-1
src/service/doc_lib.go
src/service/doc_lib.go
+1
-1
src/service/host_manage.go
src/service/host_manage.go
+178
-27
No files found.
go.mod
View file @
7fabfbfe
...
@@ -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
...
...
go.sum
View file @
7fabfbfe
...
@@ -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=
...
...
src/bean/entity/host_manage.go
View file @
7fabfbfe
...
@@ -3,36 +3,36 @@ package entity
...
@@ -3,36 +3,36 @@ package entity
import
"time"
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:"host
N
ame" xorm:"host_name"`
// 主机分组名称
HostName
string
`json:"host
_n
ame" xorm:"host_name"`
// 主机分组名称
IsDelete
int
`json:"is
D
elete" xorm:"is_delete" `
// 是否删除(0 未删除 1已删除)
IsDelete
int
`json:"is
_d
elete" xorm:"is_delete" `
// 是否删除(0 未删除 1已删除)
CreateUser
string
`json:"create
U
ser" xorm:"create_user" `
// 创建人
CreateUser
string
`json:"create
_u
ser" xorm:"create_user" `
// 创建人
CreateTime
time
.
Time
`json:"create
T
ime" xorm:"create_time"`
// 创建时间
CreateTime
time
.
Time
`json:"create
_t
ime" xorm:"create_time"`
// 创建时间
UpdateUser
string
`json:"update
U
ser" xorm:"update_user" `
// 修改人
UpdateUser
string
`json:"update
_u
ser" xorm:"update_user" `
// 修改人
UpdateTime
time
.
Time
`json:"update
T
ime" xorm:"update_time"`
// 修改时间
UpdateTime
time
.
Time
`json:"update
_t
ime" 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:"voucher
Type" xorm:"voucher_type"`
// 凭证类型(0密码验证
密钥验证)
VoucherType
int
`json:"voucher
_type" xorm:"voucher_type"`
// 凭证类型(0密码验证 1
密钥验证)
UserName
string
`json:"user
Name" 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:"host
GroupI
d" xorm:"host_group_id"`
// 主机分组id
HostGroupId
int
`json:"host
_group_i
d" xorm:"host_group_id"`
// 主机分组id
HostFileUrl
string
`json:"host
FileU
rl" xorm:"host_file_url"`
// 主机文件url
HostFileUrl
string
`json:"host
_file_u
rl" xorm:"host_file_url"`
// 主机文件url
IsDelete
int
`json:"is
Delete" xorm:"is_delete" `
// 是否删除(0 未删除 1已删除)
IsDelete
int
`json:"is
_delete" xorm:"is_delete" `
// 是否删除(0 未删除 1已删除)
ConnStatus
int
`json:"conn
Status" xorm:"conn_status" `
// 连接状态(0正常 1异常)
ConnStatus
int
`json:"conn
_status" xorm:"conn_status" `
// 连接状态(0正常 1异常)
IpGroup
int
`json:"ip
Group" 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:"voucher
T
ype" xorm:"voucher_type"`
// 凭证类型(0密码验证 密钥验证)
VoucherType
int
`json:"voucher
_t
ype" xorm:"voucher_type"`
// 凭证类型(0密码验证 密钥验证)
UserName
string
`json:"user
N
ame" xorm:"user_name"`
// 用户名
UserName
string
`json:"user
_n
ame" xorm:"user_name"`
// 用户名
Password
string
`json:"password" xorm:"password"`
// 密码
Password
string
`json:"password" xorm:"password"`
// 密码
ConnStatus
int
`json:"conn
S
tatus" xorm:"conn_status" `
// 连接状态(0正常 1异常)
ConnStatus
int
`json:"conn
_s
tatus" xorm:"conn_status" `
// 连接状态(0正常 1异常)
IpGroup
int
`json:"ip
G
roup" xorm:"ip_group" `
// ip分组
IpGroup
int
`json:"ip
_g
roup" xorm:"ip_group" `
// ip分组
}
}
src/bean/entity/task_manage.go
View file @
7fabfbfe
...
@@ -3,18 +3,18 @@ package entity
...
@@ -3,18 +3,18 @@ package entity
import
"time"
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:"task
Name" xorm:"task_name"`
// 任务名称
TaskName
string
`json:"task
_name" xorm:"task_name"`
// 任务名称
TaskDesc
string
`json:"task
Desc" xorm:"task_desc"`
// 任务描述
TaskDesc
string
`json:"task
_desc" xorm:"task_desc"`
// 任务描述
YamlDesc
string
`json:"yaml
Desc" xorm:"yaml_desc"`
// yaml文件
YamlDesc
string
`json:"yaml
_desc" xorm:"yaml_desc"`
// yaml文件
YamlUrl
string
`json:"yaml
Url" xorm:"yaml_url"`
// yaml文件地址
YamlUrl
string
`json:"yaml
_url" xorm:"yaml_url"`
// yaml文件地址
ExecCnt
int
`json:"exec
Cnt" xorm:"exec_cnt"`
// 执行次数
ExecCnt
int
`json:"exec
_cnt" xorm:"exec_cnt"`
// 执行次数
SuccessCnt
int
`json:"success
Cnt" xorm:"success_cnt"`
// 执行成功次数
SuccessCnt
int
`json:"success
_cnt" xorm:"success_cnt"`
// 执行成功次数
FailCnt
int
`json:"fail
Cnt" xorm:"fail_cnt"`
// 执行失败次数
FailCnt
int
`json:"fail
_cnt" xorm:"fail_cnt"`
// 执行失败次数
HostGroupId
int
`json:"host
GroupI
d" xorm:"host_group_id"`
// 主机分组ID
HostGroupId
int
`json:"host
_group_i
d" xorm:"host_group_id"`
// 主机分组ID
IsDelete
int
`json:"is
Delete" xorm:"is_delete" `
// 是否删除(0 未删除 1已删除)
IsDelete
int
`json:"is
_delete" xorm:"is_delete" `
// 是否删除(0 未删除 1已删除)
CreateUser
string
`json:"create
User" xorm:"create_user" `
// 创建人
CreateUser
string
`json:"create
_user" xorm:"create_user" `
// 创建人
CreateTime
time
.
Time
`json:"create
Time" xorm:"create_time"`
// 创建时间
CreateTime
time
.
Time
`json:"create
_time" xorm:"create_time"`
// 创建时间
UpdateUser
string
`json:"update
User" xorm:"update_user" `
// 修改人
UpdateUser
string
`json:"update
_user" xorm:"update_user" `
// 修改人
UpdateTime
time
.
Time
`json:"update
Time" xorm:"update_time"`
// 修改时间
UpdateTime
time
.
Time
`json:"update
_time" xorm:"update_time"`
// 修改时间
}
}
src/bean/vo/request/host_manage.go
View file @
7fabfbfe
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:"voucher
T
ype"`
// 凭证类型(0密码验证 1密钥验证)
VoucherType
int
`json:"voucher
_t
ype"`
// 凭证类型(0密码验证 1密钥验证)
UserName
string
`json:"user
N
ame"`
// 用户名
UserName
string
`json:"user
_n
ame"`
// 用户名
Password
string
`json:"password"`
// 密码
Password
string
`json:"password"`
// 密码
IpGroup
int
`json:"ip
G
roup"`
// ip分组
IpGroup
int
`json:"ip
_g
roup"`
// 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
{
...
@@ -26,24 +28,24 @@ type DelHostManageReq struct {
...
@@ -26,24 +28,24 @@ type DelHostManageReq struct {
}
}
type
ListHostManageReq
struct
{
type
ListHostManageReq
struct
{
Search
string
`json:"search"`
//关键词
Search
string
`json:"search"`
//关键词
CreateDateFrom
string
`json:"create
DateF
rom"`
//创建时间从
CreateDateFrom
string
`json:"create
_date_f
rom"`
//创建时间从
CreateDateTo
string
`json:"create
DateT
o"`
//创建时间至
CreateDateTo
string
`json:"create
_date_t
o"`
//创建时间至
Pagination
Pagination
}
}
// StateHostManageReq 状态检测
// StateHostManageReq 状态检测
type
StateHostManageReq
struct
{
type
StateHostManageReq
struct
{
DetectionType
int
`json:"detection
Type" form:"detectionT
ype" binding:"oneof=1 2 3"`
//1主页列表手动检测 2输入ip列表保存时检测 3上传ip列表文件保存时检测
DetectionType
int
`json:"detection
_type" form:"detection_t
ype" 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:"hostF
ile"` // 主机文件
//HostFile
file `form:"host_f
ile"` // 主机文件
HostManageList
string
`json:"host
ManageList" form:"hostManageL
ist"`
//主机ip列表
HostManageList
string
`json:"host
_manage_list" form:"host_manage_l
ist"`
//主机ip列表
}
}
// HostIpExceptionListReq 异常列表
// HostIpExceptionListReq 异常列表
type
HostIpExceptionListReq
struct
{
type
HostIpExceptionListReq
struct
{
DetectionType
int
`json:"detection
T
ype" binding:"oneof=1 2"`
//1主页异常ip列表 2保存检测时异常列表
DetectionType
int
`json:"detection
_t
ype" 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
}
}
src/bean/vo/request/task_manage.go
View file @
7fabfbfe
package
request
package
request
type
AddTaskManageReq
struct
{
type
AddTaskManageReq
struct
{
TaskName
string
`json:"task
N
ame" vd:"len($)>0;msg:'请输入任务名称'"`
// 任务名称
TaskName
string
`json:"task
_n
ame" vd:"len($)>0;msg:'请输入任务名称'"`
// 任务名称
TaskDesc
string
`json:"task
D
esc"`
// 任务描述
TaskDesc
string
`json:"task
_d
esc"`
// 任务描述
YamlDesc
string
`json:"yaml
D
esc"`
// yaml内容
YamlDesc
string
`json:"yaml
_d
esc"`
// yaml内容
YamlUrl
string
`json:"yaml
U
rl"`
// yaml文件url
YamlUrl
string
`json:"yaml
_u
rl"`
// yaml文件url
HostGroupId
int
`json:"host
GroupId" 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:"task
Desc"`
// 任务描述
TaskDesc
string
`json:"task
_desc"`
// 任务描述
YamlDesc
string
`json:"yaml
Desc"`
// yaml内容
YamlDesc
string
`json:"yaml
_desc"`
// yaml内容
YamlUrl
string
`json:"yaml
Url"`
// yaml文件url
YamlUrl
string
`json:"yaml
_url"`
// yaml文件url
HostGroupId
int
`json:"host
GroupI
d" vd:"$>0;msg:'请选择主机分组'"`
// 主机分组ID
HostGroupId
int
`json:"host
_group_i
d" vd:"$>0;msg:'请选择主机分组'"`
// 主机分组ID
}
}
type
DelTaskManageReq
struct
{
type
DelTaskManageReq
struct
{
...
@@ -25,9 +25,9 @@ type DetailsTaskManageReq struct {
...
@@ -25,9 +25,9 @@ type DetailsTaskManageReq struct {
}
}
type
ListTaskManageReq
struct
{
type
ListTaskManageReq
struct
{
Search
string
`json:"search" form:"search"`
//关键词
Search
string
`json:"search" form:"search"`
//关键词
CreateDateFrom
string
`json:"create
DateF
rom" form:"createDateFrom"`
//创建时间从
CreateDateFrom
string
`json:"create
_date_f
rom" form:"createDateFrom"`
//创建时间从
CreateDateTo
string
`json:"create
DateT
o" form:"createDateTo"`
//创建时间至
CreateDateTo
string
`json:"create
_date_t
o" form:"createDateTo"`
//创建时间至
Pagination
Pagination
}
}
...
...
src/bean/vo/response/host_manage.go
View file @
7fabfbfe
...
@@ -3,71 +3,71 @@ package response
...
@@ -3,71 +3,71 @@ package response
import
"time"
import
"time"
type
HostManageRes
struct
{
type
HostManageRes
struct
{
Id
int
`json:"id"`
// id
Id
int
`json:"id"`
// id
HostName
string
`json:"host
Name"`
// 主机分组名称
HostName
string
`json:"host
_name"`
// 主机分组名称
TaskCnt
int
`json:"task
Cnt"`
// 任务数量
TaskCnt
int
`json:"task
_cnt"`
// 任务数量
IpCnt
int
`json:"ip
Cnt"`
// ip数量
IpCnt
int
`json:"ip
_cnt"`
// ip数量
CreateUser
string
`json:"create
User"`
// 创建人
CreateUser
string
`json:"create
_user"`
// 创建人
CreateTime
time
.
Time
`json:"create
Time"`
// 创建时间
CreateTime
time
.
Time
`json:"create
_time"`
// 创建时间
UpdateUser
string
`json:"update
User"`
// 修改人
UpdateUser
string
`json:"update
_user"`
// 修改人
UpdateTime
time
.
Time
`json:"update
Time"`
// 修改时间
UpdateTime
time
.
Time
`json:"update
_time"`
// 修改时间
HostFileUrl
string
`json:"host
FileU
rl"`
// 主机文件url
HostFileUrl
string
`json:"host
_file_u
rl"`
// 主机文件url
HostList
[]
HostList
`json:"host
List"`
// 主机列表
HostList
[]
HostList
`json:"host
_list"`
// 主机列表
TaskList
[]
TaskList
`json:"task
List"`
// 主机
列表
TaskList
[]
TaskList
`json:"task
_list"`
// 任务
列表
}
}
type
HostManage
struct
{
type
HostManage
struct
{
Id
int
`json:"id"`
// id
Id
int
`json:"id"`
// id
HostName
string
`json:"host
N
ame"`
// 主机分组名称
HostName
string
`json:"host
_n
ame"`
// 主机分组名称
CreateUser
string
`json:"create
U
ser"`
// 创建人
CreateUser
string
`json:"create
_u
ser"`
// 创建人
CreateTime
time
.
Time
`json:"create
T
ime"`
// 创建时间
CreateTime
time
.
Time
`json:"create
_t
ime"`
// 创建时间
UpdateUser
string
`json:"update
U
ser"`
// 修改人
UpdateUser
string
`json:"update
_u
ser"`
// 修改人
UpdateTime
time
.
Time
`json:"update
T
ime"`
// 修改时间
UpdateTime
time
.
Time
`json:"update
_t
ime"`
// 修改时间
}
}
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:"host
FileU
rl"`
// 主机文件url
HostFileUrl
string
`json:"host
_file_u
rl"`
// 主机文件url
}
}
type
TaskList
struct
{
type
TaskList
struct
{
Id
int
`json:"id"`
// id
Id
int
`json:"id"`
// id
TaskName
string
`json:"task
N
ame"`
// 任务名称
TaskName
string
`json:"task
_n
ame"`
// 任务名称
TaskDesc
string
`json:"task
D
esc"`
// 任务描述
TaskDesc
string
`json:"task
_d
esc"`
// 任务描述
ExecCnt
int
`json:"exec
C
nt"`
// 执行次数
ExecCnt
int
`json:"exec
_c
nt"`
// 执行次数
}
}
type
HostManagesRes
struct
{
type
HostManagesRes
struct
{
Id
int
`json:"id"`
// id
Id
int
`json:"id"`
// id
HostName
string
`json:"host
N
ame"`
// 主机分组名称
HostName
string
`json:"host
_n
ame"`
// 主机分组名称
CreateUser
string
`json:"create
U
ser"`
// 创建人
CreateUser
string
`json:"create
_u
ser"`
// 创建人
CreateTime
time
.
Time
`json:"create
T
ime"`
// 创建时间
CreateTime
time
.
Time
`json:"create
_t
ime"`
// 创建时间
TaskCnt
int
`json:"task
C
nt"`
// 任务数量
TaskCnt
int
`json:"task
_c
nt"`
// 任务数量
IpCntErr
int
`json:"ip
CntErr"`
// ip数量(异常)
IpCntErr
int
`json:"ip
_cnt_err"`
// ip数量(异常)
IpCnt
int
`json:"ip
C
nt"`
// ip数量(全部)
IpCnt
int
`json:"ip
_c
nt"`
// 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:"voucher
T
ype"`
// 凭证类型(0密码验证 密钥验证)
VoucherType
int
`json:"voucher
_t
ype"`
// 凭证类型(0密码验证 密钥验证)
UserName
string
`json:"user
N
ame"`
// 用户名
UserName
string
`json:"user
_n
ame"`
// 用户名
Password
string
`json:"password"`
// 密码
Password
string
`json:"password"`
// 密码
}
}
type
HostManageListCacheRes
struct
{
//
type HostManageListCacheRes struct {
AormalHost
[]
HostManageListCache
`json:"normalH
ost"`
// 正常ip
// AormalHost []HostManageListCache `json:"normal_h
ost"` // 正常ip
AbnormalHost
[]
HostManageListCache
`json:"abnormalH
ost"`
// 异常ip
// AbnormalHost []HostManageListCache `json:"abnormal_h
ost"` // 异常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:"voucher
Type"`
// 凭证类型(0密码验证
密钥验证)
VoucherType
int
`json:"voucher
_type"`
// 凭证类型(0密码验证 1
密钥验证)
UserName
string
`json:"user
N
ame"`
// 用户名
UserName
string
`json:"user
_n
ame"`
// 用户名
Password
string
`json:"password"`
// 密码
Password
string
`json:"password"`
// 密码
IpGroup
int
`json:"ip
G
roup"`
// ip分组
IpGroup
int
`json:"ip
_g
roup"`
// ip分组
}
}
src/bean/vo/response/task_manage.go
View file @
7fabfbfe
...
@@ -3,17 +3,17 @@ package response
...
@@ -3,17 +3,17 @@ package response
import
"time"
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:"task
Name" xorm:"task_name"`
// 任务名称
TaskName
string
`json:"task
_name" xorm:"task_name"`
// 任务名称
TaskDesc
string
`json:"task
Desc" xorm:"task_desc"`
// 任务描述
TaskDesc
string
`json:"task
_desc" xorm:"task_desc"`
// 任务描述
YamlDesc
string
`json:"yaml
Desc" xorm:"yaml_desc"`
// yaml文件
YamlDesc
string
`json:"yaml
_desc" xorm:"yaml_desc"`
// yaml文件
YamlUrl
string
`json:"yaml
Url" xorm:"yaml_url"`
// yaml文件地址
YamlUrl
string
`json:"yaml
_url" xorm:"yaml_url"`
// yaml文件地址
ExecCnt
int
`json:"exec
Cnt" xorm:"exec_cnt"`
// 执行次数
ExecCnt
int
`json:"exec
_cnt" xorm:"exec_cnt"`
// 执行次数
SuccessCnt
int
`json:"success
Cnt" xorm:"success_cnt"`
// 执行成功次数
SuccessCnt
int
`json:"success
_cnt" xorm:"success_cnt"`
// 执行成功次数
FailCnt
int
`json:"fail
Cnt" xorm:"fail_cnt"`
// 执行失败次数
FailCnt
int
`json:"fail
_cnt" xorm:"fail_cnt"`
// 执行失败次数
HostGroupId
int
`json:"host
GroupI
d" xorm:"host_group_id"`
// 主机分组ID
HostGroupId
int
`json:"host
_group_i
d" xorm:"host_group_id"`
// 主机分组ID
CreateUser
string
`json:"create
User" xorm:"create_user" `
// 创建人
CreateUser
string
`json:"create
_user" xorm:"create_user" `
// 创建人
CreateTime
time
.
Time
`json:"create
Time" xorm:"create_time"`
// 创建时间
CreateTime
time
.
Time
`json:"create
_time" xorm:"create_time"`
// 创建时间
UpdateUser
string
`json:"update
User" xorm:"update_user" `
// 修改人
UpdateUser
string
`json:"update
_user" xorm:"update_user" `
// 修改人
UpdateTime
time
.
Time
`json:"update
Time" xorm:"update_time"`
// 修改时间
UpdateTime
time
.
Time
`json:"update
_time" xorm:"update_time"`
// 修改时间
}
}
src/common/conf/options.go
View file @
7fabfbfe
...
@@ -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
(
...
...
src/controller/host_manage.go
View file @
7fabfbfe
...
@@ -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
(
"host
F
ile"
)
metaData
,
_
,
err
:=
c
.
Request
.
FormFile
(
"host
_f
ile"
)
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
)
}
src/main.go
View file @
7fabfbfe
...
@@ -51,19 +51,20 @@ func initConfig() {
...
@@ -51,19 +51,20 @@ 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"
),
// 日志目录
LogDirName
:
util
.
SetEnvStr
(
"LOG_NAME"
,
"syslog"
),
// 日志名称
LogDirName
:
util
.
SetEnvStr
(
"LOG_NAME"
,
"syslog"
),
// 日志名称
LogSaveDays
:
util
.
SetEnvInt
(
"LOG_SAVE_DAYS"
,
7
),
// 日志最大存储天数
LogSaveDays
:
util
.
SetEnvInt
(
"LOG_SAVE_DAYS"
,
7
),
// 日志最大存储天数
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/"
),
//模板目录前缀
}
}
}
}
...
...
src/router/automatedmaintenrouter.go
View file @
7fabfbfe
...
@@ -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/automated
M
ainten"
,
conf
.
Options
.
Prefix
))
so
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/automated
_m
ainten"
,
conf
.
Options
.
Prefix
))
//任务管理
//任务管理
task
:=
so
.
Group
(
"/task
M
anage"
)
task
:=
so
.
Group
(
"/task
_m
anage"
)
{
{
task
.
POST
(
"/add"
,
controller
.
AddTaskManage
)
// 新增
task
.
POST
(
"/add"
,
controller
.
AddTaskManage
)
// 新增
task
.
PUT
(
"/edit"
,
controller
.
EditTaskManage
)
// 编辑
task
.
PUT
(
"/edit"
,
controller
.
EditTaskManage
)
// 编辑
...
@@ -21,14 +21,15 @@ func InitAutomatedMaintenRouter(e *gin.Engine) {
...
@@ -21,14 +21,15 @@ func InitAutomatedMaintenRouter(e *gin.Engine) {
task
.
POST
(
"/exec/script"
,
controller
.
ExecScript
)
// 立即执行
task
.
POST
(
"/exec/script"
,
controller
.
ExecScript
)
// 立即执行
}
}
//主机管理
//主机管理
host
:=
so
.
Group
(
"/host
M
anage"
)
host
:=
so
.
Group
(
"/host
_m
anage"
)
{
{
host
.
POST
(
"/add"
,
controller
.
AddHostManage
)
// 新增
host
.
POST
(
"/add"
,
controller
.
AddHostManage
)
// 新增
host
.
PUT
(
"/edit"
,
controller
.
EditHostManage
)
// 编辑
host
.
PUT
(
"/edit"
,
controller
.
EditHostManage
)
// 编辑
host
.
DELETE
(
"/del"
,
controller
.
DelHostManage
)
// 删除
host
.
DELETE
(
"/del"
,
controller
.
DelHostManage
)
// 删除
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列表
}
}
}
}
src/router/router.go
View file @
7fabfbfe
...
@@ -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
(
"add
F
ile"
,
controller
.
AddFile
)
//文件上传
base
.
POST
(
"add
_f
ile"
,
controller
.
AddFile
)
//文件上传
// 初始化自动化运维路由
// 初始化自动化运维路由
InitAutomatedMaintenRouter
(
r
)
InitAutomatedMaintenRouter
(
r
)
...
...
src/service/doc_lib.go
View file @
7fabfbfe
...
@@ -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
(
"upload
F
ile"
)
uploadFile
,
err
=
c
.
FormFile
(
"upload
_f
ile"
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
errors
.
Wrap
(
err
,
"上传的文件不存在"
)
err
=
errors
.
Wrap
(
err
,
"上传的文件不存在"
)
return
return
...
...
src/service/host_manage.go
View file @
7fabfbfe
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment