// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.monitor.generated;

import com.azure.core.util.Context;
import com.azure.resourcemanager.monitor.fluent.models.DataCollectionRuleResourceInner;
import com.azure.resourcemanager.monitor.models.DataCollectionRuleDataSources;
import com.azure.resourcemanager.monitor.models.DataCollectionRuleDestinations;
import com.azure.resourcemanager.monitor.models.DataFlow;
import com.azure.resourcemanager.monitor.models.KnownDataFlowStreams;
import com.azure.resourcemanager.monitor.models.KnownPerfCounterDataSourceStreams;
import com.azure.resourcemanager.monitor.models.KnownSyslogDataSourceFacilityNames;
import com.azure.resourcemanager.monitor.models.KnownSyslogDataSourceLogLevels;
import com.azure.resourcemanager.monitor.models.KnownSyslogDataSourceStreams;
import com.azure.resourcemanager.monitor.models.KnownWindowsEventLogDataSourceStreams;
import com.azure.resourcemanager.monitor.models.LogAnalyticsDestination;
import com.azure.resourcemanager.monitor.models.PerfCounterDataSource;
import com.azure.resourcemanager.monitor.models.SyslogDataSource;
import com.azure.resourcemanager.monitor.models.WindowsEventLogDataSource;
import java.util.Arrays;

/** Samples for DataCollectionRules Create. */
public final class DataCollectionRulesCreateSamples {
    /*
     * x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2021-09-01-preview/examples/DataCollectionRulesCreate.json
     */
    /**
     * Sample code: Create or update data collection rule.
     *
     * @param azure The entry point for accessing resource management APIs in Azure.
     */
    public static void createOrUpdateDataCollectionRule(com.azure.resourcemanager.AzureResourceManager azure) {
        azure
            .diagnosticSettings()
            .manager()
            .serviceClient()
            .getDataCollectionRules()
            .createWithResponse(
                "myResourceGroup",
                "myCollectionRule",
                new DataCollectionRuleResourceInner()
                    .withLocation("eastus")
                    .withDataSources(
                        new DataCollectionRuleDataSources()
                            .withPerformanceCounters(
                                Arrays
                                    .asList(
                                        new PerfCounterDataSource()
                                            .withStreams(
                                                Arrays.asList(KnownPerfCounterDataSourceStreams.MICROSOFT_PERF))
                                            .withSamplingFrequencyInSeconds(15)
                                            .withCounterSpecifiers(
                                                Arrays
                                                    .asList(
                                                        "\\Processor(_Total)\\% Processor Time",
                                                        "\\Memory\\Committed Bytes",
                                                        "\\LogicalDisk(_Total)\\Free Megabytes",
                                                        "\\PhysicalDisk(_Total)\\Avg. Disk Queue Length"))
                                            .withName("cloudTeamCoreCounters"),
                                        new PerfCounterDataSource()
                                            .withStreams(
                                                Arrays.asList(KnownPerfCounterDataSourceStreams.MICROSOFT_PERF))
                                            .withSamplingFrequencyInSeconds(30)
                                            .withCounterSpecifiers(Arrays.asList("\\Process(_Total)\\Thread Count"))
                                            .withName("appTeamExtraCounters")))
                            .withWindowsEventLogs(
                                Arrays
                                    .asList(
                                        new WindowsEventLogDataSource()
                                            .withStreams(
                                                Arrays
                                                    .asList(
                                                        KnownWindowsEventLogDataSourceStreams.MICROSOFT_WINDOWS_EVENT))
                                            .withXPathQueries(Arrays.asList("Security!"))
                                            .withName("cloudSecurityTeamEvents"),
                                        new WindowsEventLogDataSource()
                                            .withStreams(
                                                Arrays
                                                    .asList(
                                                        KnownWindowsEventLogDataSourceStreams.MICROSOFT_WINDOWS_EVENT))
                                            .withXPathQueries(
                                                Arrays
                                                    .asList(
                                                        "System![System[(Level = 1 or Level = 2 or Level = 3)]]",
                                                        "Application!*[System[(Level = 1 or Level = 2 or Level = 3)]]"))
                                            .withName("appTeam1AppEvents")))
                            .withSyslog(
                                Arrays
                                    .asList(
                                        new SyslogDataSource()
                                            .withStreams(Arrays.asList(KnownSyslogDataSourceStreams.MICROSOFT_SYSLOG))
                                            .withFacilityNames(Arrays.asList(KnownSyslogDataSourceFacilityNames.CRON))
                                            .withLogLevels(
                                                Arrays
                                                    .asList(
                                                        KnownSyslogDataSourceLogLevels.DEBUG,
                                                        KnownSyslogDataSourceLogLevels.CRITICAL,
                                                        KnownSyslogDataSourceLogLevels.EMERGENCY))
                                            .withName("cronSyslog"),
                                        new SyslogDataSource()
                                            .withStreams(Arrays.asList(KnownSyslogDataSourceStreams.MICROSOFT_SYSLOG))
                                            .withFacilityNames(Arrays.asList(KnownSyslogDataSourceFacilityNames.SYSLOG))
                                            .withLogLevels(
                                                Arrays
                                                    .asList(
                                                        KnownSyslogDataSourceLogLevels.ALERT,
                                                        KnownSyslogDataSourceLogLevels.CRITICAL,
                                                        KnownSyslogDataSourceLogLevels.EMERGENCY))
                                            .withName("syslogBase"))))
                    .withDestinations(
                        new DataCollectionRuleDestinations()
                            .withLogAnalytics(
                                Arrays
                                    .asList(
                                        new LogAnalyticsDestination()
                                            .withWorkspaceResourceId(
                                                "/subscriptions/703362b3-f278-4e4b-9179-c76eaf41ffc2/resourceGroups/myResourceGroup/providers/Microsoft.OperationalInsights/workspaces/centralTeamWorkspace")
                                            .withName("centralWorkspace"))))
                    .withDataFlows(
                        Arrays
                            .asList(
                                new DataFlow()
                                    .withStreams(
                                        Arrays
                                            .asList(
                                                KnownDataFlowStreams.MICROSOFT_PERF,
                                                KnownDataFlowStreams.MICROSOFT_SYSLOG,
                                                KnownDataFlowStreams.MICROSOFT_WINDOWS_EVENT))
                                    .withDestinations(Arrays.asList("centralWorkspace")))),
                Context.NONE);
    }
}
