Skip to content

Commit 3a1b45b

Browse files
authored
Merge pull request solarwinds#42 from radek-necas2-sw/master
Adding examples for Netflow.
2 parents aeb5e5b + 615c532 commit 3a1b45b

7 files changed

+289
-0
lines changed

samples/nta_add_cbqos_sources.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from __future__ import print_function
2+
import re
3+
import requests
4+
from orionsdk import SwisClient
5+
6+
def main():
7+
# Connect to SWIS
8+
server = 'localhost'
9+
username = 'admin'
10+
password = ''
11+
swis = SwisClient(server, username, password)
12+
13+
engine_id = 1
14+
node_caption = 'example.com'
15+
node_props = {
16+
'IPAddress': '1.1.1.2',
17+
'EngineID': engine_id,
18+
'Caption': node_caption,
19+
'ObjectSubType': 'SNMP',
20+
'Community': 'public',
21+
'SNMPVersion': 2,
22+
'DNS': '',
23+
'SysName': ''
24+
}
25+
26+
# Add node
27+
swis.create('Orion.Nodes', **node_props)
28+
query_results = swis.query('SELECT NodeID FROM Orion.Nodes WHERE Caption = @caption_par', caption_par=node_caption)
29+
node_id = query_results['results'][0]['NodeID']
30+
print('New node with ID {0} created'.format(node_id))
31+
32+
# Discovere and add interfaces
33+
results = swis.invoke('Orion.NPM.Interfaces', 'DiscoverInterfacesOnNode', node_id)
34+
swis.invoke('Orion.NPM.Interfaces', 'AddInterfacesOnNode', node_id, results['DiscoveredInterfaces'], 'AddDefaultPollers')
35+
query_results = swis.query('SELECT InterfaceID FROM Orion.NPM.Interfaces WHERE NodeID = @node_id_par', node_id_par=node_id)
36+
print('Discovered and added {0} interfaces for node with id {1}'.format(len(query_results['results']), node_id))
37+
38+
# Add CBQoS source for every interface
39+
for row in query_results['results']:
40+
props = {
41+
'NodeID': node_id,
42+
'InterfaceID': row['InterfaceID'],
43+
'EngineID': engine_id,
44+
'Enabled': True
45+
}
46+
47+
swis.create('Orion.Netflow.CBQoSSource', **props)
48+
49+
query_results = swis.query('SELECT CBQoSSourceID FROM Orion.Netflow.CBQoSSource WHERE NodeID = @node_id_par', node_id_par=node_id)
50+
print('Added {0} CBQoS sources for node with id {1}'.format(len(query_results['results']), node_id))
51+
52+
53+
if __name__ == '__main__':
54+
main()
55+

samples/nta_add_flow_sources.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from __future__ import print_function
2+
import re
3+
import requests
4+
from orionsdk import SwisClient
5+
6+
def main():
7+
# Connect to SWIS
8+
server = 'localhost'
9+
username = 'admin'
10+
password = ''
11+
swis = SwisClient(server, username, password)
12+
13+
engine_id = 1
14+
node_caption = 'example.com'
15+
node_props = {
16+
'IPAddress': '10.0.0.1',
17+
'EngineID': engine_id,
18+
'Caption': node_caption,
19+
'ObjectSubType': 'SNMP',
20+
'Community': 'public',
21+
'SNMPVersion': 2,
22+
'DNS': '',
23+
'SysName': ''
24+
}
25+
26+
# Add node
27+
swis.create('Orion.Nodes', **node_props)
28+
query_results = swis.query('SELECT NodeID FROM Orion.Nodes WHERE Caption = @caption_par', caption_par=node_caption)
29+
node_id = query_results['results'][0]['NodeID']
30+
print('New node with ID {0} created'.format(node_id))
31+
32+
# Discovere and add interfaces
33+
results = swis.invoke('Orion.NPM.Interfaces', 'DiscoverInterfacesOnNode', node_id)
34+
swis.invoke('Orion.NPM.Interfaces', 'AddInterfacesOnNode', node_id, results['DiscoveredInterfaces'], 'AddDefaultPollers')
35+
query_results = swis.query('SELECT InterfaceID FROM Orion.NPM.Interfaces WHERE NodeID = @node_id_par', node_id_par=node_id)
36+
print('Discovered and added {0} interfaces for node with id {1}'.format(len(query_results['results']), node_id))
37+
interface_ids = [ r['InterfaceID'] for r in query_results['results'] ]
38+
39+
# Add Flow sources for every interface - enable flow collection on every interface
40+
swis.invoke('Orion.Netflow.Source', 'EnableFlowSources', interface_ids, 'AddDefaultPollers')
41+
query_results = swis.query('SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @node_id_par', node_id_par=node_id)
42+
print('Added {0} Flow sources for node with id {1}'.format(len(query_results['results']), node_id))
43+
44+
45+
if __name__ == '__main__':
46+
main()

