Didn't the Software page used to have an export bu...
# fleet
s
Didn't the Software page used to have an export button?
d
hmmm. I don't think so? But now I'm second guessing myself. There is the export list of hosts that match the software you've filtered on. Is that what you're thinking?
s
No, we need the opposite... list of all software installed on specific hosts. I'm managing now with a MySQL query against the Fleet DB, but would be nice if my users could export and filter themselves.
d
https://fleetdm.com/docs/rest-api/rest-api#list-software will GET you all the software in json. I'll check with the product team to see if an export software button was removed recently.
@Shawn Maddock looks like we did not have an export button for the software list. I can create a Feature Request for this if you like, though. What format for the export would you want to see?
s
CSV would be best for us. Thank you for checking and creating the FR!
d
b
Confirmed this button never, ever existed with our longest-standing UI engineer. 🙂
She also said it sounded like a good FR!
s
lol I believed y'all
j
I wrote a python script to do this from the api a while back if you need it
Copy code
import json
import requests

import truststore

truststore.inject_into_ssl()

AUTH_TOKEN = ""
FLEET_URL = ""
REQUESTHEADERS = {"Authorization": f"Bearer {AUTH_TOKEN}"}


def request(method, path, **kwargs):
    response = requests.request(
        method, f"https://{FLEET_URL}/{path}", headers=REQUESTHEADERS, **kwargs
    )

    print({"Status Code": response.status_code})
    if response.status_code == 403:
        raise Exception("Access Denied")
    if response.status_code not in [200, 201]:
        print(
            {
                "Error": "Not 200 or 201",
                "Headers": response.headers,
                "Response": response.text,
                "StatusCode": response.status_code,
            }
        )

    return response


def csv_transform(software_json):
    import csv
    import io

    # csv module can write data in io.StringIO buffer only
    csv_memory = io.StringIO()

    csv.writer(csv_memory).writerow(
        ["ID", "Name", "Version", "Source", "Generated CPE", "Host Count"]
    )
    for software in software_json["software"]:
        csv.writer(csv_memory).writerow(
            [
                software["id"],
                software["name"],
                software["version"],
                software["source"],
                # software["release"],
                # software["vendor"],
                # software["arch"],
                software["generated_cpe"],
                software["hosts_count"],
            ]
        )
    return csv_memory.getvalue()


r = request(method="GET", path="/api/v1/fleet/software")
software_json = r.json()

# print(json.dumps(software_json, sort_keys=True, indent=4))
with open("software.json", "w") as outfile:
    outfile.write(json.dumps(software_json, sort_keys=True, indent=4))

with open("software.csv", "w") as outfile:
    outfile.write(csv_transform(software_json))