Paul Collinge 2020-03-06 13:47:40 +00:00
Родитель 6633cdf598 c7f4e8b184
Коммит 697111c378
6 изменённых файлов: 239 добавлений и 10 удалений

Просмотреть файл

@ -0,0 +1,197 @@
<#
.COPYRIGHT
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
See LICENSE in the project root for license information.
#>
####################################################
#Script to generate Log Analytics query for Office 365 endpoint categories optimize and allow
# Accepted input for Category parameter are Optimize or Allow
# Accepted input format for startdate and enddate is
#startdate: 2018-11-01T09:00
#enddate: 2018-11-12T09:00
######################################################################################################
[CmdletBinding(SupportsShouldProcess=$True)]
Param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $Category,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $startdate,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $enddate
)
function Get-IPrange
{
<#
.SYNOPSIS
Get the IP addresses in a range
.EXAMPLE
Get-IPrange -start 192.168.8.2 -end 192.168.8.20
.EXAMPLE
Get-IPrange -ip 192.168.8.2 -mask 255.255.255.0
.EXAMPLE
Get-IPrange -ip 192.168.8.3 -cidr 24
#>
param
(
[string]$start,
[string]$end,
[string]$ip,
[string]$mask,
[int]$cidr
)
function IP-toINT64 () {
param ($ip)
$octets = $ip.split(".")
return [int64]([int64]$octets[0]*16777216 +[int64]$octets[1]*65536 +[int64]$octets[2]*256 +[int64]$octets[3])
}
function INT64-toIP() {
param ([int64]$int)
return (([math]::truncate($int/16777216)).tostring()+"."+([math]::truncate(($int%16777216)/65536)).tostring()+"."+([math]::truncate(($int%65536)/256)).tostring()+"."+([math]::truncate($int%256)).tostring() )
}
if ($ip) {$ipaddr = [Net.IPAddress]::Parse($ip)}
if ($cidr) {$maskaddr = [Net.IPAddress]::Parse((INT64-toIP -int ([convert]::ToInt64(("1"*$cidr+"0"*(32-$cidr)),2)))) }
if ($mask) {$maskaddr = [Net.IPAddress]::Parse($mask)}
if ($ip) {$networkaddr = new-object net.ipaddress ($maskaddr.address -band $ipaddr.address)}
if ($ip) {$broadcastaddr = new-object net.ipaddress (([system.net.ipaddress]::parse("255.255.255.255").address -bxor $maskaddr.address -bor $networkaddr.address))}
if ($ip) {
$startaddr = IP-toINT64 -ip $networkaddr.ipaddresstostring
$endaddr = IP-toINT64 -ip $broadcastaddr.ipaddresstostring
} else {
$startaddr = IP-toINT64 -ip $start
$endaddr = IP-toINT64 -ip $end
}
INT64-toIP -int $startaddr
INT64-toIP -int $endaddr
}
function GetIpAddressesForCategory ($optimize) {
<#
.SYNOPSIS
Get the IP addresses for a given O365 endpoint category
.EXAMPLE
GetIpAddressesForCategory("Optimize")
#>
#if (!$optimize) {
# $optimize = "Optimize"
#}
# webservice root URL
$ws = "https://endpoints.office.com"
$clientRequestId = [guid]::NewGuid()
$O365instance = "Worldwide"
# invoke endpoints method to get the new data
$endpointSets = Invoke-RestMethod -Uri ($ws + "/endpoints/"+$O365instance+"?clientRequestId=" + $clientRequestId)
$flatIps = $endpointSets | ForEach-Object {
$endpointSet = $_
if ($endpointSet.category -eq $category ) {
$ips = $(if ($endpointSet.ips.Count -gt 0) { $endpointSet.ips } else { @() })
# IPv4 strings have dots while IPv6 strings have colons
$ip4s = $ips | Where-Object { $_ -like '*.*' }
$IpCustomObjects = @()
if ($endpointSet.tcpPorts -or $endpointSet.udpPorts) {
$IpCustomObjects = $ip4s | ForEach-Object {
[PSCustomObject]@{
category = "Allow";
ip = $_;
tcpPorts = $endpointSet.tcpPorts;
udpPorts = $endpointSet.udpPorts;
}
}
}
$IpCustomObjects
}
}
return $flatIps
}
function Get-BwData($optimize) {
$mySubnets = GetIpAddressesForCategory($optimize)
$firstItem = 0
$IpRanges = $mySubnets.ip | ForEach-Object {
$mySubnet = $_.split("/")
if ($mySubnet[1] -eq "32") {
$IpRange = $mySubnet[0]
if ($firstItem -eq 0) {
$KustoQuery += " | where (parse_ipv4(DestinationIp) == parse_ipv4('"+$IpRange+"'))"
} else {
$KustoQuery += " or (parse_ipv4(DestinationIp) == parse_ipv4('"+$IpRange+"'))"
}
} elseif ($mysubnet[1] -ne "32") {
$IpRange = Get-IPrange -ip $mySubnet[0] -cidr $mySubnet[1]
if ($firstItem -eq 0) {
$KustoQuery += " | where (parse_ipv4(DestinationIp) >= parse_ipv4('"+$IpRange[0]+"') and parse_ipv4(DestinationIp) <= parse_ipv4('"+$IpRange[1]+"')) "
} else {
$KustoQuery += " or (parse_ipv4(DestinationIp) >= parse_ipv4('"+$IpRange[0]+"') and parse_ipv4(DestinationIp) <= parse_ipv4('"+$IpRange[1]+"')) "
}
}
$firstItem = 1
}
return $KustoQuery
}
$OutputData = "VMConnection " # Change to VMConnection
$secondService = 1
foreach ($optimize in $category) {
$OutputData += Get-BwData($optimize)
$secondService++
}
$OutputData += " | where TimeGenerated > todatetime('"+$startdate+"') and TimeGenerated < todatetime('"+$enddate+"')"
##$OutputData += " | project SessionStartTime, TotalBytes " ## Potentially not needed anymore.
$ReturnMessage = ''+$OutputData+''
$Date = Get-Date
$Filename = "LogAnalyticsquery" + "_" + "$category" + "_" + $Date.Day + "-" + $Date.Month + "-" + $Date.Year + "_" + $Date.Hour + "-" + $Date.Minute + ".txt"
Out-File -Encoding ascii -FilePath "$ENV:Temp\$FileName" -InputObject $ReturnMessage
Write-Host "Log Analytics query written to '$ENv:Temp\$FileName'" -ForegroundColor Yellow

