2016-12-13 22:22:05 +00:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
import (
|
2017-06-22 19:50:45 +00:00
|
|
|
"github.com/kolide/fleet/server/kolide"
|
2016-12-22 19:29:29 +00:00
|
|
|
"github.com/pkg/errors"
|
2016-12-13 22:22:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (d *Datastore) ListScheduledQueriesInPack(id uint, opts kolide.ListOptions) ([]*kolide.ScheduledQuery, error) {
|
2016-12-22 19:29:29 +00:00
|
|
|
query := `
|
2018-01-03 19:18:05 +00:00
|
|
|
SELECT
|
|
|
|
sq.id, sq.pack_id, sq.name, sq.query_name, q.query,
|
|
|
|
sq.description, sq.interval, sq.snapshot, sq.removed, sq.platform,
|
|
|
|
sq.version, sq.shard
|
2016-12-13 22:22:05 +00:00
|
|
|
FROM scheduled_queries sq
|
|
|
|
JOIN queries q
|
2018-01-03 19:18:05 +00:00
|
|
|
ON sq.query_name = q.name
|
2016-12-13 22:22:05 +00:00
|
|
|
WHERE sq.pack_id = ?
|
|
|
|
AND NOT sq.deleted
|
|
|
|
`
|
2016-12-22 19:29:29 +00:00
|
|
|
query = appendListOptionsToSQL(query, opts)
|
2016-12-13 22:22:05 +00:00
|
|
|
results := []*kolide.ScheduledQuery{}
|
|
|
|
|
2016-12-22 19:29:29 +00:00
|
|
|
if err := d.db.Select(&results, query, id); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "listing scheduled queries")
|
2016-12-13 22:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return results, nil
|
|
|
|
}
|