예제 #1
0
def loadConf(loc):
    loc = loc.replace('\\', '/')
    c = configparser.ConfigParser()
    c.read(loc)
    section = 'Config'
    options = c.options(section)
    paramlst = {}
    for o in options:
        if o == 'parameters':
            arg = c.get(section, o)
            paramlst = getFilters(arg)
        elif o == 'input':
            g.inputDir = helperFunctions.getFolderPath(c.get(section, o))
        elif o == 'output':
            g.outputDir = helperFunctions.getFolderPath(c.get(section, o))
        elif o == 'timeframe':
            g.parameters['Timestamp'] = ''
            arg = c.get(section, o)
            g.start_time, g.end_time = arg.split(',')[0].split(' '), arg.split(
                ',')[1].split(' ')
        elif o == 'outputformat':
            arg = c.get(section, o)
            if arg == 'H':
                g.outputFormat = 0
            elif arg == 'C':
                g.outputFormat = 1
            elif arg == 'T':
                g.outputFormat = 2

    getParameters(paramlst)
예제 #2
0
def loadConf(loc):
    loc = loc.replace("\\", "/")
    c = configparser.ConfigParser()
    c.read(loc)
    section = "Config"
    options = c.options(section)
    paramlst = {}
    for o in options:
        if o == "parameters":
            arg = c.get(section, o)
            paramlst = getFilters(arg)
        elif o == "input":
            g.inputDir = helperFunctions.getFolderPath(c.get(section, o))
        elif o == "output":
            g.outputDir = helperFunctions.getFolderPath(c.get(section, o))
        elif o == "timeframe":
            g.parameters["Timestamp"] = ""
            arg = c.get(section, o)
            g.start_time, g.end_time = arg.split(",")[0].split(" "), arg.split(",")[1].split(" ")
        elif o == "outputformat":
            arg = c.get(section, o)
            if arg == "H":
                g.outputFormat = 0
            elif arg == "C":
                g.outputFormat = 1
            elif arg == "T":
                g.outputFormat = 2

    getParameters(paramlst)
예제 #3
0
def main():

    parser = argparse.ArgumentParser(prog="""
               ,   .,---.,---.          |         
,---.,---.,---.|\  ||---'`---.,---.,---.|__/ ,---.
|   ||   ||---'| \ ||        ||   |,---||  \ |---'
`---'|---'`---'`  `'`    `---'`   '`---^`   ``---'
     |
""",
                                     description=helpfile)
    parser.add_argument('--input',
                        '-i',
                        dest='inputDir',
                        required=True,
                        help='The directory where your logs are stored')
    parser.add_argument('--output',
                        '-o',
                        dest='outputDir',
                        help='The directory where the report will be placed')
    parser.add_argument('--showParams',
                        '-P',
                        action='store_true',
                        help='Shows the possible parameters')
    parser.add_argument('--params',
                        '-p',
                        dest='paramlst',
                        help='The parameters and filters used')
    parser.add_argument('--timestamp',
                        '-t',
                        dest='time',
                        help='Time frame of the information you want')
    parser.add_argument('--config',
                        '-c',
                        dest='configFile',
                        help='The location of the configuration file')
    parser.add_argument('--HTML',
                        '-H',
                        action='store_true',
                        help='If you want an HTML report')
    parser.add_argument('--CSV',
                        '-C',
                        action='store_true',
                        help='If you want a CSV report')
    parser.add_argument('--TSV',
                        '-T',
                        action='store_true',
                        help='If you want a TSV report')

    args = parser.parse_args()
    g.inputDir = helperFunctions.getFolderPath(args.inputDir)
    if args.outputDir:
        g.outputDir = helperFunctions.getFolderPath(args.outputDir)
    if args.showParams:
        g.possible_params = fileParser.checkFilesForParameters(g.inputDir)
        for param in g.possible_params:
            print(param.replace("-", " "))
    if args.paramlst:
        paramlst = getFilters(args.paramlst)
        getParameters(paramlst)
    if args.time:
        g.parameters['Timestamp'] = ''
        g.start_time, g.end_time = args.time.split(',')[0].split(
            ' '), args.time.split(',')[1].split(' ')
    if args.configFile:
        loadConf(args.configFile)
    if args.HTML:
        g.outputFormat = 'html'
    elif args.CSV:
        g.outputFormat = 'csv'
    elif args.TSV:
        g.outputFormat = 'tsv'

    if args.paramlst:
        getParameters(paramlst)
        if len(g.parameters) > 0:
            g.values, g.count = fileParser.parseFiles(g.inputDir, g.parameters)
            #stupid way to check if -t
            if 'Timestamp' in g.parameters:
                #take out everything except events in specified time range
                tempv = []
                for v in g.values:
                    date = v[list(g.parameters.keys()).index("Timestamp")]
                    dt = datetime.datetime(
                        int(date.split('/')[2].split(" ")[0]),
                        int(date.split('/')[0]), int(date.split('/')[1]),
                        int(date.split(' ')[1].split(':')[0]),
                        int(date.split(':')[1]))
                    if helperFunctions.checkDateinRange(
                            g.start_time, g.end_time, dt):
                        tempv.append(v)
                g.values = tempv
                for v in g.values:
                    v.remove(v[list(g.parameters.keys()).index("Timestamp")])
                del (g.parameters['Timestamp'])
                temp = []
                for v in g.values:
                    if v in temp:
                        g.count[temp.index(v)] += 1
                    else:
                        temp.append(v)
                        g.count.append(1)
                g.values = temp

            #Generating the reports

            if g.outputFormat == 'html':
                #If there wasn't a specified outputDir we just use the default(cwd)
                if g.outputDir == '':
                    htmlReportGen.generate(g.values, g.parameters, g.count)
                else:
                    htmlReportGen.generate(g.values, g.parameters, g.count,
                                           g.outputDir)
            else:
                if g.outputDir == '':
                    helperFunctions.genReport(g.values,
                                              g.parameters,
                                              g.count,
                                              repType=g.outputFormat)
                else:
                    helperFunctions.genReport(g.values, g.parameters, g.count,
                                              g.outputDir, g.outputFormat)

        elif ('-P', '') not in opts and ('-h', '') not in opts:
            print(helpfile)
            print("You did not specify any parameters")
