Ingest Report CSVΒΆ

This script submits each row of a CSV to TruSTAR as an incident report.

Reads reports from a CSV and submits them to TruSTAR.

from trustar import log, Report, TruStar
import csv

logger = log.get_logger(__name__)

# mapping of CSV column names to report fields
    "title": "name",
    "body": "content",
    "external_id": "id"

CSV_PATH = "reports.csv"

# initialize SDK
ts = TruStar()

# read in CSV
with open(CSV_PATH, 'r') as f:
    reader = csv.DictReader(f)

    # iterate over rows
    for row in reader:

        # define method to get report field from CSV row
        def get_field(field):
            return row.get(MAPPING.get(field))

        # construct report from CSV row
        report = Report(title=get_field('title'),

        # submit report
        ts.submit_report(report)"Submitted report: %s" % report)

Below is an example of a CSV that would work with this script.