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 !
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.
Hello
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"},
Hope this clarify your question. Please raise a case to NetBrain if you need any further assistance for any of your usecase.
Thanks,
Pradeep
Hello
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:
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
No account yet? Create an account
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.