Ejemplo n.º 1
0
        private void ReplaceDataCollectionRule()
        {
            if (Location != null)
            {
                Dcr.Location = Location;
            }
            if (Description != null)
            {
                Dcr.Description = Description;
            }
            if (Tag != null)
            {
                Dcr.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);
            }

            if (ShouldProcess(
                    target: string.Format("Data collection rule '{0}' in resource group '{1}'", RuleName, ResourceGroupName),
                    action: "Update a data collection rule"))
            {
                var dcrResponse = this.MonitorManagementClient.DataCollectionRules.Create(
                    resourceGroupName: ResourceGroupName,
                    dataCollectionRuleName: RuleName,
                    body: Dcr);

                var output = new PSDataCollectionRuleResource(dcrResponse);
                WriteObject(sendToPipeline: output);
            }
        }
        /// <summary>
        /// Executes the cmdlet. Update-AzDataCollectionRule
        /// </summary>
        protected override void ProcessRecordInternal()
        {
            switch (ParameterSetName)
            {
            case ByName:
                break;

            case ByInputObject:
                RuleId = InputObject.Id;
                SetNameAndResourceFromResourceId();
                break;

            case ByResourceId:
                SetNameAndResourceFromResourceId();
                break;

            default:
                throw new Exception("Unkown ParameterSetName");
            }

            var resourceForUpdate = new ResourceForUpdate();

            if (Tag != null)
            {
                resourceForUpdate.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);
            }

            if (ShouldProcess(
                    target: string.Format("Data collection rule '{0}' in resource group '{1}'", RuleName, ResourceGroupName),
                    action: "Update a data collection rule"))
            {
                var dcrRespone = this.MonitorManagementClient.DataCollectionRules.Update(
                    resourceGroupName: ResourceGroupName,
                    dataCollectionRuleName: RuleName,
                    body: resourceForUpdate
                    );

                var output = new PSDataCollectionRuleResource(dcrRespone);
                WriteObject(sendToPipeline: output);
            }
        }
        private void ProcessRecordInternalByFile()
        {
            string rawJsonContent = Utilities.ReadFileContent(this.TryResolvePath(RuleFile));

            DataCollectionRuleResource   dcr;
            PSDataCollectionRuleResource psDcr = SafeJsonConvert.DeserializeObject <PSDataCollectionRuleResource>(rawJsonContent, MonitorManagementClient.DeserializationSettings);

            if (psDcr == null || psDcr.DataSources == null)
            {
                dcr = SafeJsonConvert.DeserializeObject <DataCollectionRuleResource>(rawJsonContent, MonitorManagementClient.DeserializationSettings);
            }
            else
            {
                dcr = psDcr.ConvertToApiObject();
            }

            if (!string.IsNullOrWhiteSpace(Location))
            {
                dcr.Location = Location;
            }
            if (!string.IsNullOrWhiteSpace(Description))
            {
                dcr.Description = Description;
            }
            if (Tag != null)
            {
                dcr.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);
            }

            if (ShouldProcess(
                    target: string.Format("Data collection rule '{0}' in resource group '{1}'", RuleName, ResourceGroupName),
                    action: "Create a data collection rule"))
            {
                var dcrResponse = MonitorManagementClient.DataCollectionRules.Create(resourceGroupName: ResourceGroupName, dataCollectionRuleName: RuleName, body: dcr);

                var output = new PSDataCollectionRuleResource(dcrResponse);
                WriteObject(sendToPipeline: output);
            }
        }