Add screenshots and update gitignore for alpha release
- Fixed gitignore to allow Screenshots/*.png files - Added all screenshots for README documentation - Fixed gitignore to be less restrictive with image files - Includes dashboard, agent, updates, and docker screenshots
This commit is contained in:
@@ -45,7 +45,7 @@ func (q *AgentQueries) GetAgentByID(id uuid.UUID) (*models.Agent, error) {
|
||||
// UpdateAgentLastSeen updates the agent's last_seen timestamp
|
||||
func (q *AgentQueries) UpdateAgentLastSeen(id uuid.UUID) error {
|
||||
query := `UPDATE agents SET last_seen = $1, status = 'online' WHERE id = $2`
|
||||
_, err := q.db.Exec(query, time.Now(), id)
|
||||
_, err := q.db.Exec(query, time.Now().UTC(), id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -81,3 +81,77 @@ func (q *AgentQueries) MarkOfflineAgents(threshold time.Duration) error {
|
||||
_, err := q.db.Exec(query, time.Now().Add(-threshold))
|
||||
return err
|
||||
}
|
||||
|
||||
// GetAgentLastScan gets the last scan time from update events
|
||||
func (q *AgentQueries) GetAgentLastScan(id uuid.UUID) (*time.Time, error) {
|
||||
var lastScan time.Time
|
||||
query := `SELECT MAX(created_at) FROM update_events WHERE agent_id = $1`
|
||||
err := q.db.Get(&lastScan, query, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &lastScan, nil
|
||||
}
|
||||
|
||||
// GetAgentWithLastScan gets agent information including last scan time
|
||||
func (q *AgentQueries) GetAgentWithLastScan(id uuid.UUID) (*models.AgentWithLastScan, error) {
|
||||
var agent models.AgentWithLastScan
|
||||
query := `
|
||||
SELECT
|
||||
a.*,
|
||||
(SELECT MAX(created_at) FROM update_events WHERE agent_id = a.id) as last_scan
|
||||
FROM agents a
|
||||
WHERE a.id = $1`
|
||||
err := q.db.Get(&agent, query, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &agent, nil
|
||||
}
|
||||
|
||||
// ListAgentsWithLastScan returns all agents with their last scan times
|
||||
func (q *AgentQueries) ListAgentsWithLastScan(status, osType string) ([]models.AgentWithLastScan, error) {
|
||||
var agents []models.AgentWithLastScan
|
||||
query := `
|
||||
SELECT
|
||||
a.*,
|
||||
(SELECT MAX(created_at) FROM update_events WHERE agent_id = a.id) as last_scan
|
||||
FROM agents a
|
||||
WHERE 1=1`
|
||||
args := []interface{}{}
|
||||
argIdx := 1
|
||||
|
||||
if status != "" {
|
||||
query += ` AND a.status = $` + string(rune(argIdx+'0'))
|
||||
args = append(args, status)
|
||||
argIdx++
|
||||
}
|
||||
if osType != "" {
|
||||
query += ` AND a.os_type = $` + string(rune(argIdx+'0'))
|
||||
args = append(args, osType)
|
||||
argIdx++
|
||||
}
|
||||
|
||||
query += ` ORDER BY a.last_seen DESC`
|
||||
err := q.db.Select(&agents, query, args...)
|
||||
return agents, err
|
||||
}
|
||||
|
||||
// DeleteAgent removes an agent and all associated data
|
||||
func (q *AgentQueries) DeleteAgent(id uuid.UUID) error {
|
||||
// Start a transaction for atomic deletion
|
||||
tx, err := q.db.Beginx()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
// Delete the agent (CASCADE will handle related records)
|
||||
_, err = tx.Exec("DELETE FROM agents WHERE id = $1", id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Commit the transaction
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user