Skip to content

Commit

Permalink
V1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaclawik committed Sep 15, 2022
1 parent 04a469e commit 359a0a7
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 70 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
9/15/2022 - Version 1.1

CHANGELOG:
- Snapshot result is now renamed to "%y%m%d-%H%M%S-Report.png"
- Results are also sent to "reports" directory
- Added progress bar
- Added title font
44 changes: 27 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@

This is a command-line tool that uses the [SumoLogic Python SDK](https://github.com/SumoLogic/sumologic-python-sdk) to generate a dashboard report. For more information on the SumoLogic API, [view the documentation here.](https://api.us2.sumologic.com/docs/#section/Getting-Started)

### Usage
### Configuration

In *config.ini* you can change several values that will allow you to access your SumoLogic API. They are as follows:

1. accessID
* Your API Access ID.
2. accessKey
* Your API Access Key.
3. dashboardID
* The ID of the dashboard you want to generate a report on.
4. actionType
* Only one action type right now, so leave this be.
5. exportFormat
* Png
* Pdf
6. timezone
* [IANA Format](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List)
7. template
* "DashboardTemplate" is the default.
* "DashboardReportModeTemplate" is a printer-friendly version.
1. accessID
* Your API Access ID.
2. accessKey
* Your API Access Key.
3. dashboardID
* The ID of the dashboard you want to generate a report on.
4. actionType
* Only one action type at the moment.
5. exportFormat
* Png
* Pdf
6. timezone
* [IANA Format](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List)
7. template
* "DashboardTemplate" is the default.
* "DashboardReportModeTemplate" is a printer-friendly version.

### Usage

Once you have setup your config file, you can run *sumotool.exe* and it will produce a snapshot of your specified dashboard. The snapshot is titled with a format of *%Yr%Mo%Day-%Hr%Min%Sec-Report.png* and is saved into *./reports/*.

### Credits

1. [SumoLogic Python SDK](https://github.com/SumoLogic/sumologic-python-sdk)
2. [Progress Bar](https://gist.github.com/vladignatyev/06860ec2040cb497f0f3)
3. [Pyfiglet](https://github.com/pwaller/pyfiglet)
53 changes: 0 additions & 53 deletions main.py

This file was deleted.

79 changes: 79 additions & 0 deletions sumotool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import sys
import time
import configparser
import shutil
import os
import pathlib
from datetime import datetime
from pyfiglet import Figlet
from lib.sumologic import SumoLogic

cwd = pathlib.Path().resolve()

config = configparser.ConfigParser()
config.read("config.ini")
now = datetime.now()
c_date = now.strftime("%y/%m/%d")
c_time = now.strftime("%H:%M:%S")
f_datetime = now.strftime("%y%m%d-%H%M%S")
f = Figlet(font='smslant')
print(f.renderText('SumoLogic SDK'))
print("The date is " + c_date + " and the time is currently " + c_time)

args = sys.argv
accessID = config['API']['accessID']
accessKey = config['API']['accessKey']
sumo = SumoLogic(accessID, accessKey)
dashID = config['REPORT']['dashboardID']
actionType = config['REPORT']['actionType']
exportFormat = config['REPORT']['exportFormat']
timezone = config['REPORT']['timezone']
template = config['REPORT']['template']

def main():
time.sleep(3)
reportID = sumo.start_report(actionType, exportFormat, timezone, template, dashID)
print("Report Job ID: " + reportID)
keepGoing = True
count = 0
total = 43
while (keepGoing):
reportStatus = sumo.report_status(reportID)
if reportStatus == "InProgress":
progress(count, total)
time.sleep(0.5)
count += 1
continue
elif reportStatus == "Failed":
print("ERROR: Report Job Has Failed")
keepGoing = False
elif reportStatus == "Success":
print("SUCCESS: Report Job Complete")
time.sleep(0.5)
reportGenerate = sumo.report_result(reportID)
rename_and_move()
print("SUCCESS: Report Generation Complete")
keepGoing = False


def progress(count, total):
status = "Report Job In Progress..."
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s %s\r' % (bar, percents, '%', status))
sys.stdout.flush()


def rename_and_move():
filename = f_datetime + "-Report.png"
src = str(cwd) + "\\result.png"
dst = "../reports/"
os.rename(src, filename)
report = "./" + filename
shutil.copy(report, dst)
os.remove(filename)

if __name__ == "__main__":
main()

0 comments on commit 359a0a7

Please sign in to comment.