Skip to content

Commit

Permalink
Merge pull request #42 from radek-necas2-sw/master
Browse files Browse the repository at this point in the history
Adding examples for Netflow.
  • Loading branch information
danjagnow committed Oct 25, 2019
2 parents aeb5e5b + 615c532 commit 3a1b45b
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 0 deletions.
55 changes: 55 additions & 0 deletions samples/nta_add_cbqos_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from __future__ import print_function
import re
import requests
from orionsdk import SwisClient

def main():
# Connect to SWIS
server = 'localhost'
username = 'admin'
password = ''
swis = SwisClient(server, username, password)

engine_id = 1
node_caption = 'example.com'
node_props = {
'IPAddress': '1.1.1.2',
'EngineID': engine_id,
'Caption': node_caption,
'ObjectSubType': 'SNMP',
'Community': 'public',
'SNMPVersion': 2,
'DNS': '',
'SysName': ''
}

# Add node
swis.create('Orion.Nodes', **node_props)
query_results = swis.query('SELECT NodeID FROM Orion.Nodes WHERE Caption = @caption_par', caption_par=node_caption)
node_id = query_results['results'][0]['NodeID']
print('New node with ID {0} created'.format(node_id))

# Discovere and add interfaces
results = swis.invoke('Orion.NPM.Interfaces', 'DiscoverInterfacesOnNode', node_id)
swis.invoke('Orion.NPM.Interfaces', 'AddInterfacesOnNode', node_id, results['DiscoveredInterfaces'], 'AddDefaultPollers')
query_results = swis.query('SELECT InterfaceID FROM Orion.NPM.Interfaces WHERE NodeID = @node_id_par', node_id_par=node_id)
print('Discovered and added {0} interfaces for node with id {1}'.format(len(query_results['results']), node_id))

# Add CBQoS source for every interface
for row in query_results['results']:
props = {
'NodeID': node_id,
'InterfaceID': row['InterfaceID'],
'EngineID': engine_id,
'Enabled': True
}

swis.create('Orion.Netflow.CBQoSSource', **props)

query_results = swis.query('SELECT CBQoSSourceID FROM Orion.Netflow.CBQoSSource WHERE NodeID = @node_id_par', node_id_par=node_id)
print('Added {0} CBQoS sources for node with id {1}'.format(len(query_results['results']), node_id))


if __name__ == '__main__':
main()

46 changes: 46 additions & 0 deletions samples/nta_add_flow_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from __future__ import print_function
import re
import requests
from orionsdk import SwisClient

def main():
# Connect to SWIS
server = 'localhost'
username = 'admin'
password = ''
swis = SwisClient(server, username, password)

engine_id = 1
node_caption = 'example.com'
node_props = {
'IPAddress': '10.0.0.1',
'EngineID': engine_id,
'Caption': node_caption,
'ObjectSubType': 'SNMP',
'Community': 'public',
'SNMPVersion': 2,
'DNS': '',
'SysName': ''
}

# Add node
swis.create('Orion.Nodes', **node_props)
query_results = swis.query('SELECT NodeID FROM Orion.Nodes WHERE Caption = @caption_par', caption_par=node_caption)
node_id = query_results['results'][0]['NodeID']
print('New node with ID {0} created'.format(node_id))

# Discovere and add interfaces
results = swis.invoke('Orion.NPM.Interfaces', 'DiscoverInterfacesOnNode', node_id)
swis.invoke('Orion.NPM.Interfaces', 'AddInterfacesOnNode', node_id, results['DiscoveredInterfaces'], 'AddDefaultPollers')
query_results = swis.query('SELECT InterfaceID FROM Orion.NPM.Interfaces WHERE NodeID = @node_id_par', node_id_par=node_id)
print('Discovered and added {0} interfaces for node with id {1}'.format(len(query_results['results']), node_id))
interface_ids = [ r['InterfaceID'] for r in query_results['results'] ]

# Add Flow sources for every interface - enable flow collection on every interface
swis.invoke('Orion.Netflow.Source', 'EnableFlowSources', interface_ids, 'AddDefaultPollers')
query_results = swis.query('SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @node_id_par', node_id_par=node_id)
print('Added {0} Flow sources for node with id {1}'.format(len(query_results['results']), node_id))


if __name__ == '__main__':
main()
31 changes: 31 additions & 0 deletions samples/nta_change_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import print_function
import re
import requests
import pprint
from orionsdk import SwisClient

def main():
# Connect to SWIS
server = 'localhost'
username = 'admin'
password = ''
swis = SwisClient(server, username, password)

# List available Orion Settings
# Uncomment if you want to get all available Orion Settings
# query_results = swis.query('SELECT SettingID, Name, Description, Units, Minimum, Maximum, CurrentValue, DefaultValue, Hint FROM Orion.Settings')
# pprint.pprint(query_results['results'])

setting_id = 'CBQoS_Enabled'
query_results = swis.query('SELECT Uri FROM Orion.Settings WHERE SettingID = @settingid_par', settingid_par=setting_id)
uri = query_results['results'][0]['Uri']
props = {
'CurrentValue': 0 # Change this value to 1 to enable setting
}
swis.update(uri, **props)
query_results = swis.query('SELECT SettingID, Name, Description, Units, Minimum, Maximum, CurrentValue, DefaultValue, Hint FROM Orion.Settings WHERE SettingID = @settingid_par', settingid_par=setting_id)
print('Status of the setting {0} after the change'.format(setting_id))
pprint.pprint(query_results['results'])

