/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.Connect;
using Amazon.Connect.Model;
namespace Amazon.PowerShell.Cmdlets.CONN
{
///
/// Gets the real-time metric data from the specified Amazon Connect instance.
///
///
///
/// For a description of each metric, see Real-time
/// Metrics Definitions in the Amazon Connect Administrator Guide.
///
In the AWS.Tools.Connect module, this cmdlet automatically pages all available results to the pipeline - parameters related to iteration are only needed if you want to manually control the paginated output. To disable autopagination, use -NoAutoIteration.
///
[Cmdlet("Get", "CONNCurrentMetricData")]
[OutputType("Amazon.Connect.Model.GetCurrentMetricDataResponse")]
[AWSCmdlet("Calls the Amazon Connect Service GetCurrentMetricData API operation.", Operation = new[] {"GetCurrentMetricData"}, SelectReturnType = typeof(Amazon.Connect.Model.GetCurrentMetricDataResponse))]
[AWSCmdletOutput("Amazon.Connect.Model.GetCurrentMetricDataResponse",
"This cmdlet returns an Amazon.Connect.Model.GetCurrentMetricDataResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class GetCONNCurrentMetricDataCmdlet : AmazonConnectClientCmdlet, IExecutor
{
#region Parameter Filters_Channel
///
///
/// The channel to use to filter the metrics.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Filters_Channels")]
public System.String[] Filters_Channel { get; set; }
#endregion
#region Parameter CurrentMetric
///
///
/// The metrics to retrieve. Specify the name and unit for each metric. The following
/// metrics are available. For a description of all the metrics, see Real-time
/// Metrics Definitions in the Amazon Connect Administrator Guide.- AGENTS_AFTER_CONTACT_WORK
- Unit: COUNTName in real-time metrics report: ACW
- AGENTS_AVAILABLE
- Unit: COUNTName in real-time metrics report: Available
- AGENTS_ERROR
- Unit: COUNTName in real-time metrics report: Error
- AGENTS_NON_PRODUCTIVE
- Unit: COUNTName in real-time metrics report: NPT
/// (Non-Productive Time)
- AGENTS_ON_CALL
- Unit: COUNTName in real-time metrics report: On
/// contact
- AGENTS_ON_CONTACT
- Unit: COUNTName in real-time metrics report: On
/// contact
- AGENTS_ONLINE
- Unit: COUNTName in real-time metrics report: Online
- AGENTS_STAFFED
- Unit: COUNTName in real-time metrics report: Staffed
- CONTACTS_IN_QUEUE
- Unit: COUNTName in real-time metrics report: In
/// queue
- CONTACTS_SCHEDULED
- Unit: COUNTName in real-time metrics report: Scheduled
- OLDEST_CONTACT_AGE
- Unit: SECONDSWhen you use groupings, Unit says SECONDS and the Value is returned in SECONDS. When you do not use groupings, Unit says SECONDS but the Value is returned in MILLISECONDS.
/// For example, if you get a response like this:
{ "Metric": { "Name": "OLDEST_CONTACT_AGE", "Unit": "SECONDS" }, "Value": 24113.0
///
}The actual OLDEST_CONTACT_AGE is 24 seconds.Name in real-time metrics report: Oldest - SLOTS_ACTIVE
- Unit: COUNTName in real-time metrics report: Active
- SLOTS_AVAILABLE
- Unit: COUNTName in real-time metrics report: Availability
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyCollection]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
[Alias("CurrentMetrics")]
public Amazon.Connect.Model.CurrentMetric[] CurrentMetric { get; set; }
#endregion
#region Parameter Grouping
///
///
/// The grouping applied to the metrics returned. For example, when grouped by QUEUE
,
/// the metrics returned apply to each queue rather than aggregated for all queues. - If you group by
CHANNEL
, you should include a Channels filter. VOICE,
/// CHAT, and TASK channels are supported. - If you group by
ROUTING_PROFILE
, you must include either a queue or routing
/// profile filter. In addition, a routing profile filter is required for metrics CONTACTS_SCHEDULED
,
/// CONTACTS_IN_QUEUE
, and OLDEST_CONTACT_AGE
. - If no
Grouping
is included in the request, a summary of metrics is returned.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Groupings")]
public System.String[] Grouping { get; set; }
#endregion
#region Parameter InstanceId
///
///
/// The identifier of the Amazon Connect instance. You can find
/// the instance ID in the Amazon Resource Name (ARN) of the instance.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String InstanceId { get; set; }
#endregion
#region Parameter Filters_Queue
///
///
/// The queues to use to filter the metrics. You should specify at least one queue, and
/// can specify up to 100 queues per request. The GetCurrentMetricsData
API
/// in particular requires a queue when you include a Filter
in your request.
///
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Filters_Queues")]
public System.String[] Filters_Queue { get; set; }
#endregion
#region Parameter Filters_RoutingProfile
///
///
/// A list of up to 100 routing profile IDs or ARNs.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Filters_RoutingProfiles")]
public System.String[] Filters_RoutingProfile { get; set; }
#endregion
#region Parameter SortCriterion
///
///
/// The way to sort the resulting response based on metrics. You can enter one sort criteria.
/// By default resources are sorted based on AGENTS_ONLINE
, DESCENDING
.
/// The metric collection is sorted based on the input metrics.Note the following:- Sorting on
SLOTS_ACTIVE
and SLOTS_AVAILABLE
is not supported.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("SortCriteria")]
public Amazon.Connect.Model.CurrentMetricSortCriteria[] SortCriterion { get; set; }
#endregion
#region Parameter MaxResult
///
///
/// The maximum number of results to return per page.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("MaxResults")]
public System.Int32? MaxResult { get; set; }
#endregion
#region Parameter NextToken
///
///
/// The token for the next set of results. Use the value returned in the previous response
/// in the next request to retrieve the next set of results.The token expires after 5 minutes from the time it is created. Subsequent requests
/// that use the token must use the same request parameters as the request that generated
/// the token.
///
///
///
Note: In the AWS.Tools.Connect module, this parameter is only used if you are manually controlling output pagination of the service API call.
///
In order to manually control output pagination, use '-NextToken $null' for the first call and '-NextToken $AWSHistory.LastServiceResponse.NextToken' for subsequent calls.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String NextToken { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is '*'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Connect.Model.GetCurrentMetricDataResponse).
/// Specifying the name of a property of type Amazon.Connect.Model.GetCurrentMetricDataResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "*";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the InstanceId parameter.
/// The -PassThru parameter is deprecated, use -Select '^InstanceId' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^InstanceId' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter NoAutoIteration
#if MODULAR
///
/// By default the cmdlet will auto-iterate and retrieve all results to the pipeline by performing multiple
/// service calls. If set, the cmdlet will retrieve only the next 'page' of results using the value of NextToken
/// as the start point.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter NoAutoIteration { get; set; }
#endif
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.InstanceId;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (this.CurrentMetric != null)
{
context.CurrentMetric = new List(this.CurrentMetric);
}
#if MODULAR
if (this.CurrentMetric == null && ParameterWasBound(nameof(this.CurrentMetric)))
{
WriteWarning("You are passing $null as a value for parameter CurrentMetric which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
if (this.Filters_Channel != null)
{
context.Filters_Channel = new List(this.Filters_Channel);
}
if (this.Filters_Queue != null)
{
context.Filters_Queue = new List(this.Filters_Queue);
}
if (this.Filters_RoutingProfile != null)
{
context.Filters_RoutingProfile = new List(this.Filters_RoutingProfile);
}
if (this.Grouping != null)
{
context.Grouping = new List(this.Grouping);
}
context.InstanceId = this.InstanceId;
#if MODULAR
if (this.InstanceId == null && ParameterWasBound(nameof(this.InstanceId)))
{
WriteWarning("You are passing $null as a value for parameter InstanceId which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.MaxResult = this.MaxResult;
context.NextToken = this.NextToken;
if (this.SortCriterion != null)
{
context.SortCriterion = new List(this.SortCriterion);
}
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
#if MODULAR
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
var useParameterSelect = this.Select.StartsWith("^") || this.PassThru.IsPresent;
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
// create request and set iteration invariants
var request = new Amazon.Connect.Model.GetCurrentMetricDataRequest();
if (cmdletContext.CurrentMetric != null)
{
request.CurrentMetrics = cmdletContext.CurrentMetric;
}
// populate Filters
var requestFiltersIsNull = true;
request.Filters = new Amazon.Connect.Model.Filters();
List requestFilters_filters_Channel = null;
if (cmdletContext.Filters_Channel != null)
{
requestFilters_filters_Channel = cmdletContext.Filters_Channel;
}
if (requestFilters_filters_Channel != null)
{
request.Filters.Channels = requestFilters_filters_Channel;
requestFiltersIsNull = false;
}
List requestFilters_filters_Queue = null;
if (cmdletContext.Filters_Queue != null)
{
requestFilters_filters_Queue = cmdletContext.Filters_Queue;
}
if (requestFilters_filters_Queue != null)
{
request.Filters.Queues = requestFilters_filters_Queue;
requestFiltersIsNull = false;
}
List requestFilters_filters_RoutingProfile = null;
if (cmdletContext.Filters_RoutingProfile != null)
{
requestFilters_filters_RoutingProfile = cmdletContext.Filters_RoutingProfile;
}
if (requestFilters_filters_RoutingProfile != null)
{
request.Filters.RoutingProfiles = requestFilters_filters_RoutingProfile;
requestFiltersIsNull = false;
}
// determine if request.Filters should be set to null
if (requestFiltersIsNull)
{
request.Filters = null;
}
if (cmdletContext.Grouping != null)
{
request.Groupings = cmdletContext.Grouping;
}
if (cmdletContext.InstanceId != null)
{
request.InstanceId = cmdletContext.InstanceId;
}
if (cmdletContext.MaxResult != null)
{
request.MaxResults = cmdletContext.MaxResult.Value;
}
if (cmdletContext.SortCriterion != null)
{
request.SortCriteria = cmdletContext.SortCriterion;
}
// Initialize loop variant and commence piping
var _nextToken = cmdletContext.NextToken;
var _userControllingPaging = this.NoAutoIteration.IsPresent || ParameterWasBound(nameof(this.NextToken));
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
do
{
request.NextToken = _nextToken;
CmdletOutput output;
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
if (!useParameterSelect)
{
pipelineOutput = cmdletContext.Select(response, this);
}
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
_nextToken = response.NextToken;
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
ProcessOutput(output);
} while (!_userControllingPaging && AutoIterationHelpers.HasValue(_nextToken));
if (useParameterSelect)
{
WriteObject(cmdletContext.Select(null, this));
}
return null;
}
#else
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.Connect.Model.GetCurrentMetricDataRequest();
if (cmdletContext.CurrentMetric != null)
{
request.CurrentMetrics = cmdletContext.CurrentMetric;
}
// populate Filters
var requestFiltersIsNull = true;
request.Filters = new Amazon.Connect.Model.Filters();
List requestFilters_filters_Channel = null;
if (cmdletContext.Filters_Channel != null)
{
requestFilters_filters_Channel = cmdletContext.Filters_Channel;
}
if (requestFilters_filters_Channel != null)
{
request.Filters.Channels = requestFilters_filters_Channel;
requestFiltersIsNull = false;
}
List requestFilters_filters_Queue = null;
if (cmdletContext.Filters_Queue != null)
{
requestFilters_filters_Queue = cmdletContext.Filters_Queue;
}
if (requestFilters_filters_Queue != null)
{
request.Filters.Queues = requestFilters_filters_Queue;
requestFiltersIsNull = false;
}
List requestFilters_filters_RoutingProfile = null;
if (cmdletContext.Filters_RoutingProfile != null)
{
requestFilters_filters_RoutingProfile = cmdletContext.Filters_RoutingProfile;
}
if (requestFilters_filters_RoutingProfile != null)
{
request.Filters.RoutingProfiles = requestFilters_filters_RoutingProfile;
requestFiltersIsNull = false;
}
// determine if request.Filters should be set to null
if (requestFiltersIsNull)
{
request.Filters = null;
}
if (cmdletContext.Grouping != null)
{
request.Groupings = cmdletContext.Grouping;
}
if (cmdletContext.InstanceId != null)
{
request.InstanceId = cmdletContext.InstanceId;
}
if (cmdletContext.MaxResult != null)
{
request.MaxResults = cmdletContext.MaxResult.Value;
}
if (cmdletContext.NextToken != null)
{
request.NextToken = cmdletContext.NextToken;
}
if (cmdletContext.SortCriterion != null)
{
request.SortCriteria = cmdletContext.SortCriterion;
}
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
#endif
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.Connect.Model.GetCurrentMetricDataResponse CallAWSServiceOperation(IAmazonConnect client, Amazon.Connect.Model.GetCurrentMetricDataRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Connect Service", "GetCurrentMetricData");
try
{
#if DESKTOP
return client.GetCurrentMetricData(request);
#elif CORECLR
return client.GetCurrentMetricDataAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public List CurrentMetric { get; set; }
public List Filters_Channel { get; set; }
public List Filters_Queue { get; set; }
public List Filters_RoutingProfile { get; set; }
public List Grouping { get; set; }
public System.String InstanceId { get; set; }
public System.Int32? MaxResult { get; set; }
public System.String NextToken { get; set; }
public List SortCriterion { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}