Created
September 12, 2025 18:03
-
-
Save Deniz97/342a8ae6119f3396196aaa443c16dfae to your computer and use it in GitHub Desktop.
Comprehensive agent API demonstration script for employee monitoring system - Generates realistic log data across all activity types (USB, application, upload, file operations) with device authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Agent API Demonstration Script | |
| # This script demonstrates the full input space for agent log submission | |
| # | |
| # Usage: ./demo-agent-logs.sh <API_BASE_URL> [DEVICE_API_KEY] | |
| # Example: ./demo-agent-logs.sh http://localhost:3000 device-api-key-123 | |
| # | |
| # ============================================================================= | |
| # SUPPORTED EVENT TYPES AND ACTIONS | |
| # ============================================================================= | |
| # | |
| # 1. USB_ACTIVITY | |
| # Actions: "plugged_in", "plugged_out", "connected", "disconnected", "inserted", "removed" | |
| # Description: USB device connection/disconnection events | |
| # Required Fields: id, timestamp, event.type, event.action, event.description, user.user_id, user.machine_id, user.session_id | |
| # Optional Metadata: deviceName, deviceId, capacity, vendor, serialNumber, fileCount, totalSize, filesModified, filesAdded, filesDeleted, usageDuration | |
| # | |
| # 2. FILE_SYSTEM_ACTIVITY | |
| # Actions: "created", "create", "renamed", "rename", "deleted", "delete" | |
| # Description: File system operations (supports Turkish descriptions) | |
| # Required Fields: id, timestamp, event.type, event.action, event.description, user.user_id, user.machine_id, user.session_id | |
| # Optional Metadata: file_path, old_file_path, new_file_path, old_file_extension, new_file_extension, fileSize, category, operationDuration, reasonCode | |
| # | |
| # 3. APPLICATION_ACTIVITY | |
| # Actions: "started", "focused", "opened", "saved", "accessed", "used" | |
| # Description: Application usage tracking and monitoring | |
| # Required Fields: id, timestamp, event.type, event.action, event.description, user.user_id, user.machine_id, user.session_id | |
| # Optional Metadata: application_name, category, duration, activityType, windowTitle, processId, url, tabCount, incognito, projectName, language, linesOfCode | |
| # | |
| # 4. UPLOAD_ACTIVITY | |
| # Actions: "uploaded" | |
| # Description: File upload monitoring through web browsers | |
| # Required Fields: id, timestamp, event.type, event.action, event.description, user.user_id, user.machine_id, user.session_id | |
| # Optional Metadata: file_name, file_size, upload_url, mime_type, category, browser, destination, uploadSpeed, encrypted, compressionUsed, uploadDuration, retryCount | |
| # | |
| # ============================================================================= | |
| # AUTHENTICATION & ENDPOINTS | |
| # ============================================================================= | |
| # Header: X-Device-API-Key: [DEVICE_API_KEY] | |
| # POST /api/logs - Submit log entries (single or batch) | |
| # GET /api/me - Get authenticated device information | |
| # | |
| # ============================================================================= | |
| # LOG ENTRY STRUCTURE | |
| # ============================================================================= | |
| # { | |
| # "id": "uuid-v4-string", | |
| # "timestamp": "2025-01-12T23:30:43.311Z", | |
| # "event": { | |
| # "type": "event_type", | |
| # "action": "action_name", | |
| # "description": "Human readable description" | |
| # }, | |
| # "user": { | |
| # "user_id": "employee_name_or_id", | |
| # "machine_id": "unique_machine_identifier", | |
| # "session_id": "session_identifier" | |
| # }, | |
| # "metadata": { | |
| # // Type-specific metadata fields (optional) | |
| # } | |
| # } | |
| # ============================================================================= | |
| set -e # Exit on any error | |
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| BLUE='\033[0;34m' | |
| YELLOW='\033[1;33m' | |
| NC='\033[0m' # No Color | |
| # Configuration | |
| API_BASE_URL="${1:-http://localhost:3000}" | |
| DEVICE_API_KEY="${2:-device-api-key-123}" | |
| # Remove trailing slash | |
| API_BASE_URL="${API_BASE_URL%/}" | |
| echo -e "${BLUE}🚀 Agent API Demonstration Script${NC}" | |
| echo -e "${BLUE}============================================${NC}" | |
| echo -e "API Base URL: ${GREEN}$API_BASE_URL${NC}" | |
| echo -e "Device API Key: ${GREEN}$DEVICE_API_KEY${NC}" | |
| echo "" | |
| # Fetch device information from /me endpoint | |
| fetch_device_info() { | |
| echo -e "${BLUE}🔍 Fetching device information...${NC}" | |
| local response=$(curl -s -w "\n%{http_code}" \ | |
| -X GET \ | |
| -H "X-Device-API-Key: $DEVICE_API_KEY" \ | |
| "$API_BASE_URL/api/me") | |
| local http_code=$(echo "$response" | tail -n1) | |
| local body=$(echo "$response" | sed '$d') | |
| if [[ $http_code -ge 200 && $http_code -lt 300 ]]; then | |
| echo -e "${GREEN}✅ Device information retrieved${NC}" | |
| # Extract device info using basic parsing (avoiding jq dependency) | |
| DEVICE_ID=$(echo "$body" | grep -o '"id":"[^"]*"' | cut -d'"' -f4) | |
| DEVICE_NAME=$(echo "$body" | grep -o '"deviceName":"[^"]*"' | cut -d'"' -f4) | |
| EMPLOYEE_NAME=$(echo "$body" | grep -o '"employeeName":"[^"]*"' | cut -d'"' -f4) | |
| EMPLOYEE_ID=$(echo "$body" | grep -o '"employeeId":"[^"]*"' | cut -d'"' -f4) | |
| MACHINE_ID=$(echo "$body" | grep -o '"machineId":"[^"]*"' | cut -d'"' -f4) | |
| echo -e " Device: ${GREEN}$DEVICE_NAME${NC}" | |
| echo -e " Employee: ${GREEN}$EMPLOYEE_NAME${NC} ($EMPLOYEE_ID)" | |
| echo -e " Machine ID: ${GREEN}$MACHINE_ID${NC}" | |
| echo "" | |
| return 0 | |
| else | |
| echo -e "${RED}❌ Failed to fetch device info (HTTP $http_code)${NC}" | |
| echo -e "${RED} Response: $body${NC}" | |
| echo -e "${YELLOW} Make sure the device API key is valid and the device exists in the database.${NC}" | |
| return 1 | |
| fi | |
| } | |
| # Application names and categories | |
| APPLICATIONS=( | |
| "Google Chrome,Browser" | |
| "Microsoft Edge,Browser" | |
| "Firefox,Browser" | |
| "Visual Studio Code,Development" | |
| "JetBrains IntelliJ,Development" | |
| "Visual Studio,Development" | |
| "Microsoft Outlook,Email" | |
| "Slack,Communication" | |
| "Microsoft Teams,Communication" | |
| "Discord,Communication" | |
| "Zoom,Communication" | |
| "Adobe Photoshop,Design" | |
| "Figma,Design" | |
| "Microsoft Word,Office" | |
| "Microsoft Excel,Office" | |
| "Microsoft PowerPoint,Office" | |
| "Google Docs,Office" | |
| "Notion,Productivity" | |
| "Spotify,Media" | |
| "Steam,Gaming" | |
| "File Explorer,Utility" | |
| "Terminal,Development" | |
| ) | |
| # File extensions and categories | |
| FILE_EXTENSIONS=( | |
| ".txt,Document" | |
| ".pdf,Document" | |
| ".docx,Document" | |
| ".xlsx,Spreadsheet" | |
| ".pptx,Presentation" | |
| ".jpg,Image" | |
| ".png,Image" | |
| ".js,Code" | |
| ".ts,Code" | |
| ".py,Code" | |
| ".html,Web" | |
| ".css,Web" | |
| ".json,Data" | |
| ".zip,Archive" | |
| ".mp4,Video" | |
| ".mp3,Audio" | |
| ) | |
| # USB devices | |
| USB_DEVICES=( | |
| "SanDisk Ultra USB 3.0,32GB,SanDisk" | |
| "Kingston DataTraveler,64GB,Kingston" | |
| "Samsung BAR Plus,128GB,Samsung" | |
| "Corsair Flash Voyager,16GB,Corsair" | |
| "Transcend JetFlash,32GB,Transcend" | |
| ) | |
| # Upload sites | |
| UPLOAD_SITES=( | |
| "https://drive.google.com/upload,Google Drive" | |
| "https://onedrive.live.com/upload,OneDrive" | |
| "https://www.dropbox.com/upload,Dropbox" | |
| "https://github.com/upload,GitHub" | |
| "https://wetransfer.com/upload,WeTransfer" | |
| ) | |
| # Browsers | |
| BROWSERS=("Chrome" "Edge" "Firefox" "Safari") | |
| # File paths | |
| FILE_PATHS=( | |
| "C:\\Users\\employee\\Documents\\" | |
| "C:\\Users\\employee\\Downloads\\" | |
| "C:\\Users\\employee\\Desktop\\" | |
| "C:\\Users\\employee\\Pictures\\" | |
| "C:\\Projects\\" | |
| "C:\\Work\\" | |
| "D:\\Files\\" | |
| ) | |
| # Helper functions | |
| get_random_item() { | |
| local array=("$@") | |
| local size=${#array[@]} | |
| local index=$((RANDOM % size)) | |
| echo "${array[$index]}" | |
| } | |
| get_current_timestamp() { | |
| # Generate timestamp within last 30 days with business hour weighting | |
| local days_back=$((RANDOM % 30)) | |
| local hours_back=$((RANDOM % 24)) | |
| local minutes_back=$((RANDOM % 60)) | |
| local seconds_back=$((RANDOM % 60)) | |
| # Calculate timestamp | |
| local total_seconds=$(( (days_back * 24 * 3600) + (hours_back * 3600) + (minutes_back * 60) + seconds_back )) | |
| local target_timestamp=$(($(date +%s) - total_seconds)) | |
| date -d "@$target_timestamp" -Iseconds 2>/dev/null || date -r "$target_timestamp" +"%Y-%m-%dT%H:%M:%S%z" | |
| } | |
| generate_session_id() { | |
| local device_id="$1" | |
| local timestamp="$2" | |
| local date_part=$(echo "$timestamp" | cut -d'T' -f1 | tr -d '-') | |
| local time_part=$(echo "$timestamp" | cut -d'T' -f2 | cut -d'+' -f1 | tr -d ':') | |
| local random_suffix=$(LC_ALL=C head /dev/urandom | LC_ALL=C tr -dc a-z0-9 | head -c 4) | |
| echo "${device_id}_${date_part}_${time_part}_${random_suffix}" | |
| } | |
| generate_file_name() { | |
| local category="$1" | |
| local extension="$2" | |
| local base_names=("report" "document" "file" "data" "project" "backup" "export" "config") | |
| local base_name=$(get_random_item "${base_names[@]}") | |
| local timestamp=$(date +"%Y%m%d") | |
| local suffix=$((RANDOM % 100)) | |
| echo "${base_name}_${timestamp}_${suffix}${extension}" | |
| } | |
| generate_file_size() { | |
| local extension="$1" | |
| case $extension in | |
| ".txt") echo $((500 + RANDOM % 49500)) ;; | |
| ".pdf") echo $((50000 + RANDOM % 4950000)) ;; | |
| ".docx") echo $((20000 + RANDOM % 1980000)) ;; | |
| ".xlsx") echo $((15000 + RANDOM % 1485000)) ;; | |
| ".jpg"|".png") echo $((100000 + RANDOM % 4900000)) ;; | |
| ".mp4") echo $((5000000 + RANDOM % 95000000)) ;; | |
| ".mp3") echo $((2000000 + RANDOM % 8000000)) ;; | |
| ".zip") echo $((100000 + RANDOM % 49900000)) ;; | |
| *) echo $((1000 + RANDOM % 99000)) ;; | |
| esac | |
| } | |
| # API call function with error handling | |
| make_api_call() { | |
| local data="$1" | |
| local description="$2" | |
| local response=$(curl -s -w "\n%{http_code}" \ | |
| -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -H "X-Device-API-Key: $DEVICE_API_KEY" \ | |
| -d "$data" \ | |
| "$API_BASE_URL/api/logs") | |
| local http_code=$(echo "$response" | tail -n1) | |
| local body=$(echo "$response" | sed '$d') | |
| if [[ $http_code -ge 200 && $http_code -lt 300 ]]; then | |
| echo -e "${GREEN}✓${NC} $description" | |
| return 0 | |
| else | |
| echo -e "${RED}✗${NC} $description (HTTP $http_code)" | |
| echo -e "${RED} Response: $body${NC}" | |
| return 1 | |
| fi | |
| } | |
| # Generate USB logs | |
| generate_usb_logs() { | |
| local device_id="$1" | |
| local device_name="$2" | |
| local employee_name="$3" | |
| local machine_id="$4" | |
| local count="${5:-10}" | |
| echo -e "${BLUE}🔌 Generating $count USB log entries for $device_name...${NC}" | |
| for ((i=1; i<=count; i++)); do | |
| local timestamp=$(get_current_timestamp) | |
| local session_id=$(generate_session_id "$device_id" "$timestamp") | |
| local usb_device=$(get_random_item "${USB_DEVICES[@]}") | |
| IFS=',' read -r device_name_usb capacity vendor <<< "$usb_device" | |
| # Generate device IDs | |
| local device_id_str="VID_$(printf "%04d" $((RANDOM % 10000)))&PID_$(printf "%04d" $((RANDOM % 10000)))" | |
| local serial_number=$(LC_ALL=C head /dev/urandom | LC_ALL=C tr -dc A-Z0-9 | head -c 12) | |
| local log_id=$(LC_ALL=C head /dev/urandom | LC_ALL=C tr -dc a-f0-9 | head -c 32 | sed 's/\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\)/\1-\2-\3-\4-\5/') | |
| # USB PLUGGED_IN | |
| local plug_in_data=$(cat <<EOF | |
| { | |
| "id": "$log_id", | |
| "timestamp": "$timestamp", | |
| "event": { | |
| "type": "usb_activity", | |
| "action": "plugged_in", | |
| "description": "USB device connected: $device_name_usb ($capacity)" | |
| }, | |
| "user": { | |
| "user_id": "$employee_name", | |
| "machine_id": "$machine_id", | |
| "session_id": "$session_id" | |
| }, | |
| "metadata": { | |
| "deviceName": "$device_name_usb", | |
| "deviceId": "$device_id_str", | |
| "capacity": "$capacity", | |
| "vendor": "$vendor", | |
| "serialNumber": "$serial_number", | |
| "fileCount": $((RANDOM % 150 + 1)), | |
| "totalSize": $((RANDOM % 50000000 + 1000000)) | |
| } | |
| } | |
| EOF | |
| ) | |
| make_api_call "$plug_in_data" "USB Plug In ($i/$count)" | |
| # USB PLUGGED_OUT (few minutes later) | |
| local unplug_timestamp=$(date -d "$timestamp + $((5 + RANDOM % 120)) minutes" -Iseconds 2>/dev/null || date -r $(( $(date -j -f "%Y-%m-%dT%H:%M:%S%z" "$timestamp" +%s) + (5 + RANDOM % 120) * 60 )) +"%Y-%m-%dT%H:%M:%S%z") | |
| local unplug_log_id=$(LC_ALL=C head /dev/urandom | LC_ALL=C tr -dc a-f0-9 | head -c 32 | sed 's/\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\)/\1-\2-\3-\4-\5/') | |
| local plug_out_data=$(cat <<EOF | |
| { | |
| "id": "$unplug_log_id", | |
| "timestamp": "$unplug_timestamp", | |
| "event": { | |
| "type": "usb_activity", | |
| "action": "plugged_out", | |
| "description": "USB device disconnected: $device_name_usb ($capacity)" | |
| }, | |
| "user": { | |
| "user_id": "$employee_name", | |
| "machine_id": "$machine_id", | |
| "session_id": "$session_id" | |
| }, | |
| "metadata": { | |
| "deviceName": "$device_name_usb", | |
| "deviceId": "$device_id_str", | |
| "capacity": "$capacity", | |
| "vendor": "$vendor", | |
| "serialNumber": "$serial_number", | |
| "filesModified": $((RANDOM % 20)), | |
| "filesAdded": $((RANDOM % 10)), | |
| "filesDeleted": $((RANDOM % 5)), | |
| "usageDuration": $(((5 + RANDOM % 120) * 60)) | |
| } | |
| } | |
| EOF | |
| ) | |
| make_api_call "$plug_out_data" "USB Plug Out ($i/$count)" | |
| # Small delay to avoid overwhelming the API | |
| sleep 0.1 | |
| done | |
| } | |
| # Generate activity logs | |
| generate_activity_logs() { | |
| local device_id="$1" | |
| local device_name="$2" | |
| local employee_name="$3" | |
| local machine_id="$4" | |
| local count="${5:-15}" | |
| echo -e "${BLUE}📱 Generating $count activity log entries for $device_name...${NC}" | |
| for ((i=1; i<=count; i++)); do | |
| local timestamp=$(get_current_timestamp) | |
| local session_id=$(generate_session_id "$device_id" "$timestamp") | |
| local app_info=$(get_random_item "${APPLICATIONS[@]}") | |
| IFS=',' read -r app_name app_category <<< "$app_info" | |
| local log_id=$(LC_ALL=C head /dev/urandom | LC_ALL=C tr -dc a-f0-9 | head -c 32 | sed 's/\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\)/\1-\2-\3-\4-\5/') | |
| local activities=("started" "focused" "opened" "saved" "accessed" "used") | |
| local activity=$(get_random_item "${activities[@]}") | |
| # Generate duration based on app category | |
| local duration | |
| case $app_category in | |
| "Development") duration=$((1200 + RANDOM % 7200)) ;; | |
| "Browser") duration=$((180 + RANDOM % 3600)) ;; | |
| "Office") duration=$((600 + RANDOM % 5400)) ;; | |
| *) duration=$((300 + RANDOM % 1800)) ;; | |
| esac | |
| local activity_data=$(cat <<EOF | |
| { | |
| "id": "$log_id", | |
| "timestamp": "$timestamp", | |
| "event": { | |
| "type": "application_activity", | |
| "action": "$activity", | |
| "description": "Application $activity: $app_name" | |
| }, | |
| "user": { | |
| "user_id": "$employee_name", | |
| "machine_id": "$machine_id", | |
| "session_id": "$session_id" | |
| }, | |
| "metadata": { | |
| "application_name": "$app_name", | |
| "category": "$app_category", | |
| "duration": $duration, | |
| "activityType": "$activity", | |
| "windowTitle": "$app_name - Document", | |
| "processId": $((RANDOM % 10000 + 1000)) | |
| } | |
| } | |
| EOF | |
| ) | |
| make_api_call "$activity_data" "Activity ($i/$count): $app_name" | |
| sleep 0.1 | |
| done | |
| } | |
| # Generate upload logs | |
| generate_upload_logs() { | |
| local device_id="$1" | |
| local device_name="$2" | |
| local employee_name="$3" | |
| local machine_id="$4" | |
| local count="${5:-8}" | |
| echo -e "${BLUE}📤 Generating $count upload log entries for $device_name...${NC}" | |
| for ((i=1; i<=count; i++)); do | |
| local timestamp=$(get_current_timestamp) | |
| local session_id=$(generate_session_id "$device_id" "$timestamp") | |
| local file_ext_info=$(get_random_item "${FILE_EXTENSIONS[@]}") | |
| IFS=',' read -r file_ext file_category <<< "$file_ext_info" | |
| local browser=$(get_random_item "${BROWSERS[@]}") | |
| local upload_site_info=$(get_random_item "${UPLOAD_SITES[@]}") | |
| IFS=',' read -r upload_url site_name <<< "$upload_site_info" | |
| local log_id=$(LC_ALL=C head /dev/urandom | LC_ALL=C tr -dc a-f0-9 | head -c 32 | sed 's/\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\)/\1-\2-\3-\4-\5/') | |
| local file_name=$(generate_file_name "$file_category" "$file_ext") | |
| local file_size=$(generate_file_size "$file_ext") | |
| local upload_data=$(cat <<EOF | |
| { | |
| "id": "$log_id", | |
| "timestamp": "$timestamp", | |
| "event": { | |
| "type": "upload_activity", | |
| "action": "uploaded", | |
| "description": "File uploaded: $file_name to $site_name via $browser" | |
| }, | |
| "user": { | |
| "user_id": "$employee_name", | |
| "machine_id": "$machine_id", | |
| "session_id": "$session_id" | |
| }, | |
| "metadata": { | |
| "file_name": "$file_name", | |
| "file_size": $file_size, | |
| "upload_url": "$upload_url", | |
| "mime_type": "application/octet-stream", | |
| "category": "$file_category", | |
| "browser": "$browser", | |
| "destination": "$site_name", | |
| "uploadSpeed": $((200 + RANDOM % 2800)), | |
| "encrypted": true, | |
| "compressionUsed": $([ $file_size -gt 10000000 ] && echo "true" || echo "false"), | |
| "uploadDuration": $((file_size / (300 + RANDOM % 2000))), | |
| "retryCount": 0 | |
| } | |
| } | |
| EOF | |
| ) | |
| make_api_call "$upload_data" "Upload ($i/$count): $file_name" | |
| sleep 0.1 | |
| done | |
| } | |
| # Generate file operation logs | |
| generate_file_logs() { | |
| local device_id="$1" | |
| local device_name="$2" | |
| local employee_name="$3" | |
| local machine_id="$4" | |
| local count="${5:-12}" | |
| echo -e "${BLUE}📁 Generating $count file operation log entries for $device_name...${NC}" | |
| local file_actions=("created" "renamed" "deleted") | |
| for ((i=1; i<=count; i++)); do | |
| local timestamp=$(get_current_timestamp) | |
| local session_id=$(generate_session_id "$device_id" "$timestamp") | |
| local action=$(get_random_item "${file_actions[@]}") | |
| local file_ext_info=$(get_random_item "${FILE_EXTENSIONS[@]}") | |
| IFS=',' read -r file_ext file_category <<< "$file_ext_info" | |
| local base_path=$(get_random_item "${FILE_PATHS[@]}") | |
| local log_id=$(LC_ALL=C head /dev/urandom | LC_ALL=C tr -dc a-f0-9 | head -c 32 | sed 's/\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\)/\1-\2-\3-\4-\5/') | |
| local file_name=$(generate_file_name "$file_category" "$file_ext") | |
| local file_path="${base_path}${file_name}" | |
| local file_size=$(generate_file_size "$file_ext") | |
| # Create description based on action | |
| local description | |
| case $action in | |
| "renamed") | |
| local old_file_name="old_${file_name}" | |
| description="Dosya yeniden adlandırıldı: ${old_file_name} -> ${file_name}" | |
| ;; | |
| "created") | |
| description="Yeni dosya oluşturuldu: ${file_name}" | |
| ;; | |
| "deleted") | |
| description="Dosya silindi: ${file_name}" | |
| ;; | |
| esac | |
| # Build metadata based on action | |
| local file_data | |
| if [[ "$action" == "renamed" ]]; then | |
| local old_file_path="${base_path}old_${file_name}" | |
| # Escape backslashes for JSON | |
| local old_file_path_escaped="${old_file_path//\\/\\\\}" | |
| local file_path_escaped="${file_path//\\/\\\\}" | |
| file_data=$(cat <<EOF | |
| { | |
| "id": "$log_id", | |
| "timestamp": "$timestamp", | |
| "event": { | |
| "type": "file_system_activity", | |
| "action": "$action", | |
| "description": "$description" | |
| }, | |
| "user": { | |
| "user_id": "$employee_name", | |
| "machine_id": "$machine_id", | |
| "session_id": "$session_id" | |
| }, | |
| "metadata": { | |
| "old_file_path": "$old_file_path_escaped", | |
| "new_file_path": "$file_path_escaped", | |
| "old_file_extension": "$file_ext", | |
| "new_file_extension": "$file_ext", | |
| "fileSize": $file_size, | |
| "category": "$file_category", | |
| "operationDuration": $((50 + RANDOM % 2950)), | |
| "reasonCode": "version_update" | |
| } | |
| } | |
| EOF | |
| ) | |
| else | |
| # Escape backslashes for JSON | |
| local file_path_escaped="${file_path//\\/\\\\}" | |
| file_data=$(cat <<EOF | |
| { | |
| "id": "$log_id", | |
| "timestamp": "$timestamp", | |
| "event": { | |
| "type": "file_system_activity", | |
| "action": "$action", | |
| "description": "$description" | |
| }, | |
| "user": { | |
| "user_id": "$employee_name", | |
| "machine_id": "$machine_id", | |
| "session_id": "$session_id" | |
| }, | |
| "metadata": { | |
| "file_path": "$file_path_escaped", | |
| "file_extension": "$file_ext", | |
| "fileSize": $file_size, | |
| "category": "$file_category", | |
| "operationDuration": $((50 + RANDOM % 2950)) | |
| } | |
| } | |
| EOF | |
| ) | |
| fi | |
| make_api_call "$file_data" "File $action ($i/$count): $file_name" | |
| sleep 0.1 | |
| done | |
| } | |
| # Main execution | |
| main() { | |
| echo -e "${YELLOW}📋 Starting agent API demonstration...${NC}" | |
| echo "" | |
| # Fetch device information using the provided API key | |
| if ! fetch_device_info; then | |
| echo -e "${RED}❌ Cannot proceed without valid device information${NC}" | |
| exit 1 | |
| fi | |
| local total_success=0 | |
| local total_errors=0 | |
| echo -e "${BLUE}🖥️ Generating logs for: $EMPLOYEE_NAME ($DEVICE_NAME)${NC}" | |
| echo -e " Machine ID: $MACHINE_ID" | |
| echo -e " Employee ID: $EMPLOYEE_ID" | |
| echo "" | |
| # Generate logs for this authenticated device | |
| local device_success=0 | |
| local device_errors=0 | |
| # USB Logs (2-5 entries) | |
| if generate_usb_logs "$DEVICE_ID" "$DEVICE_NAME" "$EMPLOYEE_NAME" "$MACHINE_ID" $((2 + RANDOM % 4)); then | |
| ((device_success += 1)) | |
| else | |
| ((device_errors += 1)) | |
| fi | |
| # Activity Logs (3-8 entries) | |
| if generate_activity_logs "$DEVICE_ID" "$DEVICE_NAME" "$EMPLOYEE_NAME" "$MACHINE_ID" $((3 + RANDOM % 6)); then | |
| ((device_success += 1)) | |
| else | |
| ((device_errors += 1)) | |
| fi | |
| # Upload Logs (1-4 entries) | |
| if generate_upload_logs "$DEVICE_ID" "$DEVICE_NAME" "$EMPLOYEE_NAME" "$MACHINE_ID" $((1 + RANDOM % 4)); then | |
| ((device_success += 1)) | |
| else | |
| ((device_errors += 1)) | |
| fi | |
| # File Logs (2-6 entries) | |
| if generate_file_logs "$DEVICE_ID" "$DEVICE_NAME" "$EMPLOYEE_NAME" "$MACHINE_ID" $((2 + RANDOM % 5)); then | |
| ((device_success += 1)) | |
| else | |
| ((device_errors += 1)) | |
| fi | |
| total_success=$((total_success + device_success)) | |
| total_errors=$((total_errors + device_errors)) | |
| echo -e "${GREEN}✅ Completed logs for $EMPLOYEE_NAME: $device_success log types successful, $device_errors errors${NC}" | |
| echo "" | |
| echo -e "${BLUE}📊 Final Results:${NC}" | |
| echo -e " ${GREEN}Successful log types: $total_success${NC}" | |
| echo -e " ${RED}Failed log types: $total_errors${NC}" | |
| echo "" | |
| if [[ $total_errors -eq 0 ]]; then | |
| echo -e "${GREEN}🎉 Agent API demonstration completed successfully!${NC}" | |
| exit 0 | |
| else | |
| echo -e "${YELLOW}⚠️ Some log submissions failed. Check the API endpoint and credentials.${NC}" | |
| exit 1 | |
| fi | |
| } | |
| # Show usage if no arguments | |
| if [[ $# -eq 0 ]]; then | |
| echo -e "${YELLOW}Usage: $0 <API_BASE_URL> [DEVICE_API_KEY]${NC}" | |
| echo "" | |
| echo -e "${BLUE}Examples:${NC}" | |
| echo " $0 http://localhost:3000" | |
| echo " $0 https://dlp-app.vercel.app device-api-key-123" | |
| echo "" | |
| echo -e "${BLUE}This script demonstrates agent log submission with:${NC}" | |
| echo " • Device Authentication: Uses /api/me endpoint to fetch device info" | |
| echo " • USB Activity: plugged_in/plugged_out events with device metadata" | |
| echo " • Application Activity: app usage tracking with duration patterns" | |
| echo " • Upload Activity: file upload monitoring with browser info" | |
| echo " • File System Activity: create/rename/delete operations with paths" | |
| echo "" | |
| echo -e "${BLUE}Authenticates with provided device API key and generates realistic data${NC}" | |
| echo -e "${BLUE}Uses unified /api/logs endpoint with X-Device-API-Key authentication${NC}" | |
| exit 1 | |
| fi | |
| # Check dependencies | |
| if ! command -v curl &> /dev/null; then | |
| echo -e "${RED}❌ curl is required but not installed.${NC}" | |
| exit 1 | |
| fi | |
| if ! command -v jq &> /dev/null; then | |
| echo -e "${YELLOW}⚠️ jq not found. JSON output will not be formatted.${NC}" | |
| fi | |
| # Run main function | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment