コード例 #1
0
def sendEmailSwatExtension():
	emailChoice=raw_input("Do you need to send the generated files to your email? (yes/no). Unless you want to scp the files out, it is Recommended to type 'yes': " )
	if emailChoice=='no' or emailChoice=='n' or emailChoice=='N':
		return
	else:
		try:
			#Compressing the 3 files into a zip file
			logging.info("---------------------------------------------------------")
			logging.info("[MESSAGE] Compressing the files into zip: ")
			os.system('zip topology_generated.zip TopologyGenerated.txt Topology.gv.pdf Topology.gv')
			logging.info("---------------------------------------------------------\n")

			emailTo=raw_input("Enter your Arista email address (To address): ")
			emailSubj= "Topology generation files- Graphic PDF, Graphic GV and Text"
			emailBody='TopologyGenerated.txt'
			emailAttachment='topology_generated.zip'
			
			#Calling SWAT function to send email
			sendEmail(emailTo=emailTo, emailSubj=emailSubj, emailBody=emailBody, attachments=emailAttachment)
			logging.info("--------------------------------------------------------------------------------------------")
			logging.info("[MESSAGE] Email has been sent successfully if no error is shown above\n")
			logging.info("--------------------------------------------------------------------------------------------\n \n")
			
			return

		except Exception as e:
			logging.info("-------------------------------")
			logging.info("[ERROR]: Error in sending Email. Reason:")
			logging.info(e)
			logging.info("[MESSAGE]: Maybe 'mutt' has not been configured on this device. Skipping sending email and proceeding...\n")
			logging.info("-------------------------------")
			return
コード例 #2
0
def sendEmailSwatExtension():
    emailChoice = raw_input(
        "Do you need to send the generated files to your email? (yes/no). Unless you want to scp the files out, it is Recommended to type 'yes': "
    )
    if emailChoice == 'no' or emailChoice == 'n' or emailChoice == 'N':
        return
    else:
        try:
            #Compressing the 3 files into a zip file
            print "---------------------------------------------------------"
            print "[MESSAGE] Compressing the files into zip: "
            os.system(
                'zip topology_generated.zip TopologyGenerated.txt Topology.gv.pdf Topology.gv'
            )
            print "---------------------------------------------------------\n"

            emailTo = raw_input(
                "Enter your Arista email address (To address): ")
            emailSubj = "Topology generation files- Graphic PDF, Graphic GV and Text"
            emailBody = 'TopologyGenerated.txt'
            emailAttachment = 'topology_generated.zip'

            #SWAT function to send email...did not support attachment...hence commenting this
            sendEmail(emailTo=emailTo,
                      emailSubj=emailSubj,
                      emailBody=emailBody,
                      attachments=emailAttachment)
            print "--------------------------------------------------------------------------------------------"
            print "[MESSAGE] Email has been sent successfully if no error is shown above\n"
            print "--------------------------------------------------------------------------------------------\n \n"

            #Sending Email using this script instead of SWAT tool
            #mailCmd='''mutt -s "%s" -a %s < %s -- %s'''%(emailSubj, emailAttachment, emailBody, emailTo)
            #            os.system(mailCmd)
            #print "--------------------------------------------------------------------------------------------"
            #print "[MESSAGE] Email will be sent if mutt had been setup correctly. If you haven't done this, run this from arst or syscon servers since thay are already configured with mutt.\n"
            #print "--------------------------------------------------------------------------------------------\n \n"

            return

        except Exception as e:
            print "-------------------------------"
            print "[ERROR]: Error in sending Email. Reason:"
            print e
            print "[MESSAGE]: Maybe 'mutt' has not been configured on this device. Skipping sending email and proceeding...\n"
            print "-------------------------------"
            return