Exemple #1
0
def getParameters(params):
    g.possible_params = fileParser.checkFilesForParameters(g.inputDir)
    for p in params:
        if p[0] == " ":
            p = p[1:]
        if p not in g.parameters and p in g.possible_params:
            g.parameters[p] = params[p]
        elif p not in g.possible_params:
            print(p + " is not a valid parameter")
def getParameters(params):
    g.possible_params = fileParser.checkFilesForParameters(g.inputDir)
    for p in params:
        if p[0] == " ":
            p = p[1:]
        if p not in g.parameters and p in g.possible_params:
            g.parameters[p] = params[p]
        elif p not in g.possible_params:
            print(p + " is not a valid parameter")
Exemple #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")
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")