Variables.ps1

#
# Logging
#
New-Variable -Name 'IN_MEMORY_LOGS' -Value ([System.Collections.ArrayList]::new()) -Option ReadOnly -Scope Script -Force
New-Variable -Name 'CONSOLE_LOG_LEVEL' -Value 'INFO' -Option ReadOnly -Scope Script -Force
#
# Spools
#
New-Variable -Name 'SPOOL_FOLDER_NAME' -Value 'Spool' -Option ReadOnly -Scope Script -Force
New-Variable -Name "SPOOL_MAX_FILE_COUNT" -Value 100 -Option ReadOnly -Scope Script -Force

#
# Virtual Machines
#
New-Variable -Name 'STORAGE_FOLDER_NAME' -Value 'Storage' -Option ReadOnly -Scope Script -Force
New-Variable -Name 'VM_ENRICHMENT_BATCH_SIZE' -Value 1000 -Option ReadOnly -Scope Script -Force
New-Variable -Name 'VM_CACHE_EXPIRATION' -Value 'PT1H' -Option ReadOnly -Scope Script -Force

#
# Time window constants
#
New-Variable -Name 'MAX_MINUTES_READ' -Value 20 -Option ReadOnly -Scope Script -Force

#
# Nutanix Prism Central v4 API tuning
#

# Event duration: Prism Central's native stats resolution (it returns 30s-spaced points for any
# $samplingInterval at or below 30, lab-validated with 10, 20 and 30), sent 1:1 without resampling.
# The Nexthink hypervisor-processor routes source=nutanix-connector to its 30s converter, which only
# accepts whole minutes per host (2 events starting at :00 and :30) and rejects the entire host
# entry otherwise.
New-Variable -Name 'NUTANIX_STATS_SAMPLING_INTERVAL_SECONDS' -Value 30 -Option ReadOnly -Scope Script -Force

# Memory counters that only exist on clustermgmt v4.3+ host stats (pc.7.x rejects them with HTTP 500).
# PM decision: send them as an explicit JSON null, not 0 and not omitted, until validated on a lab cluster.
# Wire name -> data model field: committed -> memory.committed, swap_used_average -> memory.swap_size,
# vm_mem_ctl_average -> memory.ballooning.
New-Variable -Name 'NUTANIX_NULL_MEMORY_FIELDS' -Value @('committed', 'swap_used_average', 'vm_mem_ctl_average') -Option ReadOnly -Scope Script -Force

# Retry budget for transient Prism Central failures.
New-Variable -Name 'NUTANIX_API_MAX_RETRIES' -Value 3 -Option ReadOnly -Scope Script -Force

# v4 list endpoints accept $limit 1-100 and default to 50 when omitted; always page at the maximum.
New-Variable -Name 'NUTANIX_STATS_PAGE_LIMIT' -Value 100 -Option ReadOnly -Scope Script -Force

# Outbound request-start ceiling, well below the smallest documented Prism Central rate limit
# (30 req/s for an X-Small PC). Prism Central answers HTTP 429 above its limit.
New-Variable -Name 'NUTANIX_API_MAX_REQUESTS_PER_SECOND' -Value 10 -Option ReadOnly -Scope Script -Force
New-Variable -Name 'NUTANIX_HOST_STATS_MAX_CONCURRENCY' -Value 5 -Option ReadOnly -Scope Script -Force

# clustermgmt/v4.0/config/clusters. clusterFunction tells the Prism Central's own registration
# (PRISM_CENTRAL, no AHV hosts) apart from the AOS clusters it manages.
New-Variable -Name 'NUTANIX_CLUSTER_SELECT' -Value 'extId,name,config/clusterFunction' -Option ReadOnly -Scope Script -Force
New-Variable -Name 'NUTANIX_CLUSTER_FUNCTION_SKIP' -Value @('PRISM_CENTRAL') -Option ReadOnly -Scope Script -Force

# clustermgmt/v4.0/stats/clusters/{clusterExtId}/hosts/{hostExtId}. The series are top-level
# properties of the HostStats object, so $select takes bare names (lab-validated: a 'stats/' prefix
# is rejected with CLU-10007). The controller* series are the CVM storage-path counters, the same
# layer Prism Element v2 reported for read/write bandwidth and average I/O latency.
New-Variable -Name 'NUTANIX_HOST_STATS_SELECT' -Value (@(
    'hypervisorCpuUsagePpm',
    'aggregateHypervisorMemoryUsagePpm',
    'memoryCapacityBytes',
    'controllerReadIoBandwidthKbps',
    'controllerWriteIoBandwidthKbps',
    'controllerAvgIoLatencyUsecs'
) -join ',') -Option ReadOnly -Scope Script -Force

# Host series that mark a real performance bucket. memoryCapacityBytes is deliberately absent: Prism
# Central returns it as one point stamped with the last capacity change, not per bucket.
New-Variable -Name 'NUTANIX_HOST_EVENT_SERIES' -Value @(
    'hypervisorCpuUsagePpm',
    'aggregateHypervisorMemoryUsagePpm',
    'controllerReadIoBandwidthKbps',
    'controllerWriteIoBandwidthKbps',
    'controllerAvgIoLatencyUsecs'
) -Option ReadOnly -Scope Script -Force

# vmm/v4.0/ahv/config/vms. Leave empty to request the full VM object.
New-Variable -Name 'NUTANIX_VM_CONFIG_SELECT' -Value (@(
    'extId',
    'name',
    'host',
    'cluster',
    'powerState',
    'numSockets',
    'numCoresPerSocket',
    'numThreadsPerCore',
    'memorySizeBytes',
    'guestTools',
    'storageConfig'
) -join ',') -Option ReadOnly -Scope Script -Force

# vmm/v4.0/ahv/stats/vms down-sampling operator; the list endpoint requires one.
New-Variable -Name 'NUTANIX_VM_STATS_TYPE' -Value 'AVG' -Option ReadOnly -Scope Script -Force

# vmm/v4.0/ahv/stats/vms. Tuples live under 'stats', so these take the 'stats/' prefix and must
# include the timestamp. The endpoint rejects an empty $select.
New-Variable -Name 'NUTANIX_VM_STATS_SELECT' -Value (@(
    'extId',
    'stats/timestamp',
    'stats/hypervisorCpuReadyTimePpm',
    'stats/hypervisorSwapInRateKbps',
    'stats/hypervisorSwapOutRateKbps',
    'stats/hypervisorMemoryBalloonReclaimedBytes'
) -join ',') -Option ReadOnly -Scope Script -Force