Двоичный файл не отображается.

Двоичный файл не отображается.

Просмотреть файл

@ -1,9 +1,14 @@
# /Office 365 Network Bandwidth meter/
This is a beta solution we released recently in September 2018 to:
1. Measure network bandwidth usage for pilot users on-boarded to Office 365 or network bandwidth usage of on-premises users.
2. Build and maintain endpoint monitoring dashboards post on-boarding users to Office 365
You can use this solution if you intend to:
1. Measure network bandwidth usage for pilot users on-boarded to Office 365
2. Measure network bandwidth usage for services like Exchange Online, SharePoint Online/OneDrive for Business and Microsoft Teams
3. Measure network bandwidth usage for traffic to 'Optimize' category Office 365 endpoints
4. Measure number of TCP connections used while connecting to Office 365 services like Exchange Online, SharePoint Online/OneDrive for Business
5. Measure number of TCP connections used while connecting to 'Optimize' category Office 365 endpoints
This solution uses Azure monitoring, specifically Service Map. You can apply this concept for measuring any SaaS/PaaS traffic, not just Office 365.
This solution uses Azure monitoring, specifically Service Map, dependencies for Service Map like Microsoft Monitoring Agent, Dependency Agent are applicable to this solution. This concept assumes you have pilot batch of users on-boarded to Office 365 or you can monitor a subset of user traffic accessing Office 365 services.
You can apply this concept for measuring any SaaS/PaaS traffic as long as you can filter the traffic based on Process Name or Destination IP endpoints, not limited to Office 365.
This solution will allow you to monitor and analyse the following example scenarios:
@ -20,7 +25,16 @@ This solution will allow you to monitor and analyse the following example scenar
# Prerequisites
Azure Subscription
Azure Log analytics workspace
Azure Monitoring/Log analytics workspace
Microsoft Monitoring Agent (MMA)
Dependency Agent
# New Announcements (December 2019)
1. UDP now supported for measuring network bandwidth usage of Teams media traffic (Audio, Video, Screen Sharing), update your Dependency Agent to the latest version for UDP support
2. Sample Queries for measuring network bandwidth usage and TCP connections to 'Optimize' category Office 365 endpoints
# Support Statement
The scripts, samples, and tools made available through the Open Source initiative are provided as-is. These resources are developed in partnership with the community and do not represent official Microsoft software. As such, support is not available through premier or other official support channels. If you find an issue or have questions please reach out through the issues list and we'll do our best to assist, but there is no support SLA associated with these tools.

