Skip to main content

Hi Team,

 

Can you please let me know how we can accomplish this in a Qapp - Sending email to stakeholders Only if certain conditions are met. 

 

Thanks  !

Hello,

You can use the function "SendEmail(emailInfo)" which can be imported from netbrain.sysapi.datamodel.

Below is a sample code:

from netbrain.sysapi import datamodel 


mailContent = {
"subject":"NetBrain Alert",
"body":"<html><body>Hello, <br>This is a sample alert </body>",
"recipients":["user@netbraintech.com"],
"Ccs":["user2@netbraintech.com"],
"attachments":[{"content":"place,location\ndalian_beach, dalian\nqingdao_beach,qingdao", "contenttype":"text/csv", "filename":"place.csv"},
{"content":"This is a sample alert ,\n this is a new line", "contenttype":"text/plain; charset=us-ascii","filename":"test.txt"}]
}

datamodel.SendEmail(mailContent)

 

Sample email sent by this script:

 

 

Thankyou.


@Rakesh Mandava @pradeep.gaddameedi Can you please further explain the attachment “content” key value? I am confused on how to specify the content location. Thanks!


Hello @mosessefah ,

If you are asking to mention the file location, please be noted that there is no file from NetBrain system that will be attached to this mail. 

 

Lets have a look at the same sample code that is mentioned in the example (string in the “content” is finetuned to make it understand easily):

 "attachments":
b
{"content":"place,location \n
dalian_beach, dalian \n
qingdao_beach,qingdao",
"contenttype":"text/csv",
"filename":"place.csv"},
  • The value of the “content” key is actually a string is a set of words separated by commas and new line characters(\n).
  • The value of “filename” key is a csv file (“place.csv”). 
  • The string value that is mentioned as a value of “content” key is the content of attachment.
  • So it will be interpreted as a csv file called “place.csv” and the content of the csv file is the value of the “content” key.

Hope this clarify your question. Please raise a case to NetBrain if you need any further assistance for any of your usecase. 

 

Thanks,

Pradeep


@pradeep.gaddameedi Thanks so much for your response. I really understand your explanation, but I have this script configured as an output in a Qapp, which needs to export contents of a table containing CRC and Input Error values. Can I use the variables spelt out in the Qapp table to be the value of the contents key?


Hello @mosessefah ,

 

As you would like to get a Qapp table as an attachment in an email alert. There are multiple ways to achieve this. 

  • Using Script Node
  • Using Qapp Scheduler

Using Script Node:

For example, lets assume that below is a sample Qapp table.

You can use below sample code :

from netbrain.sysapi import datamodel 

InterfaceTable = $InterfaceTable.GetRows()
csvAttachmentContent = "DeviceName,InterfaceName,CRC_Errors\n"

for row in InterfaceTable:
csvAttachmentContent = csvAttachmentContent + row "DeviceName"] + "," + row "InterfaceName"] + "," + row "CRC_Errors"] + "\n"

mailContent = {
"subject":"NetBrain : Interface Errors ",
"body":"NetBrain : Interface Errors ",
"recipients": s"user1@company.com" , "user2@company.com"] ,
"attachments":t{"content":csvAttachmentContent ,
"contenttype":"text/csv",
"filename":"InterfaceErrors.csv"}]
}

datamodel.SendEmail(mailContent)

 

Using Qapp Scheduler:

Step1: Define Qapp to export the InterfaceTable into CSV File and save it.

 

Step2: Click on start button, then search for “Schedule Qapp” and the open it.

 Step2: Click on + Add Task button, then follow the Edit Task dialogue box wizard to add basic info, add target devices, select Qapp, execution timings, then in the Output Section, Check the “Export Report File” option. 

Step3: Specify the email address to which the report related attachment to be sent. 

Qapp will be auto executed on the selected schedule and csv report will be sent as attachment to the specified recipient list. 

 

Hope this clarifies your question.

 

Regards,

Pradeep


@pradeep.gaddameedi Awesome, thanks so much! 


Reply