samples/nta_change_settings.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from __future__ import print_function
2+
import re
3+
import requests
4+
import pprint
5+
from orionsdk import SwisClient
6+
7+
def main():
8+
# Connect to SWIS
9+
server = 'localhost'
10+
username = 'admin'
11+
password = ''
12+
swis = SwisClient(server, username, password)
13+
14+
# List available Orion Settings
15+
# Uncomment if you want to get all available Orion Settings
16+
# query_results = swis.query('SELECT SettingID, Name, Description, Units, Minimum, Maximum, CurrentValue, DefaultValue, Hint FROM Orion.Settings')
17+
# pprint.pprint(query_results['results'])
18+
19+
setting_id = 'CBQoS_Enabled'
20+
query_results = swis.query('SELECT Uri FROM Orion.Settings WHERE SettingID = @settingid_par', settingid_par=setting_id)
21+
uri = query_results['results'][0]['Uri']
22+
props = {
23+
'CurrentValue': 0 # Change this value to 1 to enable setting
24+
}
25+
swis.update(uri, **props)
26+
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)
27+
print('Status of the setting {0} after the change'.format(setting_id))
28+
pprint.pprint(query_results['results'])
29+
30+
if __name__ == '__main__':
31+
main()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from __future__ import print_function
2+
import re
3+
import requests
4+
import pprint
5+
from orionsdk import SwisClient
6+
7+
def main():
8+
# Connect to SWIS
9+
server = 'localhost'
10+
username = 'admin'
11+
password = ''
12+
swis = SwisClient(server, username, password)
13+
14+
node_name = 'example.com'
15+
interface_name = 'GigabitEthernet0/1'
16+
17+
# Get information about requested node and interface
18+
query = '''
19+
SELECT s.NetflowSourceID, s.NodeID, s.InterfaceID, s.Enabled, s.LastTimeFlow, s.LastTime, s.EngineID,
20+
s.Node.NodeName,
21+
s.Interface.Name as InterfaceName, s.Interface.Index as RouterIndex
22+
FROM Orion.Netflow.Source s
23+
WHERE s.Node.NodeName = @nodename_par AND s.Interface.InterfaceName = @interfacename_par
24+
'''
25+
params = {
26+
'nodename_par': node_name,
27+
'interfacename_par': interface_name
28+
}
29+
query_results = swis.query(query, **params)
30+
print('Netflow source information for node {0} and interface {1}'.format(node_name, interface_name))
31+
pprint.pprint(query_results['results'])
32+
node_id = query_results['results'][0]['NodeID']
33+
34+
# Download node configuration from NCM
35+
query = '''
36+
SELECT TOP 1 C.NodeID AS NcmNodeId, C.NodeProperties.CoreNodeId, C.DownloadTime, C.ConfigType, C.Config
37+
FROM NCM.ConfigArchive C
38+
WHERE C.NodeProperties.CoreNodeID = @orionnodeid_par
39+
ORDER BY C.DownloadTime DESC
40+
'''
41+
params = {
42+
'orionnodeid_par': node_id
43+
}
44+
45+
query_results = swis.query(query, **params)
46+
last_config = query_results['results'][0]['Config']
47+
48+
# Uncomment if you want to write configuration to console
49+
# print(last_config)
50+
51+
# You can analyze configuration manually or write some parser. To identify data related to concrete Netflow Source
52+
# you can use retrieved information from the first query
53+
54+
55+
if __name__ == '__main__':
56+
main()

