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
e4d1223e
Commit
e4d1223e
authored
Jul 12, 2023
by
陈子龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
主机管理状态检测 fix
parent
a6c3d61e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
51 deletions
+68
-51
src/common/conf/options.go
src/common/conf/options.go
+6
-6
src/main.go
src/main.go
+33
-33
src/service/host_manage.go
src/service/host_manage.go
+29
-11
src/service/task_manage.go
src/service/task_manage.go
+0
-1
No files found.
src/common/conf/options.go
View file @
e4d1223e
...
...
@@ -31,12 +31,12 @@ type Config struct {
MinioSecretKey
string
MinioBucket
string
//TempDirPrefix string
PrometheusHost
string
AccessRuleModeKey
string
LocationUrl
string
LocationKey
string
PrivateKeySSH
string
PublicKeySSH
string
PrometheusHost
string
AccessRuleModeKey
string
LocationUrl
string
LocationKey
string
PrivateKeySSH
string
//
PublicKeySSH string
OrderDingTalkAccessToken
string
OrderDingTalkSecret
string
SmsAccessKeyId
string
...
...
src/main.go
View file @
e4d1223e
...
...
@@ -56,28 +56,28 @@ func initConfig() {
conf
.
LoggerLevel
=
util
.
SetEnvStr
(
"LOG_LEVEL"
,
"info"
)
conf
.
RunMode
=
util
.
SetEnvStr
(
"GIN_MODE"
,
"debug"
)
// project run mode, available parameters: debug、release
conf
.
Options
=
&
conf
.
Config
{
Prefix
:
*
prefix
,
DbURL
:
util
.
SetEnvStr
(
"DB_URL"
,
"host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"
),
DbDriver
:
util
.
SetEnvStr
(
"DB_DRIVER"
,
"postgres"
),
RedisURL
:
util
.
SetEnvStr
(
"REDIS_URL"
,
"localhost:7001"
),
RedisDB
:
0
,
RedisTag
:
"bg"
,
LogDirPrefix
:
util
.
SetEnvStr
(
"LOG_DIR_PREFIX"
,
"/app/log"
),
// 日志目录
LogDirName
:
util
.
SetEnvStr
(
"LOG_NAME"
,
"syslog"
),
// 日志名称
LogSaveDays
:
util
.
SetEnvInt
(
"LOG_SAVE_DAYS"
,
7
),
// 日志最大存储天数
LogMode
:
util
.
SetEnvInt
(
"LOG_MODE"
,
1
),
// 1.标准打印 2.输出文件
ArgBool
:
util
.
SetEnvBool
(
"ARG_BOOL"
,
false
),
// 示例参数
ArgInt
:
util
.
SetEnvInt
(
"ARG_INT"
,
10
),
// 示例参数
MinioServer
:
util
.
SetEnvStr
(
"MINIO_SERVER"
,
"https://cache.wodcloud.com"
),
// Minio 服务地址
MinioAccessKey
:
util
.
SetEnvStr
(
"MINIO_ACCESS_KEY"
,
"beagleadmin"
),
// Minio Access Key
MinioSecretKey
:
util
.
SetEnvStr
(
"MINIO_SECRET_KEY"
,
"H76cPmwvH7vJ"
),
// Minio Secret
MinioBucket
:
util
.
SetEnvStr
(
"MINIO_BUCKET"
,
"so-operation"
),
// Minio Bucket
PrometheusHost
:
util
.
SetEnvStr
(
"PROMETHEUS_HOST"
,
"https://prometheus.wodcloud.com"
),
// Prometheus Host
AccessRuleModeKey
:
"accessRuleMode"
,
LocationUrl
:
util
.
SetEnvStr
(
"LOCATION_URL"
,
"https://apis.map.qq.com/ws/location/v1/ip"
),
LocationKey
:
util
.
SetEnvStr
(
"LOCATION_KEY"
,
"QKFBZ-PGGWJ-VZQFF-FHPA7-QWT5H-YHF4T"
),
PrivateKeySSH
:
util
.
SetEnvStr
(
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H PRIVATE KEY-----
\n
"
),
PublicKeySSH
:
util
.
SetEnvStr
(
"PUBLIC_KEY_SSH"
,
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCw4WT05QHzCD19348MfJfycS1NI9Jlj62PGrZ1rU9/kWQif5TV1rqHZ6qjAX2WfK+W3u4SV51MhZBkMZZOgZgJmdGiaZJkSmj+8gj6XU/bxslUd+BYUKqbE18gFkVDgqs6n2tcqJ2at3x+WEr81Msk2qvKuGEiIOzcJPICWKxwiw== chenzilong@example.com
\n
"
),
Prefix
:
*
prefix
,
DbURL
:
util
.
SetEnvStr
(
"DB_URL"
,
"host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"
),
DbDriver
:
util
.
SetEnvStr
(
"DB_DRIVER"
,
"postgres"
),
RedisURL
:
util
.
SetEnvStr
(
"REDIS_URL"
,
"localhost:7001"
),
RedisDB
:
0
,
RedisTag
:
"bg"
,
LogDirPrefix
:
util
.
SetEnvStr
(
"LOG_DIR_PREFIX"
,
"/app/log"
),
// 日志目录
LogDirName
:
util
.
SetEnvStr
(
"LOG_NAME"
,
"syslog"
),
// 日志名称
LogSaveDays
:
util
.
SetEnvInt
(
"LOG_SAVE_DAYS"
,
7
),
// 日志最大存储天数
LogMode
:
util
.
SetEnvInt
(
"LOG_MODE"
,
1
),
// 1.标准打印 2.输出文件
ArgBool
:
util
.
SetEnvBool
(
"ARG_BOOL"
,
false
),
// 示例参数
ArgInt
:
util
.
SetEnvInt
(
"ARG_INT"
,
10
),
// 示例参数
MinioServer
:
util
.
SetEnvStr
(
"MINIO_SERVER"
,
"https://cache.wodcloud.com"
),
// Minio 服务地址
MinioAccessKey
:
util
.
SetEnvStr
(
"MINIO_ACCESS_KEY"
,
"beagleadmin"
),
// Minio Access Key
MinioSecretKey
:
util
.
SetEnvStr
(
"MINIO_SECRET_KEY"
,
"H76cPmwvH7vJ"
),
// Minio Secret
MinioBucket
:
util
.
SetEnvStr
(
"MINIO_BUCKET"
,
"so-operation"
),
// Minio Bucket
PrometheusHost
:
util
.
SetEnvStr
(
"PROMETHEUS_HOST"
,
"https://prometheus.wodcloud.com"
),
// Prometheus Host
AccessRuleModeKey
:
"accessRuleMode"
,
LocationUrl
:
util
.
SetEnvStr
(
"LOCATION_URL"
,
"https://apis.map.qq.com/ws/location/v1/ip"
),
LocationKey
:
util
.
SetEnvStr
(
"LOCATION_KEY"
,
"QKFBZ-PGGWJ-VZQFF-FHPA7-QWT5H-YHF4T"
),
PrivateKeySSH
:
util
.
SetEnvStr
(
"PRIVATE_KEY_SSH"
,
"
"
),
//
PublicKeySSH: util.SetEnvStr("PUBLIC_KEY_SSH", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCw4WT05QHzCD19348MfJfycS1NI9Jlj62PGrZ1rU9/kWQif5TV1rqHZ6qjAX2WfK+W3u4SV51MhZBkMZZOgZgJmdGiaZJkSmj+8gj6XU/bxslUd+BYUKqbE18gFkVDgqs6n2tcqJ2at3x+WEr81Msk2qvKuGEiIOzcJPICWKxwiw== chenzilong@example.com\n"),
OrderDingTalkAccessToken
:
util
.
SetEnvStr
(
"ORDER_DING_TALK_ACCESS_TOKEN"
,
"203fe1644b446bba0a34e6e622c523d39ee9916fdad94b9c64224449f659e20b"
),
OrderDingTalkSecret
:
util
.
SetEnvStr
(
"ORDER_DING_TALK_SECRET"
,
"SECa73d8372e336451c9daf29a99f750ee1bdd170c1dab910eab9cd06d729a831b7"
),
SmsAccessKeyId
:
util
.
SetEnvStr
(
"SMS_ACCESS_KEY"
,
"LTAI4GBcVubRjzX7ABPcHnhB"
),
// 短信key
...
...
@@ -161,19 +161,19 @@ func initAnsibleSSH() {
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
else
{
_
,
err
:=
f
.
Write
([]
byte
(
conf
.
Options
.
PrivateKeySSH
))
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
}
f2
,
err
:=
os
.
Create
(
"/root/.ssh/id_rsa.pub"
)
defer
f2
.
Close
()
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
else
{
_
,
err
:=
f
.
Write
([]
byte
(
conf
.
Options
.
PublicKeySSH
))
_
,
err
=
f
.
Write
([]
byte
(
conf
.
Options
.
PrivateKeySSH
))
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
}
//f2, err := os.Create("/root/.ssh/id_rsa.pub")
//defer f2.Close()
//if err != nil {
// fmt.Println(err.Error())
//} else {
// _, err := f.Write([]byte(conf.Options.PublicKeySSH))
// if err != nil {
// fmt.Println(err.Error())
// }
//}
}
src/service/host_manage.go
View file @
e4d1223e
...
...
@@ -455,7 +455,11 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
for
_
,
v
:=
range
hostManageList
{
//修改状态
connStatus
:=
StatusDetection
(
v
.
Ip
)
connStatus
,
err1
:=
StatusDetection
(
v
.
Ip
)
if
err1
!=
nil
{
session
.
Rollback
()
return
err1
}
hostManageListConn
:=
entity
.
HostManageList
{
ConnStatus
:
connStatus
,
}
...
...
@@ -545,7 +549,10 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL
id
=
uuid
.
New
()
.
String
()
for
k
,
v
:=
range
hostManageListCaches
{
//调用状态检测函数
hostManageListCaches
[
k
]
.
ConnStatus
=
StatusDetection
(
v
.
Ip
)
hostManageListCaches
[
k
]
.
ConnStatus
,
err
=
StatusDetection
(
v
.
Ip
)
if
err
!=
nil
{
return
}
hostManageListCaches
[
k
]
.
Id
=
id
}
...
...
@@ -614,16 +621,25 @@ func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq)
}
// StatusDetection 状态检测
func
StatusDetection
(
ip
string
)
(
ipConn
int
)
{
func
StatusDetection
(
ip
string
)
(
ipConn
int
,
err
error
)
{
var
cmd
*
exec
.
Cmd
cmd
=
exec
.
Command
(
"ansible"
,
fmt
.
Sprintf
(
"%s"
,
AnsibleIp
+
ip
),
"-m"
,
"ping"
)
output
,
err
:=
cmd
.
Output
()
if
err
!=
nil
{
fmt
.
Println
(
"ping:"
,
string
(
output
))
return
1
//执行cmd命令
if
err
=
cmd
.
Start
();
err
!=
nil
{
err
=
resp
.
CmdExecError
.
WithError
(
err
)
return
}
if
cmd
.
ProcessState
.
Success
()
{
return
0
,
nil
}
fmt
.
Println
(
"ping:"
,
string
(
output
))
return
0
return
1
,
nil
//output, err := cmd.Output()
//if err != nil {
// fmt.Println("ping:", string(output))
// return 1
//}
//fmt.Println("ping:", string(output))
//return 0
}
// ExportIpStr 结果导出
...
...
@@ -780,7 +796,10 @@ func CronStatusDetection() {
// }
//}
for
_
,
v
:=
range
hostManageList
{
connStatus
:=
StatusDetection
(
v
.
Ip
)
connStatus
,
err1
:=
StatusDetection
(
v
.
Ip
)
if
err1
!=
nil
{
fmt
.
Println
(
"CronStatusDetection err:"
,
err1
.
Error
())
}
//修改状态
_
,
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND id = ?"
,
v
.
Id
)
.
Cols
(
"conn_status"
)
.
Update
(
&
entity
.
HostManageList
{
...
...
@@ -788,7 +807,6 @@ func CronStatusDetection() {
})
if
err
!=
nil
{
fmt
.
Println
(
"CronStatusDetection err:"
,
err
.
Error
())
return
}
}
fmt
.
Println
(
"CronPersonalCardDate success!"
)
...
...
src/service/task_manage.go
View file @
e4d1223e
...
...
@@ -237,7 +237,6 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq, script string) (id
}
//写入主机信息
//hostsIp := strings.Replace(strings.Trim(fmt.Sprint(hosts), "[]"), " ", " ", -1)
hostsGroup
,
err
:=
os
.
Create
(
"/etc/ansible/hosts_"
+
fmt
.
Sprintf
(
"%d"
,
req
.
TaskId
))
if
err
!=
nil
{
...
...
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