SDNDataExporter.ps1.txt
# Fill in the following information
$uri = 'https://sdn-pod06.tailwindtraders.com' $WorkspaceID = "" $SharedKey = "" $LogType = "SDNLogs" $NCURI = "cppe-pod01.tailwindtraders.com" # Create the function to create the authorization signature Function Build-Signature ($WorkspaceID, $sharedKey, $date, $contentLength, $method, $contentType, $resource) { $xHeaders = "x-ms-date:" + $date $stringToHash = $method + "`n" + $contentLength + "`n" + $contentType + "`n" + $xHeaders + "`n" + $resource $bytesToHash = [Text.Encoding]::UTF8.GetBytes($stringToHash) $keyBytes = [Convert]::FromBase64String($sharedKey) $sha256 = New-Object System.Security.Cryptography.HMACSHA256 $sha256.Key = $keyBytes $calculatedHash = $sha256.ComputeHash($bytesToHash) $encodedHash = [Convert]::ToBase64String($calculatedHash) $authorization = 'SharedKey {0}:{1}' -f $WorkspaceId,$encodedHash return $authorization } # Create the function to create and post the request Function Post-LogAnalyticsData($WorkspaceID, $sharedKey, $body, $logType) { $method = "POST" $contentType = "application/json" $resource = "/api/logs" $rfc1123date = [DateTime]::UtcNow.ToString("r") $contentLength = $body.Length $signature = Build-Signature ` -WorkspaceId $WorkspaceID ` -sharedKey $sharedKey ` -date $rfc1123date ` -contentLength $contentLength ` -method $method ` -contentType $contentType ` -resource $resource $uri = "https://" + $WorkspaceId + ".ods.opinsights.azure.com" + $resource + "?api-version=2016-04-01" $headers = @{ "Authorization" = $signature; "Log-Type" = $logType; "x-ms-date" = $rfc1123date; } $response = Invoke-WebRequest -Uri $uri -Method $method -ContentType $contentType -Headers $headers -Body $body -UseBasicParsing return $response.StatusCode } # main $SDNURI = Get-SdnNetworkController -NetworkController $NCuri $logNetworks = Get-NetworkControllerLogicalNetwork -ConnectionUri $uri $vNets = Get-NetworkControllerVirtualNetwork -ConnectionUri $uri $vServers = Get-NetworkControllerVirtualServer -ConnectionUri $uri $nics = Get-NetworkControllerNetworkInterface -ConnectionUri $uri $servers = Get-NetworkControllerServer -ConnectionUri $uri $lb = Get-NetworkControllerLoadBalancer -ConnectionUri $uri $lbMux = Get-NetworkControllerLoadBalancerMux -ConnectionUri $uri $lbConfig = Get-NetworkControllerLoadBalancerConfiguration -ConnectionUri $uri $acls = Get-NetworkControllerAccessControlList -ConnectionUri $uri $ncCreds = Get-NetworkControllerCredential -ConnectionUri $uri $pips = Get-NetworkControllerPublicIpAddress -ConnectionUri $uri $udrs = Get-NetworkControllerRouteTable -ConnectionUri $uri $gateways = Get-NetworkControllerGateway -ConnectionUri $uri $gatewayPools = Get-NetworkControllerGatewayPool -ConnectionUri $uri $virtualgateways = Get-NetworkControllerVirtualGateway -ConnectionUri $uri # Format data # Format Logical Networks #Format SDN Master Config $SDNURI1 = @() $SDNURI1 += [pscustomobject]@{ NCRestName = $SDNURI.RestName NCIPAddress = $SDNURI.RestIP NCNodeNames = $SDNURI.Node SDNVersion = $SDNURI.Version } $logNetworkFMT = @() foreach ($logNetwork in $logNetworks) { $logNetworkFMT += [pscustomobject]@{ Name = $logNetwork.ResourceRef ResourceID = $logNetwork.ResourceId NetworkVirtualizationEnabled = $logNetwork.Properties.NetworkVirtualizationEnabled ProvisioningState = $logNetwork.Properties.ProvisioningState Subnets = $logNetwork.Properties.Subnets VirtualNetworks = $logNetwork.Properties.VirtualNetworks } } # Format Virtual Networks $vNetsFMT = @() foreach ($vNet in $vNets) { $vNetsFMT += [pscustomobject]@{ Name = $vNets.ResourceRef ResourceID = $vNets.ResourceId ProvisioningState = $vNets.Properties.ProvisioningState Subnets = $vNets.Properties.Subnets VirtualNetworkPeerings = $vNets.Properties.VirtualNetworkPeerings } } # Format Virtual Servers $vServersFMT = @() foreach ($vServer in $vServers) { $vServersFMT += [pscustomobject]@{ Name = $vServer.ResourceRef ResourceID = $vServer.InstanceId Certificate = $vServer.Properties.Certificate ProvisioningState = $vServer.Properties.ProvisioningState VMGuid = $vServer.Properties.VMGuid Connections = $vServer.Properties.Connections.ManagementAddresses } } # Format Network Interfaces $nicsFMT = @() foreach ($nic in $nics) { $nicsFMT += [pscustomobject]@{ Name = $nic.ResourceRef ResourceID = $nic.ResourceId PrivateMacAddress = $nic.Properties.PrivateMacAddress PrivateMacAllocationMethod = $nic.Properties.PrivateMacAllocationMethod InternalDnsNameLabel = $nic.Properties.InternalDnsNameLabel ProvisioningState = $nic.Properties.ProvisioningState IsHostVirtualNetworkInterface = $nic.Properties.IsHostVirtualNetworkInterface ConfigurationState = $nic.Properties.ConfigurationState.Status DetailedInfo = $nic.Properties.ConfigurationState.DetailedInfo } } # Format Servers $serversFMT = @() foreach ($server in $servers) { $serversFMT += [pscustomobject]@{ Name = $server.Properties.Connections.ManagementAddresses.ToString() ResourceID = $server.ResourceId ProvisioningState = $server.Properties.ProvisioningState ConfigurationState = $server.Properties.ConfigurationState.Status ConfigurationStateLastUpdated = $server.Properties.ConfigurationState.LastUpdatedTime ConfigurationStateDetailedInfo = $server.Properties.ConfigurationState.DetailedInfo NetworkInterfaces = $server.Properties.NetworkInterfaces.ResourceID } } # Format load balancers $lbFMT = @() foreach ($loadb in $lb) { $lbFMT += [pscustomobject]@{ Name = $loadb.ResourceRef ResourceId = $loadb.ResourceId ProvisioningState = $loadb.Properties.ProvisioningState FrontEndIPConfigurationProvisioningState = $loadb.Properties.FrontendIPConfigurations.properties.ProvisioningState BackendAddressProvisioningState = $loadb.Properties.BackendAddressPools.properties.ProvisioningState LoadBalancingRules = $loadb.Properties.LoadBalancingRules.ResourceID -join ',' LoadBalacningRulesDetailed = $loadb.Properties.LoadBalancingRules } } # format MUX $lbMuxFMT = @() foreach ($lbMuxInst in $lbMux) { $lbMuxFMT += [pscustomobject]@{ Name = $lbMuxInst.ResourceId ResourceRef = $lbMuxInst.ResourceRef ProvisioningState = $lbMuxInst.Properties.ProvisioningState ConfigurationState = $lbMuxInst.Properties.ConfigurationState.Status ConfigurationStateDetailedInfo = $lbMuxInst.Properties.ConfigurationState.DetailedInfo.Message } } # format MUX Config $lbMuxConfigFMT = @() foreach ($lbMuxConfig in $lbConfig) { $lbMuxConfigFMT += [pscustomobject]@{ ResourceID = $lbMuxConfig.ResourceId ResourceRef = $lbMuxConfig.ResourceRef ProvisioningState = $lbMuxConfig.Properties.ProvisioningState } } # format nsg $nsgFMT = @() foreach ($nsg in $acls) { $nsgFMT+= [pscustomobject]@{ ResourceID = $nsg.ResourceId ResourceRef = $nsg.ResourceRef ProvisioningState = $nsg.Properties.ProvisioningState ACLRules = $nsg.Properties.AclRules ACLIPConfigurations = $nsg.Properties.IpConfigurations ACLSubnets = $nsg.Properties.Subnets } } # format Public IPs $pipsFMT = @() foreach ($pip in $pips) { $pipsFMT += [pscustomobject]@{ ResourceID = $pip.ResourceId ResourceRef = $pip.ResourceRef ProvisioningState = $pip.Properties.ProvisioningState IPAddress = $pip.Properties.IpAddress } } # Format UDRS/Route Tables $udrsFMT = @() foreach ($udr in $udrs) { $udrsFMT += [pscustomobject]@{ ResourceID = $udr.ResourceId ResourceRef = $udr.ResourceRef ProvisioningState = $udr.Properties.ProvisioningState RouteAddressPrefix = $udr.properties.routes.properties.AddressPrefix RouteNextHopType = $udr.properties.routes.properties.NextHopType RouteHextHopIPAddress = $udr.properties.routes.properties.NextHopIpAddress RouteProvisioningState = $udr.properties.routes.properties.ProvisioningState } } # format Gateways $gatewaysFMT = @() foreach ($gateway in $gateways) { $gatewaysFMT += [pscustomobject]@{ ResourceID = $gateway.ResourceId ResourceRef = $gateway.ResourceRef State = $gateway.Properties.state HealthState = $gateway.Properties.HealthState TotalCapacity = $gateway.Properties.TotalCapacity AvailableCapacity = $gateway.Properties.AvailableCapacity BGPConfig = $gateway.Properties.BgpConfig } } # Format Gateway Pools $gatewayPoolsFMT = @() foreach ($gatewayPool in $gatewayPools) { $gatewayPoolsFMT += [pscustomobject]@{ ResourceID = $gatewayPool.ResourceId ResourceRef = $gatewayPool.ResourceRef ProvisioningState = $gatewayPool.Properties.ProvisioningState } } # Format VirtualGateways $virtualgatewaysFMT = @() foreach ($virtualgateway in $virtualgateways) { $virtualgatewaysFMT += [pscustomobject]@{ ResourceID = $virtualgateway.ResourceId ResourceRef = $virtualgateway.ResourceRef ProvisioningState = $virtualgateway.Properties.ProvisioningState NetworkConnectionName = $virtualgateway.Properties.NetworkConnections.ResourceId NetworkConnectionStatus = $virtualgateway.Properties.NetworkConnections.properties.ConnectionStatus NetworkConnectionState = $virtualgateway.Properties.NetworkConnections.properties.ConnectionState NetworkConnectionProvisioningState = $virtualgateway.Properties.NetworkConnections.properties.ConnectionState } } #> $NetworkControllerInfo = New-Object -TypeName PSObject $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name NCURI -Value $uri $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name NCMaster5 -Value $SDNURI1 $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name LogicalNetworks -Value $logNetworkFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name VirtualNetworks -Value $vNetsFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name VirtualServers -Value $vServersFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name NetworkInterfaces -Value $nicsFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name Servers -Value $vServersFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name LoadBalancers -Value $lbFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name LoadBalancerMux -Value $lbMuxFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name LoadBalancerConfig -Value $lbMuxConfig $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name NetworkSecurityGroups -Value $nsgFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name NCCredentials -Value $ncCreds $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name PublicIPs -Value $pips $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name UserDefinedRoutes -Value $udrsFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name Gateways -Value $gatewaysFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name GatewayPools -Value $gatewayPoolsFMT $NetworkControllerInfo | Add-Member -MemberType NoteProperty -Name VirtualGateways -Value $virtualgatewaysFMT $json = $NetworkControllerInfo | ConvertTo-Json -Depth 100 -Compress Post-LogAnalyticsData -WorkspaceID $WorkspaceID -sharedKey $sharedKey -body ([System.Text.Encoding]::UTF8.GetBytes($json)) -logType $logType |