<# .SYNOPSIS Report and set the engine start timeout parameter for Login Enterprise tests .DESCRIPTION This script will generate a list of available tests from a Login Enterprise server, and provide a way to read and write the engineStartTimeout test paramater. You need to provide the server name and a Configuration-level API key. .PARAMETER server Specifies the LE Server FQDN .PARAMETER key Specifies a Secret API Key from the Login Enterprise appliance with Configuration permissions .PARAMETER action Specifies what action to perform: list (list available tests), get (report on a single test) and set (update a single test). .PARAMETER testguid Specifies a Test ID GUID to perform the get/set operation on. .PARAMETER value The value to set engineStartTime to. Set to 0 to return to the system default. .PARAMETER quiet If set, only output the test UUIDs during the "list" function. Otherwise will also output the test name and the current setting. .INPUTS None. You can't pipe objects into this script. .OUTPUTS Text list or output .EXAMPLE PS> .\engine-start-timeout.ps1 -server FQDN -key KEY -action list List all available tests. .EXAMPLE PS> .\engine-start-timeout.ps1 -server FQDN -key KEY -action get -testguid XXX Get the currently configured timeout for a specific test. .EXAMPLE PS> .\engine-start-timeout.ps1 -server FQDN -key KEY -action set -testguid XXX -value 300 Set the timeout on the specific test to 300 seconds. #> [CmdletBinding()] param( [Parameter(mandatory=$true)] [string]$server, [Parameter(mandatory=$true)] [string]$key, [Parameter(mandatory=$true)] [ValidateSet('list', 'set', 'get')] [string]$action, [string]$testguid = "", [string]$value = "", [switch]$quiet = $false ) if (($action -eq "get" -or $action -eq "set") -and $testguid -eq "") { write-output "You must specify a test GUID and a property ID to get/set a value." return } if ($action -eq "set" -and $value -eq "") { write-output "You must specify a value." return } # Function: get-APIVersion # Parameters: none # Tests determine what API version is available (using a dummy "tests" query) # Returns the appropriate string function get-APIVersion{ $Parameters = @{ Uri = 'https://' + $server + "/publicApi/v1/tests/" Method = "GET" ContentType = 'application/json' } try { $ignore = Invoke-WebRequest @Parameters "v1" } catch { $_.Exception.response.headers["api-supported-versions"].split(",")[-1].trim() } } # Function: get-RestResults # Parameters: API portion of the URL # Request BODY hashtable # Returns results ofsingle REST API call. function get-RestResults{ param( $API, $Body = "", $Encoding = "application/json", $method = "GET" ) # Define authorization header $Header = @{ "Accept" = "application/json" "Authorization" = "Bearer $key" } #Parameters of the API command $Parameters = @{ Uri = 'https://' + $server + $API Headers = $Header Method = $method ContentType = 'application/json' } if ($Body) { $Parameters.body = $Body } Invoke-RestMethod @Parameters } function get-LETests{ # Define Tests query parameters $Body = @{ "orderBy" = "Name" "direction" = "asc" "count" = "1000" } get-RestResults "/publicApi/$($apiVersion)/tests/" $Body } # WARNING: ignoring SSL/TLS certificate errors is a security risk $code = @" public class SSLHandler {public static System.Net.Security.RemoteCertificateValidationCallback GetSSLHandler() {return new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });} } "@ Add-Type -TypeDefinition $code # WARNING: ignoring SSL/TLS certificate errors is a security risk [System.Net.ServicePointManager]::ServerCertificateValidationCallback = [SSLHandler]::GetSSLHandler() # this is only required for older version of PowerShell/.NET [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 $apiVersion = get-APIVersion if ($action -eq "list") { $myTests = get-LETests for ($i = 0; $i -lt $myTests.items.Length; $i++) { if (-not $quiet) { if ($myTests.items[$i].PSObject.Properties.name -contains "Timeouts") { write-output "$($myTests.items[$i].Name): $($myTests.items[$i].Id) ($($myTests.items[$i].Timeouts.connectionAttempted))" } else { write-output "$($myTests.items[$i].Name): $($myTests.items[$i].Id) ($($myTests.items[$i].engineStartTimeout))" } } else { write-output "$($myTests.items[$i].Id)" } } } if ($action -eq "set") { $myTest = get-RestResults "/publicApi/$($apiVersion)/tests/$($testguid)" if ($myTest.PSObject.Properties.name -contains "Timeouts") { write-output "$($myTest.Name): $($myTest.Id) ($($myTest.Timeouts.connectionAttempted))" } else { write-output "$($myTest.Name): $($myTest.Id) ($($myTest.engineStartTimeout))" } if ($myTest.PSObject.Properties.name -contains "sessionMetricDefinitionGroupId") { $myTest | add-member -membertype NoteProperty -name "sessionMetricGroupId" -value $myTest.sessionMetricDefinitionGroupId } if ((-not $myTest.intervalInMinutes) -and $myTest.scheduleIntervalInMinutes -ne "") { $myTest | add-member -membertype NoteProperty -name "intervalInMinutes" -value $myTest.scheduleIntervalInMinutes } if ($myTest.PSObject.Properties.name -contains "Timeouts") { if ($myTest.Timeouts -ne $null) { if ($myTest.Timeouts.PSObject.Properties.name -contains "ConnectionAttempted") { $myTest.Timeouts.ConnectionAttempted = $value } else { $myTest.Timeouts | add-member -membertype NoteProperty -name "ConnectionAttempted" -value "$($value)" } } else { $myTest.Timeouts = @{ "ConnectionAttempted" = "$($value)" } } } else { $myTest.engineStartTimeout = "$($value)" } get-RestResults "/publicApi/$($apiVersion)/tests/$($testguid)" ($myTest | convertto-json) -method PUT } if ($action -eq "get" -or $action -eq "set") { $myTest = get-RestResults "/publicApi/$($apiVersion)/tests/$($testguid)" if ($myTest.PSObject.Properties.name -contains "Timeouts") { write-output "$($myTest.Name): $($myTest.Id) ($($myTest.Timeouts.connectionAttempted))" } else { write-output "$($myTest.Name): $($myTest.Id) ($($myTest.engineStartTimeout))" } }