if __name__ == '__main__':
main()
56 changes: 56 additions & 0 deletions samples/nta_download_router_config_from_ncm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from __future__ import print_function
import re
import requests
import pprint
from orionsdk import SwisClient

def main():
# Connect to SWIS
server = 'localhost'
username = 'admin'
password = ''
swis = SwisClient(server, username, password)

node_name = 'example.com'
interface_name = 'GigabitEthernet0/1'

# Get information about requested node and interface
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_par AND s.Interface.InterfaceName = @interfacename_par
'''
params = {
'nodename_par': node_name,
'interfacename_par': interface_name
}
query_results = swis.query(query, **params)
print('Netflow source information for node {0} and interface {1}'.format(node_name, interface_name))
pprint.pprint(query_results['results'])
node_id = query_results['results'][0]['NodeID']

# Download node configuration from NCM
query = '''
SELECT TOP 1 C.NodeID AS NcmNodeId, C.NodeProperties.CoreNodeId, C.DownloadTime, C.ConfigType, C.Config
FROM NCM.ConfigArchive C
WHERE C.NodeProperties.CoreNodeID = @orionnodeid_par
ORDER BY C.DownloadTime DESC
'''
params = {
'orionnodeid_par': node_id
}

query_results = swis.query(query, **params)
last_config = query_results['results'][0]['Config']

# Uncomment if you want to write configuration to console
# print(last_config)

# You can analyze configuration manually or write some parser. To identify data related to concrete Netflow Source
# you can use retrieved information from the first query


if __name__ == '__main__':
main()
33 changes: 33 additions & 0 deletions samples/nta_enable_disable_alert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import print_function
import re
import requests
import pprint
from orionsdk import SwisClient

def main():
# Connect to SWIS
server = 'localhost'
username = 'admin'
password = ''
swis = SwisClient(server, username, password)

alert_name = 'NTA Alert on machine-hostname'
query_results = swis.query('Select Uri FROM Orion.AlertConfigurations WHERE Name = @alertname_par', alertname_par=alert_name)
uri = query_results['results'][0]['Uri']

# Disable alert
props = {
'Enabled': False
}
swis.update(uri, **props)

# Enable alert
props = {
'Enabled': True
}
swis.update(uri, **props)


if __name__ == '__main__':
main()

35 changes: 35 additions & 0 deletions samples/nta_enable_disable_cbqos_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import print_function
import re
import requests
import pprint
from orionsdk import SwisClient

def main():
# Connect to SWIS
server = 'localhost'
username = 'admin'
password = ''
swis = SwisClient(server, username, password)

# Disable/Enable CBQoS Sources
node_caption = 'My testing router'
query_results = swis.query('SELECT NodeID FROM Orion.Nodes WHERE Caption = @nodecaption_par', nodecaption_par=node_caption)
node_id = query_results['results'][0]['NodeID']
query_results = swis.query('SELECT Uri FROM Orion.Netflow.CBQoSSource WHERE NodeID = @nodeid_par', nodeid_par = node_id)
enabled_flag = False # Change this value to True if you want to enable sources
props = {
'Enabled': enabled_flag
}

for row in query_results['results']:
swis.update(row['Uri'], **props)

# Print results
query_results = swis.query('SELECT CBQoSSourceID FROM Orion.Netflow.CBQoSSource WHERE NodeID = @nodeid_par and Enabled = @enabled_par',
nodeid_par=node_id, enabled_par=enabled_flag)
print('Changed enabled status to {0} for {1} CBQoS sources for node with ID {2}'
.format(enabled_flag, len(query_results['results']), node_id))


if __name__ == '__main__':
main()
33 changes: 33 additions & 0 deletions samples/nta_enable_disable_flow_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import print_function
import re
import requests
import pprint
from orionsdk import SwisClient

def main():
# Connect to SWIS
server = 'localhost'
username = 'admin'
password = ''
swis = SwisClient(server, username, password)

# Get data required for configuration
node_caption = 'My test node'
query_results = swis.query('SELECT NodeID FROM Orion.Nodes WHERE Caption = @nodecaption_par', nodecaption_par=node_caption)
node_id = query_results['results'][0]['NodeID']
query_results = swis.query('SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeid_par', nodeid_par = node_id)
netflow_sources_ids = [ r['NetflowSourceID'] for r in query_results['results'] ]

# Disable Flow Sources
swis.invoke('Orion.Netflow.Source', 'DisableFlowSources', netflow_sources_ids)
query_results = swis.query('SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeid_par and Enabled = false', nodeid_par = node_id)
print('Disabled {0} Flow Sources for node with ID {1}'.format(len(query_results['results']), node_id))

# Enable Flow Sources
swis.invoke('Orion.Netflow.Source', 'EnableFlowSources', netflow_sources_ids)
query_results = swis.query('SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeid_par and Enabled = true', nodeid_par = node_id)
print('Enabled {0} Flow Sources for node with ID {1}'.format(len(query_results['results']), node_id))


if __name__ == '__main__':
main()

0 comments on commit 3a1b45b

Please sign in to comment.