[PR #2347] [CLOSED] Add management command to remove duplicate agents #1925

Closed
opened 2026-03-02 02:25:19 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amidaware/tacticalrmm/pull/2347
Author: @PeetMcK
Created: 11/16/2025
Status: Closed

Base: developHead: macOS-refactorv2


📝 Commits (4)

  • 36eae42 Add macOS mesh agent tar.gz archive delivery with .msh config
  • 90953eb Enhance macOS mesh agent download with SHA256 checksums and randomized filenames
  • ce5cc77 Add management command to remove duplicate agents
  • 136032a Merge branch 'amidaware:develop' into macOS-refactorv2

📊 Changes

4 files changed (+323 additions, -5 deletions)

View changed files

api/tacticalrmm/agents/management/commands/remove_duplicate_agents.py (+221 -0)
📝 api/tacticalrmm/apiv3/views.py (+12 -1)
📝 api/tacticalrmm/core/tests.py (+4 -4)
📝 api/tacticalrmm/core/utils.py (+86 -0)

📄 Description

Summary

Add new management command to identify and remove duplicate agent records based on serial number or hostname.

Features

  • Deduplication modes:
    • --serialnumber (default): Remove duplicates by serial number
    • --hostname: Remove duplicates by hostname
  • Smart handling: Keeps most recently seen agent, deletes older duplicates
  • Data quality: Reports agents with empty serial numbers or hostnames
  • Safety: Dry-run by default, requires --delete flag to execute
  • Clean uninstall: Sends uninstall command to duplicates before deletion
  • Flexible options: --ignore-empty-serial flag to skip agents without serial numbers

Usage

# Check for duplicates by serial number (dry-run)
python manage.py remove_duplicate_agents

# Check for duplicates by hostname
python manage.py remove_duplicate_agents --hostname

# Actually delete duplicates
python manage.py remove_duplicate_agents --delete

# Skip agents without serial numbers
python manage.py remove_duplicate_agents --ignore-empty-serial

Example Output

Scanning for duplicate agents by serial number...

Found 15 serial numbers with duplicate agents:

Serial: ABC123 (3 duplicates found)
  Keeping: SERVER-001 | Last Seen: 2025-11-15 10:30:00 | Version: 2.6.0 | Acme Corp > Main
  Deleting: SERVER-001-OLD | Last Seen: 2025-11-10 08:20:00 | Version: 2.5.9 | Acme Corp > Main
  Deleting: SERVER-001-BACKUP | Last Seen: 2025-11-05 15:45:00 | Version: 2.5.8 | Acme Corp > Main

Found duplicates for 15 devices (57 total agent records)
Keeping 15 most recent agents, deleting 42 older duplicates. Run again with --delete to actually delete them.

Testing

Already Tested

  • --serialnumber dry-run and --delete on test instance and live data
  • --hostname dry-run and --delete on test instance and live data
  • Test --ignore-empty-serial flag behavior with agents missing serial numbers
  • Verify agents with empty serial numbers are properly reported
  • Verify agents with empty hostnames are properly reported
  • Test edge cases: agents with null last_seen timestamps
  • Confirm summary statistics accuracy across different duplicate scenarios

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amidaware/tacticalrmm/pull/2347 **Author:** [@PeetMcK](https://github.com/PeetMcK) **Created:** 11/16/2025 **Status:** ❌ Closed **Base:** `develop` ← **Head:** `macOS-refactorv2` --- ### 📝 Commits (4) - [`36eae42`](https://github.com/amidaware/tacticalrmm/commit/36eae4272608643354bb17e47f8c6dd2f007c8c5) Add macOS mesh agent tar.gz archive delivery with .msh config - [`90953eb`](https://github.com/amidaware/tacticalrmm/commit/90953eb12ec1752b538e6a1daab2855448fbb2b6) Enhance macOS mesh agent download with SHA256 checksums and randomized filenames - [`ce5cc77`](https://github.com/amidaware/tacticalrmm/commit/ce5cc77a6865ef75073990c3f570720ecd4cca21) Add management command to remove duplicate agents - [`136032a`](https://github.com/amidaware/tacticalrmm/commit/136032af3567b9a9beee792260e0a8957db5ee49) Merge branch 'amidaware:develop' into macOS-refactorv2 ### 📊 Changes **4 files changed** (+323 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `api/tacticalrmm/agents/management/commands/remove_duplicate_agents.py` (+221 -0) 📝 `api/tacticalrmm/apiv3/views.py` (+12 -1) 📝 `api/tacticalrmm/core/tests.py` (+4 -4) 📝 `api/tacticalrmm/core/utils.py` (+86 -0) </details> ### 📄 Description ## Summary Add new management command to identify and remove duplicate agent records based on serial number or hostname. ## Features - **Deduplication modes**: - `--serialnumber` (default): Remove duplicates by serial number - `--hostname`: Remove duplicates by hostname - **Smart handling**: Keeps most recently seen agent, deletes older duplicates - **Data quality**: Reports agents with empty serial numbers or hostnames - **Safety**: Dry-run by default, requires `--delete` flag to execute - **Clean uninstall**: Sends uninstall command to duplicates before deletion - **Flexible options**: `--ignore-empty-serial` flag to skip agents without serial numbers ## Usage ```bash # Check for duplicates by serial number (dry-run) python manage.py remove_duplicate_agents # Check for duplicates by hostname python manage.py remove_duplicate_agents --hostname # Actually delete duplicates python manage.py remove_duplicate_agents --delete # Skip agents without serial numbers python manage.py remove_duplicate_agents --ignore-empty-serial ``` ## Example Output ``` Scanning for duplicate agents by serial number... Found 15 serial numbers with duplicate agents: Serial: ABC123 (3 duplicates found) Keeping: SERVER-001 | Last Seen: 2025-11-15 10:30:00 | Version: 2.6.0 | Acme Corp > Main Deleting: SERVER-001-OLD | Last Seen: 2025-11-10 08:20:00 | Version: 2.5.9 | Acme Corp > Main Deleting: SERVER-001-BACKUP | Last Seen: 2025-11-05 15:45:00 | Version: 2.5.8 | Acme Corp > Main Found duplicates for 15 devices (57 total agent records) Keeping 15 most recent agents, deleting 42 older duplicates. Run again with --delete to actually delete them. ``` ## Testing ### Already Tested - ✅ `--serialnumber` dry-run and `--delete` on test instance and live data - ✅ `--hostname` dry-run and `--delete` on test instance and live data ### Recommended Test Validation Plan - [ ] Test `--ignore-empty-serial` flag behavior with agents missing serial numbers - [ ] Verify agents with empty serial numbers are properly reported - [ ] Verify agents with empty hostnames are properly reported - [ ] Test edge cases: agents with null `last_seen` timestamps - [ ] Confirm summary statistics accuracy across different duplicate scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 02:25:19 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tacticalrmm#1925
No description provided.