зеркало из https://github.com/mozilla/mig.git
removing function that isn't being used yet
This commit is contained in:
Родитель
9b3205867a
Коммит
49476d62b7
|
@ -324,86 +324,6 @@ func (db *DB) GetActionCounters(aid float64) (counters mig.ActionCounters, err e
|
|||
return
|
||||
}
|
||||
|
||||
// SetupRunnableActionsForAgent retrieves actions that are ready to be run by a particular agent.
|
||||
func (db *DB) SetupRunnableActionsForAgent(agent mig.Agent) ([]mig.Action, error) {
|
||||
actions := []mig.Action{}
|
||||
|
||||
actionRows, err := db.c.Query(`
|
||||
update actions
|
||||
set status='scheduled'
|
||||
where status='pending'
|
||||
and validfrom < now()
|
||||
and expireafter > now()
|
||||
returning id,
|
||||
name,
|
||||
target,
|
||||
description,
|
||||
threat,
|
||||
operations,
|
||||
validfrom,
|
||||
expireafter,
|
||||
status,
|
||||
pgpsignatures,
|
||||
syntaxversion;
|
||||
`)
|
||||
|
||||
if actionRows != nil {
|
||||
defer actionRows.Close()
|
||||
}
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
err = fmt.Errorf("Error while setting up runnable actions: '%s'", err.Error())
|
||||
return []mig.Action{}, err
|
||||
}
|
||||
|
||||
for actionRows.Next() {
|
||||
retrieved := actionFromDB{}
|
||||
agentIsTargeted := false
|
||||
|
||||
err := actionRows.Scan(
|
||||
&retrieved.ID,
|
||||
&retrieved.Name,
|
||||
&retrieved.Target,
|
||||
&retrieved.DescriptionJSON,
|
||||
&retrieved.ThreatJSON,
|
||||
&retrieved.OperationsJSON,
|
||||
&retrieved.ValidFrom,
|
||||
&retrieved.ExpireAfter,
|
||||
&retrieved.Status,
|
||||
&retrieved.SignaturesJSON,
|
||||
&retrieved.SyntaxVersion)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error retrieving action: '%s'", err.Error())
|
||||
return []mig.Action{}, err
|
||||
}
|
||||
|
||||
action, err := deserializeActionFromDB(retrieved)
|
||||
if err != nil {
|
||||
return []mig.Action{}, err
|
||||
}
|
||||
|
||||
// This is a very unfortunate concession to have to make, but it's essentially
|
||||
// the same thing that `ActiveAgentsByTarget` does in `database/agents.go`.
|
||||
query := fmt.Sprintf(`
|
||||
select $1 in
|
||||
(select distinct on (queueloc) id
|
||||
from agents
|
||||
where status in ('%s', '%s')
|
||||
and (%s)
|
||||
);
|
||||
`, mig.AgtStatusOnline, mig.AgtStatusIdle, action.Target)
|
||||
err = db.c.QueryRow(query, agent.ID).Scan(&agentIsTargeted)
|
||||
if err != nil {
|
||||
return []mig.Action{}, err
|
||||
}
|
||||
|
||||
if agentIsTargeted {
|
||||
actions = append(actions, action)
|
||||
}
|
||||
}
|
||||
|
||||
return actions, nil
|
||||
}
|
||||
|
||||
// SetupRunnableActions retrieves actions that are ready to run. This function is designed
|
||||
// to run concurrently across multiple schedulers, by update the status of the action at
|
||||
// the same time as retrieving it. It returns an array of actions rady to be run.
|
||||
|
|
Загрузка…
Ссылка в новой задаче