Exemple #1
0
        public PSFlowLog SetFlowLogConfig(string resourceGroupName, string name, MNM.FlowLogInformation parameters)
        {
            MNM.FlowLogInformation flowLog = this.NetworkWatcherClient.SetFlowLogConfiguration(resourceGroupName, name, parameters);
            PSFlowLog psFlowLog            = NetworkResourceManagerProfile.Mapper.Map <PSFlowLog>(flowLog);

            return(psFlowLog);
        }
        public PSFlowLog GetFlowLogStatus(string resourceGroupName, string name, MNM.FlowLogStatusParameters parameters)
        {
            MNM.FlowLogInformation flowLog = this.NetworkWatcherClient.GetFlowLogStatus(resourceGroupName, name, parameters);
            PSFlowLog psFlowLog            = Mapper.Map <PSFlowLog>(flowLog);

            return(psFlowLog);
        }
Exemple #3
0
        public override void Execute()
        {
            base.Execute();
            string resourceGroupName;
            string name;

            if (string.Equals(this.ParameterSetName, "SetByLocation", StringComparison.OrdinalIgnoreCase))
            {
                var networkWatcher = this.GetNetworkWatcherByLocation(this.Location);

                if (networkWatcher == null)
                {
                    throw new ArgumentException("There is no network watcher in location {0}", this.Location);
                }

                resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id);
                name = networkWatcher.Name;
            }
            else if (ParameterSetName.Contains("SetByResource"))
            {
                resourceGroupName = this.NetworkWatcher.ResourceGroupName;
                name = this.NetworkWatcher.Name;
            }
            else
            {
                resourceGroupName = this.ResourceGroupName;
                name = this.NetworkWatcherName;
            }

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                "FlowLogConfig",
                () =>
            {
                MNM.FlowLogInformation parameters = new MNM.FlowLogInformation();
                parameters.TargetResourceId       = this.TargetResourceId;
                parameters.Enabled   = this.EnableFlowLog;
                parameters.StorageId = this.StorageAccountId;

                if (this.EnableRetention == true || this.EnableRetention == false)
                {
                    parameters.RetentionPolicy         = new MNM.RetentionPolicyParameters();
                    parameters.RetentionPolicy.Enabled = this.EnableRetention;
                    parameters.RetentionPolicy.Days    = this.RetentionInDays;
                }

                PSFlowLog flowLog = new PSFlowLog();
                flowLog           = SetFlowLogConfig(resourceGroupName, name, parameters);

                WriteObject(flowLog);
            });
        }
Exemple #4
0
        public override void Execute()
        {
            base.Execute();
            string resourceGroupName;
            string name;

            if (ParameterSetName.Contains("SetByResource"))
            {
                resourceGroupName = this.NetworkWatcher.ResourceGroupName;
                name = this.NetworkWatcher.Name;
            }
            else
            {
                resourceGroupName = this.ResourceGroupName;
                name = this.NetworkWatcherName;
            }

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                "FlowLogConfig",
                () =>
            {
                MNM.FlowLogInformation parameters = new MNM.FlowLogInformation();
                parameters.TargetResourceId       = this.TargetResourceId;
                parameters.Enabled   = this.EnableFlowLog;
                parameters.StorageId = this.StorageAccountId;

                if (this.EnableRetention == true || this.EnableRetention == false)
                {
                    parameters.RetentionPolicy         = new MNM.RetentionPolicyParameters();
                    parameters.RetentionPolicy.Enabled = this.EnableRetention;
                    parameters.RetentionPolicy.Days    = this.RetentionInDays;
                }

                PSFlowLog flowLog = new PSFlowLog();
                flowLog           = SetFlowLogConfig(resourceGroupName, name, parameters);

                WriteObject(flowLog);
            });
        }
Exemple #5
0
        public override void Execute()
        {
            base.Execute();
            string resourceGroupName;
            string name;
            string WorkspaceResourceId;
            string WorkspaceGUID;
            string WorkspaceLocation;


            if (ParameterSetName.Contains(SetFlowlogByLocation))
            {
                var networkWatcher = this.GetNetworkWatcherByLocation(this.Location);

                if (networkWatcher == null)
                {
                    throw new System.ArgumentException("There is no network watcher in location {0}", this.Location);
                }

                resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id);
                name = networkWatcher.Name;
            }
            else if (ParameterSetName.Contains(SetFlowlogByResource))
            {
                resourceGroupName = this.NetworkWatcher.ResourceGroupName;
                name = this.NetworkWatcher.Name;
            }
            else
            {
                resourceGroupName = this.ResourceGroupName;
                name = this.NetworkWatcherName;
            }

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                "FlowLogConfig",
                () =>
            {
                MNM.FlowLogInformation parameters = new MNM.FlowLogInformation();
                parameters.TargetResourceId       = this.TargetResourceId;
                parameters.Enabled   = this.EnableFlowLog;
                parameters.StorageId = this.StorageAccountId;

                if (this.EnableRetention == true || this.EnableRetention == false)
                {
                    parameters.RetentionPolicy         = new MNM.RetentionPolicyParameters();
                    parameters.RetentionPolicy.Enabled = this.EnableRetention;
                    parameters.RetentionPolicy.Days    = this.RetentionInDays;
                }

                if (ParameterSetName.Contains(WithTA))
                {
                    parameters.FlowAnalyticsConfiguration = new MNM.TrafficAnalyticsProperties();
                    parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration = new MNM.TrafficAnalyticsConfigurationProperties();

                    parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled = this.EnableTrafficAnalytics.IsPresent;

                    if (ParameterSetName.Contains(TAByDetails))
                    {
                        string[] workspaceDetailsComponents = this.WorkspaceResourceId.Split('/');

                        //Expected format : /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-
                        if (workspaceDetailsComponents.Length != 9)
                        {
                            throw new System.ArgumentException("The given workspace resource id is not in format of: /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-.");
                        }

                        WorkspaceResourceId = this.WorkspaceResourceId;
                        WorkspaceGUID       = this.WorkspaceGUID;
                        WorkspaceLocation   = this.WorkspaceLocation;
                    }
                    else
                    {
                        WorkspaceResourceId = this.Workspace.ResourceId;
                        WorkspaceGUID       = this.Workspace.CustomerId.ToString();
                        WorkspaceLocation   = this.Workspace.Location;
                    }

                    parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId = WorkspaceResourceId;
                    parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId         = WorkspaceGUID;
                    parameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion     = WorkspaceLocation;
                }

                PSFlowLog flowLog = new PSFlowLog();
                flowLog           = SetFlowLogConfig(resourceGroupName, name, parameters);

                WriteObject(flowLog);
            });
        }