protected override void ProcessRecordInternal()
        {
            ServiceDiagnosticSettingsGetResponse result = this.InsightsManagementClient.ServiceDiagnosticSettingsOperations.GetAsync(this.ResourceId, CancellationToken.None).Result;

            PSServiceDiagnosticSettings psResult = new PSServiceDiagnosticSettings(result.Properties);

            WriteObject(psResult);
        }
Ejemplo n.º 2
0
        protected override void ProcessRecordInternal()
        {
            ServiceDiagnosticSettingsResource result = this.InsightsManagementClient.ServiceDiagnosticSettings.GetAsync(resourceUri: this.ResourceId, cancellationToken: CancellationToken.None).Result;

            PSServiceDiagnosticSettings psResult = new PSServiceDiagnosticSettings(result);

            WriteObject(psResult);
        }
Ejemplo n.º 3
0
        protected override void ProcessRecordInternal()
        {
            // Temporary service name constant provided for backwards compatibility
            DiagnosticSettingsResource result = this.MonitorManagementClient.DiagnosticSettings.Get(
                resourceUri: this.ResourceId,
                name: string.IsNullOrWhiteSpace(this.Name) ? SetAzureRmDiagnosticSettingCommand.TempServiceName : this.Name);

            var psResult = new PSServiceDiagnosticSettings(result);

            WriteObject(psResult);
        }
Ejemplo n.º 4
0
        protected override void ProcessRecordInternal()
        {
            Validate();

            IList <MetricSettings> metrics = null;
            IList <LogSettings>    logs    = null;

            if (this.IsParameterBound(c => c.Setting) && Setting.Length != 0)
            {
                foreach (PSDiagnosticDetailSettings setting in Setting)
                {
                    switch (setting.CategoryType)
                    {
                    case PSDiagnosticSettingCategoryType.Metrics:
                        if (metrics == null)
                        {
                            metrics = new List <MetricSettings>();
                        }
                        metrics.Add(((PSMetricSettings)setting).GetMetricSetting());
                        break;

                    case PSDiagnosticSettingCategoryType.Logs:
                        if (logs == null)
                        {
                            logs = new List <LogSettings>();
                        }
                        logs.Add(((PSLogSettings)setting).GetLogSetting());
                        break;

                    default:
                        throw new ArgumentException("Invalid diagnostic setting type");
                    }
                }
            }

            PSServiceDiagnosticSettings DiagnosticSetting = new PSServiceDiagnosticSettings(id: GetTargetUri() + "/providers/Microsoft.Insights/diagnosticSettings/" + this.Name, name: this.Name)
            {
                StorageAccountId            = this.IsParameterBound(c => c.StorageAccountId) ? this.StorageAccountId : null,
                ServiceBusRuleId            = this.IsParameterBound(c => c.ServiceBusRuleId) ? this.ServiceBusRuleId : null,
                EventHubName                = this.IsParameterBound(c => c.EventHubName) ? this.EventHubName : null,
                EventHubAuthorizationRuleId = this.IsParameterBound(c => c.EventHubAuthorizationRuleId) ? this.EventHubAuthorizationRuleId : null,
                WorkspaceId = this.IsParameterBound(c => c.WorkspaceId) ? this.WorkspaceId : null,
                LogAnalyticsDestinationType = this.IsParameterBound(c => c.DedicatedLogAnalyticsDestinationType) ? "Dedicated" : null,
                Metrics = metrics,
                Logs    = logs
            };

            WriteObject(DiagnosticSetting);
        }
        protected override void ProcessRecordInternal()
        {
            var putParameters = new ServiceDiagnosticSettingsPutParameters();

            ServiceDiagnosticSettingsGetResponse getResponse = this.InsightsManagementClient.ServiceDiagnosticSettingsOperations.GetAsync(this.ResourceId, CancellationToken.None).Result;

            ServiceDiagnosticSettings properties = getResponse.Properties;

            if (this.Enabled && string.IsNullOrWhiteSpace(this.StorageAccountId))
            {
                throw new ArgumentException("StorageAccountId can't be null when enabling");
            }

            if (!string.IsNullOrWhiteSpace(this.StorageAccountId))
            {
                properties.StorageAccountId = this.StorageAccountId;
            }

            if (this.Categories == null && this.Timegrains == null)
            {
                foreach (var log in properties.Logs)
                {
                    log.Enabled = this.Enabled;
                }

                foreach (var metric in properties.Metrics)
                {
                    metric.Enabled = this.Enabled;
                }
            }
            else
            {
                if (this.Categories != null)
                {
                    foreach (string category in this.Categories)
                    {
                        LogSettings logSettings = properties.Logs.FirstOrDefault(x => string.Equals(x.Category, category, StringComparison.OrdinalIgnoreCase));

                        if (logSettings == null)
                        {
                            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Log category '{0}' is not available for '{1}'", category, this.StorageAccountId));
                        }

                        logSettings.Enabled = this.Enabled;
                    }
                }

                if (this.Timegrains != null)
                {
                    foreach (string timegrainString in this.Timegrains)
                    {
                        TimeSpan       timegrain      = XmlConvert.ToTimeSpan(timegrainString);
                        MetricSettings metricSettings = properties.Metrics.FirstOrDefault(x => TimeSpan.Equals(x.TimeGrain, timegrain));

                        if (metricSettings == null)
                        {
                            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Metric timegrain '{0}' is not available for '{1}'", timegrainString, this.StorageAccountId));
                        }
                        metricSettings.Enabled = this.Enabled;
                    }
                }
            }

            putParameters.Properties = properties;

            this.InsightsManagementClient.ServiceDiagnosticSettingsOperations.PutAsync(this.ResourceId, putParameters, CancellationToken.None).Wait();
            PSServiceDiagnosticSettings psResult = new PSServiceDiagnosticSettings(putParameters.Properties);

            WriteObject(psResult);
        }