| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- -- =========================================================
- -- TEST DATA FOR AGENT MANAGEMENT SYSTEM
- -- PostgreSQL
- -- =========================================================
- -- =========================================================
- -- 100 USERS
- -- =========================================================
- INSERT INTO users (
- username,
- password_hash,
- role
- )
- SELECT
- 'user_' || gs,
- md5(random()::text),
- (
- ARRAY[
- 'admin',
- 'operator',
- 'viewer'
- ]
- )[floor(random() * 3 + 1)::int]::user_role
- FROM generate_series(1, 100) gs;
- -- =========================================================
- -- 50 AGENTS
- -- =========================================================
- INSERT INTO agents (
- hostname,
- token_hash,
- cert_fingerprint,
- os_info,
- status,
- last_seen
- )
- SELECT
- 'agent-' || gs,
- md5(random()::text),
- md5(random()::text),
- jsonb_build_object(
- 'os',
- (
- ARRAY[
- 'Windows 11',
- 'Ubuntu 22.04',
- 'Debian 12',
- 'CentOS 9',
- 'Windows Server 2022'
- ]
- )[floor(random() * 5 + 1)::int],
- 'ram_gb',
- floor(random() * 64 + 4),
- 'cpu_cores',
- floor(random() * 16 + 1)
- ),
- (
- ARRAY[
- 'online',
- 'offline',
- 'busy',
- 'error'
- ]
- )[floor(random() * 4 + 1)::int]::agent_status,
- NOW() - (random() * interval '10 days')
- FROM generate_series(1, 50) gs;
- -- =========================================================
- -- 200 COMMANDS (OPERATIONS HISTORY)
- -- =========================================================
- INSERT INTO commands (
- agent_id,
- issued_by,
- command_type_id,
- command,
- status,
- output,
- exit_code,
- created_at,
- completed_at
- )
- SELECT
- random_agent_id,
- random_user_id,
- random_command_type_id,
- (
- ARRAY[
- 'whoami',
- 'hostname',
- 'ipconfig',
- 'ifconfig',
- 'ls -la',
- 'df -h',
- 'uptime',
- 'systemctl status nginx',
- 'docker ps',
- 'cat /etc/os-release'
- ]
- )[floor(random() * 10 + 1)::int],
- random_status,
- (
- ARRAY[
- 'Command executed successfully',
- 'Permission denied',
- 'Host unreachable',
- 'Completed with warnings',
- 'Execution timeout',
- 'No output'
- ]
- )[floor(random() * 6 + 1)::int],
- floor(random() * 10)::int,
- created_time,
- CASE
- WHEN random_status IN ('completed', 'failed', 'cancelled')
- THEN created_time + (random() * interval '5 hours')
- ELSE NULL
- END
- FROM (
- SELECT
- (
- SELECT id
- FROM agents
- ORDER BY random()
- LIMIT 1
- ) AS random_agent_id,
- (
- SELECT id
- FROM users
- ORDER BY random()
- LIMIT 1
- ) AS random_user_id,
- (
- SELECT id
- FROM command_types
- ORDER BY random()
- LIMIT 1
- ) AS random_command_type_id,
- (
- ARRAY[
- 'pending',
- 'running',
- 'completed',
- 'failed',
- 'cancelled'
- ]
- )[floor(random() * 5 + 1)::int]::command_status AS random_status,
- NOW() - (random() * interval '30 days') AS created_time
- FROM generate_series(1, 200)
- ) t;
- -- =========================================================
- -- 80 FILE TRANSFERS
- -- =========================================================
- INSERT INTO file_transfers (
- agent_id,
- initiated_by,
- command_id,
- direction,
- filename,
- sha256,
- size_bytes,
- status,
- created_at
- )
- SELECT
- (
- SELECT id
- FROM agents
- ORDER BY random()
- LIMIT 1
- ),
- (
- SELECT id
- FROM users
- ORDER BY random()
- LIMIT 1
- ),
- (
- SELECT id
- FROM commands
- ORDER BY random()
- LIMIT 1
- ),
- (
- ARRAY[
- 'upload',
- 'download'
- ]
- )[floor(random() * 2 + 1)::int]::transfer_direction,
- (
- ARRAY[
- 'backup.zip',
- 'logs.tar.gz',
- 'report.pdf',
- 'config.json',
- 'database.dump',
- 'image.iso',
- 'script.sh'
- ]
- )[floor(random() * 7 + 1)::int],
- md5(random()::text) || md5(random()::text),
- floor(random() * 1000000000),
- (
- ARRAY[
- 'pending',
- 'running',
- 'completed',
- 'failed'
- ]
- )[floor(random() * 4 + 1)::int]::command_status,
- NOW() - (random() * interval '30 days')
- FROM generate_series(1, 80);
- -- =========================================================
- -- 150 AUDIT LOGS
- -- =========================================================
- INSERT INTO audit_logs (
- actor_id,
- actor_type,
- action,
- target,
- details,
- ip_address,
- created_at
- )
- SELECT
- (
- SELECT id
- FROM users
- ORDER BY random()
- LIMIT 1
- ),
- 'user'::actor_type_enum,
- (
- ARRAY[
- 'login',
- 'logout',
- 'command_created',
- 'agent_updated',
- 'file_uploaded',
- 'settings_changed',
- 'password_changed'
- ]
- )[floor(random() * 7 + 1)::int],
- (
- ARRAY[
- 'agent',
- 'command',
- 'system',
- 'user',
- 'file_transfer'
- ]
- )[floor(random() * 5 + 1)::int],
- jsonb_build_object(
- 'result',
- (
- ARRAY[
- 'success',
- 'failed',
- 'warning'
- ]
- )[floor(random() * 3 + 1)::int],
- 'session_id',
- md5(random()::text)
- ),
- (
- floor(random() * 255)::int || '.' ||
- floor(random() * 255)::int || '.' ||
- floor(random() * 255)::int || '.' ||
- floor(random() * 255)::int
- )::inet,
- NOW() - (random() * interval '30 days')
- FROM generate_series(1, 150);
- -- =========================================================
- -- 100 HEARTBEATS
- -- =========================================================
- INSERT INTO agent_heartbeats (
- agent_id,
- received_at,
- metadata
- )
- SELECT
- (
- SELECT id
- FROM agents
- ORDER BY random()
- LIMIT 1
- ),
- NOW() - (random() * interval '30 days'),
- jsonb_build_object(
- 'cpu_usage',
- floor(random() * 100),
- 'ram_usage',
- floor(random() * 100),
- 'disk_usage',
- floor(random() * 100)
- )
- FROM generate_series(1, 100);
- -- =========================================================
- -- 50 USER SESSIONS
- -- =========================================================
- INSERT INTO user_sessions (
- user_id,
- refresh_token_hash,
- user_agent,
- ip_address,
- expires_at,
- created_at
- )
- SELECT
- (
- SELECT id
- FROM users
- ORDER BY random()
- LIMIT 1
- ),
- md5(random()::text),
- (
- ARRAY[
- 'Chrome',
- 'Firefox',
- 'Edge',
- 'Safari',
- 'Postman'
- ]
- )[floor(random() * 5 + 1)::int],
- (
- floor(random() * 255)::int || '.' ||
- floor(random() * 255)::int || '.' ||
- floor(random() * 255)::int || '.' ||
- floor(random() * 255)::int
- )::inet,
- NOW() + (random() * interval '30 days'),
- NOW() - (random() * interval '30 days')
- FROM generate_series(1, 50);
- -- =========================================================
- -- AGENT GROUPS
- -- =========================================================
- INSERT INTO agent_groups (
- name,
- description
- )
- VALUES
- ('Production', 'Production infrastructure'),
- ('Testing', 'Testing infrastructure'),
- ('Development', 'Development infrastructure'),
- ('Monitoring', 'Monitoring servers'),
- ('Backup', 'Backup infrastructure');
- -- =========================================================
- -- AGENT GROUP MEMBERS
- -- =========================================================
- INSERT INTO agent_group_members (
- agent_id,
- group_id
- )
- SELECT DISTINCT
- (
- SELECT id
- FROM agents
- ORDER BY random()
- LIMIT 1
- ),
- (
- SELECT id
- FROM agent_groups
- ORDER BY random()
- LIMIT 1
- )
- FROM generate_series(1, 100)
- ON CONFLICT DO NOTHING;
|