Skip to content

Commit

Permalink
Merge pull request #844 from WeBankPartners/release_v3.3.0
Browse files Browse the repository at this point in the history
Release v3.3.0
  • Loading branch information
zgyzgyhero authored Nov 15, 2024
2 parents 7fd4b8a + c50a31d commit d3f56e7
Show file tree
Hide file tree
Showing 59 changed files with 1,413 additions and 479 deletions.
15 changes: 14 additions & 1 deletion build/register.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
<systemParameter name="MONITOR_PROMETHEUS_PORT_BIND" scopeType="global" defaultValue=""/>
<systemParameter name="MONITOR_HOST_PORT" scopeType="global" defaultValue="9100"/>
<systemParameter name="MONITOR_MAIL_AUTH_USER" scopeType="global" defaultValue=""/>
<systemParameter name="MONITOR_LOG_MONITOR_TYPE" scopeType="global" defaultValue="logMonitor"/>
<systemParameter name="MONITOR_LOG_KEYWORD_TYPE" scopeType="global" defaultValue="logKeyword"/>
</systemParameters>


Expand All @@ -153,7 +155,11 @@
<resourceDependencies>
<docker imageName="open-monitor:{{PLUGIN_VERSION}}" containerName="open-monitor-{{PLUGIN_VERSION}}" portBindings="19091:19091,14241:14241,{{ALLOCATE_PORT}}:8080,{{MONITOR_PROMETHEUS_PORT_BIND}}" volumeBindings="{{BASE_MOUNT_PATH}}/prometheus/logs:/app/monitor/prometheus/logs,{{BASE_MOUNT_PATH}}/prometheus/data:/app/monitor/prometheus/data,{{BASE_MOUNT_PATH}}/prometheus/rules:/app/monitor/prometheus/rules,{{BASE_MOUNT_PATH}}/alertmanager/logs:/app/monitor/alertmanager/logs,{{BASE_MOUNT_PATH}}/alertmanager/data:/app/monitor/alertmanager/data,{{BASE_MOUNT_PATH}}/consul/logs:/app/monitor/consul/logs,{{BASE_MOUNT_PATH}}/consul/data:/app/monitor/consul/data,{{BASE_MOUNT_PATH}}/monitor/logs:/app/monitor/monitor/logs,{{BASE_MOUNT_PATH}}/agent_deploy:/app/deploy,{{BASE_MOUNT_PATH}}/transgateway/logs:/app/monitor/transgateway/logs,{{BASE_MOUNT_PATH}}/transgateway/data:/app/monitor/transgateway/data,{{BASE_MOUNT_PATH}}/archive_mysql_tool/logs:/app/monitor/archive_mysql_tool/logs,/etc/localtime:/etc/localtime,{{BASE_MOUNT_PATH}}/certs:/data/certs,{{BASE_MOUNT_PATH}}/archive_mysql_tool/keytab:/app/monitor/archive_mysql_tool/keytab,{{BASE_MOUNT_PATH}}/metric_comparison_exporter/config:/app/monitor/metric_comparison_exporter/config" envVariables="MONITOR_DB_HOST={{DB_HOST}},MONITOR_DB_PORT={{DB_PORT}},MONITOR_DB_SCHEMA={{DB_SCHEMA}},MONITOR_DB_USER={{DB_USER}},MONITOR_DB_PWD={{DB_PWD}},CORE_ADDR={{CORE_ADDR}},GATEWAY_URL={{GATEWAY_URL}},MONITOR_HOST_IP={{ALLOCATE_HOST}},MONITOR_CHECK_EVENT_KEY={{MONITOR_CHECK_EVENT_KEY}},MONITOR_CHECK_EVENT_TO_MAIL={{MONITOR_CHECK_EVENT_TO_MAIL}},MONITOR_CHECK_EVENT_INTERVAL_MIN={{MONITOR_CHECK_EVENT_INTERVAL_MIN}},MONITOR_ARCHIVE_ENABLE={{MONITOR_ARCHIVE_ENABLE}},MONITOR_ARCHIVE_MYSQL_HOST={{MONITOR_ARCHIVE_MYSQL_HOST}},MONITOR_ARCHIVE_MYSQL_PORT={{MONITOR_ARCHIVE_MYSQL_PORT}},MONITOR_ARCHIVE_MYSQL_USER={{MONITOR_ARCHIVE_MYSQL_USER}},MONITOR_ARCHIVE_MYSQL_PWD={{MONITOR_ARCHIVE_MYSQL_PWD}},MONITOR_LOG_LEVEL={{MONITOR_LOG_LEVEL}},JWT_SIGNING_KEY={{JWT_SIGNING_KEY}},ALARM_FIRING_CALLBACK={{MONITOR_ALARM_FIRING_CALLBACK}},ALARM_RECOVER_CALLBACK={{MONITOR_ALARM_RECOVER_CALLBACK}},SUB_SYSTEM_CODE={{SUB_SYSTEM_CODE}},SUB_SYSTEM_KEY={{SUB_SYSTEM_KEY}},MONITOR_ALARM_ALIVE_MAX_DAY={{MONITOR_ALARM_ALIVE_MAX_DAY}},PLUGIN_MODE=yes,MONITOR_SMS_PARAM_LENGTH={{MONITOR_SMS_PARAM_LENGTH}},MONITOR_MAIL_SENDER_USER={{MONITOR_MAIL_SENDER_USER}},MONITOR_MAIL_SENDER_SERVER={{MONITOR_MAIL_SENDER_SERVER}},MONITOR_MAIL_SENDER_PASSWORD={{MONITOR_MAIL_SENDER_PASSWORD}},MONITOR_MAIL_SENDER_SSL={{MONITOR_MAIL_SENDER_SSL}},MONITOR_LOCAL_DNS_MAP={{MONITOR_LOCAL_DNS_MAP}},MONITOR_ALARM_MAIL_ENABLE={{MONITOR_ALARM_MAIL_ENABLE}},MONITOR_ALARM_CALLBACK_LEVEL_MIN={{MONITOR_ALARM_CALLBACK_LEVEL_MIN}},MONITOR_ARCHIVE_UNIT_SPEED={{MONITOR_ARCHIVE_UNIT_SPEED}},MONITOR_ARCHIVE_CONCURRENT_NUM={{MONITOR_ARCHIVE_CONCURRENT_NUM}},MONITOR_ARCHIVE_MAX_HTTP_OPEN={{MONITOR_ARCHIVE_MAX_HTTP_OPEN}},MONITOR_PROMETHEUS_ARCHIVE_DAY={{MONITOR_PROMETHEUS_ARCHIVE_DAY}},MONITOR_AGENT_MANAGER_REMOTE_MODE={{MONITOR_AGENT_MANAGER_REMOTE_MODE}},MONITOR_NOTIFY_TREEVENT_ENABLE={{MONITOR_NOTIFY_TREEVENT_ENABLE}},ENCRYPT_SEED={{ENCRYPT_SEED}},MONITOR_MAIL_AUTH_USER={{MONITOR_MAIL_AUTH_USER}}"/>
<mysql schema="monitor" initFileName="init.sql" upgradeFileName="upgrade.sql"/>
<s3 bucketName="wecube-agent"/>
<s3 bucketName="wecube-agent">
<fileSet>
<file source="node_exporter.tar.gz" toFile="node_exporter.tar.gz"/>
</fileSet>
</s3>
</resourceDependencies>

