コード例 #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)
	}
}
コード例 #2
0
func (a *AgentSession) HandleCatalog() interface{} {
	return func(body []byte) {
		catalog := make([]*rbody.Metric, 0)
		if err := json.Unmarshal(body, &catalog); err != nil {
			log.Error(3, err.Error())
			return
		}
		log.Debug("Received catalog for session %s: %s", a.SocketSession.Id, body)
		metrics := make([]*model.Metric, len(catalog))
		for i, m := range catalog {
			metrics[i] = &model.Metric{
				OrgId:     a.Agent.OrgId,
				Public:    a.Agent.Public,
				Namespace: m.Namespace,
				Version:   int64(m.Version),
				Policy:    m.Policy,
			}
		}
		err := sqlstore.AddMissingMetricsForAgent(a.Agent, metrics)
		if err != nil {
			log.Error(3, "failed to update metrics in DB. %s", err)
		}
	}
}