Insights 3rd Party Integration
The Nexus Dashboard Insights service is capable of integrating with 3rd party applications/environments in one of the following 3 ways:
Streaming data to an existing Kafka bus
- Uses a push mechanism to send data
- Encodes the messages in JSON format
Sending syslog messages to a central syslog server
- Uses a push mechanism to send data
- Encodes the messages in Syslog format
Using the API to pull data from the system
- Uses a pull mechanism to retrieve data
- Encodes the messages in JSON format
In the following sections, we will look specifically at streaming data to an existing Kafka bus.
In this example we will use Nexus Dashboard Insights to stream audit logs to an existing Kafka Cluster. These messages are then consumed by a Python script and posted to a WebEx chat room by a specific user.
Prerequisites
Before you proceed with NDI configuration, you must have:
General understanding and familiarity with Kafka concepts, terminology, and configuration.
You can learn more about Kafka from Kafka documentation.
A Kafka Cluster configured.
This example uses a preconfigured Kafka server with the following settings:
- The existing Kafka Cluster used in this example consists of a single server.
- The server is not using any kind of authentication or encryption.
- The broker IP and port:
192.168.10.49:9092
, Topic isNI62
.
For more information on how to set up a Kafka server, visit the Apache Kafka Quickstart Guide.
Configure NDI Message Bus
Log in to your Nexus Dashboard Insights
In the Overview page, select the site group and choose "Configure Site Group*.
In the Configure Site Group page, choose the Export Data tab.
In the Message Bus Configuration tile, click +Add New.
In the Message Bus Configuration dialog, choose the site, provide the Kafka server information, and select the data to send.
Create Python Script to Consume Messages
The following script consumes the message of the topic NI62 and outputs them in JSON format on the console.
import requests
from kafka import KafkaConsumer
from pymongo import MongoClient
from json import loads
import json
# Connect to Broker to topic NI62cd /op
consumer = KafkaConsumer(
'NI62',
bootstrap_servers=['192.168.10.49:9092'],
auto_offset_reset='earliest',
enable_auto_commit=True,
group_id='my-group',
value_deserializer=lambda x: loads(x.decode('utf-8')))
# Read and print message from consumer
for msg in consumer:
message = msg.value
print(json.dumps(message, sort_keys=True, indent=4))
# Terminate the script
sys.exit()
Example output of the above script:
# python3 kafka-ni.py
{
"auditCode": 4214451,
"auditId": 4295363777,
"changeSet": "adminSt (Old: disabled, New: enabled)",
"className": "qosDppPol",
"configDn": "uni/tn-Customer-A/qosdpppol-backend",
"createTime": "2023-03-02T14:44:55.549Z",
"descr": "DppPol backend modified",
"fabricName": "ACI_ERL",
"modType": "modification",
"nodeName": "apic1-erl",
"nodeType": "apic",
"severity": "info",
"txId": 576460752331777947,
"type": "auditlog",
"user": "camillo",
"vendor": "CISCO_ACI"
}
Python Script to Consume Messages and Post Them to WebEx
Another Python script is used to listen to the messages on Kafka bus and post them as a specific user to a specific WebEx room for testing purposes. You could expand on this idea by filtering for specific messages to be posted to different rooms or even use a WebEx bot to take over this task. More details about WebEx API, bots, integrations can be found at https://developer.webex.com.
Obtain a
BEARER-TOKEN
used to log in to WebEx API and a WebEx room ID where you want to post the messages.To get the
BEARER-TOKEN
, follow the instructions described in Getting Started with the Webex API.Obtain the WebEx room ID.
You can run the following Python script to get all room IDs of type
group
for your user name:import requests from json import loads import json url = " https://webexapis.com/v1/rooms?type=group" headers = { 'Authorization': 'Bearer BEARER-TOKEN', 'Content-Type': 'application/json' } response = requests.request("GET", url, headers=headers, data = payload) print(json.dumps(response, sort_keys=True, indent=4))
And then filtering the response based on the
title
of the room (for example,Support-Team
) and copy itsid
:{ "items": [ { "id": "ROOMID", "title": "Support-Team", "type": "group", "isLocked": false, "lastActivity": "2023-03-08T23:28:43.850Z", "creatorId": "CREATORID", "created": "2023-03-02T22:53:44.342Z", "ownerId": "OWNERID", "isPublic": false, "isReadOnly": false } }
Use the
BEARER-TOKEN
and theROOMID
you obtained in the previous steps to post messages.import requests from kafka import KafkaConsumer from pymongo import MongoClient from json import loads import json url = "https://webexapis.com/v1/messages" #Login Data to WebEx (put BEARER-TOKEN here) headers = { 'Authorization': 'Bearer BEARER-TOKEN', 'Content-Type': 'application/json' } # Connect to Kafka Bus as consumer consumer = KafkaConsumer( 'nirstats', bootstrap_servers=['192.168.10.245:9092'], auto_offset_reset='earliest', enable_auto_commit=True, group_id='my-group', value_deserializer=lambda x: loads(x.decode('utf-8'))) # Read a message from topic as consumer and post it into the WebEx Room (put room id here) for msg in consumer: message = msg.value payload_message = "Fabric=%s, Type=%s, Object=%s, Description=%s\n"%(message['fabricName'], message["anomalyType"], message["entityName"], message["description"]) payload = "{\n "roomId": "ROOMID",\n %s\n}", payload_message response = requests.request("POST", url, headers=headers, data = payload) # Terminate the script sys.exit()