<!-- 7.插件列表 - 描述插件包中单个插件的输入和输出 -->
Expand Down Expand Up @@ -512,6 +518,7 @@
<parameter datatype="string" sensitiveData="N" mappingType="context">errorCode</parameter>
<parameter datatype="string" sensitiveData="N" mappingType="context">errorMessage</parameter>
<parameter datatype="string" sensitiveData="N" mappingType="context">guid</parameter>
<parameter datatype="string" sensitiveData="N" mappingType="context">monitor_key</parameter>
</outputParameters>
</interface>
<interface action="delete" path="/monitor/api/v1/dashboard/system/delete" filterRule="" type="EXECUTION">
Expand Down Expand Up @@ -896,6 +903,12 @@
<parameter datatype="string" required="Y" sensitiveData="N" mappingType="constant" mappingEntityExpression="">guid</parameter>
<parameter datatype="string" required="Y" sensitiveData="N" mappingType="constant" mappingEntityExpression="">monitorType</parameter>
<parameter datatype="string" required="Y" sensitiveData="N" mappingType="constant" mappingEntityExpression="" multiple="Y">logPathList</parameter>
<parameter datatype="string" required="N" sensitiveData="N" mappingType="constant" mappingEntityExpression="">logMonitorTemplate</parameter>
<parameter datatype="string" required="N" sensitiveData="N" mappingType="constant" mappingEntityExpression="">logMonitorPrefixCode</parameter>
<parameter datatype="string" required="N" sensitiveData="N" mappingType="constant" mappingEntityExpression="">logMonitorName</parameter>
<parameter datatype="string" required="N" sensitiveData="N" mappingType="constant" mappingEntityExpression="">deployPath</parameter>
<parameter datatype="string" required="N" sensitiveData="N" mappingType="system_variable" mappingSystemVariableName="MONITOR_LOG_MONITOR_TYPE">pathType</parameter>
<parameter datatype="object" required="N" sensitiveData="N" mappingType="constant" mappingEntityExpression="" multiple="N">logServiceCodeList</parameter>
</inputParameters>
<outputParameters>
<parameter datatype="string" sensitiveData="N" mappingType="context">errorCode</parameter>
Expand Down
5 changes: 5 additions & 0 deletions monitor-server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ func init() {

// 给平台分析迁移数据
&handlerFuncObj{Url: "/trans-export/analyze", Method: http.MethodPost, HandlerFunc: monitor.AnalyzeTransExportData},
// 平台迁移 根据id读取监控名称数据
&handlerFuncObj{Url: "/trans-export/log_monitor_template/batch", Method: http.MethodPost, HandlerFunc: service.BatchGetLogMonitorTemplate},
&handlerFuncObj{Url: "/trans-export/dashboard/batch", Method: http.MethodPost, HandlerFunc: monitor.BatchGetDashboard},
&handlerFuncObj{Url: "/trans-export/service_group/batch", Method: http.MethodPost, HandlerFunc: alarm.BatchGetServiceGroup},
&handlerFuncObj{Url: "/trans-export/config/type/batch", Method: http.MethodPost, HandlerFunc: monitor.BatchGetTypeConfigList},
)
}

