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
a9f61204
Commit
a9f61204
authored
Jul 04, 2023
by
黄智
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
619689fa
7f25cae8
Changes
32
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
870 additions
and
114 deletions
+870
-114
src/bean/entity/alert_class.go
src/bean/entity/alert_class.go
+9
-8
src/bean/entity/alert_rules.go
src/bean/entity/alert_rules.go
+41
-0
src/bean/entity/metric_config.go
src/bean/entity/metric_config.go
+1
-0
src/bean/entity/work_order.go
src/bean/entity/work_order.go
+19
-0
src/bean/vo/request/alert_class.go
src/bean/vo/request/alert_class.go
+4
-3
src/bean/vo/request/alert_rules.go
src/bean/vo/request/alert_rules.go
+75
-0
src/bean/vo/request/doc_lib.go
src/bean/vo/request/doc_lib.go
+6
-0
src/bean/vo/request/metric_config.go
src/bean/vo/request/metric_config.go
+4
-2
src/bean/vo/request/task_history.go
src/bean/vo/request/task_history.go
+7
-1
src/bean/vo/response/alert_rules.go
src/bean/vo/response/alert_rules.go
+12
-0
src/bean/vo/response/host_manage.go
src/bean/vo/response/host_manage.go
+2
-1
src/bean/vo/response/metric_config.go
src/bean/vo/response/metric_config.go
+1
-1
src/bean/vo/response/task_manage.go
src/bean/vo/response/task_manage.go
+1
-0
src/common/conf/options.go
src/common/conf/options.go
+1
-1
src/controller/alert_class.go
src/controller/alert_class.go
+13
-2
src/controller/alert_rules.go
src/controller/alert_rules.go
+99
-0
src/controller/doc_lib.go
src/controller/doc_lib.go
+33
-0
src/controller/host_manage.go
src/controller/host_manage.go
+6
-7
src/controller/metric_config.go
src/controller/metric_config.go
+13
-2
src/controller/task_history.go
src/controller/task_history.go
+2
-2
src/controller/work_order_manage.go
src/controller/work_order_manage.go
+114
-0
src/main.go
src/main.go
+19
-11
src/router/alertrulesrouter.go.go
src/router/alertrulesrouter.go.go
+20
-0
src/router/router.go
src/router/router.go
+6
-1
src/router/workorderrouter.go
src/router/workorderrouter.go
+45
-0
src/service/alert_class.go
src/service/alert_class.go
+14
-20
src/service/alert_rules.go
src/service/alert_rules.go
+203
-0
src/service/doc_lib.go
src/service/doc_lib.go
+33
-0
src/service/host_manage.go
src/service/host_manage.go
+13
-10
src/service/metric_config.go
src/service/metric_config.go
+18
-29
src/service/task_history.go
src/service/task_history.go
+8
-3
src/service/task_manage.go
src/service/task_manage.go
+28
-10
No files found.
src/bean/entity/alert_class.go
View file @
a9f61204
...
@@ -3,14 +3,15 @@ package entity
...
@@ -3,14 +3,15 @@ package entity
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
type
AlertClass
struct
{
type
AlertClass
struct
{
ClassId
int
`json:"class_id" xorm:"'class_id' pk autoincr" `
// 主键id
ClassId
int
`json:"class_id" xorm:"'class_id' pk autoincr" `
// 主键id
ClassName
string
`json:"class_name" xorm:"'class_name'"`
// 分类名称
ClassName
string
`json:"class_name" xorm:"'class_name'"`
// 分类名称
ParentId
int
`json:"parent_id" xorm:"'parent_id'"`
// 父级id
ParentId
int
`json:"parent_id" xorm:"'parent_id'"`
// 父级id
SortOrder
int
`json:"sort_order" xorm:"'sort_order'"`
// 排序
SortOrder
int
`json:"sort_order" xorm:"'sort_order'"`
// 排序
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
SourceFrom
int
`json:"source_from" xorm:"source_from"`
// 数据来源 1:默认 2:自定义
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
}
}
func
(
m
*
AlertClass
)
TableName
()
string
{
func
(
m
*
AlertClass
)
TableName
()
string
{
...
...
src/bean/entity/alert_rules.go
0 → 100644
View file @
a9f61204
package
entity
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
// AlertRules 预警规则配置
type
AlertRules
struct
{
Id
string
`json:"id" xorm:"'id' pk"`
// 主键id
MetricName
string
`json:"metric_name" xorm:"'metric_name'"`
// 预警规则名称(指标名称)
DetectionType
int
`json:"detection_type" xorm:"'detection_type'"`
// 检测类型 1:静态阈值 2:自定义
ClassId
int
`json:"class_id" xorm:"'class_id'"`
// 预警对象id(级联:预警分类/预警对象)
MetricConfigId
string
`json:"metric_config_id" xorm:"'metric_config_id'"`
// 预警指标id
AlertRange
string
`json:"alert_range" xorm:"'alert_range'"`
// 预警范围 字典值
AlertCondition
string
`json:"alert_condition" xorm:"'alert_condition'"`
// 预警规则 字典值
Duration
int
`json:"duration" xorm:"'duration'"`
// 持续时间
DurationUnit
string
`json:"duration_unit" xorm:"'duration_unit'"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" xorm:"'check_period'"`
// 检查周期 单位:分钟
NotifyMethod
string
`json:"notify_method" xorm:"'notify_method'"`
// 预警通知方式 all dingtalk sms
NotifyPushCount
int
`json:"notify_push_count" xorm:"'notify_push_count'"`
// 消息推送次数
NotifyPushFrequency
int
`json:"notify_push_frequency" xorm:"'notify_push_frequency'"`
// 消息推送频率 分钟
IsEnabled
int
`json:"is_enabled" xorm:"'is_enabled'"`
// 是否开启 0:关闭 1:启动
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
}
func
(
m
*
AlertRules
)
TableName
()
string
{
return
"alert_rules"
}
type
RulesAlertRange
struct
{
Name
string
`json:"name" form:"name" binding:"required"`
Value
string
`json:"value" form:"value" binding:"required"`
Compare
string
`json:"compare" form:"compare" binding:"required"`
}
type
AlertCondition
struct
{
ThresholdsMax
int
`json:"thresholds_max" form:"thresholds_max" binding:"required"`
ThresholdsMin
int
`json:"thresholds_min" form:"thresholds_min" binding:"required"`
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"required"`
}
src/bean/entity/metric_config.go
View file @
a9f61204
...
@@ -13,6 +13,7 @@ type MetricConfig struct {
...
@@ -13,6 +13,7 @@ type MetricConfig struct {
CheckPeriod
int
`json:"check_period" xorm:"'check_period'"`
// 检查周期 单位:分钟
CheckPeriod
int
`json:"check_period" xorm:"'check_period'"`
// 检查周期 单位:分钟
IsEnabled
int
`json:"is_enabled" xorm:"'is_enabled'"`
// 是否开启 0:关闭 1:启动
IsEnabled
int
`json:"is_enabled" xorm:"'is_enabled'"`
// 是否开启 0:关闭 1:启动
AlertRuleType
string
`json:"alert_rule_type" xorm:"'alert_rule_type'"`
// 预警规则类型 关联字典表
AlertRuleType
string
`json:"alert_rule_type" xorm:"'alert_rule_type'"`
// 预警规则类型 关联字典表
SourceFrom
int
`json:"source_from" xorm:"source_from"`
// 数据来源 1:默认 2:自定义
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
...
...
src/bean/entity/work_order.go
0 → 100644
View file @
a9f61204
package
entity
import
"time"
type
WorkOrder
struct
{
Id
int
`json:"id" xorm:"pk autoincr" `
// id
OrderName
string
`json:"order_name" xorm:"order_name"`
// 工单名称
OrderLevel
int
`json:"order_level" xorm:"order_level"`
// 工单等级(1紧急任务 2重要任务 3一般任务)
OrderDesc
string
`json:"order_desc" xorm:"order_desc"`
// 工单描述
OrderCnt
int
`json:"order_cnt" xorm:"order_cnt"`
// 实例工单数
PushObj
string
`json:"push_obj" xorm:"push_obj"`
// 推送对象
TimingType
int
`json:"timing_type" xorm:"timing_type"`
// 定时类型(1手动下发 2按周 3自定义时间)
TimingRule
string
`json:"timing_rule" xorm:"timing_rule"`
// 定时规则
TimingState
int
`json:"timing_state" xorm:"timing_state"`
// 定时状态(0禁用 1启用)
CreateUser
string
`json:"create_user" xorm:"create_user" `
// 创建人
CreateTime
time
.
Time
`json:"create_time" xorm:"create_time" `
// 创建时间
UpdateUser
string
`json:"update_user" xorm:"update_user"`
// 修改人
UpdateTime
time
.
Time
`json:"update_time" xorm:"update_time" `
// 修改时间
}
src/bean/vo/request/alert_class.go
View file @
a9f61204
package
request
package
request
type
AddAlertClass
struct
{
type
AddAlertClass
struct
{
ClassName
string
`json:"class_name" form:"class_name" binding:"required"`
ClassName
string
`json:"class_name" form:"class_name" binding:"required"`
ParentId
int
`json:"parent_id" form:"parent_id" binding:"omitempty,oneof=0 1"`
ParentId
int
`json:"parent_id" form:"parent_id" binding:"omitempty,oneof=0 1"`
SortOrder
int
`json:"sort_order" form:"sort_order"`
SortOrder
int
`json:"sort_order" form:"sort_order"`
SourceFrom
int
`json:"source_from" form:"source_from" binding:"omitempty,oneof=1 2"`
// 数据来源 1:默认 2:自定义
}
}
type
UpdateAlertClass
struct
{
type
UpdateAlertClass
struct
{
...
...
src/bean/vo/request/alert_rules.go
0 → 100644
View file @
a9f61204
package
request
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
type
AddAlertRules
struct
{
MetricName
string
`json:"metric_name" form:"metric_name" binding:"required"`
// 预警规则名称(指标名称)
DetectionType
int
`json:"detection_type" form:"detection_type" binding:"oneof=1 2"`
// 检测类型 1:静态阈值 2:自定义
ClassId
int
`json:"class_id" form:"class_id" binding:"required_if=DetectionType 1"`
// 预警对象id(级联:预警分类/预警对象)
ClassParentName
string
`json:"class_parent_name" form:"class_parent_name" binding:"required_if=DetectionType 2"`
// 预警分类名称
ClassName
string
`json:"class_name" form:"class_name" binding:"required_if=DetectionType 2"`
// 预警对象名称
MetricConfigName
string
`json:"metric_config_name" form:"metric_config_name" binding:"required_if=DetectionType 2"`
// 预警指标名称(映射entity.MetricConfig.MetricName)
Expr
string
`json:"expr" form:"expr" binding:"required_if=DetectionType 2"`
// 指标表达式(PromQL语句)
AlertCondition
[]
entity
.
AlertCondition
`json:"alert_condition" form:"alert_condition" binding:"required"`
// 预警规则 字典值
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required_if=DetectionType 2"`
// 预警规则类型 关联字典表
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" form:"alert_range" binding:"required,dive"`
// 预警范围 字典值
Duration
int
`json:"duration" form:"duration" binding:"gte=0"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"oneof=s m h"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
NotifyMethod
string
`json:"notify_method" form:"notify_method" binding:"oneof=all dingtalk sms"`
// 预警通知方式 all dingtalk sms
NotifyPushCount
int
`json:"notify_push_count" form:"notify_push_count" binding:"gte=1"`
// 消息推送次数
NotifyPushFrequency
int
`json:"notify_push_frequency" form:"notify_push_frequency" binding:"gte=1"`
// 消息推送频率 分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=0 1 2"`
// 是否开启 1:是 2:否
}
type
UpdateAlertRules
struct
{
Id
string
`json:"id" binding:"required"`
MetricName
string
`json:"metric_name" form:"metric_name" binding:"required"`
// 预警规则名称(指标名称)
DetectionType
int
`json:"detection_type" form:"detection_type" binding:"oneof=1 2"`
// 检测类型 1:静态阈值 2:自定义
ClassId
int
`json:"class_id" form:"class_id" binding:"required"`
// 预警对象id(级联:预警分类/预警对象)
ClassParentName
string
`json:"class_parent_name" form:"class_parent_name" binding:"required_if=DetectionType 2"`
// 预警分类名称
ClassName
string
`json:"class_name" form:"class_name" binding:"required_if=DetectionType 2"`
// 预警对象名称
MetricConfigName
string
`json:"metric_config_name" form:"metric_config_name" binding:"required_if=DetectionType 2"`
// 预警指标名称(detection_type=2时有值)
Expr
string
`json:"expr" form:"expr" binding:"required_if=DetectionType 2"`
// 指标表达式(PromQL语句)
AlertCondition
string
`json:"alert_condition" form:"alert_condition" binding:"required"`
// 预警规则 字典值
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required_if=DetectionType 2"`
// 预警规则类型 关联字典表
AlertRange
string
`json:"alert_range" form:"alert_range"`
// 预警范围 字典值
Duration
int
`json:"duration" form:"duration" binding:"gte=0"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"oneof=s m h"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"gte=0"`
// 检查周期 单位:分钟
NotifyMethod
string
`json:"notify_method" form:"notify_method" binding:"oneof=all dingtalk sms"`
// 预警通知方式 all dingtalk sms
NotifyPushCount
int
`json:"notify_push_count" form:"notify_push_count" binding:"gte=1"`
// 消息推送次数
NotifyPushFrequency
int
`json:"notify_push_frequency" form:"notify_push_frequency" binding:"gte=1"`
// 消息推送频率 分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=0 1 2"`
// 是否开启 1:是 2:否
}
type
DeleteAlertRules
struct
{
Id
string
`json:"id" form:"id"`
Ids
[]
string
`json:"ids" form:"ids" binding:"required_without=Id"`
}
type
DetailAlertRules
struct
{
Id
string
`json:"id" form:"id" binding:"required"`
}
type
ListAlertRules
struct
{
Id
string
`json:"id" form:"id"`
MetricName
string
`json:"metric_name" form:"metric_name"`
// 预警规则名称(指标名称)
DetectionType
int
`json:"detection_type" form:"detection_type"`
// 检测类型 1:静态阈值 2:自定义
ClassId
int
`json:"class_id" form:"class_id"`
// 预警对象id(级联:预警分类/预警对象)
ClassParentName
string
`json:"class_parent_name" form:"class_parent_name"`
// 预警分类名称
ClassName
string
`json:"class_name" form:"class_name"`
// 预警对象名称
MetricConfigName
string
`json:"metric_config_name" form:"metric_config_name"`
// 预警指标名称(detection_type=2时有值)
Expr
string
`json:"expr" form:"expr"`
// 指标表达式(PromQL语句)
AlertCondition
string
`json:"alert_condition" form:"alert_condition"`
// 预警规则 字典值
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type"`
// 预警规则类型 关联字典表
AlertRange
string
`json:"alert_range" form:"alert_range"`
// 预警范围 字典值
Duration
int
`json:"duration" form:"duration"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period"`
// 检查周期 单位:分钟
NotifyMethod
string
`json:"notify_method" form:"notify_method"`
// 预警通知方式 all dingtalk sms
NotifyPushCount
int
`json:"notify_push_count" form:"notify_push_count"`
// 消息推送次数
NotifyPushFrequency
int
`json:"notify_push_frequency" form:"notify_push_frequency"`
// 消息推送频率 分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled"`
// 是否开启 1:是 2:否
Pagination
}
src/bean/vo/request/doc_lib.go
View file @
a9f61204
package
request
package
request
type
DocLibGetReq
struct
{
FileName
string
`uri:"file_name" binding:"required"`
//文档名称
Ext
string
`uri:"ext" binding:"required"`
//后缀格式
Opt
string
`uri:"opt" binding:"required,oneof=preview download"`
//操作
}
src/bean/vo/request/metric_config.go
View file @
a9f61204
...
@@ -10,8 +10,9 @@ type AddMetricConfig struct {
...
@@ -10,8 +10,9 @@ type AddMetricConfig struct {
Duration
int
`json:"duration" form:"duration"`
// 持续时间
Duration
int
`json:"duration" form:"duration"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"required,oneof=s m h"`
// 持续时间单位 s m h
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"required,oneof=s m h"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"o
neof=0 1 2"`
// 是否开启 1:启动 2:停用
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"o
mitempty,oneof=0 1 2"`
// 是否开启 1:是 2:否
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required"`
// 预警规则类型 关联字典表
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required"`
// 预警规则类型 关联字典表
SourceFrom
int
`json:"source_from" form:"source_from" binding:"omitempty,oneof=1 2"`
// 数据来源 1:默认 2:自定义
}
}
type
UpdateMetricConfig
struct
{
type
UpdateMetricConfig
struct
{
...
@@ -23,8 +24,9 @@ type UpdateMetricConfig struct {
...
@@ -23,8 +24,9 @@ type UpdateMetricConfig struct {
Duration
int
`json:"duration" form:"duration"`
// 持续时间
Duration
int
`json:"duration" form:"duration"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"omitempty,oneof=s m h"`
// 持续时间单位 s m h
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"omitempty,oneof=s m h"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"omitempty,oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"omitempty,oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=0 1 2"`
// 是否开启 1:
启动 2:停用
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=0 1 2"`
// 是否开启 1:
是 2:否
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type"`
// 预警规则类型 关联字典表
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type"`
// 预警规则类型 关联字典表
SourceFrom
int
`json:"source_from" form:"source_from" binding:"omitempty,oneof=1 2"`
// 数据来源 1:默认 2:自定义
}
}
type
DeleteMetricConfig
struct
{
type
DeleteMetricConfig
struct
{
...
...
src/bean/vo/request/task_history.go
View file @
a9f61204
package
request
package
request
type
TaskHistoryReq
struct
{
type
TaskHistoryReq
struct
{
TaskId
int
`json:"task_id" form:"task_id" binding:"required"`
// 主键ID
Search
string
`json:"search" form:"search"`
// 关键词
Pagination
}
type
TaskInfoListReq
struct
{
TaskId
int
`json:"task_id" form:"task_id" binding:"required"`
// 主键ID
Search
string
`json:"search" form:"search"`
// 关键词
Pagination
Pagination
}
}
src/bean/vo/response/alert_rules.go
0 → 100644
View file @
a9f61204
package
response
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
type
AlertRulesItem
struct
{
entity
.
AlertRules
`xorm:"extends"`
}
type
AlertRulesList
struct
{
TotalCount
int64
`json:"total_count"`
List
[]
AlertRulesItem
`json:"list"`
}
src/bean/vo/response/host_manage.go
View file @
a9f61204
...
@@ -26,13 +26,14 @@ type HostManage struct {
...
@@ -26,13 +26,14 @@ type HostManage struct {
}
}
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"`
// 端口
VoucherType
int
`json:"voucher_type"`
// 凭证类型(0密码验证 密钥验证)
VoucherType
int
`json:"voucher_type"`
// 凭证类型(0密码验证 密钥验证)
UserName
string
`json:"user_name"`
// 用户名
UserName
string
`json:"user_name"`
// 用户名
Password
string
`json:"password"`
// 密码
Password
string
`json:"password"`
// 密码
HostFileUrl
string
`json:"-"`
// 主机文件url
HostFileUrl
string
`json:"-"`
// 主机文件url
Cnt
int
`json:"cnt""`
//主机ip数量
}
}
type
TaskList
struct
{
type
TaskList
struct
{
...
...
src/bean/vo/response/metric_config.go
View file @
a9f61204
...
@@ -7,7 +7,7 @@ type MetricConfigItem struct {
...
@@ -7,7 +7,7 @@ type MetricConfigItem struct {
AlertRange
[]
entity
.
AlertRange
`json:"alert_range" xorm:"alert_range"`
AlertRange
[]
entity
.
AlertRange
`json:"alert_range" xorm:"alert_range"`
}
}
type
Units
List
struct
{
type
MetricConfig
List
struct
{
TotalCount
int64
`json:"total_count"`
TotalCount
int64
`json:"total_count"`
List
[]
MetricConfigItem
`json:"list"`
List
[]
MetricConfigItem
`json:"list"`
}
}
src/bean/vo/response/task_manage.go
View file @
a9f61204
...
@@ -13,6 +13,7 @@ type TaskManageListRes struct {
...
@@ -13,6 +13,7 @@ type TaskManageListRes struct {
type
TaskManageRes
struct
{
type
TaskManageRes
struct
{
Id
int
`json:"id"`
// id
Id
int
`json:"id"`
// id
HostGroupId
int
`json:"host_group_id"`
// 主机分组id
TaskName
string
`json:"task_name"`
// 任务名称
TaskName
string
`json:"task_name"`
// 任务名称
TaskDesc
string
`json:"task_desc"`
// 任务描述
TaskDesc
string
`json:"task_desc"`
// 任务描述
YamlDesc
string
`json:"yaml_desc"`
// yaml文件
YamlDesc
string
`json:"yaml_desc"`
// yaml文件
...
...
src/common/conf/options.go
View file @
a9f61204
...
@@ -30,7 +30,7 @@ type Config struct {
...
@@ -30,7 +30,7 @@ type Config struct {
MinioAccessKey
string
MinioAccessKey
string
MinioSecretKey
string
MinioSecretKey
string
MinioBucket
string
MinioBucket
string
TempDirPrefix
string
//
TempDirPrefix string
PrometheusHost
string
PrometheusHost
string
}
}
...
...
src/controller/alert_class.go
View file @
a9f61204
...
@@ -3,6 +3,7 @@ package controller
...
@@ -3,6 +3,7 @@ package controller
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"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/client"
"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/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
...
@@ -17,7 +18,12 @@ func AddAlertClass(c *gin.Context) {
...
@@ -17,7 +18,12 @@ func AddAlertClass(c *gin.Context) {
}
}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Add
(
req
)
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
_
,
err
=
svc
.
Add
(
db
.
NewSession
(),
req
)
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
return
...
@@ -33,7 +39,12 @@ func UpdateAlertClass(c *gin.Context) {
...
@@ -33,7 +39,12 @@ func UpdateAlertClass(c *gin.Context) {
}
}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
AlertClassSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Update
(
req
)
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
err
=
svc
.
Update
(
db
.
NewSession
(),
req
)
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
return
...
...
src/controller/alert_rules.go
0 → 100644
View file @
a9f61204
package
controller
import
(
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
// AddAlertRules 新增任务
func
AddAlertRules
(
c
*
gin
.
Context
)
{
var
req
request
.
AddAlertRules
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertRulesSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Add
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
UpdateAlertRules
(
c
*
gin
.
Context
)
{
var
req
request
.
UpdateAlertRules
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertRulesSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Update
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
DeleteAlertRules
(
c
*
gin
.
Context
)
{
var
req
request
.
DeleteAlertRules
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
var
ids
[]
string
switch
len
(
req
.
Ids
)
{
case
0
:
ids
=
append
(
ids
,
req
.
Id
)
default
:
ids
=
req
.
Ids
}
svc
:=
service
.
AlertRulesSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Delete
(
ids
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
func
DetailAlertRules
(
c
*
gin
.
Context
)
{
var
req
request
.
DetailAlertRules
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertRulesSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
GetDataById
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
func
ListAlertRules
(
c
*
gin
.
Context
)
{
var
req
request
.
ListAlertRules
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
AlertRulesSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
List
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
src/controller/doc_lib.go
View file @
a9f61204
...
@@ -2,8 +2,12 @@ package controller
...
@@ -2,8 +2,12 @@ package controller
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"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"
"net/http"
"net/http/httputil"
"net/url"
)
)
func
AddFile
(
c
*
gin
.
Context
)
{
func
AddFile
(
c
*
gin
.
Context
)
{
...
@@ -16,3 +20,32 @@ func AddFile(c *gin.Context) {
...
@@ -16,3 +20,32 @@ func AddFile(c *gin.Context) {
}
}
SendJsonResponse
(
c
,
resp
.
OK
,
doc
)
SendJsonResponse
(
c
,
resp
.
OK
,
doc
)
}
}
func
DownloadFile
(
c
*
gin
.
Context
)
{
var
req
request
.
DocLibGetReq
if
err
:=
c
.
ShouldBindUri
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
return
}
docLibSvc
:=
service
.
DocLibSvc
{}
docUrl
,
err
:=
docLibSvc
.
DownloadFile
(
c
,
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
switch
req
.
Opt
{
case
"download"
:
//c.Redirect(http.StatusMovedPermanently, docUrl.String())
docUrlParse
,
_
:=
url
.
Parse
(
docUrl
.
String
())
proxy
:=
httputil
.
ReverseProxy
{
Director
:
func
(
req
*
http
.
Request
)
{
req
.
Header
=
c
.
Request
.
Header
req
.
Host
=
docUrlParse
.
Host
req
.
URL
=
docUrlParse
},
}
proxy
.
ServeHTTP
(
c
.
Writer
,
c
.
Request
)
case
"preview"
:
c
.
Redirect
(
http
.
StatusMovedPermanently
,
docUrl
.
String
())
}
}
src/controller/host_manage.go
View file @
a9f61204
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ 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"
...
@@ -74,14 +73,14 @@ func GetMinioFiles(fileName string) (hostManageList []request.HostManageList, er
...
@@ -74,14 +73,14 @@ func GetMinioFiles(fileName string) (hostManageList []request.HostManageList, er
//读取工作簿
//读取工作簿
rows
:=
xlsxData
.
GetRows
(
"Sheet1"
)
rows
:=
xlsxData
.
GetRows
(
"Sheet1"
)
if
len
(
rows
)
>
100
1
{
if
len
(
rows
)
>
100
3
{
err
=
resp
.
FailedToParseFile
.
WithError
(
errors
.
New
(
"ip数量不可超过1000"
))
err
=
resp
.
FailedToParseFile
.
WithError
(
errors
.
New
(
"ip数量不可超过1000"
))
return
return
}
}
for
i
:=
0
;
i
<
len
(
rows
);
i
++
{
for
i
:=
0
;
i
<
len
(
rows
);
i
++
{
//默认跳过
第一
行
//默认跳过
前两
行
if
i
<
1
{
if
i
<
2
{
continue
continue
}
}
...
@@ -371,11 +370,11 @@ func ExportIp(c *gin.Context) {
...
@@ -371,11 +370,11 @@ func ExportIp(c *gin.Context) {
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"导出类型解析错误"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"导出类型解析错误"
)),
nil
)
return
return
}
}
if
id
==
""
{
if
cast
.
ToInt
(
detectionType
)
==
1
&&
id
==
""
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"id为空"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"id为空"
)),
nil
)
return
return
}
}
if
uuid
==
""
{
if
cast
.
ToInt
(
detectionType
)
==
0
&&
uuid
==
""
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"uuid为空"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"uuid为空"
)),
nil
)
return
return
}
}
...
@@ -390,7 +389,7 @@ func ExportIp(c *gin.Context) {
...
@@ -390,7 +389,7 @@ func ExportIp(c *gin.Context) {
c
.
Writer
.
Header
()
.
Add
(
"Content-Transfer-Encoding"
,
"binary"
)
c
.
Writer
.
Header
()
.
Add
(
"Content-Transfer-Encoding"
,
"binary"
)
c
.
Writer
.
Header
()
.
Add
(
"Content-Disposition"
,
"filename="
+
fileName
)
c
.
Writer
.
Header
()
.
Add
(
"Content-Disposition"
,
"filename="
+
fileName
)
c
.
File
(
conf
.
Options
.
TempDirPrefix
+
fileName
)
c
.
File
(
"/app/xlsx/"
+
fileName
)
}
}
// ListHostManage 列表
// ListHostManage 列表
...
...
src/controller/metric_config.go
View file @
a9f61204
...
@@ -3,6 +3,7 @@ package controller
...
@@ -3,6 +3,7 @@ package controller
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"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/client"
"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/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
...
@@ -17,7 +18,12 @@ func AddMetricConfig(c *gin.Context) {
...
@@ -17,7 +18,12 @@ func AddMetricConfig(c *gin.Context) {
}
}
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Add
(
req
)
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
_
,
err
=
svc
.
Add
(
db
.
NewSession
(),
req
)
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
return
...
@@ -33,7 +39,12 @@ func UpdateMetricConfig(c *gin.Context) {
...
@@ -33,7 +39,12 @@ func UpdateMetricConfig(c *gin.Context) {
}
}
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
MetricConfigSvc
{
User
:
header
.
GetUser
(
c
)}
err
:=
svc
.
Update
(
req
)
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
err
=
svc
.
Update
(
db
.
NewSession
(),
req
)
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
return
...
...
src/controller/task_history.go
View file @
a9f61204
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
// TaskHistoryList 任务历史列表
// TaskHistoryList 任务历史列表
func
TaskHistoryList
(
c
*
gin
.
Context
)
{
func
TaskHistoryList
(
c
*
gin
.
Context
)
{
var
req
request
.
Pagination
var
req
request
.
TaskHistoryReq
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
return
return
...
@@ -28,7 +28,7 @@ func TaskHistoryList(c *gin.Context) {
...
@@ -28,7 +28,7 @@ func TaskHistoryList(c *gin.Context) {
// TaskInfoList 任务历史详情列表
// TaskInfoList 任务历史详情列表
func
TaskInfoList
(
c
*
gin
.
Context
)
{
func
TaskInfoList
(
c
*
gin
.
Context
)
{
var
req
request
.
Task
History
Req
var
req
request
.
Task
InfoList
Req
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
return
return
...
...
src/controller/work_order_manage.go
0 → 100644
View file @
a9f61204
package
controller
import
(
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
)
// AddWorkOrderManage 新增业务工单管理
func
AddWorkOrderManage
(
c
*
gin
.
Context
)
{
//var req request.AddTaskManageReq
//if err := c.ShouldBindJSON(&req); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
//}
////参数校验
//if err := util.ValidateSimple(req, "TaskName,HostGroupId"); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
//}
//
//taskManageSvc := service.TaskManageSvc{}
//err := taskManageSvc.AddTaskManage(req)
//if err != nil {
// SendJsonResponse(c, err, nil)
// return
//}
SendJsonResponse
(
c
,
resp
.
OK
,
nil
)
}
//
//// EditTaskManage 编辑任务
//func EditTaskManage(c *gin.Context) {
// var req request.EditTaskManageReq
// if err := c.ShouldBindJSON(&req); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
// //参数校验
// if err := util.ValidateSimple(req, "Id,HostGroupId"); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
//
// taskManageSvc := service.TaskManageSvc{}
// err := taskManageSvc.EditTaskManage(req)
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.OK, nil)
//}
//
//// DelTaskManage 删除任务
//func DelTaskManage(c *gin.Context) {
// var req request.DelTaskManageReq
// if err := c.ShouldBindJSON(&req); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
// //参数校验
// if err := util.ValidateSimple(req, "Id"); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
//
// taskManageSvc := service.TaskManageSvc{}
// err := taskManageSvc.DelTaskManage(req)
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.OK, nil)
//}
//
//// DetailsTaskManage 任务详情
//func DetailsTaskManage(c *gin.Context) {
// var (
// err error
// id string
// )
//
// if id = c.Query("id"); id == "" {
// id = c.Param("id")
// }
// if id == "" {
// SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("id为空")), nil)
// return
// }
//
// taskManageSvc := service.TaskManageSvc{}
// data, err := taskManageSvc.DetailsTaskManage(cast.ToInt(id))
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.OK, data)
//}
//
//// ListTaskManage 任务列表
//func ListTaskManage(c *gin.Context) {
// var req request.ListTaskManageReq
// if err := c.ShouldBind(&req); err != nil {
// SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
// return
// }
//
// taskManageSvc := service.TaskManageSvc{}
// total, list, err := taskManageSvc.ListTaskManage(req)
// if err != nil {
// SendJsonPageResponse(c, err, nil, 0)
// return
// }
// SendJsonPageResponse(c, resp.OK, list, total)
//}
src/main.go
View file @
a9f61204
...
@@ -29,6 +29,7 @@ func main() {
...
@@ -29,6 +29,7 @@ func main() {
initTimeZone
()
initTimeZone
()
// init ansible hosts
// init ansible hosts
initAnsibleHosts
()
initAnsibleHosts
()
initTempDirPrefix
()
pflag
.
Parse
()
// init start args
pflag
.
Parse
()
// init start args
initConfig
()
initConfig
()
// init log config
// init log config
...
@@ -59,17 +60,17 @@ func initConfig() {
...
@@ -59,17 +60,17 @@ func initConfig() {
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/"
),
//模板目录前缀
//
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
}
}
}
}
...
@@ -129,3 +130,10 @@ func initAnsibleHosts() {
...
@@ -129,3 +130,10 @@ func initAnsibleHosts() {
}
}
}
}
}
}
func
initTempDirPrefix
()
{
err
:=
os
.
Mkdir
(
"/app/xlsx/"
,
os
.
ModePerm
)
if
err
!=
nil
{
fmt
.
Println
(
"创建目录失败!"
)
}
}
src/router/alertrulesrouter.go.go
0 → 100644
View file @
a9f61204
package
router
import
(
"fmt"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
)
// InitAlertRulesRouter 初始化预警规则配置路由
func
InitAlertRulesRouter
(
e
*
gin
.
Engine
)
{
group
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/alert_rules"
,
conf
.
Options
.
Prefix
))
{
group
.
POST
(
""
,
controller
.
AddAlertRules
)
group
.
PUT
(
""
,
controller
.
UpdateAlertRules
)
group
.
DELETE
(
""
,
controller
.
DeleteAlertRules
)
group
.
GET
(
""
,
controller
.
DetailAlertRules
)
group
.
GET
(
"list"
,
controller
.
ListAlertRules
)
}
}
src/router/router.go
View file @
a9f61204
...
@@ -28,7 +28,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
...
@@ -28,7 +28,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
base
.
GET
(
"/example/list"
,
controller
.
GetExampleList
)
// 示例获取列表
base
.
GET
(
"/example/list"
,
controller
.
GetExampleList
)
// 示例获取列表
}
}
base
.
POST
(
"/add_file"
,
controller
.
AddFile
)
//文件上传
base
.
POST
(
"/add_file"
,
controller
.
AddFile
)
//文件上传
base
.
GET
(
"/download_file/:file_name/:ext/:opt"
,
controller
.
DownloadFile
)
//文件下载
// 初始化自动化运维路由
// 初始化自动化运维路由
InitAutomatedMaintenRouter
(
r
)
InitAutomatedMaintenRouter
(
r
)
...
@@ -44,6 +45,10 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
...
@@ -44,6 +45,10 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
InitSystemMenuRouter
(
r
)
InitSystemMenuRouter
(
r
)
// 初始化指标配置路由
// 初始化指标配置路由
InitMetricConfigRouter
(
r
)
InitMetricConfigRouter
(
r
)
// 初始化预警规则配置路由
InitAlertRulesRouter
(
r
)
// 初始化prometheus路由
// 初始化prometheus路由
InitPrometheusRouter
(
r
)
InitPrometheusRouter
(
r
)
// 初始化工单管理路由
InitWorkOrderRouter
(
r
)
}
}
src/router/workorderrouter.go
0 → 100644
View file @
a9f61204
package
router
import
(
"fmt"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
)
// InitWorkOrderRouter 初始化工单路由
func
InitWorkOrderRouter
(
e
*
gin
.
Engine
)
{
so
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/work_order"
,
conf
.
Options
.
Prefix
))
//业务工单管理
manage
:=
so
.
Group
(
"/work_order_manage"
)
{
manage
.
POST
(
"/add"
,
controller
.
AddWorkOrderManage
)
// 新增
//manage.PUT("/edit", controller.EditTaskManage) // 编辑
//manage.DELETE("/del", controller.DelTaskManage) // 删除
//manage.GET("/details", controller.DetailsTaskManage) // 详情
//manage.GET("/list", controller.ListTaskManage) // 列表
//manage.POST("/exec/script", controller.ExecScript) // 立即执行
}
////任务历史
//taskHistory := so.Group("/task_history")
//{
// taskHistory.GET("/list", controller.TaskHistoryList) // 任务历史列表
// taskHistory.GET("/task_info_list", controller.TaskInfoList) // 任务历史详情列表
// taskHistory.GET("/task_exec_log", controller.TaskExecLog) // 任务执行日志
//}
//
////主机管理
//host := so.Group("/host_manage")
//{
// host.POST("/add", controller.AddHostManage) // 新增
// host.PUT("/edit", controller.EditHostManage) // 编辑
// host.DELETE("/del", controller.DelHostManage) // 删除
// host.GET("/details", controller.DetailsHostManage) // 详情
// host.GET("/page_list", controller.PageListHostManage) // 列表
// host.POST("/state", controller.StateHostManage) // 状态检测
// host.GET("/ip_exception_list", controller.HostIpExceptionList) // 主机ip异常列表
// host.GET("/export", controller.ExportIp) // 导出ip列表
// host.GET("/list", controller.ListHostManage) // 主机分组列表-不分页
//}
}
src/service/alert_class.go
View file @
a9f61204
...
@@ -11,23 +11,19 @@ import (
...
@@ -11,23 +11,19 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"sort"
"sort"
"xorm.io/xorm"
)
)
type
AlertClassSvc
struct
{
type
AlertClassSvc
struct
{
User
entity
.
SystemUserInfo
User
entity
.
SystemUserInfo
}
}
func
(
m
*
AlertClassSvc
)
Add
(
req
request
.
AddAlertClass
)
(
err
error
)
{
func
(
m
*
AlertClassSvc
)
Add
(
session
*
xorm
.
Session
,
req
request
.
AddAlertClass
)
(
classId
int
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertClass
{
data
:=
entity
.
AlertClass
{
CreatedBy
:
""
,
CreatedBy
:
m
.
User
.
SystemAccount
,
CreatedAt
:
now
,
CreatedAt
:
now
,
UpdatedBy
:
""
,
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
}
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
...
@@ -37,23 +33,19 @@ func (m *AlertClassSvc) Add(req request.AddAlertClass) (err error) {
...
@@ -37,23 +33,19 @@ func (m *AlertClassSvc) Add(req request.AddAlertClass) (err error) {
return
return
}
}
data
.
SortOrder
=
max
+
1
data
.
SortOrder
=
max
+
1
_
,
err
=
db
.
NewSession
()
.
Insert
(
&
data
)
_
,
err
=
session
.
Insert
(
&
data
)
return
nil
classId
=
data
.
ClassId
return
}
}
func
(
m
*
AlertClassSvc
)
Update
(
req
request
.
UpdateAlertClass
)
error
{
func
(
m
*
AlertClassSvc
)
Update
(
session
*
xorm
.
Session
,
req
request
.
UpdateAlertClass
)
error
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertClass
{
data
:=
entity
.
AlertClass
{
UpdatedBy
:
""
,
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
}
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
,
err
=
db
.
NewSession
()
.
Cols
(
"class_name"
,
"updated_by"
,
"updated_at"
)
.
ID
(
data
.
ClassId
)
.
Update
(
&
data
)
_
,
err
:=
session
.
Cols
(
"class_name"
,
"updated_by"
,
"updated_at"
)
.
ID
(
data
.
ClassId
)
.
Update
(
&
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -71,7 +63,7 @@ func (m *AlertClassSvc) Move(req request.MoveAlertClass) (err error) {
...
@@ -71,7 +63,7 @@ func (m *AlertClassSvc) Move(req request.MoveAlertClass) (err error) {
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
var
list
[]
entity
.
AlertClass
var
list
[]
entity
.
AlertClass
_
,
err
=
db
.
NewSession
()
.
Where
(
"class_id = ?"
,
req
.
ClassId
)
.
Get
(
&
data
)
_
,
err
=
db
.
NewSession
()
.
Where
(
"class_id = ?"
,
req
.
ClassId
)
.
Get
(
&
data
)
err
=
db
.
NewSession
()
.
Where
(
"parent_id = ?"
,
data
.
ParentId
)
.
OrderBy
(
"sort_order asc"
)
.
Find
(
&
list
)
err
=
db
.
NewSession
()
.
Where
(
"parent_id = ?"
,
data
.
ParentId
)
.
Where
(
"source_from = 1"
)
.
OrderBy
(
"sort_order asc"
)
.
Find
(
&
list
)
var
previousIndex
int
var
previousIndex
int
var
nextIndex
int
var
nextIndex
int
for
i
:=
0
;
i
<
len
(
list
);
i
++
{
for
i
:=
0
;
i
<
len
(
list
);
i
++
{
...
@@ -144,6 +136,7 @@ func (m *AlertClassSvc) List(req request.ListAlertClass) (resp response.AlertCla
...
@@ -144,6 +136,7 @@ func (m *AlertClassSvc) List(req request.ListAlertClass) (resp response.AlertCla
}
}
session
:=
db
.
NewSession
()
session
:=
db
.
NewSession
()
defer
session
.
Close
()
defer
session
.
Close
()
session
.
Where
(
"source_from = 1"
)
if
req
.
ClassId
!=
0
{
if
req
.
ClassId
!=
0
{
session
.
Where
(
"class_id = ?"
,
req
.
ClassId
)
session
.
Where
(
"class_id = ?"
,
req
.
ClassId
)
}
}
...
@@ -163,6 +156,7 @@ func (m *AlertClassSvc) Tree(req request.ListAlertClass) (resp []*response.Alert
...
@@ -163,6 +156,7 @@ func (m *AlertClassSvc) Tree(req request.ListAlertClass) (resp []*response.Alert
session
:=
db
.
NewSession
()
session
:=
db
.
NewSession
()
defer
session
.
Close
()
defer
session
.
Close
()
var
list
[]
entity
.
AlertClass
var
list
[]
entity
.
AlertClass
session
.
Where
(
"source_from = 1"
)
_
,
err
=
session
.
OrderBy
(
"sort_order"
)
.
FindAndCount
(
&
list
)
_
,
err
=
session
.
OrderBy
(
"sort_order"
)
.
FindAndCount
(
&
list
)
// TODO 对req进行过滤
// TODO 对req进行过滤
resp
,
err
=
AlertClassTree
(
list
)
resp
,
err
=
AlertClassTree
(
list
)
...
@@ -214,7 +208,7 @@ func (m *AlertClassSvc) SortOrderMax(parentId int) (max int, err error) {
...
@@ -214,7 +208,7 @@ func (m *AlertClassSvc) SortOrderMax(parentId int) (max int, err error) {
}
}
_
,
err
=
db
.
NewSession
()
.
Table
(
new
(
entity
.
AlertClass
))
.
_
,
err
=
db
.
NewSession
()
.
Table
(
new
(
entity
.
AlertClass
))
.
Select
(
"max(sort_order)"
)
.
Select
(
"max(sort_order)"
)
.
Where
(
"parent_id = ?"
,
parentId
)
.
Get
(
&
max
)
Where
(
"parent_id = ?"
,
parentId
)
.
Where
(
"source_from = 1"
)
.
Get
(
&
max
)
return
return
}
}
...
...
src/service/alert_rules.go
0 → 100644
View file @
a9f61204
package
service
import
(
"github.com/google/uuid"
"github.com/jinzhu/copier"
"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/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"xorm.io/xorm"
)
type
AlertRulesSvc
struct
{
User
entity
.
SystemUserInfo
}
func
(
m
*
AlertRulesSvc
)
Add
(
req
request
.
AddAlertRules
)
error
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertRules
{
Id
:
uuid
.
New
()
.
String
(),
CreatedBy
:
m
.
User
.
SystemAccount
,
CreatedAt
:
now
,
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
switch
req
.
DetectionType
{
case
1
:
_
,
err
=
db
.
Update
(
&
data
)
if
err
!=
nil
{
return
err
}
case
2
:
// 自定义
_
,
err
=
db
.
Transaction
(
func
(
session
*
xorm
.
Session
)
(
interface
{},
error
)
{
// 添加自定义分类
var
(
classParentId
int
classId
int
addMetricConfig
request
.
AddMetricConfig
metricConfigId
string
)
alertClassSvc
:=
AlertClassSvc
{
User
:
m
.
User
}
classParentId
,
err
=
alertClassSvc
.
Add
(
session
,
request
.
AddAlertClass
{
ClassName
:
req
.
ClassParentName
,
SortOrder
:
-
1
,
SourceFrom
:
2
,
})
if
err
!=
nil
{
return
nil
,
err
}
classId
,
err
=
alertClassSvc
.
Add
(
session
,
request
.
AddAlertClass
{
ClassName
:
req
.
ClassName
,
ParentId
:
classParentId
,
SortOrder
:
-
1
,
SourceFrom
:
2
,
})
if
err
!=
nil
{
return
nil
,
err
}
data
.
ClassId
=
classId
// 添加指标配置
metricConfigSvc
:=
MetricConfigSvc
{
User
:
m
.
User
}
_
=
copier
.
Copy
(
&
addMetricConfig
,
&
req
)
addMetricConfig
.
SourceFrom
=
2
addMetricConfig
.
MetricName
=
req
.
MetricConfigName
metricConfigId
,
err
=
metricConfigSvc
.
Add
(
session
,
addMetricConfig
)
if
err
!=
nil
{
return
nil
,
err
}
data
.
MetricConfigId
=
metricConfigId
// 添加预警规则配置
_
,
err
=
session
.
Insert
(
&
data
)
return
nil
,
err
})
}
// TODO 告警规则添加到普罗米修斯表
return
nil
}
func
(
m
*
AlertRulesSvc
)
Update
(
req
request
.
UpdateAlertRules
)
error
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertRules
{
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
session
:=
db
.
NewSession
()
var
dbAlertRules
entity
.
AlertRules
_
,
err
=
session
.
Table
(
data
.
TableName
())
.
ID
(
data
.
Id
)
.
Get
(
&
dbAlertRules
)
if
err
!=
nil
{
return
err
}
switch
req
.
DetectionType
{
case
1
:
_
,
err
=
db
.
Update
(
&
data
)
if
err
!=
nil
{
return
err
}
case
2
:
// 自定义
_
,
err
=
db
.
Transaction
(
func
(
session
*
xorm
.
Session
)
(
interface
{},
error
)
{
// 更新自定义分类
var
(
updateMetricConfig
request
.
UpdateMetricConfig
alertClassItem
response
.
AlertClassItem
)
alertClassSvc
:=
AlertClassSvc
{
User
:
m
.
User
}
alertClassItem
,
err
=
alertClassSvc
.
GetDataById
(
request
.
DetailAlertClass
{
ClassId
:
dbAlertRules
.
ClassId
})
if
err
!=
nil
{
return
nil
,
err
}
err
=
alertClassSvc
.
Update
(
session
,
request
.
UpdateAlertClass
{
ClassId
:
dbAlertRules
.
ClassId
,
ClassName
:
req
.
ClassName
,
})
if
err
!=
nil
{
return
nil
,
err
}
err
=
alertClassSvc
.
Update
(
session
,
request
.
UpdateAlertClass
{
ClassId
:
alertClassItem
.
ParentId
,
ClassName
:
req
.
ClassParentName
,
})
if
err
!=
nil
{
return
nil
,
err
}
// 更新指标配置
metricConfigSvc
:=
MetricConfigSvc
{
User
:
m
.
User
}
_
=
copier
.
Copy
(
&
updateMetricConfig
,
&
req
)
updateMetricConfig
.
SourceFrom
=
2
updateMetricConfig
.
Id
=
dbAlertRules
.
MetricConfigId
err
=
metricConfigSvc
.
Update
(
session
,
updateMetricConfig
)
if
err
!=
nil
{
return
nil
,
err
}
// 更新预警规则配置
_
,
err
=
session
.
Update
(
&
data
)
return
nil
,
err
})
}
return
nil
}
func
(
m
*
AlertRulesSvc
)
GetDataById
(
req
request
.
DetailAlertRules
)
(
resp
response
.
AlertRulesItem
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
_
,
err
=
db
.
NewSession
()
.
Table
(
resp
.
TableName
())
.
Where
(
"id = ?"
,
req
.
Id
)
.
Get
(
&
resp
)
return
}
func
(
m
*
AlertRulesSvc
)
List
(
req
request
.
ListAlertRules
)
(
resp
response
.
MetricConfigList
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
session
:=
db
.
NewSession
()
defer
session
.
Close
()
if
req
.
Id
!=
""
{
session
.
Where
(
"id = ?"
,
req
.
Id
)
}
if
req
.
ClassId
!=
0
{
session
.
Where
(
"class_id = ?"
,
req
.
ClassId
)
}
if
req
.
MetricName
!=
""
{
session
.
Where
(
"metric_name LIKE ?"
,
"%"
+
req
.
MetricName
+
"%"
)
}
if
req
.
IsEnabled
!=
0
{
session
.
Where
(
"is_enabled = ?"
,
req
.
IsEnabled
)
}
resp
.
TotalCount
,
err
=
session
.
Table
(
new
(
entity
.
AlertRules
))
.
Limit
(
req
.
GetPageSize
(),
(
req
.
GetPage
()
-
1
)
*
req
.
GetPageSize
())
.
OrderBy
(
"id"
)
.
FindAndCount
(
&
resp
.
List
)
return
}
func
(
m
*
AlertRulesSvc
)
Delete
(
ids
[]
string
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
return
}
// TODO 批量删除表中的多出数据
_
,
err
=
db
.
NewSession
()
.
In
(
"id"
,
ids
)
.
Delete
(
new
(
entity
.
AlertRules
))
return
}
src/service/doc_lib.go
View file @
a9f61204
...
@@ -7,12 +7,15 @@ import (
...
@@ -7,12 +7,15 @@ import (
"github.com/google/uuid"
"github.com/google/uuid"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7"
"github.com/pkg/errors"
"github.com/pkg/errors"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"io"
"io"
"mime/multipart"
"mime/multipart"
"net/http"
"net/http"
"net/url"
"path"
"path"
"time"
)
)
var
maxFileByte
int64
=
20971520
//20M
var
maxFileByte
int64
=
20971520
//20M
...
@@ -111,3 +114,33 @@ func (d DocLibSvc) GetFile(fileName string) (obj io.Reader, err error) {
...
@@ -111,3 +114,33 @@ func (d DocLibSvc) GetFile(fileName string) (obj io.Reader, err error) {
// return
// return
//}
//}
}
}
func
(
d
DocLibSvc
)
DownloadFile
(
ctx
*
gin
.
Context
,
req
request
.
DocLibGetReq
)
(
docUrl
*
url
.
URL
,
err
error
)
{
var
(
minioClient
*
minio
.
Client
)
minioClient
,
err
=
client
.
GetMinioConnect
()
if
err
!=
nil
{
err
=
errors
.
Wrap
(
err
,
"getMinio"
)
return
}
remotePath
:=
fmt
.
Sprintf
(
"%s%s"
,
req
.
FileName
,
req
.
Ext
)
reqParams
:=
make
(
url
.
Values
)
switch
req
.
Opt
{
case
"info"
:
return
case
"preview"
:
reqParams
.
Set
(
"response-Content-Type"
,
req
.
Ext
)
case
"download"
:
reqParams
.
Set
(
"response-Content-Disposition"
,
fmt
.
Sprintf
(
"attachment; filename=%s%s"
,
req
.
FileName
,
req
.
Ext
))
reqParams
.
Set
(
"response-Content-Type"
,
"application/octet-stream"
)
reqParams
.
Set
(
"response-Content-Transfer-Encoding"
,
"binary"
)
}
docUrl
,
err
=
minioClient
.
PresignedGetObject
(
ctx
,
conf
.
Options
.
MinioBucket
,
remotePath
,
time
.
Second
*
60
*
60
,
reqParams
)
if
err
!=
nil
{
err
=
errors
.
Wrap
(
err
,
"get file url from minio fail"
)
return
}
return
}
src/service/host_manage.go
View file @
a9f61204
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/tools"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/tools"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"os/exec"
"os/exec"
...
@@ -305,7 +304,9 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
...
@@ -305,7 +304,9 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
return
return
}
}
//查询主机列表
//查询主机列表
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
id
)
.
Find
(
&
hostList
)
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
id
)
.
Select
(
"string_agg(ip,',') as ip,port,voucher_type,user_name,password,host_file_url,count(1) as cnt"
)
.
GroupBy
(
"ip_group,port,voucher_type,user_name,PASSWORD,host_file_url"
)
.
Find
(
&
hostList
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbSelectError
.
WithError
(
err
)
err
=
resp
.
DbSelectError
.
WithError
(
err
)
return
return
...
@@ -321,18 +322,20 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
...
@@ -321,18 +322,20 @@ func (h *HostManageSvc) DetailsHostManage(id int) (hostManageRes response.HostMa
if
v
.
HostFileUrl
!=
""
{
if
v
.
HostFileUrl
!=
""
{
hostManageRes
.
HostFileUrl
=
v
.
HostFileUrl
hostManageRes
.
HostFileUrl
=
v
.
HostFileUrl
}
}
hostManageRes
.
IpCnt
=
hostManageRes
.
IpCnt
+
v
.
Cnt
}
}
hostManageRes
.
Id
=
hostManage
.
Id
hostManageRes
.
Id
=
hostManage
.
Id
hostManageRes
.
HostName
=
hostManage
.
HostName
hostManageRes
.
HostName
=
hostManage
.
HostName
hostManageRes
.
TaskCnt
=
len
(
taskList
)
hostManageRes
.
TaskCnt
=
len
(
taskList
)
hostManageRes
.
IpCnt
=
len
(
hostList
)
//
hostManageRes.IpCnt = len(hostList)
hostManageRes
.
CreateUser
=
hostManage
.
CreateUser
hostManageRes
.
CreateUser
=
hostManage
.
CreateUser
hostManageRes
.
CreateTime
=
hostManage
.
CreateTime
hostManageRes
.
CreateTime
=
hostManage
.
CreateTime
hostManageRes
.
UpdateUser
=
hostManage
.
UpdateUser
hostManageRes
.
UpdateUser
=
hostManage
.
UpdateUser
hostManageRes
.
UpdateTime
=
hostManage
.
UpdateTime
hostManageRes
.
UpdateTime
=
hostManage
.
UpdateTime
hostManageRes
.
HostList
=
hostList
if
hostManageRes
.
HostFileUrl
==
""
{
hostManageRes
.
HostList
=
hostList
}
hostManageRes
.
TaskList
=
taskList
hostManageRes
.
TaskList
=
taskList
return
return
...
@@ -598,16 +601,16 @@ func (h *HostManageSvc) ExportIp(id, uuid string, detectionType int) (fileName s
...
@@ -598,16 +601,16 @@ func (h *HostManageSvc) ExportIp(id, uuid string, detectionType int) (fileName s
if
detectionType
==
1
{
if
detectionType
==
1
{
//列表检测导出
//列表检测导出
finder
:=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
cast
.
ToInt
(
id
))
finder
:=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND
conn_status = 1 AND
host_group_id = ?"
,
cast
.
ToInt
(
id
))
err
=
finder
.
Select
(
""
)
.
Find
(
&
hostManageList
)
err
=
finder
.
Select
(
"
ip,port,voucher_type,user_name,password
"
)
.
Find
(
&
hostManageList
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbSelectError
.
WithError
(
err
)
err
=
resp
.
DbSelectError
.
WithError
(
err
)
return
return
}
}
}
else
{
}
else
{
//新增/编辑检测导出
//新增/编辑检测导出
finder
:=
db
.
Table
(
"host_manage_list_cache"
)
.
Where
(
"id = ?"
,
uuid
)
finder
:=
db
.
Table
(
"host_manage_list_cache"
)
.
Where
(
"
conn_status = 1 AND
id = ?"
,
uuid
)
err
=
finder
.
Select
(
""
)
.
Find
(
&
hostManageList
)
err
=
finder
.
Select
(
"
ip,port,voucher_type,user_name,password
"
)
.
Find
(
&
hostManageList
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbSelectError
.
WithError
(
err
)
err
=
resp
.
DbSelectError
.
WithError
(
err
)
return
return
...
@@ -666,7 +669,7 @@ func generatePushExportXlsx(push []ExportIpStr) (string, error) {
...
@@ -666,7 +669,7 @@ func generatePushExportXlsx(push []ExportIpStr) (string, error) {
}
}
saveFileName
:=
"IP列表导出数据.xlsx"
saveFileName
:=
"IP列表导出数据.xlsx"
err
:=
file
.
Save
(
conf
.
Options
.
TempDirPrefix
+
saveFileName
)
err
:=
file
.
Save
(
"/app/xlsx/"
+
saveFileName
)
return
saveFileName
,
err
return
saveFileName
,
err
}
}
...
...
src/service/metric_config.go
View file @
a9f61204
...
@@ -8,53 +8,42 @@ import (
...
@@ -8,53 +8,42 @@ import (
"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/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
"xorm.io/xorm"
)
)
type
MetricConfigSvc
struct
{
type
MetricConfigSvc
struct
{
User
entity
.
SystemUserInfo
User
entity
.
SystemUserInfo
}
}
func
(
m
*
MetricConfigSvc
)
Add
(
req
request
.
AddMetricConfig
)
error
{
func
(
m
*
MetricConfigSvc
)
Add
(
session
*
xorm
.
Session
,
req
request
.
AddMetricConfig
)
(
id
string
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
mc
:=
entity
.
MetricConfig
{
data
:=
entity
.
MetricConfig
{
Id
:
uuid
.
New
()
.
String
(),
Id
:
uuid
.
New
()
.
String
(),
CreatedBy
:
""
,
CreatedBy
:
m
.
User
.
SystemAccount
,
CreatedAt
:
now
,
CreatedAt
:
now
,
UpdatedBy
:
""
,
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
}
}
_
=
copier
.
Copy
(
&
mc
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
mc
.
AlertRange
=
util
.
ConvertToString
(
req
.
AlertRange
)
data
.
AlertRange
=
util
.
ConvertToString
(
req
.
AlertRange
)
_
,
err
=
session
.
Insert
(
&
data
)
_
,
err
=
db
.
NewSession
()
.
Insert
(
&
mc
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
}
}
return
nil
id
=
data
.
Id
return
}
}
func
(
m
*
MetricConfigSvc
)
Update
(
req
request
.
UpdateMetricConfig
)
error
{
func
(
m
*
MetricConfigSvc
)
Update
(
session
*
xorm
.
Session
,
req
request
.
UpdateMetricConfig
)
error
{
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
return
err
}
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
mc
:=
entity
.
MetricConfig
{
data
:=
entity
.
MetricConfig
{
UpdatedBy
:
""
,
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
}
}
_
=
copier
.
Copy
(
&
mc
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
mc
.
AlertRange
=
util
.
ConvertToString
(
req
.
AlertRange
)
data
.
AlertRange
=
util
.
ConvertToString
(
req
.
AlertRange
)
_
,
err
:=
session
.
ID
(
req
.
Id
)
.
Update
(
&
data
)
_
,
err
=
db
.
NewSession
()
.
ID
(
req
.
Id
)
.
Update
(
&
mc
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -70,7 +59,7 @@ func (m *MetricConfigSvc) GetDataById(req request.DetailMetricConfig) (resp resp
...
@@ -70,7 +59,7 @@ func (m *MetricConfigSvc) GetDataById(req request.DetailMetricConfig) (resp resp
return
return
}
}
func
(
m
*
MetricConfigSvc
)
List
(
req
request
.
ListMetricConfig
)
(
resp
response
.
Units
List
,
err
error
)
{
func
(
m
*
MetricConfigSvc
)
List
(
req
request
.
ListMetricConfig
)
(
resp
response
.
MetricConfig
List
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
...
src/service/task_history.go
View file @
a9f61204
...
@@ -15,7 +15,7 @@ type TaskHistorySvc struct {
...
@@ -15,7 +15,7 @@ type TaskHistorySvc struct {
}
}
// TaskHistoryList 任务历史列表
// TaskHistoryList 任务历史列表
func
(
t
*
TaskHistorySvc
)
TaskHistoryList
(
req
request
.
Pagination
)
(
total
int64
,
taskHistoryListRes
[]
response
.
TaskHistoryListRes
,
err
error
)
{
func
(
t
*
TaskHistorySvc
)
TaskHistoryList
(
req
request
.
TaskHistoryReq
)
(
total
int64
,
taskHistoryListRes
[]
response
.
TaskHistoryListRes
,
err
error
)
{
var
(
var
(
//dueDate int
//dueDate int
start
time
.
Time
start
time
.
Time
...
@@ -32,6 +32,9 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, t
...
@@ -32,6 +32,9 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, t
" WHERE ID IN (SELECT MAX(ID) FROM task_history GROUP BY task_id) ORDER BY ID DESC) t2"
,
"t1.id = t2.task_id"
)
.
" WHERE ID IN (SELECT MAX(ID) FROM task_history GROUP BY task_id) ORDER BY ID DESC) t2"
,
"t1.id = t2.task_id"
)
.
Where
(
"t1.is_delete = 0"
)
Where
(
"t1.is_delete = 0"
)
if
req
.
Search
!=
""
{
finder
.
Where
(
"t1.task_name LIKE ?"
,
"%"
+
req
.
Search
+
"%"
)
}
//查询任务历史
//查询任务历史
total
,
err
=
finder
.
Select
(
"t2.state,t2.task_id,t1.task_name,t2.exec_start_time,t2.exec_end_time,t2.create_user"
)
.
total
,
err
=
finder
.
Select
(
"t2.state,t2.task_id,t1.task_name,t2.exec_start_time,t2.exec_end_time,t2.create_user"
)
.
Limit
(
req
.
PageSize
,
(
req
.
Page
-
1
)
*
req
.
PageSize
)
.
FindAndCount
(
&
taskHistoryListRes
)
Limit
(
req
.
PageSize
,
(
req
.
Page
-
1
)
*
req
.
PageSize
)
.
FindAndCount
(
&
taskHistoryListRes
)
...
@@ -61,7 +64,7 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, t
...
@@ -61,7 +64,7 @@ func (t *TaskHistorySvc) TaskHistoryList(req request.Pagination) (total int64, t
}
}
// TaskInfoList 任务历史详情列表
// TaskInfoList 任务历史详情列表
func
(
t
*
TaskHistorySvc
)
TaskInfoList
(
req
request
.
Task
History
Req
)
(
total
int64
,
taskInfoListRes
[]
response
.
TaskInfoListRes
,
err
error
)
{
func
(
t
*
TaskHistorySvc
)
TaskInfoList
(
req
request
.
Task
InfoList
Req
)
(
total
int64
,
taskInfoListRes
[]
response
.
TaskInfoListRes
,
err
error
)
{
var
(
var
(
//dueDate int
//dueDate int
start
time
.
Time
start
time
.
Time
...
@@ -74,7 +77,9 @@ func (t *TaskHistorySvc) TaskInfoList(req request.TaskHistoryReq) (total int64,
...
@@ -74,7 +77,9 @@ func (t *TaskHistorySvc) TaskInfoList(req request.TaskHistoryReq) (total int64,
}
}
finder
:=
db
.
Table
(
"task_history"
)
.
Where
(
"task_id = ?"
,
req
.
TaskId
)
finder
:=
db
.
Table
(
"task_history"
)
.
Where
(
"task_id = ?"
,
req
.
TaskId
)
if
req
.
Search
!=
""
{
finder
.
Where
(
"exec_desc LIKE ?"
,
"%"
+
req
.
Search
+
"%"
)
}
//查询任务历史
//查询任务历史
total
,
err
=
finder
.
OrderBy
(
"id desc"
)
.
Limit
(
req
.
PageSize
,
(
req
.
Page
-
1
)
*
req
.
PageSize
)
.
FindAndCount
(
&
taskInfoListRes
)
total
,
err
=
finder
.
OrderBy
(
"id desc"
)
.
Limit
(
req
.
PageSize
,
(
req
.
Page
-
1
)
*
req
.
PageSize
)
.
FindAndCount
(
&
taskInfoListRes
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
src/service/task_manage.go
View file @
a9f61204
package
service
package
service
import
(
import
(
"bufio"
"context"
"context"
"errors"
"errors"
"fmt"
"fmt"
...
@@ -117,7 +118,7 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa
...
@@ -117,7 +118,7 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa
//查询任务详情
//查询任务详情
finder
:=
db
.
Table
(
"task_manage"
)
.
Alias
(
"tm"
)
.
finder
:=
db
.
Table
(
"task_manage"
)
.
Alias
(
"tm"
)
.
Where
(
"is_delete = 0 AND id = ?"
,
id
)
Where
(
"is_delete = 0 AND id = ?"
,
id
)
_
,
err
=
finder
.
Select
(
"tm.id,tm.task_name,tm.task_desc,tm.yaml_desc,tm.yaml_url,tm.create_user,tm.create_time,"
+
_
,
err
=
finder
.
Select
(
"tm.id,tm.task_name,tm.task_desc,tm.yaml_desc,tm.yaml_url,tm.create_user,tm.create_time,
tm.host_group_id,
"
+
"(select count(1) from task_history th where th.task_id = tm.id) as exec_cnt,"
+
"(select count(1) from task_history th where th.task_id = tm.id) as exec_cnt,"
+
"(select count(1) from task_history th where th.task_id = tm.id and th.state = 1) as success_cnt,"
+
"(select count(1) from task_history th where th.task_id = tm.id and th.state = 1) as success_cnt,"
+
"(select count(1) from task_history th where th.task_id = tm.id and th.state = 2) as fail_cnt"
)
.
Get
(
&
taskManageRes
)
"(select count(1) from task_history th where th.task_id = tm.id and th.state = 2) as fail_cnt"
)
.
Get
(
&
taskManageRes
)
...
@@ -128,18 +129,27 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa
...
@@ -128,18 +129,27 @@ func (t *TaskManageSvc) DetailsTaskManage(id int) (taskManageRes response.TaskMa
//查询主机列表
//查询主机列表
hostList
:=
make
([]
response
.
HostList
,
0
)
hostList
:=
make
([]
response
.
HostList
,
0
)
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
id
)
.
Find
(
&
hostList
)
err
=
db
.
Table
(
"host_manage_list"
)
.
Where
(
"is_delete = 0 AND host_group_id = ?"
,
taskManageRes
.
HostGroupId
)
.
Select
(
"string_agg(ip,',') as ip,port,voucher_type,user_name,password,host_file_url"
)
.
GroupBy
(
"ip_group,port,voucher_type,user_name,PASSWORD,host_file_url"
)
.
Find
(
&
hostList
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbSelectError
.
WithError
(
err
)
err
=
resp
.
DbSelectError
.
WithError
(
err
)
return
return
}
}
//err = db.Table("host_manage_list").Where("is_delete = 0 AND host_group_id = ?", id).Find(&hostList)
//if err != nil {
// err = resp.DbSelectError.WithError(err)
// return
//}
for
_
,
v
:=
range
hostList
{
for
_
,
v
:=
range
hostList
{
if
v
.
HostFileUrl
!=
""
{
if
v
.
HostFileUrl
!=
""
{
taskManageRes
.
HostFileUrl
=
v
.
HostFileUrl
taskManageRes
.
HostFileUrl
=
v
.
HostFileUrl
}
}
}
}
taskManageRes
.
HostList
=
hostList
if
taskManageRes
.
HostFileUrl
==
""
{
taskManageRes
.
HostList
=
hostList
}
return
return
}
}
...
@@ -177,7 +187,7 @@ func (t *TaskManageSvc) ListTaskManage(req request.ListTaskManageReq) (total int
...
@@ -177,7 +187,7 @@ func (t *TaskManageSvc) ListTaskManage(req request.ListTaskManageReq) (total int
return
return
}
}
func
(
t
*
TaskManageSvc
)
ExecScript
(
req
request
.
ExecScriptReq
)
(
data
interface
{},
err
error
)
{
func
(
t
*
TaskManageSvc
)
ExecScript
(
req
request
.
ExecScriptReq
)
(
data
map
[
string
]
interface
{},
err
error
)
{
if
req
.
ScriptUrl
!=
""
{
if
req
.
ScriptUrl
!=
""
{
minioClient
,
err
:=
client
.
GetMinioConnect
()
minioClient
,
err
:=
client
.
GetMinioConnect
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -242,11 +252,19 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{},
...
@@ -242,11 +252,19 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data interface{},
}
else
{
}
else
{
cmd
=
exec
.
Command
(
"ansible-playbook"
,
"-i"
,
"/etc/ansible/hosts"
,
"/etc/ansible/ansible.yml"
)
cmd
=
exec
.
Command
(
"ansible-playbook"
,
"-i"
,
"/etc/ansible/hosts"
,
"/etc/ansible/ansible.yml"
)
}
}
output
,
err
:=
cmd
.
Output
()
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
CmdExecError
.
WithError
(
err
)
return
nil
,
resp
.
CmdExecError
.
WithError
(
err
)
return
}
}
fmt
.
Println
(
string
(
output
))
outputBuf
:=
bufio
.
NewReader
(
stdout
)
return
string
(
output
),
nil
output
,
isPrefix
,
err
:=
outputBuf
.
ReadLine
()
//output, err := cmd.Output()
//if err != nil {
// err = resp.CmdExecError.WithError(err)
// return
//}
//fmt.Println(string(output))
data
[
"step"
]
=
isPrefix
data
[
"output"
]
=
string
(
output
)
return
data
,
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