public PSConnectionMonitorResult GetConnectionMonitor(string resourceGroupName, string name, string connectionMonitorName)
        {
            ConnectionMonitorResult   connectionMonitor   = this.ConnectionMonitors.Get(resourceGroupName, name, connectionMonitorName);
            PSConnectionMonitorResult psConnectionMonitor = NetworkResourceManagerProfile.Mapper.Map <PSConnectionMonitorResult>(connectionMonitor);

            return(psConnectionMonitor);
        }
示例#2
0
        public override void Execute()
        {
            base.Execute();

            string connectionMonitorName = this.Name;
            string resourceGroupName     = string.Empty;
            string networkWatcherName    = string.Empty;

            if (ParameterSetName.Contains("SetByResourceId"))
            {
                ConnectionMonitorDetails connectionMonitorDetails = new ConnectionMonitorDetails();
                connectionMonitorDetails = this.GetConnectionMonitorDetails(this.ResourceId);

                connectionMonitorName = connectionMonitorDetails.ConnectionMonitorName;
                resourceGroupName     = connectionMonitorDetails.ResourceGroupName;
                networkWatcherName    = connectionMonitorDetails.NetworkWatcherName;
            }
            else if (ParameterSetName.Contains("SetByResource"))
            {
                resourceGroupName  = this.NetworkWatcher.ResourceGroupName;
                networkWatcherName = this.NetworkWatcher.Name;
            }
            else if (ParameterSetName.Contains("SetByName"))
            {
                resourceGroupName  = this.ResourceGroupName;
                networkWatcherName = this.NetworkWatcherName;
            }
            else
            {
                var networkWatcher = this.GetNetworkWatcherByLocation(this.Location);

                if (networkWatcher == null)
                {
                    throw new ArgumentException("There is no network watcher in the specified location");
                }

                resourceGroupName  = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id);
                networkWatcherName = networkWatcher.Name;
            }

            if (!string.IsNullOrEmpty(connectionMonitorName))
            {
                PSConnectionMonitorResult connectionMonitor = new PSConnectionMonitorResult();
                connectionMonitor = this.GetConnectionMonitor(resourceGroupName, networkWatcherName, connectionMonitorName);

                WriteObject(connectionMonitor);
            }
            else
            {
                List <PSConnectionMonitorResult> psConnectionMonitorList = new List <PSConnectionMonitorResult>();
                var connectionMonitorList = this.ConnectionMonitors.List(resourceGroupName, networkWatcherName);

                foreach (var cm in connectionMonitorList)
                {
                    PSConnectionMonitorResult psConnectionMonitor = NetworkResourceManagerProfile.Mapper.Map <PSConnectionMonitorResult>(cm);
                    psConnectionMonitorList.Add(psConnectionMonitor);
                }
                WriteObject(psConnectionMonitorList, true);
            }
        }
示例#3
0
        private PSConnectionMonitorResult UpdateConnectionMonitor(string resourceGroupName, string networkWatcherName)
        {
            MNM.ConnectionMonitor parameters = new MNM.ConnectionMonitor
            {
                Source = new MNM.ConnectionMonitorSource
                {
                    ResourceId = this.SourceResourceId,
                    Port       = this.SourcePort
                },
                Destination = new MNM.ConnectionMonitorDestination
                {
                    ResourceId = this.DestinationResourceId,
                    Address    = this.DestinationAddress,
                    Port       = this.DestinationPort
                },
                Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true)
            };

            if (this.ConfigureOnly)
            {
                parameters.AutoStart = false;
            }

            if (this.MonitoringIntervalInSeconds != null)
            {
                parameters.MonitoringIntervalInSeconds = this.MonitoringIntervalInSeconds;
            }

            PSConnectionMonitorResult getConnectionMonitor = new PSConnectionMonitorResult();

            // Execute the CreateOrUpdate Connection monitor call
            if (ParameterSetName.Contains("SetByResource") && !ParameterSetName.Contains("SetByResourceId"))
            {
                parameters.Location = this.NetworkWatcher.Location;
            }
            else if (ParameterSetName.Contains("SetByLocation"))
            {
                parameters.Location = this.Location;
            }
            else
            {
                MNM.NetworkWatcher networkWatcher = this.NetworkClient.NetworkManagementClient.NetworkWatchers.Get(resourceGroupName, networkWatcherName);
                parameters.Location = networkWatcher.Location;
            }

            this.ConnectionMonitors.CreateOrUpdate(resourceGroupName, networkWatcherName, connectionMonitorName, parameters);
            getConnectionMonitor = this.GetConnectionMonitor(resourceGroupName, networkWatcherName, connectionMonitorName);

            return(getConnectionMonitor);
        }
        public PSConnectionMonitorResult ConvertConnectionMonitorResultV2ToPSFormat(ConnectionMonitorResult connectionMonitor)
        {
            PSConnectionMonitorResult psConnectionMonitor = null;

            if (String.Equals(connectionMonitor.ConnectionMonitorType, "SingleSourceDestination"))
            {
                psConnectionMonitor = ConvertConnectionMonitorResultToPSConnectionMonitorResultV1(connectionMonitor);
            }
            else
            {
                psConnectionMonitor = MapConnectionMonitorResultToPSConnectionMonitorResultV2(connectionMonitor);
            }
            return(psConnectionMonitor);
        }