예제 #1
0
func (this *OpsMonitorRestController) Get() {
	agentId := this.GetString("agent_id")

	//TODO 暂时直接从nats请求信息,需要持久话健康信息和负载信息
	monitorStr, err := getMonitorByAgentId(agentId)

	result := entity.ResponseMessage{}

	if err != nil {
		result.Code = utils.ResponseCodeFailed
		result.Data = fmt.Sprintf("Request AgentId [%s] monitor info error: %s", agentId, err)
		beego.Error("Request AgentId %s monitor info error %s", agentId, err)
		monitor := entity.Monitor{}
		monitor.AgentId = agentId
		err = monitor.DeleteByAgentId()
		if err != nil {
			this.Data["AgentError"] = fmt.Sprintf("Delete Monitor error %s", err)
		}

	} else {
		result.Code = utils.ResponseCodeSuccess
		result.Data = monitorStr
		err = saveOrUpdateMonitor(monitorStr)
		beego.Error("saveOrUpdateMonitor monitorStr [%s] Error %s", monitorStr, err)
	}
	this.Data["json"] = &result
	this.ServeJSON(false)
}
예제 #2
0
func (this *OpsController) Post() {
	agentId := this.GetString("agent_id")
	action := this.GetString("action")

	switch action {
	case "":
		monitorStr, err := getMonitorByAgentId(agentId)
		if err != nil {
			this.Data["AgentError"] = fmt.Sprintf("Request AgentId [%s] monitor info error: %s", agentId, err)
			beego.Error("Request AgentId [%s] monitor info error: %s", agentId, err)
		} else {
			err = saveOrUpdateMonitor(monitorStr)
			this.Data["AgentError"] = fmt.Sprintf("Save error: %s", err)
			beego.Error("saveOrUpdateMonitor monitorStr [%s] Error %s", monitorStr, err)
		}
	case "delete":
		monitor := entity.Monitor{}
		monitor.AgentId = agentId
		err := monitor.DeleteByAgentId()
		if err != nil {
			this.Data["AgentError"] = fmt.Sprintf("Delete Monitor error %s", err)
		}
	}

	this.Get()
}