#!/usr/bin/python

import os
from optparse import OptionParser

ALERTS = '/var/log/snort/alert'
PRI = 1
NUM = 10

def main():
    f = open(ALERTS)
    alerts = f.read().split('\n\n')
    pri = [a for a in alerts if 'Priority: {}'.format(PRI) in a]
    for a in pri[len(pri) - NUM:]:
        print a + '\n'

if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option('-p', help = 'priority level', metavar = 'PRI', default =  PRI) 
    parser.add_option('-n', help = 'number of logs to get',metavar = 'NUM', default = NUM, type = int)
    (opts, args) = parser.parse_args()
    PRI = opts.p
    NUM = opts.n
    main()
