Esempio n. 1
0
func addTestMetrics(agent *model.AgentDTO) {
	metrics := []*model.Metric{
		{
			OrgId:     1,
			Public:    true,
			Namespace: "/testing/demo/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:     1,
			Public:    true,
			Namespace: "/testing/demo2/demo",
			Version:   2,
			Policy:    nil,
		},
	}
	lock.Lock()
	err := sqlstore.AddMissingMetricsForAgent(agent, metrics)
	lock.Unlock()
	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)
	}
}
func (a *AgentSession) saveDbSession() error {
	host, _ := os.Hostname()
	dbSess := &model.AgentSession{
		Id:       a.SocketSession.Id,
		AgentId:  a.Agent.Id,
		Version:  a.AgentVersion,
		RemoteIp: a.SocketSession.Conn.RemoteAddr().String(),
		Server:   host,
		Created:  time.Now(),
	}
	err := sqlstore.AddAgentSession(dbSess)
	if err != nil {
		return err
	}
	a.dbSession = dbSess
	return nil
}