Ejemplo n.º 1
0
func AddAgent(ctx *Context, agent model.AgentDTO) {
	if !agent.ValidName() {
		ctx.JSON(400, "invalde agent Name. must match /^[0-9a-Z_-]+$/")
		return
	}
	agent.Id = 0
	//need to add suport for middelware context with AUTH/
	agent.OrgId = ctx.OrgId
	err := sqlstore.AddAgent(&agent)
	if err != nil {
		log.Error(3, err.Error())
		ctx.JSON(200, rbody.ErrResp(500, err))
		return
	}
	ctx.JSON(200, rbody.OkResp("agent", agent))
}
Ejemplo n.º 2
0
func addTestData() {
	// add public agent

	agent := &model.AgentDTO{
		Name:    "publicTest",
		Enabled: true,
		OrgId:   1000,
		Public:  true,
	}
	err := sqlstore.AddAgent(agent)
	if err != nil {
		panic(err.Error())
	}
	metrics := []*model.Metric{
		{
			OrgId:     1000,
			Public:    true,
			Namespace: "/testing/public/demo1",
			Version:   1,
			Policy: []rbody.PolicyTable{
				{
					Name:     "user",
					Type:     "string",
					Required: true,
				},
				{
					Name:     "passwd",
					Type:     "string",
					Required: true,
				},
				{
					Name:     "limit",
					Type:     "integer",
					Required: false,
					Default:  10,
				},
			},
		},
		{
			OrgId:     1000,
			Public:    true,
			Namespace: "/testing/demo2/demo",
			Version:   2,
			Policy:    nil,
		},
	}
	err = sqlstore.AddMissingMetricsForAgent(agent, metrics)
	if err != nil {
		panic(err)
	}
	err = sqlstore.AddAgentSession(&model.AgentSession{
		Id:       uuid.NewUUID().String(),
		AgentId:  agent.Id,
		Version:  1,
		RemoteIp: "127.0.0.1",
		Server:   "localhost",
		Created:  time.Now(),
	})
	if err != nil {
		panic(err)
	}
}