Просмотреть файл

@ -1,15 +1,33 @@
# Microsoft Office 365 Network Tools
Welcome to the home for Microsoft Office 365 Network Tools. Through this initiative we are collecting tools, scripts, and guidance from across engineering teams with the aim to make them easier to find, grow, and improve with help from the community and partners.
Welcome to the home for Microsoft Office 365 Network Tools, you will find here resources to help you:
1. Plan for Network Connectivity to Office 365 services
2. Optimize Network Connectivity and performance for users accessing Office 365 services
Through this initiative we are collecting solutions, scripts, and guidance from across Office 365 engineering teams with aim to make on-premises network infrastructure readiness easier for Office 365 on-boarding, we also intend to grow and improve these resources with help from the community and partners.
## Folders & Description:
#### /Office 365 Network Bandwidth meter/
This is a beta solution we released recently in September 2018 to:
1. Measure network bandwidth usage for pilot users on-boarded to Office 365 or network bandwidth usage of on-premises users.
2. Build and maintain endpoint monitoring dashboards post on-boarding users to Office 365
You can use this solution if you intend to:
1. Measure network bandwidth usage for pilot users on-boarded to Office 365
2. Measure network bandwidth usage for services like Exchange Online, SharePoint Online/OneDrive for Business and Microsoft Teams
3. Measure network bandwidth usage for traffic to 'Optimize' category Office 365 endpoints
4. Measure number of TCP connections used while connecting to Office 365 services like Exchange Online, SharePoint Online/OneDrive for Business
5. Measure number of TCP connections used while connecting to 'Optimize' category Office 365 endpoints
This solution uses Azure monitoring, specifically Service Map. You can apply this concept for measuring any SaaS/PaaS traffic, not just Office 365.
#### /Scripts/
1. ExpressRoute PAC file creation
2. PAC file creation based on Office 365 endpoint categories by leveraging Office 365 IP address and URL webservice
# Important Links
Office 365 network connectivity principles – http://aka.ms/pnc
Office 365 URL & IP Ranges – http://aka.ms/o365ip
Office 365 URL & IP web service – http://aka.ms/ipurlws
Office 365 URL & IP web service usage – http://aka.ms/ipurlblog
Office 365 Network Onboarding Tool – http://aka.ms/netonboard
Office 365 Network scripts on Github - http://aka.ms/o365nettools
Office 365 Network Bandwidth Meter on Github – http://aka.ms/bandwidth
# Open to ideas
If you have ideas for projects that would improve our delivery, experience, or process please submit an issue and let us know. We can't promise every idea will be implemented, but we value your feedback. Please be sure to include sufficient information that we can understand your idea and respond.