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
a6c3d61e
Commit
a6c3d61e
authored
Jul 12, 2023
by
陈子龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
主机管理状态检测 fix
parent
294c864c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
57 deletions
+56
-57
src/main.go
src/main.go
+16
-17
src/service/host_manage.go
src/service/host_manage.go
+40
-40
No files found.
src/main.go
View file @
a6c3d61e
...
@@ -56,23 +56,22 @@ func initConfig() {
...
@@ -56,23 +56,22 @@ func initConfig() {
conf
.
LoggerLevel
=
util
.
SetEnvStr
(
"LOG_LEVEL"
,
"info"
)
conf
.
LoggerLevel
=
util
.
SetEnvStr
(
"LOG_LEVEL"
,
"info"
)
conf
.
RunMode
=
util
.
SetEnvStr
(
"GIN_MODE"
,
"debug"
)
// project run mode, available parameters: debug、release
conf
.
RunMode
=
util
.
SetEnvStr
(
"GIN_MODE"
,
"debug"
)
// project run mode, available parameters: debug、release
conf
.
Options
=
&
conf
.
Config
{
conf
.
Options
=
&
conf
.
Config
{
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:7001"
),
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"
,
"https://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/"), //模板目录前缀
PrometheusHost
:
util
.
SetEnvStr
(
"PROMETHEUS_HOST"
,
"https://prometheus.wodcloud.com"
),
// Prometheus Host
PrometheusHost
:
util
.
SetEnvStr
(
"PROMETHEUS_HOST"
,
"https://prometheus.wodcloud.com"
),
// Prometheus Host
AccessRuleModeKey
:
"accessRuleMode"
,
AccessRuleModeKey
:
"accessRuleMode"
,
LocationUrl
:
util
.
SetEnvStr
(
"LOCATION_URL"
,
"https://apis.map.qq.com/ws/location/v1/ip"
),
LocationUrl
:
util
.
SetEnvStr
(
"LOCATION_URL"
,
"https://apis.map.qq.com/ws/location/v1/ip"
),
...
...
src/service/host_manage.go
View file @
a6c3d61e
...
@@ -412,46 +412,46 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
...
@@ -412,46 +412,46 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
}
}
// 读取hosts中的主机组
// 读取hosts中的主机组
//
hosts, err := tools.HostsToJson()
hosts
,
err
:=
tools
.
HostsToJson
()
//
if err != nil {
if
err
!=
nil
{
//
err = resp.MarshalError.WithError(err)
err
=
resp
.
MarshalError
.
WithError
(
err
)
//
session.Rollback()
session
.
Rollback
()
//
return
return
//
}
}
//
//
if _, ok := hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"]; !ok {
if
_
,
ok
:=
hosts
[
"["
+
AnsibleGroup
+
fmt
.
Sprintf
(
"%d"
,
req
.
Id
)
+
"]"
];
!
ok
{
//
// 不存在
// 不存在
//
hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] = nil
hosts
[
"["
+
AnsibleGroup
+
fmt
.
Sprintf
(
"%d"
,
req
.
Id
)
+
"]"
]
=
nil
//
}
}
//
//
新增主机分组列表
//新增主机分组列表
//
for _, v := range hostManageList {
for
_
,
v
:=
range
hostManageList
{
//
hostsIp := ""
hostsIp
:=
""
//
if v.VoucherType == 0 {
if
v
.
VoucherType
==
0
{
//
hostsIp = fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_pass=\"%s\" ansible_host_key_checking=false",
hostsIp
=
fmt
.
Sprintf
(
"%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=
\"
%s
\"
ansible_ssh_pass=
\"
%s
\"
ansible_host_key_checking=false"
,
//
AnsibleIp+fmt.Sprintf("%d", v.Id), v.Ip, v.Port, v.UserName, v.Password)
AnsibleIp
+
fmt
.
Sprintf
(
"%d"
,
v
.
Id
),
v
.
Ip
,
v
.
Port
,
v
.
UserName
,
v
.
Password
)
//
} else {
}
else
{
//
hostsIp = fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_private_key_file=/root/.ssh/id_rsa ansible_host_key_checking=false",
hostsIp
=
fmt
.
Sprintf
(
"%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=
\"
%s
\"
ansible_ssh_private_key_file=/root/.ssh/id_rsa ansible_host_key_checking=false"
,
//
AnsibleIp+fmt.Sprintf("%d", v.Id), v.Ip, v.Port, v.UserName)
AnsibleIp
+
fmt
.
Sprintf
(
"%d"
,
v
.
Id
),
v
.
Ip
,
v
.
Port
,
v
.
UserName
)
//
}
}
//
//
flag := 0
flag
:=
0
//
for _, v1 := range hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] {
for
_
,
v1
:=
range
hosts
[
"["
+
AnsibleGroup
+
fmt
.
Sprintf
(
"%d"
,
req
.
Id
)
+
"]"
]
{
//
if v1 == hostsIp {
if
v1
==
hostsIp
{
//
flag = 1
flag
=
1
//
}
}
//
}
}
//
if flag == 0 {
if
flag
==
0
{
//
hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] = append(hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"], hostsIp)
hosts
[
"["
+
AnsibleGroup
+
fmt
.
Sprintf
(
"%d"
,
req
.
Id
)
+
"]"
]
=
append
(
hosts
[
"["
+
AnsibleGroup
+
fmt
.
Sprintf
(
"%d"
,
req
.
Id
)
+
"]"
],
hostsIp
)
//
}
}
//
}
}
//
//
//
写入hosts
//写入hosts
//
err = tools.MapToSaveHosts(hosts)
err
=
tools
.
MapToSaveHosts
(
hosts
)
//
if err != nil {
if
err
!=
nil
{
//
err = resp.MarshalError.WithError(err)
err
=
resp
.
MarshalError
.
WithError
(
err
)
//
session.Rollback()
session
.
Rollback
()
//
return
return
//
}
}
for
_
,
v
:=
range
hostManageList
{
for
_
,
v
:=
range
hostManageList
{
//修改状态
//修改状态
...
...
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