<s> import time <EOL> import getpass <EOL> import csv <EOL> from string import Template <EOL> from util . rt import RTConnect <EOL> def output ( csv_data , ticket_recipe , environ ) : <EOL> template_data = "<STR_LIT>" <EOL> try : <EOL> fh = open ( ticket_recipe , "<STR_LIT:r>" ) <EOL> template_data = fh . read ( ) . split ( "<STR_LIT:\n>" , <NUM_LIT:3> ) <EOL> except IOError : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> queue = "<STR_LIT>" <EOL> requestor = "<STR_LIT>" <EOL> subject = "<STR_LIT>" <EOL> body = "<STR_LIT>" <EOL> for line in template_data : <EOL> temp_line = line . split ( "<STR_LIT:U+0020>" , <NUM_LIT:1> ) <EOL> if temp_line [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> queue = temp_line [ <NUM_LIT:1> ] <EOL> elif temp_line [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> requestor = temp_line [ <NUM_LIT:1> ] <EOL> elif temp_line [ <NUM_LIT:0> ] == "<STR_LIT>" or temp_line [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> subject = temp_line [ <NUM_LIT:1> ] <EOL> else : <EOL> body = line <EOL> subj_template = Template ( subject ) <EOL> body_template = Template ( body ) <EOL> print "<STR_LIT>" , queue , "<STR_LIT>" <EOL> for host , vulns in csv_data . host_to_vulns . iteritems ( ) : <EOL> print host <EOL> proceed = raw_input ( "<STR_LIT>" ) . strip ( ) <EOL> if proceed != "<STR_LIT:y>" : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> rtc = RTConnect ( ) <EOL> if rtc . token == None : <EOL> print "<STR_LIT>" <EOL> while True : <EOL> user = raw_input ( "<STR_LIT>" ) <EOL> password = getpass . getpass ( ) <EOL> rtc . authenticate ( user , password ) <EOL> if rtc . token == None : <EOL> print "<STR_LIT>" <EOL> else : <EOL> break <EOL> tickets_created = [ ] <EOL> for host , vulns in csv_data . host_to_vulns . iteritems ( ) : <EOL> vulndata = "<STR_LIT>" <EOL> for vuln in vulns : <EOL> vulndata += str ( vuln ) + "<STR_LIT>" + csv_data . id_to_name [ vuln ] + "<STR_LIT:\n>" <EOL> print "<STR_LIT>" , host <EOL> created = rtc . create_ticket ( requestor , subj_template . substitute ( hostname = host ) , body_template . substitute ( vulns = vulndata , hostname = host , ip = csv_data . host_to_ip [ host ] ) , queue ) <EOL> tickets_created . append ( [ created , host , time . asctime ( ) , queue , "<STR_LIT>" + str ( created ) ] ) <EOL> filename = "<STR_LIT>" + time . strftime ( "<STR_LIT>" ) + "<STR_LIT>" <EOL> try : <EOL> oh = open ( filename , "<STR_LIT:w>" ) <EOL> writer = csv . writer ( oh , delimiter = "<STR_LIT:U+002C>" , quotechar = "<STR_LIT>" ) <EOL> for ticket in tickets_created : <EOL> writer . writerow ( ticket ) <EOL> oh . close ( ) <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , filename <EOL> except IOError : <EOL> print "<STR_LIT>" </s>
