text: # --------------------------------------------------------------------------
  # Copyright (c) Microsoft Corporation. All rights reserved.
  # Licensed under the MIT License. See License.txt in the project root for
  # license information.
  #
  # Code generated by Microsoft (R) AutoRest Code Generator.
  # Changes may cause incorrect behavior and will be lost if the code is
  # regenerated.
  # --------------------------------------------------------------------------
  
  from azure.cli.testsdk import ScenarioTest
  from azure.cli.testsdk import ResourceGroupPreparer
  
  
  def step_data_collection_rule_show(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule show '
               '--name "{myDataCollectionRule}" '
               '--resource-group "{rg}"',
               checks=checks)
  
  
  def step_data_collection_rule_list_by_resource_group(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule list '
               '--resource-group "{rg}"',
               checks=checks)
  
  
  def step_data_collection_rule_list_by_subscription(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule list ',
               checks=checks)
  
  
  def step_data_collection_rule_association_create(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule association create '
               '--name "{myAssociation}" '
               '--rule-id "{rule_id}" '
               '--resource "{vm_id}"',
               checks=checks)
  
  
  def step_data_collection_rule_association_show(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule association show '
               '--name "{myAssociation}" '
               '--resource "{vm_id}"',
               checks=checks)
  
  
  def step_data_collection_rule_association_list_by_rule(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule association list '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}"',
               checks=checks)
  
  
  def step_data_collection_rule_association_list_by_resource(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule association list '
               '--resource "{vm_id}" ',
               checks=checks)
  
  
  def step_data_collection_rule_association_delete(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule association delete -y '
               '--name "{myAssociation}" '
               '--resource "{vm_id}" ',
               checks=checks)
  
  
  def step_data_collection_rule_delete(test, _, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule delete -y '
               '--name "{myDataCollectionRule}" '
               '--resource-group "{rg}"',
               checks=checks)
  
  
  def step_data_collection_rule_create(test, rg, checks=None):
      if checks is None:
          checks = []
      rule_json = test.cmd('az monitor data-collection rule create '
                           '-g {rg} -n {myDataCollectionRule} --location "{location}" --rule-file "{ruleFile}"',
                           checks=checks).get_output_in_json()
      test.kwargs['rule_id'] = rule_json['id']
  
  
  def step_data_collection_rule_update_tags(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([
          test.check("tags.tag1", "A", case_sensitive=False),
          test.check("tags.tag2", "B", case_sensitive=False),
          test.check("tags.tag3", "C", case_sensitive=False),
      ])
      test.cmd('az monitor data-collection rule update '
               '--tags tag1="A" tag2="B" tag3="C" '
               '--name "{myDataCollectionRule}" '
               '--resource-group "{rg}"',
               checks=checks)
  
  
  def step_data_collection_rule_log_analytics_add(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule log-analytics add '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name {workspace2_name} '
               '--resource-id "{workspace2_id}"',
               checks=checks)
  
  
  def step_data_collection_rule_log_analytics_list(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule log-analytics list '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" ',
               checks=checks)
  
  
  def step_data_collection_rule_log_analytics_show(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule log-analytics show '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name {workspace2_name} ',
               checks=checks)
  
  
  def step_data_collection_rule_log_analytics_update(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule log-analytics update '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name {workspace2_name} '
               '--resource-id "{workspace3_id}"',
               checks=checks)
  
  
  def step_data_collection_rule_log_analytics_delete(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule log-analytics delete '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name {workspace2_name} ',
               checks=checks)
  
  
  def step_data_collection_rule_data_flow_list(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule data-flow list '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" ',
               checks=checks)
  
  
  def step_data_collection_rule_data_flow_add(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule data-flow add '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" --destinations {workspace2_name} --streams "Microsoft-Perf"',
               checks=checks)
  
  
  def step_data_collection_rule_performance_counter_add(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule performance-counter add '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name extraCounters '
               '--counter-specifiers "\\\\Memory\\\\Committed Bytes" "\\\\Processor(_Total)\\\\% Processor Time" '
               '--sampling-frequency 15 '
               '--streams "Microsoft-Perf"',
               checks=checks)
  
  
  def step_data_collection_rule_performance_counter_list(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule performance-counter list '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" ',
               checks=checks)
  
  
  def step_data_collection_rule_performance_counter_show(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule performance-counter show '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name extraCounters ',
               checks=checks)
  
  
  def step_data_collection_rule_performance_counter_update(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule performance-counter update '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name extraCounters '
               '--counter-specifiers "\\\\Processor(_Total)\\\\% Processor Time"',
               checks=checks)
  
  
  def step_data_collection_rule_performance_counter_delete(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule performance-counter delete '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name extraCounters ',
               checks=checks)
  
  
  def step_data_collection_rule_windows_event_log_add(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule windows-event-log add '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name extraEvents '
               '--streams "Microsoft-WindowsEvent" '
               '--x-path-queries "System![System[(Level = 1 or Level = 2 or Level = 3)]]" '
               '"Application!*[System[(Level = 1 or Level = 2 or Level = 3)]]"',
               checks=checks)
  
  
  def step_data_collection_rule_windows_event_log_list(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule windows-event-log list '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" ',
               checks=checks)
  
  
  def step_data_collection_rule_windows_event_log_show(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule windows-event-log show '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name extraEvents ',
               checks=checks)
  
  
  def step_data_collection_rule_windows_event_log_update(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule windows-event-log update '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name extraEvents '
               '--x-path-queries "Application!*[System[(Level = 1 or Level = 2 or Level = 3)]]" ',
               checks=checks)
  
  
  def step_data_collection_rule_windows_event_log_delete(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule windows-event-log delete '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name extraEvents ',
               checks=checks)
  
  
  def step_data_collection_rule_syslog_add(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule syslog add '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name "cronSyslog" '
               '--facility-names "cron" '
               '--log-levels "Debug" "Critical" "Emergency" '
               '--streams "Microsoft-Syslog" ',
               checks=checks)
  
  
  def step_data_collection_rule_syslog_list(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule syslog list '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" ',
               checks=checks)
  
  
  def step_data_collection_rule_syslog_show(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule syslog show '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name cronSyslog ',
               checks=checks)
  
  
  def step_data_collection_rule_syslog_update(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule syslog update '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name cronSyslog '
               '--log-levels "Critical" "Emergency" ',
               checks=checks)
  
  
  def step_data_collection_rule_syslog_delete(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([])
      test.cmd('az monitor data-collection rule syslog delete '
               '--rule-name "{myDataCollectionRule}" '
               '--resource-group "{rg}" '
               '--name cronSyslog ',
               checks=checks)
  
  
  def step_data_collection_rule_association_update(test, rg, checks=None):
      if checks is None:
          checks = []
      checks.extend([
          test.check("description", "{description}", case_sensitive=False),
      ])
      test.cmd('az monitor data-collection rule association update '
               '--name "{myAssociation}" '
               '--resource "{vm_id}" '
               '--description "{description}" ',
               checks=checks)
  
  
  # Env setup_scenario
  def setup_scenario(test, rg):
      test.kwargs.update({
          'rg': rg,
          'workspace_name': test.create_random_name('clitest', 20),
          'workspace2_name': test.create_random_name('clitest', 20),
          'workspace3_name': test.create_random_name('clitest', 20),
          'location': "eastus",
          'vm': "vm1",
          'description': "this is description",
      })
  
      workspace_json = test.cmd(
          "monitor log-analytics workspace create -g {rg} -n {workspace_name} --location {location} --quota 1 "
          "--level 100 --sku CapacityReservation").get_output_in_json()
      test.kwargs['workspace_id'] = workspace_json['id']
  
      workspace2_json = test.cmd(
          "monitor log-analytics workspace create -g {rg} -n {workspace2_name} --location {location} --quota 1 "
          "--level 300 --sku CapacityReservation").get_output_in_json()
      test.kwargs['workspace2_id'] = workspace2_json['id']
  
      workspace3_json = test.cmd(
          "monitor log-analytics workspace create -g {rg} -n {workspace3_name} --location {location} --quota 1 "
          "--level 200 --sku CapacityReservation").get_output_in_json()
      test.kwargs['workspace3_id'] = workspace3_json['id']
  
      vm_json = test.cmd('vm create -g {rg} -n {vm} --image UbuntuLTS --admin-password TestPassword11!! '
                         '--admin-username testadmin --authentication-type password').get_output_in_json()
      test.kwargs['vm_id'] = vm_json['id']
  
  
  # Testcase: Scenario
  def call_scenario(test, rg):
      setup_scenario(test, rg)
  
      step_data_collection_rule_create(test, rg, checks=[
          test.check("location", "{location}", case_sensitive=False),
          test.check("name", "{myDataCollectionRule}", case_sensitive=False),
      ])
      step_data_collection_rule_show(test, rg, checks=[
          test.check("location", "{location}", case_sensitive=False),
          test.check("name", "{myDataCollectionRule}", case_sensitive=False),
      ])
      step_data_collection_rule_list_by_resource_group(test, rg, checks=[
          test.check('length(@)', 1),
      ])
      step_data_collection_rule_list_by_subscription(test, rg, checks=[])
      step_data_collection_rule_update_tags(test, rg, checks=[
          test.check("location", "{location}", case_sensitive=False),
          test.check("name", "{myDataCollectionRule}", case_sensitive=False),
      ])
  
      step_data_collection_rule_log_analytics_add(test, rg, checks=[])
      step_data_collection_rule_log_analytics_list(test, rg, checks=[
          test.check('length(@)', 1),
      ])
      step_data_collection_rule_log_analytics_show(test, rg, checks=[])
      step_data_collection_rule_log_analytics_update(test, rg, checks=[])
      step_data_collection_rule_log_analytics_delete(test, rg, checks=[])
  
      step_data_collection_rule_performance_counter_add(test, rg, checks=[])
      step_data_collection_rule_performance_counter_list(test, rg, checks=[
          test.check('length(@)', 2),
      ])
      step_data_collection_rule_performance_counter_show(test, rg, checks=[])
      step_data_collection_rule_performance_counter_update(test, rg, checks=[])
      step_data_collection_rule_performance_counter_delete(test, rg, checks=[])
  
      step_data_collection_rule_windows_event_log_add(test, rg, checks=[])
      step_data_collection_rule_windows_event_log_list(test, rg, checks=[
          test.check('length(@)', 1),
      ])
      step_data_collection_rule_windows_event_log_show(test, rg, checks=[])
      step_data_collection_rule_windows_event_log_update(test, rg, checks=[])
      step_data_collection_rule_windows_event_log_delete(test, rg, checks=[])
  
      step_data_collection_rule_syslog_add(test, rg, checks=[])
      step_data_collection_rule_syslog_list(test, rg, checks=[
          test.check('length(@)', 1),
      ])
      step_data_collection_rule_syslog_show(test, rg, checks=[])
      step_data_collection_rule_syslog_update(test, rg, checks=[])
      step_data_collection_rule_syslog_delete(test, rg, checks=[])
  
      step_data_collection_rule_log_analytics_add(test, rg, checks=[])
      step_data_collection_rule_data_flow_add(test, rg, checks=[])
      step_data_collection_rule_data_flow_list(test, rg, checks=[
          test.check('length(@)', 2),
      ])
  
      step_data_collection_rule_association_create(test, rg, checks=[])
      step_data_collection_rule_association_show(test, rg, checks=[])
      step_data_collection_rule_association_list_by_rule(test, rg, checks=[])
      step_data_collection_rule_association_list_by_resource(test, rg, checks=[])
      step_data_collection_rule_association_update(test, rg, checks=[])
      step_data_collection_rule_association_delete(test, rg, checks=[])
  
      step_data_collection_rule_delete(test, rg, checks=[])
  
  
  # EXAMPLE: /DataCollectionRules/patch/Update data collection rule
  def step_data_collection_rule_update(test, rg, checks=None):
      if checks is None:
          checks = []
      test.cmd('az monitor data-collection rule update '
               '--tags tag1="A" tag2="B" tag3="C" '
               '--name "{myDataCollectionRule}" '
               '--resource-group "{rg}"',
               checks=checks)
  
  
  # Test class for Scenario
  class Monitor_control_serviceScenarioTest(ScenarioTest):
  
      @ResourceGroupPreparer(name_prefix='clitestmonitor_control_service_myResourceGroup'[:7], key='rg',
                             parameter_name='rg')
      def test_monitor_control_service_commands(self, rg):
          self.kwargs.update({
              'subscription_id': self.get_subscription_id()
          })
          import os
  
          TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
          templateFile = os.path.join(
              TEST_DIR,
              "rule_files",
              "rule_file.json",
          )
          self.kwargs.update({
              'myDataCollectionRule': 'myCollectionRule',
              'myAssociation': 'myAssociation',
              'ruleFile': templateFile
          })
  
          call_scenario(self, rg)
  
      @ResourceGroupPreparer(name_prefix='clitest_amcs_endpoints', location='eastus2euap')
      def test_amcs_data_collection_endpoint(self, resource_group):
          self.kwargs.update({
              'rg': resource_group,
              'name1': 'endpoint1',
              'name2': 'endpoint2',
          })
  
          self.cmd('monitor data-collection endpoint create -g {rg} -n {name1} --public-network-access disabled', checks=[
              self.check('networkAcls.publicNetworkAccess', 'Disabled'),
          ])
  
          self.cmd('monitor data-collection endpoint update -g {rg} -n {name1} --public-network-access enabled '
                   '--kind windows', checks=[
              self.check('networkAcls.publicNetworkAccess', 'Enabled'),
              self.check('kind', 'Windows')
          ])
  
          self.cmd('monitor data-collection endpoint create -g {rg} -n {name2} '
                   '--public-network-access enabled --kind linux')
          self.cmd('monitor data-collection endpoint show -g {rg} -n {name2}', checks=[
              self.check('networkAcls.publicNetworkAccess', 'Enabled'),
              self.check('kind', 'Linux')
          ])
  
          self.cmd('monitor data-collection endpoint list -g {rg}', checks=[
              self.check('length(@)', 2)
          ])
  
          self.cmd('monitor data-collection endpoint delete -g {rg} -n {name2} -y')
          self.cmd('monitor data-collection endpoint list -g {rg}', checks=[
              self.check('length(@)', 1)
          ])
  
      @ResourceGroupPreparer(name_prefix='clitest_amcs_rule', location='westus2')
      def test_amcs_data_collection_rule(self, resource_group):
          import os
  
          TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
          templateFile = os.path.join(
              TEST_DIR,
              "rule_files",
              "rule_file.json",
          )
  
          self.kwargs.update({
              'rg': resource_group,
              'name': 'testrule',
              'location': 'westus2',
              'rule_file': templateFile
          })
  
          self.cmd('monitor data-collection rule create  --resource-group {rg} --location {location} '
                   '--name {name} --rule-file "{rule_file}"',
                   checks=[self.check('provisioningState', 'Succeeded')])
  
          self.cmd('monitor data-collection rule update --resource-group {rg} --name {name} '
                   '--performance-counters name="perfCounter02" '
                   'counter-specifiers=["\\Processor Information(_Total)\\% Processor Time"] '
                   'sampling-frequency=20 transfer-period="PT1M" streams="Microsoft-InsightsMetrics"',
                   checks=[self.check('provisioningState', 'Succeeded')])
  
          self.cmd('monitor data-collection rule show -g {rg} -n {name}', checks=[
              self.check('name', '{name}'),
              self.check('provisioningState', 'Succeeded')
          ])
  
          self.cmd('monitor data-collection rule list -g {rg}', checks=[
              self.check('length(@)', 1)
          ])
  
          self.cmd('monitor data-collection rule delete -g {rg} -n {name} -y')
          self.cmd('monitor data-collection rule list -g {rg}', checks=[
              self.check('length(@)', 0)
          ])
  
  