예제 #4
0
def main():

    parser = argparse.ArgumentParser(
        prog="""
               ,   .,---.,---.          |         
,---.,---.,---.|\  ||---'`---.,---.,---.|__/ ,---.
|   ||   ||---'| \ ||        ||   |,---||  \ |---'
`---'|---'`---'`  `'`    `---'`   '`---^`   ``---'
     |
""",
        description=helpfile,
    )
    parser.add_argument(
        "--input", "-i", dest="inputDir", required=True, help="The directory where your logs are stored"
    )
    parser.add_argument("--output", "-o", dest="outputDir", help="The directory where the report will be placed")
    parser.add_argument("--showParams", "-P", action="store_true", help="Shows the possible parameters")
    parser.add_argument("--params", "-p", dest="paramlst", help="The parameters and filters used")
    parser.add_argument("--timestamp", "-t", dest="time", help="Time frame of the information you want")
    parser.add_argument("--config", "-c", dest="configFile", help="The location of the configuration file")
    parser.add_argument("--HTML", "-H", action="store_true", help="If you want an HTML report")
    parser.add_argument("--CSV", "-C", action="store_true", help="If you want a CSV report")
    parser.add_argument("--TSV", "-T", action="store_true", help="If you want a TSV report")

    args = parser.parse_args()
    g.inputDir = helperFunctions.getFolderPath(args.inputDir)
    if args.outputDir:
        g.outputDir = helperFunctions.getFolderPath(args.outputDir)
    if args.showParams:
        g.possible_params = fileParser.checkFilesForParameters(g.inputDir)
        for param in g.possible_params:
            print(param.replace("-", " "))
    if args.paramlst:
        paramlst = getFilters(args.paramlst)
        getParameters(paramlst)
    if args.time:
        g.parameters["Timestamp"] = ""
        g.start_time, g.end_time = args.time.split(",")[0].split(" "), args.time.split(",")[1].split(" ")
    if args.configFile:
        loadConf(args.configFile)
    if args.HTML:
        g.outputFormat = "html"
    elif args.CSV:
        g.outputFormat = "csv"
    elif args.TSV:
        g.outputFormat = "tsv"

    if args.paramlst:
        getParameters(paramlst)
        if len(g.parameters) > 0:
            g.values, g.count = fileParser.parseFiles(g.inputDir, g.parameters)
            # stupid way to check if -t
            if "Timestamp" in g.parameters:
                # take out everything except events in specified time range
                tempv = []
                for v in g.values:
                    date = v[list(g.parameters.keys()).index("Timestamp")]
                    dt = datetime.datetime(
                        int(date.split("/")[2].split(" ")[0]),
                        int(date.split("/")[0]),
                        int(date.split("/")[1]),
                        int(date.split(" ")[1].split(":")[0]),
                        int(date.split(":")[1]),
                    )
                    if helperFunctions.checkDateinRange(g.start_time, g.end_time, dt):
                        tempv.append(v)
                g.values = tempv
                for v in g.values:
                    v.remove(v[list(g.parameters.keys()).index("Timestamp")])
                del (g.parameters["Timestamp"])
                temp = []
                for v in g.values:
                    if v in temp:
                        g.count[temp.index(v)] += 1
                    else:
                        temp.append(v)
                        g.count.append(1)
                g.values = temp

            # Generating the reports

            if g.outputFormat == "html":
                # If there wasn't a specified outputDir we just use the default(cwd)
                if g.outputDir == "":
                    htmlReportGen.generate(g.values, g.parameters, g.count)
                else:
                    htmlReportGen.generate(g.values, g.parameters, g.count, g.outputDir)
            else:
                if g.outputDir == "":
                    helperFunctions.genReport(g.values, g.parameters, g.count, repType=g.outputFormat)
                else:
                    helperFunctions.genReport(g.values, g.parameters, g.count, g.outputDir, g.outputFormat)

        elif ("-P", "") not in opts and ("-h", "") not in opts:
            print(helpfile)
            print("You did not specify any parameters")