Expand Down
8 changes: 4 additions & 4 deletions monitor-server/api/v1/agent/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ExportPanelAdd(c *gin.Context) {
}
if tmpMessage != "" {
errorMessage = tmpMessage
tmpResult = append(tmpResult, resultOutputObj{CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: tmpMessage})
tmpResult = append(tmpResult, resultOutputObj{CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: tmpMessage, Guid: v.Guid, MonitorKey: v.Guid})
successFlag = "1"
continue
}
Expand Down Expand Up @@ -96,18 +96,18 @@ func ExportPanelAdd(c *gin.Context) {
}
if tmpMessage != "" {
errorMessage = tmpMessage
tmpResult = append(tmpResult, resultOutputObj{Guid: v.Guid, CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: tmpMessage})
tmpResult = append(tmpResult, resultOutputObj{Guid: v.Guid, CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: tmpMessage, MonitorKey: v.Guid})
successFlag = "1"
continue
}
err := db.UpdateRecursivePanel(m.PanelRecursiveTable{Guid: v.Guid, DisplayName: v.DisplayName, Parent: strings.Join(tmpParent, "^"), Endpoint: strings.Join(endpointStringList, "^"), Email: v.Email, Phone: v.Phone, Role: strings.Join(inputRoleList, ","), FiringCallbackKey: v.FiringCallback, RecoverCallbackKey: v.RecoverCallback, ObjType: v.Type}, mid.GetOperateUser(c))
if err != nil {
tmpMessage = fmt.Sprintf(mid.GetMessageMap(c).UpdateTableError, "recursive_panel")
errorMessage = tmpMessage
tmpResult = append(tmpResult, resultOutputObj{Guid: v.Guid, CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: tmpMessage, ErrorDetail: err.Error()})
tmpResult = append(tmpResult, resultOutputObj{Guid: v.Guid, CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: tmpMessage, ErrorDetail: err.Error(), MonitorKey: v.Guid})
successFlag = "1"
} else {
tmpResult = append(tmpResult, resultOutputObj{Guid: v.Guid, CallbackParameter: v.CallbackParameter, ErrorCode: "0", ErrorMessage: ""})
tmpResult = append(tmpResult, resultOutputObj{Guid: v.Guid, CallbackParameter: v.CallbackParameter, ErrorCode: "0", ErrorMessage: "", MonitorKey: v.Guid})
}
}
result = resultObj{ResultCode: successFlag, ResultMessage: errorMessage, Results: resultOutput{Outputs: tmpResult}}
Expand Down
20 changes: 19 additions & 1 deletion monitor-server/api/v1/alarm/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func GetOrgPanelRole(c *gin.Context) {
mid.ReturnParamEmptyError(c, "guid")
return
}
data, err := db.GetOrgRole(guid)
data, err := db.GetOrgRoleNew(guid)
if err != nil {
mid.ReturnFetchDataError(c, "panel_recursive", "guid", guid)
return
Expand Down Expand Up @@ -214,3 +214,21 @@ func SearchSysPanelData(c *gin.Context) {
result := db.SearchPanelByName(search, endpoint)
mid.ReturnSuccessData(c, result)
}

func BatchGetServiceGroup(c *gin.Context) {
var param m.IdsParam
if err := c.ShouldBindJSON(&param); err != nil {
mid.ReturnValidateError(c, err.Error())
return
}
if len(param.Ids) == 0 {
mid.ReturnSuccess(c)
return
}
result, err := db.BatchGetServiceGroupByIds(param.Ids)
if err != nil {
mid.ReturnHandleError(c, err.Error(), err)
} else {
mid.ReturnSuccessData(c, result)
}
}
2 changes: 1 addition & 1 deletion monitor-server/api/v1/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func getPieData(paramConfig *m.PieChartConfigObj) (result []*m.QueryMonitorData,
return
}
if len(chartSeries) == 0 {
err = fmt.Errorf("Can not find chart serie with guid:%d ", paramConfig.CustomChartGuid)
log.Logger.Warn("Can not find chart series", log.String("guid", paramConfig.CustomChartGuid))
return
}
seriesObj := chartSeries[0]
Expand Down
10 changes: 9 additions & 1 deletion monitor-server/api/v1/dashboard_new/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func GetCustomChartConfig(param *models.ChartQueryParam, result *models.EChartOp
return
}
if len(chartSeries) == 0 {
err = fmt.Errorf("Can not find chart serie with guid:%d ", param.CustomChartGuid)
log.Logger.Warn("Can not find chart series", log.String("guid", param.CustomChartGuid))
return
}
err = chartCompare(param)
Expand Down Expand Up @@ -540,6 +540,7 @@ func convertArray2Map(arr []string) map[string]bool {
func GetChartQueryData(queryList []*models.QueryMonitorData, param *models.ChartQueryParam, result *models.EChartOption) error {
serials := []*models.SerialModel{}
var err error
var logType string
archiveQueryFlag := false
if param.Start < (time.Now().Unix()-models.Config().ArchiveMysql.LocalStorageMaxDay*86400) && db.ArchiveEnable {
archiveQueryFlag = true
Expand All @@ -565,6 +566,13 @@ func GetChartQueryData(queryList []*models.QueryMonitorData, param *models.Chart
if param.LineType == 2 {
query.ComparisonFlag = "Y"
}
if len(query.Metric) > 0 {
// 看指标是否为 业务配置过来的,查询业务配置类型,自定义类型需要特殊处理 tags
if logType, err = db.GetLogTypeByMetric(query.Metric[0]); err != nil {
log.Logger.Error("GetLogType err", log.Error(err))
}
query.ServiceConfiguration = logType
}
tmpSerials := ds.PrometheusData(query)
// 如果归档数据可用,尝试从归档数据中补全数据
if db.ArchiveEnable {
Expand Down
3 changes: 2 additions & 1 deletion monitor-server/api/v2/alarm/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ func ImportAlarmStrategy(c *gin.Context) {
}
queryType := c.Param("queryType")
guid := c.Param("guid")
importRule := c.Query("importRule")
var metricNotFound, nameDuplicate []string
err, metricNotFound, nameDuplicate = db.ImportAlarmStrategy(queryType, guid, paramObj, middleware.GetOperateUser(c))
err, metricNotFound, nameDuplicate = db.ImportAlarmStrategy(queryType, guid, paramObj, middleware.GetOperateUser(c), importRule)
if err != nil {
if len(metricNotFound) > 0 {
err = fmt.Errorf(middleware.GetMessageMap(c).MetricNotFound, strings.Join(metricNotFound, ","))
Expand Down
16 changes: 15 additions & 1 deletion monitor-server/api/v2/monitor/custom_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func TransImportCustomDashboard(c *gin.Context) {
middleware.ReturnParamEmptyError(c, "import dashboard chart is empty")
return
}
if customDashboard, _, err = db.ImportCustomDashboard(param, middleware.GetOperateUser(c), "insert", param.MgmtRole, param.UseRoles, middleware.GetMessageMap(c)); err != nil {
if customDashboard, _, err = db.ImportCustomDashboard(param, middleware.GetOperateUser(c), "cover", param.MgmtRole, param.UseRoles, middleware.GetMessageMap(c)); err != nil {
middleware.ReturnServerHandleError(c, err)
return
}
Expand All @@ -742,3 +742,17 @@ func TransImportCustomDashboard(c *gin.Context) {
}
middleware.ReturnSuccess(c)
}

func BatchGetDashboard(c *gin.Context) {
var param models.IdsParam
if err := c.ShouldBindJSON(&param); err != nil {
middleware.ReturnValidateError(c, err.Error())
return
}
result, err := db.BatchGetCustomDashboardByIds(param.Ids)
if err != nil {
middleware.ReturnHandleError(c, err.Error(), err)
} else {
middleware.ReturnSuccessData(c, result)
}
}
15 changes: 14 additions & 1 deletion monitor-server/api/v2/monitor/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@ func ImportMetric(c *gin.Context) {
func QueryMetricTagValue(c *gin.Context) {
var param models.QueryMetricTagParam
var orginMetricRow *models.MetricTable
var logType string
if err := c.ShouldBindJSON(&param); err != nil {
middleware.ReturnHandleError(c, err.Error(), err)
return
}
result := []*models.QueryMetricTagResultObj{}
var result []*models.QueryMetricTagResultObj
if param.MetricId == "" {
middleware.ReturnSuccessData(c, result)
return
Expand All @@ -225,6 +226,14 @@ func QueryMetricTagValue(c *gin.Context) {
middleware.ReturnHandleError(c, err.Error(), err)
return
}
if metricRow == nil {
middleware.ReturnServerHandleError(c, fmt.Errorf("metricId %s is invalid", param.MetricId))
return
}
if logType, err = db.GetLogTypeByLogMetricGroup(metricRow.LogMetricGroup); err != nil {
middleware.ReturnServerHandleError(c, err)
return
}
var tagList []string
// 如果是同环比指标需要用原始指标进去查询
if orginMetricRow, err = db.GetOriginMetricByComparisonId(param.MetricId); err != nil {
Expand Down Expand Up @@ -282,6 +291,10 @@ func QueryMetricTagValue(c *gin.Context) {
if seriesMap == nil {
continue
}
// 如果该指标为自定义类型的业务配置创建,tags内容: tags="test_service_code=addUser,test_retcode=200",需要做特殊解析处理
if logType == models.LogMonitorCustomType && seriesMap["tags"] != "" {
seriesMap = datasource.ResetPrometheusMetricMap(seriesMap)
}
if tmpTagValue, ok := seriesMap[v]; ok {
if _, existFlag := tmpValueDistinctMap[tmpTagValue]; !existFlag {
tmpValueList = append(tmpValueList, tmpTagValue)
Expand Down
20 changes: 20 additions & 0 deletions monitor-server/api/v2/monitor/type_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ func QueryTypeConfigList(c *gin.Context) {
middleware.ReturnSuccessData(c, list)
}

func BatchGetTypeConfigList(c *gin.Context) {
var param models.CommonNameParam
var err error
var list []*models.TypeConfig
if err = c.ShouldBindJSON(&param); err != nil {
middleware.ReturnServerHandleError(c, err)
return
}
if len(param.Names) == 0 {
middleware.ReturnSuccess(c)
return
}
if list, err = db.GetTypeConfigListByNames(param.Names); err != nil {
middleware.ReturnServerHandleError(c, err)
return
}
middleware.ReturnSuccessData(c, list)
}

func AddTypeConfig(c *gin.Context) {
var param models.TypeConfig
var typeConfigList []*models.TypeConfig
Expand Down Expand Up @@ -68,6 +87,7 @@ func BatchAddTypeConfig(c *gin.Context) {
}
// 如果 role_new表还未初始化,需要先同步数据
if !db.ExistRoles() {
db.SyncCoreRole()
db.SyncCoreRoleList()
}
for _, monitorType := range newMonitorTypeList {
Expand Down
49 changes: 45 additions & 4 deletions monitor-server/api/v2/service/log_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func ImportLogMetric(c *gin.Context) {
for _, dbMonitor := range paramObj.DBConfig {
dbMonitor.ServiceGroup = serviceGroup
}
if err = db.ImportLogMetric(&paramObj, middleware.GetOperateUser(c), middleware.GetMessageMap(c)); err != nil {
if err = db.ImportLogMetric(&paramObj, middleware.GetOperateUser(c), middleware.GetOperateUserRoles(c), middleware.GetMessageMap(c)); err != nil {
middleware.ReturnHandleError(c, err.Error(), err)
} else {
middleware.ReturnSuccess(c)
Expand Down Expand Up @@ -661,7 +661,7 @@ func CheckLogMonitorRegExpMatch(c *gin.Context) {
middleware.ReturnValidateError(c, err.Error())
return
}
result := []*models.LogParamTemplateObj{}
var result []*models.LogParamTemplateObj
for _, v := range param.ParamList {
_, v.DemoMatchValue = db.CheckRegExpMatchPCRE(models.CheckRegExpParam{RegString: v.Regular, TestContext: param.DemoLog})
result = append(result, v)
Expand Down Expand Up @@ -852,6 +852,15 @@ func CreateLogMetricCustomGroup(c *gin.Context) {
}
}
}
if existLogMonitorTemplate, getErr := db.GetLogMonitorTemplateByName(param.Guid, param.Name); getErr != nil {
err = getErr
middleware.ReturnServerHandleError(c, err)
return
} else if existLogMonitorTemplate != nil {
err = fmt.Errorf("log monitor template name:%s duplicate", param.Name)
middleware.ReturnServerHandleError(c, err)
return
}
if err := db.ValidateLogMetricGroupName(param.Guid, param.Name, param.LogMetricMonitor); err != nil {
err = fmt.Errorf(middleware.GetMessageMap(c).LogGroupNameDuplicateError, param.Name)
middleware.ReturnHandleError(c, err.Error(), err)
Expand Down Expand Up @@ -880,7 +889,8 @@ func CreateLogMetricCustomGroup(c *gin.Context) {

func UpdateLogMetricCustomGroup(c *gin.Context) {
var param models.LogMetricGroupObj
if err := c.ShouldBindJSON(&param); err != nil {
var err error
if err = c.ShouldBindJSON(&param); err != nil {
middleware.ReturnValidateError(c, err.Error())
return
}
Expand All @@ -889,8 +899,21 @@ func UpdateLogMetricCustomGroup(c *gin.Context) {
middleware.ReturnHandleError(c, err.Error(), err)
return
}
if existLogMonitorTemplate, getErr := db.GetLogMonitorTemplateByName(param.Guid, param.Name); getErr != nil {
err = getErr
middleware.ReturnServerHandleError(c, err)
return
} else if existLogMonitorTemplate != nil {
err = fmt.Errorf("log monitor template name:%s duplicate", param.Name)
middleware.ReturnServerHandleError(c, err)
return
}
if len(param.MetricList) > 0 {
for _, metric := range param.MetricList {
// 拼接指标
if param.MetricPrefixCode != "" {
metric.Metric = fmt.Sprintf("%s_%s", param.MetricPrefixCode, metric.Metric)
}
if middleware.IsIllegalLogParamNameOrMetric(metric.LogParamName) || middleware.IsIllegalLogParamNameOrMetric(metric.Metric) {
middleware.ReturnValidateError(c, "log_param_name or metric param invalid")
return
Expand Down Expand Up @@ -962,7 +985,7 @@ func LogMonitorTemplateExport(c *gin.Context) {
middleware.ReturnHandleError(c, err.Error(), err)
return
}
resultData := []*models.LogMonitorTemplateDto{}
var resultData []*models.LogMonitorTemplateDto
for _, v := range param.GuidList {
templateObj, tmpErr := db.GetLogMonitorTemplate(v)
if tmpErr != nil {
Expand Down Expand Up @@ -1044,3 +1067,21 @@ func LogMonitorDataMapRegMatch(c *gin.Context) {
}
middleware.ReturnSuccessData(c, param)
}

func BatchGetLogMonitorTemplate(c *gin.Context) {
var param models.IdsParam
if err := c.ShouldBindJSON(&param); err != nil {
middleware.ReturnValidateError(c, err.Error())
return
}
if len(param.Ids) == 0 {
middleware.ReturnSuccess(c)
return
}
result, err := db.BatchGetLogTemplateByGuid(param.Ids)
if err != nil {
middleware.ReturnHandleError(c, err.Error(), err)
} else {
middleware.ReturnSuccessData(c, result)
}
}
Loading

0 comments on commit d3f56e7

Please sign in to comment.