Пример #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()
}
Пример #3
0
func saveOrUpdateMonitor(result string) error {
	var nats entity.NatsResult
	err := json.Unmarshal([]byte(result), &nats)

	if err != nil {
		return err
	}

	monitor := entity.Monitor{}
	monitor.AgentId = nats.Value.AgentId
	monitor.Index = nats.Value.Index
	monitor.JobName = nats.Value.Job.Name
	monitor.JobState = nats.Value.JobState
	monitor.Updated = time.Now()
	monitor.Value = result

	err = monitor.SaveOrUpdate()
	return err
}
Пример #4
0
func (this *OpsMonitorController) Get() {
	this.Layout = "index.tpl"
	this.Data["NavBarFocus"] = "ops"
	this.Data["IaaSVersion"] = iaasVersion
	this.Data["DefaultVersion"] = defaultVersion

	agentId := this.GetString("agent_id")

	agentId = this.CheckAgentId(agentId)

	this.Data["AgentId"] = agentId

	if agentId != "" {
		monitor := entity.Monitor{}
		monitor.AgentId = agentId
		err := monitor.LoadByAgentId()
		if err != nil {
			this.Data["MessageErr"] = fmt.Sprintf("Load Agent Monitor info err %s", err)
		}
		this.Data["Monitor"] = monitor
	}

	this.TplName = "ops/index_monitor.tpl"
}
	            "name": "vm-447d7acb-4a60-4932-b8fc-d2dc155eeccc"
	        },
	        "ntp": {
	            "offset": "0.134190",
	            "timestamp": "22 Feb 11:15:07"
	        }
	    }
	}`
	var nats entity.NatsResult
	BeforeEach(func() {
		err := json.Unmarshal([]byte(result), &nats)
		fmt.Println(err)
	})

	It("Testing Insert OpsMonitor", func() {
		monitor := entity.Monitor{}
		monitor.AgentId = nats.Value.AgentId
		monitor.Index = nats.Value.Index
		monitor.JobName = nats.Value.Job.Name
		monitor.JobState = nats.Value.JobState
		monitor.Value = result

		errors := monitor.Save()

		Expect(errors).NotTo(HaveOccurred())

		errors = monitor.Delete()

		Expect(errors).NotTo(HaveOccurred())
	})