DNASFirehose_MongoDB_Handler

This file is designed to create a simple interface between DNA Spaces Firehose stream, and MongoDB Atlas.

For those of you who are using a .io domain, please make sure you manually change domains.
This will be something I will add in the future, that domain will be held as a single variable.

If you have any questions or need help using the script please reach out!

image

image

How to run

Start by installing all prerequisites.
This can be done using the requirements.txt file.
There are a couple different ways to do this, so please see here.

Then I would suggest confirming whether you are an EU or IO customer.
You can tell this by which DNA Spaces domain you connect to https://dnaspaces.eu/ or https://dnaspaces.io.
If you are IO, please scroll through index.py, and change any refernce of .eu to .io.
I have commented on all so shouldnt be too taxing.
E.G. image

We then need our activation token from the DNA Spaces Partner platform.
This is found when activating an 'app' in DNA Spaces Partner Dashboard.
We wont use this until we run the script for the first time, so just hold onto it for now.
See screenshot below for more details.
image

You will also need a connection to a MongoDB Atlas account.
You can find this by hitting "connect" on your DB, then "Connect your application".
This will give you a URL you need to call to.
Paste this in as CONNECTION_STRING.
Again see the screenshots below for more details.
image
image
image
image
Obviously in this scenario, please fill in the pass with the one yopu just created.

Once this is done, simply run the index.py with 'python3 index.py'.
Firstly it will check to see if an API key already exists.
Assuming this is the first time you are running this file, it will not.
NOTE: If you ever want to change your API key, delete the contents of API_KEY.txt and run index.py again.
If no key exists, it will ask you to enter your activation token.
This is what we copied earlier, so paste in and hit enter.
image
The key will then be authenticated, and in doing so your 'app' will become activated in DNA Spaces.
image
image
This will also save your API key in API_KEY.txt.
NOTE: Your activation token and your API key are different things, an API key can be used over and over, and is how we get data from Spaces. An activation token is used once, and is how we activate an app in DNA Spaces, and how we get an API key.

From this point, data should start flowing in:
image
For debugging purposes, uncomment some of the prints in the bottom of the index.py to see what data is being sent.
image
E.G. image

If you have made it this far; well done, and if you have any issues or questions, please leave a comment or question or raise an issue in github.

published

View code on GitHub

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.