# Copyright (c) 2021-2025 community-scripts ORG # Author: michelroegl-brunner # License: MIT | https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/LICENSE # ============================================================================== # API.FUNC - TELEMETRY & DIAGNOSTICS API # ============================================================================== # # Provides functions for sending anonymous telemetry data to Community-Scripts # API for analytics and diagnostics purposes. # # Features: # - Container/VM creation statistics # - Installation success/failure tracking # - Error code mapping and reporting # - Privacy-respecting anonymous telemetry # # Usage: # source <(curl -fsSL .../api.func) # post_to_api # Report container creation # post_update_to_api # Report installation status # # Privacy: # - Only anonymous statistics (no personal data) # - User can opt-out via diagnostics settings # - Random UUID for session tracking only # # ============================================================================== # ============================================================================== # SECTION 1: DEPENDENCY LOADING # ============================================================================== # Load error_handler.func for explain_exit_code() function # This provides centralized error code descriptions (exit codes 1-255, shell, package managers, databases, custom Proxmox codes) if [[ -z "${COMMUNITY_SCRIPTS_BASE_URL:-}" ]]; then COMMUNITY_SCRIPTS_BASE_URL="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main" fi if ! declare -f explain_exit_code >/dev/null 2>&1; then source <(curl -fsSL "${COMMUNITY_SCRIPTS_BASE_URL}/misc/error_handler.func") || { echo "Failed to load error_handler.func" >&2 return 1 } fi # ============================================================================== # SECTION 2: TELEMETRY FUNCTIONS # ============================================================================== # ------------------------------------------------------------------------------ # post_to_api() # # - Sends LXC container creation statistics to Community-Scripts API # - Only executes if: # * curl is available # * DIAGNOSTICS=yes # * RANDOM_UUID is set # - Payload includes: # * Container type, disk size, CPU cores, RAM # * OS type and version # * IPv6 disable status # * Application name (NSAPP) # * Installation method # * PVE version # * Status: "installing" # * Random UUID for session tracking # - Anonymous telemetry (no personal data) # ------------------------------------------------------------------------------ post_to_api() { if ! command -v curl &>/dev/null; then return fi if [ "$DIAGNOSTICS" = "no" ]; then return fi if [ -z "$RANDOM_UUID" ]; then return fi local API_URL="http://api.community-scripts.org/dev/upload" local pve_version="not found" pve_version=$(pveversion | awk -F'[/ ]' '{print $2}') JSON_PAYLOAD=$( cat </dev/null; then return fi if [ "$POST_UPDATE_DONE" = true ]; then return 0 fi exit_code=${2:-1} local API_URL="http://api.community-scripts.org/dev/upload/updatestatus" local status="${1:-failed}" if [[ "$status" == "failed" ]]; then local exit_code="${2:-1}" elif [[ "$status" == "success" ]]; then local exit_code="${2:-0}" fi if [[ -z "$exit_code" ]]; then exit_code=1 fi error=$(explain_exit_code "$exit_code") if [ -z "$error" ]; then error="Unknown error" fi JSON_PAYLOAD=$( cat <