Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Updated to support python3 and added usage info for Mac & Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasHocker committed Apr 10, 2018
1 parent 56b838e commit a27b3b2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
41 changes: 41 additions & 0 deletions ExcelExport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,44 @@ This example demonstrates the use of Topology endpoints and small amounts of cod
- Somehow show multiple IPs & ports better in the spreadsheet
- Incorporate Application & Service data as well
- Explore real-world possible uses

## Getting Started
This example app is very simple and does not have much logic built in. On most OSes you'll already have python, but here are more detailed steps in case you're missing dependencies:
### Most Linux varients (assuming yum packages, sub in your package manager where necessary)
- Run: which python >/dev/null || sudo yum -y install python
- Run: which pip >/dev/null || sudo yum -y install python2-pip
- Run: sudo pip install pycurl
- Run: sudo pip install certifi
- Run: sudo pip install openpyxl
- Edit: dt-excel.py, change variable in SETUP VARIABLES section
- Run: python dt-excel.py

### MacOS (High Sierra)
- Run: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Run: brew install openssl
- Run: brew install python
- Confirm: "which python3" gives /usr/local/bin/python3
- Run: sudo pip3 install --upgrade pip
- Run: pip3 install --user --install-option="--with-openssl" --install-option="--openssl-dir=/usr/local/opt/openssl" pycurl
- Run: pip3 install --user openpyxl
- Run: pip3 install --user certifi
- Edit: dt-excel.py, change variable in SETUP VARIABLES section
- Run: python3 dt-excel.py

### Windows
- Download latest: https://www.python.org/downloads/windows
- Install: be sure to pick options for "add to PATH" and "include PIP"
- Open command prompt
- Run: pip install pycurl
- Run: pip install certifi
- Run: pip install openpyxl
- Edit: dt-excel.py, change variable in SETUP VARIABLES section
- Run: python dt-excel.py

## Troubleshooting
- Status: 401
- - Your API token didn't work, please check the token and URL
- Status: 400
- - Your URL is incorrect
- Dependency or module not found errors
- - Your python install is incorrect or modules are missing, try the pip steps again and check for any errors there
16 changes: 8 additions & 8 deletions ExcelExport/dt-excel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pycurl
import json
import csv
from StringIO import StringIO
import certifi
import io
from openpyxl import Workbook
from openpyxl.styles import Alignment,Font

Expand All @@ -16,15 +17,16 @@

### function to go get the data
def dtApiQuery(endpoint):
buffer=StringIO()
buffer=io.BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, URL + endpoint)
c.setopt(pycurl.CAINFO, certifi.where())
c.setopt(c.HTTPHEADER, ['Authorization: Api-Token ' + APITOKEN] )
c.setopt(pycurl.WRITEFUNCTION, buffer.write)
c.perform()
print('Status: %d' % c.getinfo(c.RESPONSE_CODE))
c.close()
return(buffer)
return(buffer.getvalue().decode('UTF-8'))


### Setup workbook
Expand All @@ -34,14 +36,13 @@ def dtApiQuery(endpoint):
wsProcess = wb.create_sheet("processes")
wsProcessProcess = wb.create_sheet("process-process")
wsProcessHost = wb.create_sheet("process-host")
wb.remove_sheet(wb.active)
wb.remove(wb.active)



### Get & Process hosts data
hostsIO=dtApiQuery('entity/infrastructure/hosts')
#print(hostsIO.getvalue())
hosts=json.loads(hostsIO.getvalue())
hosts=json.loads(hostsIO)

wsHosts.append( ['hostId','displayName','osType','osVersion','hypervisorType','ipAddress1','ipAddress2','ipAddress3'] )
for host in hosts:
Expand All @@ -67,8 +68,7 @@ def dtApiQuery(endpoint):

### Get & Process processes data
processesIO=dtApiQuery('entity/infrastructure/processes')
#print(processesIO.getvalue())
processes=json.loads(processesIO.getvalue())
processes=json.loads(processesIO)

wsProcess.append( ['processId','displayName','softwareType','softwareVersion','port1','port2','port3','port4','port5'] )
for process in processes:
Expand Down

0 comments on commit a27b3b2

Please sign in to comment.