|
| 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() |
0 commit comments