Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated powershell samples for managing NTA Sources #327

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Samples/PowerShell/NTA.AddFlowSources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $interfaceIds = Get-SwisData -SwisConnection $swis -Query "SELECT InterfaceID FR
$interfaceIds = $interfaceIds | ForEach-Object {[int]$_}
Write-Host "Discovered $($interfaceIds.Count) interfaces for new node with ID $nodeId"

# Enable Flow Collection on every interface of the router - Create Netflow Sources
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.Netflow.Source -Verb EnableFlowSources -Arguments @(,$interfaceIds) | Out-Null
$flowSourcesIds = Get-SwisData -SwisConnection $swis -Query "SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeID" -Parameters @{nodeID = $nodeId}
Write-Host("$($flowSourcesIds.Count) Netflow Sources created")
# Enable Flow Collection on every interface of the router - Create Netflow Interface Sources
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.Netflow.InterfaceSources -Verb EnableFlowInterfaceSources -Arguments @(,$interfaceIds) | Out-Null
$flowSourcesIds = Get-SwisData -SwisConnection $swis -Query "SELECT EntityID FROM Orion.Netflow.InterfaceSources WHERE Enabled = 1 AND NodeID = @nodeID" -Parameters @{nodeID = $nodeId}
Write-Host("$($flowSourcesIds.Count) Netflow Interface Sources created")
19 changes: 11 additions & 8 deletions Samples/PowerShell/NTA.DownloadRouterConfigFromNCM.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ $password = New-Object System.Security.SecureString # Update to match your c
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$swis = Connect-Swis -host $hostname -cred $cred

# Get Orion Node, Interface, Netflow Source information and Router identifiers for concrete Netflow Source
# Get Orion Node, Interface, Netflow Interface Source information and Router identifiers for concrete Netflow Interface Source
# You can use these alternative conditions
# If you know NetflowSourceID: WHERE S.NetflowSourceID = $netflowSourceId
# If you know NodeName: WHERE s.Node.NodeName = '$nodeName'
# If you know InterfaceName: WHERE s.Interface.InterfaceName = '$interfaceName'
$nodeName = "example.com" # Update to match your configuration
$interfaceName = "GigabitEthernet0/1" # Update to match your configuration

$query= "
SELECT s.NetflowSourceID, s.NodeID, s.InterfaceID, s.Enabled, s.LastTimeFlow, s.LastTime, s.EngineID,
s.Node.NodeName,
s.Interface.Name as InterfaceName, s.Interface.Index as RouterIndex
FROM Orion.Netflow.Source s
WHERE s.Node.NodeName = @nodeName AND s.Interface.InterfaceName = @interfaceName
SELECT s.NodeID, s.EntityID as InterfaceID, s.Enabled, s.LastTime, ns.EngineID,
ns.Node.NodeName,
i.InterfaceName, s.InterfaceIndex as RouterIndex
FROM Orion.Netflow.InterfaceSources s
JOIN Orion.Netflow.NodeSources ns ON s.NodeID = ns.NodeID
JOIN Orion.NPM.Interfaces i ON s.EntityID = i.InterfaceID
WHERE s.EntityType = 'Orion.NPM.Interfaces'
AND ns.Node.NodeName = @nodeName
AND i.InterfaceName = @interfaceName
"
$params = @{
nodeName = $nodeName
Expand Down Expand Up @@ -57,5 +60,5 @@ Write-Host "Configuration for node with name $nodeName, Orion ID $orionNodeId, N
# Uncomment if you want to write configuration to console
# Write-Host $lastConfigData.Config

# You can analyze configuration manually or write some parser. To identify data related to concrete Netflow Source
# You can analyze configuration manually or write some parser. To identify data related to concrete Netflow Node Source
# you can use retrieved information in $netflowSourceInfo object like: $netflowSourceInfo.InterfaceName, $netflowSourceInfo.RouterIndex
24 changes: 13 additions & 11 deletions Samples/PowerShell/NTA.EnableDisableFlowSources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ $cred = New-Object -typename System.Management.Automation.PSCredential -argument
$swis = Connect-Swis -host $hostname -cred $cred


# Disable Flow Sources
$nodeCaption = "My test router"
# Disable Node and Interface Flow Sources
$nodeCaption = "example.com"
$nodeId = Get-SwisData -SwisConnection $swis -Query "SELECT NodeID FROM Orion.Nodes WHERE Caption = @nodeCaption" -Parameters @{nodeCaption = $nodeCaption}
$flowSourcesIds = Get-SwisData -SwisConnection $swis -Query "SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeID" -Parameters @{nodeID = $nodeId}
$flowSourcesIds = $flowSourcesIds | ForEach-Object {[int]$_}
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.Netflow.Source -Verb DisableFlowSources -Arguments @(,$flowSourcesIds) | Out-Null
$disableflowSourcesIds = Get-SwisData -SwisConnection $swis -Query "SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeID and Enabled = false" -Parameters @{nodeID = $nodeId}
Write-Host "Disabled $($disableflowSourcesIds.Count) Flow Sources for node with ID $nodeId. Total interface count $($flowSourcesIds.Count)"
$interfaceIds = Get-SwisData -SwisConnection $swis -Query "SELECT InterfaceID FROM Orion.NPM.Interfaces WHERE NodeID = @nodeID" -Parameters @{nodeID = $nodeId}
$interfaceIds = $interfaceIds | ForEach-Object {[int]$_}
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.Netflow.NodeSources -Verb DisableFlowNodeSources -Arguments @(,@([int]$nodeId)) | Out-Null
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.Netflow.InterfaceSources -Verb DisableFlowInterfaceSources -Arguments @(,$interfaceIds) | Out-Null
$disableflowSourcesIds = Get-SwisData -SwisConnection $swis -Query "SELECT EntityID FROM Orion.Netflow.InterfaceSources WHERE NodeID = @nodeID and Enabled = false" -Parameters @{nodeID = $nodeId}
Write-Host "Disabled $($disableflowSourcesIds.Count) Flow Interface Sources for node with ID $nodeId. Total interface count $($interfaceIds.Count)"

# Enable Flow Sources
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.Netflow.Source -Verb EnableFlowSources -Arguments @(,$flowSourcesIds) | Out-Null
$enabledflowSourcesIds = Get-SwisData -SwisConnection $swis -Query "SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeID and Enabled = true" -Parameters @{nodeID = $nodeId}
Write-Host "Enabled $($enabledflowSourcesIds.Count) Flow Sources for Node with ID $nodeId. Total interface count $($flowSourcesIds.Count)"
# Enable Node and Interface Flow Sources
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.Netflow.NodeSources -Verb EnableFlowNodeSources -Arguments @(,@([int]$nodeId)) | Out-Null
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.Netflow.InterfaceSources -Verb EnableFlowInterfaceSources -Arguments @(,$interfaceIds) | Out-Null
$enabledflowSourcesIds = Get-SwisData -SwisConnection $swis -Query "SELECT EntityID FROM Orion.Netflow.InterfaceSources WHERE NodeID = @nodeID and Enabled = true" -Parameters @{nodeID = $nodeId}
Write-Host "Enabled $($enabledflowSourcesIds.Count) Flow Interface Sources for Node with ID $nodeId. Total interface count $($interfaceIds.Count)"