예제 #1
0
        protected override void ProcessRecordInternal()
        {
            string id = AlertId;

            switch (ParameterSetName)
            {
            case ByIdParameterSet:
                id = CommonUtils.GetIdFromARMResourceId(AlertId);
                break;

            case ByInputObjectParameterSet:
                id = CommonUtils.GetIdFromARMResourceId(InputObject.Id);
                break;
            }

            var test = this.AlertsManagementClient.Alerts.GetHistoryWithHttpMessagesAsync(id).Result.Body;
            PSAlertModification history = new PSAlertModification(test);

            WriteObject(sendToPipeline: history.Items, enumerateCollection: true);
        }
예제 #2
0
        protected override void ProcessRecordInternal()
        {
            if (ShouldProcess(
                    target: string.Format(Resources.Target, string.IsNullOrWhiteSpace(AlertId) ? InputObject.Id : AlertId),
                    action: Resources.UpdateAlertState_Action))
            {
                string id = AlertId;
                switch (ParameterSetName)
                {
                case ByIdParameterSet:
                    id = CommonUtils.GetIdFromARMResourceId(AlertId);
                    break;

                case ByInputObjectParameterSet:
                    id = CommonUtils.GetIdFromARMResourceId(InputObject.Id);
                    break;
                }

                PSAlert alert = new PSAlert(this.AlertsManagementClient.Alerts.ChangeStateWithHttpMessagesAsync(id, State).Result.Body);
                WriteObject(sendToPipeline: alert);
            }
        }
예제 #3
0
        protected override void ProcessRecordInternal()
        {
            switch (ParameterSetName)
            {
            case AlertsListByFilterParameterSet:
            case AlertsListByTargetResourceIdFilterParameterSet:
                List <Alert>  resultList = new List <Alert>();
                IPage <Alert> pageResult = new Page <Alert>();
                pageResult = this.AlertsManagementClient.Alerts.GetAllWithHttpMessagesAsync(
                    targetResource: TargetResourceId,
                    targetResourceType: TargetResourceType,
                    targetResourceGroup: TargetResourceGroup,
                    monitorService: MonitorService,
                    monitorCondition: MonitorCondition,
                    severity: Severity,
                    alertState: State,
                    alertRule: AlertRuleId,
                    smartGroupId: SmartGroupId,
                    includeContext: IncludeContext,
                    includeEgressConfig: IncludeEgressConfig,
                    pageCount: PageCount,
                    sortBy: SortBy,
                    sortOrder: SortOrder,
                    timeRange: TimeRange,
                    customTimeRange: CustomTimeRange,
                    select: Select
                    ).Result.Body;

                // Deal with paging in response
                ulong first = MyInvocation.BoundParameters.ContainsKey("First") ? this.PagingParameters.First : ulong.MaxValue;
                ulong skip  = MyInvocation.BoundParameters.ContainsKey("Skip") ? this.PagingParameters.Skip : 0;

                // Any items before this count should be return
                ulong lastCount    = MyInvocation.BoundParameters.ContainsKey("First") ? skip + first : ulong.MaxValue;
                ulong currentCount = 0;
                var   nextPageLink = pageResult.NextPageLink;

                do
                {
                    List <Alert> tempList = pageResult.ToList();
                    if (currentCount + (ulong)tempList.Count - 1 < skip)
                    {
                        // skip the whole chunk if they are all in skip
                        currentCount += (ulong)tempList.Count;
                    }
                    else
                    {
                        foreach (Alert currentAlert in tempList)
                        {
                            // not return "skip" count of items in the begin, and only return "first" count of items after that.
                            if (currentCount >= skip && currentCount < lastCount)
                            {
                                resultList.Add(currentAlert);
                            }
                            currentCount++;
                            if (currentCount >= lastCount)
                            {
                                break;
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(nextPageLink))
                    {
                        pageResult   = this.AlertsManagementClient.Alerts.GetAllNextWithHttpMessagesAsync(nextPageLink).Result.Body;
                        nextPageLink = pageResult.NextPageLink;
                    }
                } while (!string.IsNullOrEmpty(nextPageLink) && currentCount < lastCount);

                WriteObject(resultList.Select((r) => new PSAlert(r)), enumerateCollection: true);
                break;

            case AlertByIdParameterSet:
                string  id    = CommonUtils.GetIdFromARMResourceId(AlertId);
                PSAlert alert = new PSAlert(this.AlertsManagementClient.Alerts.GetByIdWithHttpMessagesAsync(id).Result.Body);
                WriteObject(sendToPipeline: alert);
                break;
            }
        }
예제 #4
0
        protected override void ProcessRecordInternal()
        {
            switch (ParameterSetName)
            {
            case SmartGroupsListByFilterParameterSet:
                IPage <SmartGroup> pageResult = new Page <SmartGroup>();
                List <SmartGroup>  resultList = new List <SmartGroup>();
                pageResult = this.AlertsManagementClient.SmartGroups.GetAllWithHttpMessagesAsync(
                    sortBy: SortBy,
                    sortOrder: SortOrder,
                    timeRange: TimeRange
                    ).Result.Body;

                // Deal with paging in response
                ulong first = MyInvocation.BoundParameters.ContainsKey("First") ? this.PagingParameters.First : ulong.MaxValue;
                ulong skip  = MyInvocation.BoundParameters.ContainsKey("Skip") ? this.PagingParameters.Skip : 0;

                // Any items before this count should be return
                ulong lastCount    = MyInvocation.BoundParameters.ContainsKey("First") ? skip + first : ulong.MaxValue;
                ulong currentCount = 0;
                var   nextPageLink = pageResult.NextPageLink;

                do
                {
                    List <SmartGroup> tempList = pageResult.ToList();
                    if (currentCount + (ulong)tempList.Count - 1 < skip)
                    {
                        // skip the whole chunk if they are all in skip
                        currentCount += (ulong)tempList.Count;
                    }
                    else
                    {
                        foreach (SmartGroup currentSmartGroup in tempList)
                        {
                            // not return "skip" count of items in the begin, and only return "first" count of items after that.
                            if (currentCount >= skip && currentCount < lastCount)
                            {
                                resultList.Add(currentSmartGroup);
                            }
                            currentCount++;
                            if (currentCount >= lastCount)
                            {
                                break;
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(nextPageLink))
                    {
                        pageResult   = this.AlertsManagementClient.SmartGroups.GetAllNextWithHttpMessagesAsync(nextPageLink).Result.Body;
                        nextPageLink = pageResult.NextPageLink;
                    }
                } while (!string.IsNullOrEmpty(nextPageLink) && currentCount < lastCount);

                WriteObject(resultList.Select((r) => new PSSmartGroup(r)), enumerateCollection: true);
                break;

            case SmartGroupByIdParameterSet:
                string       id         = CommonUtils.GetIdFromARMResourceId(SmartGroupId);
                PSSmartGroup smartGroup = new PSSmartGroup(this.AlertsManagementClient.SmartGroups.GetByIdWithHttpMessagesAsync(id).Result.Body);
                WriteObject(sendToPipeline: smartGroup);
                break;
            }
        }