add: parameter config support alarm forward config
This commit is contained in:
46
features/cm/omc/controller.go
Normal file
46
features/cm/omc/controller.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package cm_omc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"be.ems/lib/services"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (o *ConfigOMC) Get(c *gin.Context) {
|
||||
paramName := c.Param("paramName")
|
||||
results, err := o.Query(paramName)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, services.DataResp(results))
|
||||
}
|
||||
|
||||
func (o *ConfigOMC) Post(c *gin.Context) {
|
||||
err := fmt.Errorf("method not allowed")
|
||||
c.JSON(http.StatusMethodNotAllowed, services.ErrResp(err.Error()))
|
||||
}
|
||||
|
||||
func (o *ConfigOMC) Put(c *gin.Context) {
|
||||
paramName := c.Param("paramName")
|
||||
var paramData map[string]any
|
||||
|
||||
if err := c.ShouldBindJSON(¶mData); err != nil {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
result, err := o.Modify(paramName, paramData)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, services.DataResp(result))
|
||||
}
|
||||
|
||||
func (o *ConfigOMC) Delete(c *gin.Context) {
|
||||
err := fmt.Errorf("method not allowed")
|
||||
c.JSON(http.StatusMethodNotAllowed, services.ErrResp(err.Error()))
|
||||
}
|
||||
69
features/cm/omc/implement.go
Normal file
69
features/cm/omc/implement.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package cm_omc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/restagent/config"
|
||||
)
|
||||
|
||||
const (
|
||||
PASSWORD_MASK = "********"
|
||||
)
|
||||
|
||||
func (o *ConfigOMC) Query(paramName string) (any, error) {
|
||||
var results []any
|
||||
|
||||
switch paramName {
|
||||
case "alarmEmailForward":
|
||||
result := config.GetYamlConfig().Alarm.EmailForward
|
||||
result.Password = PASSWORD_MASK
|
||||
results = append(results, result)
|
||||
case "alarmSMSForward":
|
||||
result := config.GetYamlConfig().Alarm.SMSCForward
|
||||
result.Password = PASSWORD_MASK
|
||||
results = append(results, result)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid source parameter")
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (o *ConfigOMC) Add() {
|
||||
|
||||
}
|
||||
|
||||
func (o *ConfigOMC) Modify(paramName string, paramData map[string]any) (any, error) {
|
||||
var results []any
|
||||
|
||||
switch paramName {
|
||||
case "alarmEmailForward":
|
||||
param := &(config.GetYamlConfig().Alarm.EmailForward)
|
||||
config.UpdateStructFromMap(param, paramData)
|
||||
result := *param
|
||||
results = append(results, result)
|
||||
err := config.WriteOrignalConfig(config.YamlConfigInfo.FilePath, paramName, paramData)
|
||||
if err != nil {
|
||||
fmt.Println("failed to write config yaml file:", err)
|
||||
return results, err
|
||||
}
|
||||
case "alarmSMSForward":
|
||||
param := &(config.GetYamlConfig().Alarm.SMSCForward)
|
||||
config.UpdateStructFromMap(param, paramData)
|
||||
result := *param
|
||||
results = append(results, result)
|
||||
err := config.WriteOrignalConfig(config.YamlConfigInfo.FilePath, paramName, paramData)
|
||||
if err != nil {
|
||||
fmt.Println("failed to write config yaml file:", err)
|
||||
return results, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid source parameter")
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (o *ConfigOMC) Remove() {
|
||||
|
||||
}
|
||||
26
features/cm/omc/model.go
Normal file
26
features/cm/omc/model.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package cm_omc
|
||||
|
||||
type ConfigOMC struct{}
|
||||
|
||||
type SystemConfig struct {
|
||||
ForwardFlag bool `json:"forwardFlag"`
|
||||
}
|
||||
|
||||
type AlarmEmailForward struct {
|
||||
Enable bool `json:"enable"`
|
||||
EmailList string `json:"emailList"`
|
||||
SMTP string `json:"smtp"`
|
||||
Port uint16 `json:"port"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
TLSSkipVerify bool `json:"tlsSkipVerify"`
|
||||
}
|
||||
|
||||
type AlarmSMSForward struct {
|
||||
Enable bool `json:"enable"`
|
||||
MobileList string `json:"mobileList"`
|
||||
SMSCAddr string `json:"smscAddr"`
|
||||
SystemID string `json:"systemID"`
|
||||
Password string `json:"password"`
|
||||
SystemType string `json:"systemType"`
|
||||
}
|
||||
30
features/cm/omc/route.go
Normal file
30
features/cm/omc/route.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package cm_omc
|
||||
|
||||
import (
|
||||
"be.ems/src/framework/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Register Routes for file_export
|
||||
func Register(r *gin.RouterGroup) {
|
||||
cmOMC := r.Group("/omc")
|
||||
{
|
||||
var o *ConfigOMC
|
||||
cmOMC.GET("/config/:paramName",
|
||||
middleware.PreAuthorize(nil),
|
||||
o.Get,
|
||||
)
|
||||
cmOMC.POST("/config/:paramName",
|
||||
middleware.PreAuthorize(nil),
|
||||
o.Post,
|
||||
)
|
||||
cmOMC.PUT("/config/:paramName",
|
||||
middleware.PreAuthorize(nil),
|
||||
o.Put,
|
||||
)
|
||||
cmOMC.DELETE("/config/:paramName",
|
||||
middleware.PreAuthorize(nil),
|
||||
o.Delete,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user