samples/nta_enable_disable_alert.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from __future__ import print_function
2+
import re
3+
import requests
4+
import pprint
5+
from orionsdk import SwisClient
6+
7+
def main():
8+
# Connect to SWIS
9+
server = 'localhost'
10+
username = 'admin'
11+
password = ''
12+
swis = SwisClient(server, username, password)
13+
14+
alert_name = 'NTA Alert on machine-hostname'
15+
query_results = swis.query('Select Uri FROM Orion.AlertConfigurations WHERE Name = @alertname_par', alertname_par=alert_name)
16+
uri = query_results['results'][0]['Uri']
17+
18+
# Disable alert
19+
props = {
20+
'Enabled': False
21+
}
22+
swis.update(uri, **props)
23+
24+
# Enable alert
25+
props = {
26+
'Enabled': True
27+
}
28+
swis.update(uri, **props)
29+
30+
31+
if __name__ == '__main__':
32+
main()
33+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import print_function
2+
import re
3+
import requests
4+
import pprint
5+
from orionsdk import SwisClient
6+
7+
def main():
8+
# Connect to SWIS
9+
server = 'localhost'
10+
username = 'admin'
11+
password = ''
12+
swis = SwisClient(server, username, password)
13+
14+
# Disable/Enable CBQoS Sources
15+
node_caption = 'My testing router'
16+
query_results = swis.query('SELECT NodeID FROM Orion.Nodes WHERE Caption = @nodecaption_par', nodecaption_par=node_caption)
17+
node_id = query_results['results'][0]['NodeID']
18+
query_results = swis.query('SELECT Uri FROM Orion.Netflow.CBQoSSource WHERE NodeID = @nodeid_par', nodeid_par = node_id)
19+
enabled_flag = False # Change this value to True if you want to enable sources
20+
props = {
21+
'Enabled': enabled_flag
22+
}
23+
24+
for row in query_results['results']:
25+
swis.update(row['Uri'], **props)
26+
27+
# Print results
28+
query_results = swis.query('SELECT CBQoSSourceID FROM Orion.Netflow.CBQoSSource WHERE NodeID = @nodeid_par and Enabled = @enabled_par',
29+
nodeid_par=node_id, enabled_par=enabled_flag)
30+
print('Changed enabled status to {0} for {1} CBQoS sources for node with ID {2}'
31+
.format(enabled_flag, len(query_results['results']), node_id))
32+
33+
34+
if __name__ == '__main__':
35+
main()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from __future__ import print_function
2+
import re
3+
import requests
4+
import pprint
5+
from orionsdk import SwisClient
6+
7+
def main():
8+
# Connect to SWIS
9+
server = 'localhost'
10+
username = 'admin'
11+
password = ''
12+
swis = SwisClient(server, username, password)
13+
14+
# Get data required for configuration
15+
node_caption = 'My test node'
16+
query_results = swis.query('SELECT NodeID FROM Orion.Nodes WHERE Caption = @nodecaption_par', nodecaption_par=node_caption)
17+
node_id = query_results['results'][0]['NodeID']
18+
query_results = swis.query('SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeid_par', nodeid_par = node_id)
19+
netflow_sources_ids = [ r['NetflowSourceID'] for r in query_results['results'] ]
20+
21+
# Disable Flow Sources
22+
swis.invoke('Orion.Netflow.Source', 'DisableFlowSources', netflow_sources_ids)
23+
query_results = swis.query('SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeid_par and Enabled = false', nodeid_par = node_id)
24+
print('Disabled {0} Flow Sources for node with ID {1}'.format(len(query_results['results']), node_id))
25+
26+
# Enable Flow Sources
27+
swis.invoke('Orion.Netflow.Source', 'EnableFlowSources', netflow_sources_ids)
28+
query_results = swis.query('SELECT NetflowSourceID FROM Orion.Netflow.Source WHERE NodeID = @nodeid_par and Enabled = true', nodeid_par = node_id)
29+
print('Enabled {0} Flow Sources for node with ID {1}'.format(len(query_results['results']), node_id))
30+
31+
32+
if __name__ == '__main__':
33+
main()

0 commit comments

Comments
 (0)