Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bigdata import generictask
- from bigdata.utility import pretty_print
- import comm.emailout
- import datetime
- import os
- class UserTask (generictask.GenericTask):
- def action(self, srId, result, taskName, attach=False):
- """
- This task can parse and send the result output of an other task to email-in@cisco.com
- Parameters:
- - `<srId>` (STR) SR ID
- - `<result>` (DICT) The dict representation of a task output
- - `<taskName>` (STR) The task name
- - `<attach>` (BOOL) Send as an attached file
- Returns:
- -
- """
- # temp patch
- tmp = result.copy()
- result['data'] = tmp
- # /temp patch
- #output_string = pretty_print({'data': result}, nocolor=True, printlog=False, noprint=True)
- output_string = pretty_print(result, nocolor=True, printlog=False, noprint=True)
- mail = comm.emailout.EmailOut("bdb_no_reply@cisco.com", "email-in@cisco.com", "BDB - "+srId+" - Task "+taskName+" output")
- if not attach:
- mail.set_body(pretty_print(result))
- else:
- filename = str(datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
- filename += "-BDB-"
- filename += taskName
- with open(filename, 'w+') as f:
- f.write(output_string)
- mail.attach(filename)
- mail.set_body('New file attached '+filename)
- os.remove(filename)
- mail.send()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement