Skip to content

Commit

Permalink
v1.2-final
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaclawik committed Sep 20, 2022
1 parent 24c9818 commit 1e2af55
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sumotool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SumoLogic Report Tool
# Created by Alex Waclawik
# Version 1.2

import sys
import time
import configparser
Expand All @@ -8,40 +12,51 @@
from pyfiglet import Figlet
from lib.sumologic import SumoLogic

# sets the path
cwd = pathlib.Path().resolve()

# initialize configparser
config = configparser.ConfigParser()
config.read("config.ini")
# initialize date and time, as well as declare date and time vars
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")
# startup font
f = Figlet(font='smslant')
print(f.renderText('SumoLogic SDK'))
print("The date is " + c_date + " and the time is currently " + c_time)

# initialize sumologic api
args = sys.argv
accessID = config['API']['accessID']
accessKey = config['API']['accessKey']
sumo = SumoLogic(accessID, accessKey)

def main():
time.sleep(1)
# get number of sections in config then subtract one to get number of reports
sections = config.sections()
num_of_reports = len(sections) - 1
for x in range(0, num_of_reports):
# check if report is enabled
reportName = 'REPORT_' + str(x)
reportStatus = config[reportName].getboolean('enabled')
if reportStatus == True:
# get the report job parameters from the config file
name = config[reportName]['name']
print("\n|--< Starting Job for '" + name + "' >--|")
dashID = config[reportName]['dashboardID']
actionType = config[reportName]['actionType']
exportFormat = config[reportName]['exportFormat']
timezone = config[reportName]['timezone']
template = config[reportName]['template']
# start the report job
reportID = sumo.start_report(actionType, exportFormat, timezone, template, dashID)
# wait for the report job to finish
get_panel(reportID)
# rename and move the file to its final location
savedFile = rename_and_move(name, exportFormat)
print("SUCCESS: The Panel Report '" + savedFile + "' has been saved")
else:
Expand All @@ -52,8 +67,10 @@ def get_panel(reportID):
keepGoing = True
start_time = time.time()
while (keepGoing):
# check the status of the report job
reportStatus = sumo.report_status(reportID)
if reportStatus == "InProgress":
# keeps track of the elapsed time, average is around 30 seconds
elap_time = round((time.time() - start_time), 2)
sys.stdout.write('...Job In Progress... Elapsed Time: %s\r' % (elap_time))
sys.stdout.flush()
Expand All @@ -63,22 +80,28 @@ def get_panel(reportID):
print("ERROR: Report Job Has Failed")
keepGoing = False
elif reportStatus == "Success":
# save the report and return
reportGenerate = sumo.report_result(reportID)
time.sleep(0.5)
print("\nSUCCESS: Report Job Complete")
keepGoing = False

def rename_and_move(name, format):
# determine the format
if format == "Png":
fileExt = ".png"
elif format == "Pdf":
fileExt = ".pdf"
# concatenate the output filename
filename = f_datetime + "_" + name + "_Report" + fileExt
# specificy source and destination
src = str(cwd) + "\\result.png"
dst = "../reports/"
# rename the file then copy it over to new destination
os.rename(src, filename)
report = "./" + filename
shutil.copy(report, dst)
# remove the source file
os.remove(filename)
return(filename)

Expand Down

0 comments on commit 1e2af55

Please sign in to comment.