зеркало из https://github.com/mozilla/mig.git
[minor] return limited fields when evaluating agents target
This commit is contained in:
Родитель
1b44e13298
Коммит
c18cdc2a7c
|
@ -679,7 +679,7 @@ func (cli Client) EvaluateAgentTarget(target string) (agents []mig.Agent, err er
|
|||
err = fmt.Errorf("EvaluateAgentTarget() -> %v", e)
|
||||
}
|
||||
}()
|
||||
query := "search?type=agent&target=" + url.QueryEscape(target)
|
||||
query := "search?type=agent&limit=1000000&target=" + url.QueryEscape(target)
|
||||
resource, err := cli.GetAPIResource(query)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -182,7 +182,6 @@ func (db *DB) ActiveAgentsByQueue(queueloc string, pointInTime time.Time) (agent
|
|||
// ActiveAgentsByTarget runs a search for all agents that match a given target string.
|
||||
// For safety, it does so in a transaction that runs as a readonly user.
|
||||
func (db *DB) ActiveAgentsByTarget(target string) (agents []mig.Agent, err error) {
|
||||
var jTags, jEnv []byte
|
||||
// save current user
|
||||
var dbuser string
|
||||
err = db.c.QueryRow("SELECT CURRENT_USER").Scan(&dbuser)
|
||||
|
@ -198,10 +197,9 @@ func (db *DB) ActiveAgentsByTarget(target string) (agents []mig.Agent, err error
|
|||
_ = txn.Rollback()
|
||||
return
|
||||
}
|
||||
rows, err := txn.Query(fmt.Sprintf(`SELECT DISTINCT ON (queueloc) id, name, queueloc, version, pid, status,
|
||||
environment, tags, mode, starttime, heartbeattime, destructiontime
|
||||
rows, err := txn.Query(fmt.Sprintf(`SELECT DISTINCT ON (queueloc) id, name, queueloc, pid, mode
|
||||
FROM agents WHERE agents.status IN ('%s', '%s') AND (%s)
|
||||
ORDER BY agents.queueloc, agents.heartbeattime DESC`, mig.AgtStatusOnline, mig.AgtStatusIdle, target))
|
||||
ORDER BY agents.queueloc ASC`, mig.AgtStatusOnline, mig.AgtStatusIdle, target))
|
||||
if rows != nil {
|
||||
defer rows.Close()
|
||||
}
|
||||
|
@ -212,22 +210,11 @@ func (db *DB) ActiveAgentsByTarget(target string) (agents []mig.Agent, err error
|
|||
}
|
||||
for rows.Next() {
|
||||
var agent mig.Agent
|
||||
err = rows.Scan(&agent.ID, &agent.Name, &agent.QueueLoc, &agent.Version, &agent.PID, &agent.Status,
|
||||
&jEnv, &jTags, &agent.Mode, &agent.StartTime, &agent.HeartBeatTS, &agent.DestructionTime)
|
||||
err = rows.Scan(&agent.ID, &agent.Name, &agent.QueueLoc, &agent.PID, &agent.Mode)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Failed to retrieve agent data: '%v'", err)
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(jTags, &agent.Tags)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to unmarshal agent tags")
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(jEnv, &agent.Env)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to unmarshal agent environment")
|
||||
return
|
||||
}
|
||||
agents = append(agents, agent)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
|
|
Загрузка…
Ссылка в новой задаче