Created
July 13, 2016 15:46
-
-
Save badstreff/f851f5bd8b807f9b68e74ab79159541b to your computer and use it in GitHub Desktop.
Requires an export of the computers to run the report against and the installed software export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3 | |
# | |
# About: This script is designed to generate a report of an application | |
# Inputs: Path to the Installed Software export from LANrev, matplotlib | |
# Author: ajf023@shsu.edu | |
import sys | |
import getopt | |
import matplotlib.pyplot as plt | |
installed_software = [] | |
mac_status = {} | |
app = {"Installed": 0, "Missing": 0, "Offline": 0} | |
def populate_installed_software(path): | |
with open(path, encoding='utf-8') as f: | |
for line in f: | |
try: | |
# print(line) | |
parse = line.split(',') | |
# Skip nodes that are not in the computer list | |
if(parse[0][1:-1] not in mac_status): | |
continue | |
global installed_software | |
installed_software += [{"Agent Name": parse[0][1:-1], | |
"Inst. Software Name": parse[1][1:-1], | |
"Inst. Software Info": parse[2][1:-1], | |
"Inst. Software Version String": parse[3][1:-1], | |
"Inst. Software Size": parse[4][1:-1], | |
"Inst. Software Installation Date": parse[5][1:-1], | |
"Identification Type": parse[6][1:-1]}] | |
except: | |
pass | |
def populate_mac_status(path): | |
with open(path, encoding='utf-8') as f: | |
for line in f: | |
try: | |
parse = line.split(',') | |
mac_status[parse[1][1:-1]] = parse[0][1:-1] | |
except: | |
pass | |
def make_autopct(values): | |
def my_autopct(pct): | |
total = sum(values) | |
val = int(round(pct * total / 100.0)) | |
return '{p:.2f}% ({v:d})'.format(p=pct, v=val) | |
return my_autopct | |
def filter_computer(agent_name, software_list): | |
for item in software_list: | |
if(item["Agent Name"] == agent_name): | |
yield item | |
def plot(app_name, version): | |
for computer, status in mac_status.items(): | |
found = False | |
for item in filter_computer(computer, installed_software): | |
# print(item) | |
if item['Inst. Software Name'] == app_name: | |
# print(item) | |
if item['Inst. Software Version String'] == version: | |
app["Installed"] += 1 | |
else: | |
if mac_status[item["Agent Name"]] == "machine_not_available": | |
app["Offline"] += 1 | |
else: | |
app["Missing"] += 1 | |
found = True | |
if not found: | |
app["Missing"] += 1 | |
print(app) | |
# Plot Title | |
fig = plt.figure() | |
fig.suptitle(app_name + ' ' + version + ' Deployment', fontsize=14, fontweight='bold') | |
# Data to plot | |
labels = tuple(app.keys()) | |
sizes = list(app.values()) | |
colors = ['yellowgreen', 'lightcoral', 'lightskyblue'] | |
# Plot | |
plt.pie(sizes, labels=labels, colors=colors, | |
autopct=make_autopct(sizes), shadow=False, startangle=140) | |
plt.axis('equal') | |
plt.show() | |
def main(argv): | |
install_software_file = '' | |
computer_file = '' | |
app_name = '' | |
app_version = '' | |
try: | |
opts, args = getopt.getopt(argv, "hi:c:a:v", ["ifile=", "cfile=", "app=", "version="]) | |
except getopt.GetoptError: | |
print('test.py -i <installed_software_csv_path> -c <computers_csv_path> -a <app_name> -v <app_version>') | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print('generate_deployment_report.py -i <installedsoftwarefile> -c <computerfile>') | |
sys.exit() | |
elif opt in ("-i", "--ifile"): | |
install_software_file = arg | |
elif opt in ("-c", "--cfile"): | |
computer_file = arg | |
elif opt in ("-a", "--app"): | |
app_name = arg | |
elif opt in ("-v", "--version"): | |
app_version = arg | |
# if not install_software_file or not computer_file or not app_name or not app_version: | |
# print('test2.py -i <installed_software_csv_path> -c <computers_csv_path> -a <app_name> -v <app_version>') | |
# exit(1) | |
print(install_software_file) | |
print(computer_file) | |
print(app_name) | |
print(app_version) | |
populate_mac_status(computer_file) | |
populate_installed_software(install_software_file) | |
# print(mac_status) | |
plot(app_name, app_version) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment