Introduction
As a BizTalk administrator, you need to know about any issues in your BizTalk environment. It is crucial to know about these issues before they become real problems or cause any unnecessary outage for any integration services provided by your BizTalk server.
In this article I will demonstrate an easy way to send alerts in case there are any errors or warnings in the BizTalk environment.
Problem Statement
You may have some customers connecting to your integration middleware through receive adapters, such as POP3, SFTP, FTP, File, etc. In some cases you may get some warnings and errors which affect these receive adapters and make them disabled once the error threshold is exceeded.
In many instances, you would not be able to use the BizTalk Administration Console for alerting as these entries do not even register in the BizTalk Message Box.
Therefore, it is very important to be notified before the end users prompted with warning or error messages when they are trying to upload into integration middleware. It is equally important to take a proactive approach to resolve any upcoming issues you might be experiencing with your BizTalk server.
Solution
You might be attempted to use monitoring tools like SCOM or BizTalk360 ,… These tools are not free and some companies might find them costly to license and implement.
If your project does not have a budget to deploy these motioning tools, there is an easy way to get BizTalk alerts by using a combination of PowerShell scripting and the built-in Windows Task Scheduler through the following steps:
- Select Windows Start Button ->Control Panel->Administrative Tools -> Task Scheduler as shown in Figure 1 or use the shortcut command in run window control schedtasksFigure 1. Accessing Task Scheduler
- In Task Scheduler window, select Microsoft folder->click on create task -> in General Tab Name the task as shown in Figure 2Figure 2. Create Task
- Select Trigger Tab->Click New button-> in the Begin the task select on an event ->select custom->click New Event Filter button-> in Event Sources select BizTalk -> In case you want to filter by using event id you can set an event id as shown in Figure 3Figure 3. Create Trigger
- Select Action Tab->Click New Button->In Action select Send an e-mail->set email settings properties as shown in Figure 4Figure 4. Create Exchange Email Action
- If you want to add attachment of event logs to be included in email, then you need to create a new action to run the following command which write your filter log into a text file in my case I filtered on EventId 5740 which is pop3 warning that happens once pop3 user not authenticated and save it in this path C:\SendEmail\temp\logs.txt
del C:\SendEmail\temp\logs.txt
wevtutil qe Application
"/q:*[System [(EventID=5740)]]"
/f:text /rd:true /c:1> C:\SendEmail\temp\logs.txt
- Save command into cmd file and rename it into path C:\SendEmail\WriteLog.cmd
- Create new action -> In Action field, select start a program-> Set Program/Script Path as shown in Figure 5Figure 5. Create Command Action
- Sort action and make sure that running the command action in the first action as shown in Figure 6Figure 6. Sort actions
- In case you do not want to use exchange mail server, then you can write the following powershell script and save it in this path C:\SendEmail\SendEmailScript.ps1
$emailSmtpServer=
"smtp.gmail.com"
$emailSmtpServerPort=
"587"
$emailSmtpUser=
"yourusername@gmail.com"
$emailSmtpPass=
"yourpassword"
$emailFrom=
"fromusername@gmail.com"
$emailTo=
"sendtousername@gmail.com"
$emailMessage=
New
-
Object
System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.Subject=
"BizTalk Error"
$emailMessage.IsBodyHtml=$true
$emailMessage.Body=@"
<p>There is a BizTalk issue</p>
<p>Check the attachment</p>
"@
$emailAttachment=
New
-
Object
System.Net.Mail.Attachment(
"C:\SendEmail\temp\logs.txt"
)
$emailMessage.Attachments.Add($emailAttachment)
$SMTPClient=
New
-
Object
System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl=$true
$SMTPClient.Credentials=
New
-
Object
System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );
$SMTPClient.Send( $emailMessage )
- Create another command file to run powershell script as below and save it in this path C:\SendEmail\RunPowerShellScript.cmd
powershell C:\SendEmail\SendEmailScript.ps1
Now SendEmail folder should be as shown in Figure 7Figure 7. Files inside SendEmail Folders
- Update Send Email Action which we created in step 4 to run a program with path C:\SendEmail\RunPowerShellScript.cmd as shown in
Figure 8. Edit Action to use PowerShell script
- To test your work, create pop3 receive location and set a wrong username and password
As an experienced Technology Practice Head and CIO with more than 23 years of extensive experience, Amarnath brings a wealth of knowledge and expertise in driving digital transformation and IT innovation. Throughout his career, he has successfully led organizations in leveraging technology to achieve strategic objectives and enhance operational efficiency. Overall, his combination of technical expertise, strategic thinking, and leadership skills makes him a valuable asset in driving digital innovation and delivering business results as a CIO.
He has consistently demonstrated expertise in leading and managing IT functions to achieve business success. As the Head of IT, he possesses a strategic mindset, technical acumen, and a strong focus on delivering innovative solutions that align with organizational goals. Overall, his blend of strategic leadership, technical expertise, and collaborative approach makes him well-equipped to drive innovation, optimize IT operations, and deliver impactful results as the Head of IT.
Skilled consultant with a demonstrated ability to develop, migrate, and implement Hyperautomation, IOT, Microsoft Dynamics 365, Transactional Data Migration, Server-to-Server Migration, Live Migration for minimum downtime.
As an experienced Technology Practice Head and CIO with more than 23 years of extensive experience, Amarnath brings a wealth of knowledge and expertise in driving digital transformation and IT innovation. Throughout his career, he has successfully led organizations in leveraging technology to achieve strategic objectives and enhance operational efficiency. Overall, his combination of technical expertise, strategic thinking, and leadership skills makes him a valuable asset in driving digital innovation and delivering business results as a CIO.
He has consistently demonstrated expertise in leading and managing IT functions to achieve business success. As the Head of IT, he possesses a strategic mindset, technical acumen, and a strong focus on delivering innovative solutions that align with organizational goals. Overall, his blend of strategic leadership, technical expertise, and collaborative approach makes him well-equipped to drive innovation, optimize IT operations, and deliver impactful results as the Head of IT.
Skilled consultant with a demonstrated ability to develop, migrate, and implement Hyperautomation, IOT, Microsoft Dynamics 365, Transactional Data Migration, Server-to-Server Migration, Live Migration for minimum downtime.