diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e84a818 --- /dev/null +++ b/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index dc8944a..072b02a 100644 --- a/README.md +++ b/README.md @@ -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) \ No newline at end of file diff --git a/main.py b/main.py deleted file mode 100644 index 85f95c9..0000000 --- a/main.py +++ /dev/null @@ -1,53 +0,0 @@ -import sys -import time -import configparser -import datetime - -from lib.sumologic import SumoLogic - -config = configparser.ConfigParser() -config.read("config.ini") -now = datetime.now() -c_datetime = now.strftime("%y/%m/%d_%H:%M:%S") -print(c_datetime) - -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 - while (keepGoing): - reportStatus = sumo.report_status(reportID) - if reportStatus == "InProgress": - print("Report Job In Progress...") - time.sleep(5) - continue; - elif reportStatus == "Failed": - print("ERROR: Report Job Has Failed") - keepGoing = False - elif reportStatus == "Success": - print("SUCCESS: Report Job Complete") - reportGenerate = sumo.report_result(reportID) - print(reportGenerate) - keepGoing = False - - -def get_time(): - t = now.strftime("%H:%M:%S") - return(t) - -if __name__ == "__main__": - main() diff --git a/sumotool.py b/sumotool.py new file mode 100644 index 0000000..294053e --- /dev/null +++ b/sumotool.py @@ -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() \ No newline at end of file