SIOS SANless clusters

SIOS SANless clusters High-availability Machine Learning monitoring

  • Home
  • Products
    • SIOS DataKeeper for Windows
    • SIOS Protection Suite for Linux
  • News and Events
  • Clustering Simplified
  • Success Stories
  • Contact Us
  • English
  • 中文 (中国)
  • 中文 (台灣)
  • 한국어
  • Bahasa Indonesia
  • ไทย

Trigger Email Alert When Specific Windows Service Starts Or Stops

November 18, 2018 by Jason Aw Leave a Comment

How To Trigger An Email Alert When A Specific Windows Service Starts Or Stops On Windows Server 2016

Step-By-Step: How To Trigger An Email Alert When A Specific Windows Service Starts Or Stops On Windows Server 2016

Different from my previous post where I showed you how to send an email alert based upon specific Windows EventIDs being logged in a Windows Event Log, this time around I’ll share how to Trigger Email Alert When Specific Windows Service Starts Or Stops. It works great for most events. Although do note it is not ideal if you want to be notified when a specific Windows Service starts or stops.

When a Windows Service starts or stops, an EventID 7036 from the Source “Service Control Manager” is logged in the Windows System Log. Now we could simply set up a trigger to send an email whenever that EventID is logged as I described in my previous post. However, you might not want to receive an email when EVERY Windows Service starts or stops.

To get a little more specific, we will have to edit the XML data associated with the Windows Event Filter when we set up the trigger. This is to look a little deeper at the Event Properties and filter on the EventData that is only shown when you view the XML View on the Details tab of a Windows Event.

This work was verified on Windows Server 2016, but I suspect it should work on Windows Server 2012 R2 and Windows Server 2019 as well. If you get it working on any other platforms please comment and let us know if you had to change anything.

Step 1 – Write A Powershell Script

The first thing that you need to do is write a Powershell script that when run can send an email. You need that email to trigger Email Alert When Specific Windows Service Starts Or Stops. There are many ways to accomplish this task. I’m about to show you is just one way, but feel free to experiment and use what is right for your environment.

In my lab I do not run my own SMTP server, so I had to write a script that could leverage my Gmail account. You will see in my Powershell script the password to the email account that authenticates to the SMTP server is in plain text. If you are concerned that someone may have access to your script and discover your password then you will want to encrypt your credentials. Gmail requires and SSL connection so your password should be safe on the wire, just like any other email client.

Here is an example of a Powershell script that when used in conjunction with Task Scheduler which will send an email alert automatically when any specified Event is logged in the Windows Event Log. In my environment I saved this script to C:\Alerts\ServiceAlert.ps1

$filter="*[System[EventID=7036] and EventData[Data='SIOS DataKeeper']]"
$A = Get-WinEvent -LogName System -MaxEvents 1 -FilterXPath $filter
$Message = $A.Message
$EventID = $A.Id
$MachineName = $A.MachineName
$Source = $A.ProviderName


$EmailFrom = "sios@medfordband.com"
$EmailTo = "sios@medfordband.com"
$Subject ="Alert From $MachineName"
$Body = "EventID: $EventID`nSource: $Source`nMachineName: $MachineName `n$Message"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("sios@medfordband.com",
 "MySMTPP@55w0rd");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

An example of an email generated from that Powershell script looks like this.

Service Alert Email

You probably noticed that this Powershell script uses the Get-WinEvent cmdlet to grab the most recent Event Log entry based upon the LogName, EventID and EventDataspecified. It then parses that event and assigns the EventID, Source, MachineName and Message to variables that will be used to compose the email. You will see that the LogName, EventID and EventData specified is the same as what you will specify when you set up the Scheduled Task in Step 2.

While EventID, LogName are probably familiar to you, EventData may not be as familiar. To see the EventData associated with a particular Event you will need to open the Event in Event Viewer, look at the Details tab and then select XML view. From the XML view you can see all the data included with an event. Near the bottom of the XML you will see an array of data called <EventData>. Within there you will find additional Event Data stored as parameters. As show below, in the “param1” we will find the name of the Service being that either stopped or started.

Event Data

Step 2 – Set Up A Schedule Task

In Task Scheduler Create a Task as show in the following screen shots.

  1. Create Task
    Create Task
    Make sure the task is set to Run whether the user is logged on or not.
    Service - General
  2.  On the Triggers tab choose New to create a Trigger that will begin the task “On an Event”. In my example I will be creating an event that triggers any time DataKeeper (extmirr) logs an important event to the System log.
    Create Task 3
    Create a custom event and New Event Filter as shown below…Create Task - Trigger
    For my trigger you can start my setting up a trigger that monitors 7036 as I describe in my previous article. However, the Filter GUI interface does not allow us to specify the Service Name stored in Param1 of EventData as I described earlier. In order to monitor for just the specific service we are interested in we will need to edit the XML directly as shown below.Service - XML
    If you rather just skip straight to the chase feel free to copy my XML below and replace ‘SIOS DataKeeper’ with the event data stored in param1 of the Event you want to monitor.

    <QueryList>
    <Query Id="0" Path="System">
    <Select Path="System">*[System[(Level=4 or Level=0) and (EventID=7036)]] 
    and *[EventData[Data[1]='SIOS DataKeeper']]</Select>
    </Query>
    </QueryList>
  3. Once the Event Trigger is configured, you will need to configure the Action that occurs when the event is run. In our case we are going to run the Powershell script that we created in Step 1.Actions - 2Service - Task
  4. The default Condition parameters should be sufficient.
    Conditions - 1
  5. And finally, on the Settings tab make sure you allow the task to be run on demand and to “Queue a new instance” if a task is already running.

    2018-10-28_00-17-27

Step 3 (If Necessary) -Fix the Microsoft -Windows – Distributedcom Event ID: 10016 Error

In theory, if you did everything correctly you should now start receiving emails any time one of the events you are monitoring gets logged in the event log.  However, I ran into a weird permission issue on one of my servers that I had to address before everything worked. I’m not sure if you will run into this issue, but just in case here is the fix.

In my case when I manually triggered the event, or if I ran the Powershell script directly, everything worked as expected and I received an email. However, if one of the EventIDs being monitored was logged into the event log it would not result in an email being sent. The only clue I had was the Event ID: 10016 that was logged in my Systems event log each time I expected the Task Trigger to detect a logged event.

Log Name: System
Source: Microsoft-Windows-DistributedCOM
Date: 10/27/2018 5:59:47 PM
Event ID: 10016
Task Category: None
Level: Error
Keywords: Classic
User: DATAKEEPER\dave
Computer: sql1.datakeeper.local
Description:
The application-specific permission settings do not grant Local Activation permission 
for the COM Server application with CLSID 
{D63B10C5-BB46-4990-A94F-E40B9D520160}
and APPID 
{9CA88EE3-ACB7-47C8-AFC4-AB702511C276}
to the user DATAKEEPER\dave SID (S-1-5-21-25339xxxxx-208xxx580-6xxx06984-500) from 
address LocalHost (Using LRPC) 
running in the application container Unavailable SID (Unavailable). 
This security permission can be modified using the Component Services administrative tool.

Many of the Google search results for that error indicate that the error is benign and include instructions on how to suppress the error instead of fixing it. However, I was pretty sure this error was the cause of my current failure to be able to send an email alert from a Scheduled Event that was triggered from a monitored Event Log entry. I needed to fix it.

After much searching, I stumbled upon this newsgroup discussion.  The response from Marc Whittlesey pointed me in the right direction. This is what he wrote…

There are 2 registry keys you have to set permissions before you go to the DCOM Configuration in Component services: CLSID key and APPID key.

I suggest you to follow some steps to fix issue:

1. Press Windows + R keys and type regedit and press Enter.
2. Go to HKEY_Classes_Root\CLSID\*CLSID*.
3. Right click on it then select permission.
4. Click Advance and change the owner to administrator. Also click the box that will appear below the owner line.
5. Apply full control.
6. Close the tab then go to HKEY_LocalMachine\Software\Classes\AppID\*APPID*.
7. Right click on it then select permission.
8. Click Advance and change the owner to administrators.
9. Click the box that will appear below the owner line.
10. Click Apply and grant full control to Administrators.
11. Close all tabs and go to Administrative tool.
12. Open component services.
13. Click Computer, click my computer, and then click DCOM.
14. Look for the corresponding service that appears on the error viewer.
15. Right click on it then click properties.
16. Click security tab then click Add User, Add System then apply.
17. Tick the Activate local box.

So use the relevant keys here and the DCOM Config should give you access to the greyed out areas:
CLSID {D63B10C5-BB46-4990-A94F-E40B9D520160}

APPID {9CA88EE3-ACB7-47C8-AFC4-AB702511C276}

I was able to follow Steps 1-15 pretty much verbatim. However, when I got to Step 16 I really couldn’t tell exactly what he wanted me to do. At first I granted the DATAKEEPER\dave user account Full Control to the RuntimeBroker. But that didn’t fix things. Eventually I just selected “Use Default” on all three permissions and that fixed the issue.

RuntimeBroker
I’m not sure how or why this happened, but I figured I better write it all down in case it happens again because it took me a while to figure it out.

Step 4- Automating The Deployment

If you need to enable the same alerts on multiple systems you can simply export your Task to an XML file and Import it on your other systems.

Email Alert When Specific Windows Service Starts Or Stops
Export
Email Alert When Specific Windows Service Starts Or Stops
Import

Or even better yet, automate the Import as part of your build process through a Powershell script after making your XML file available on a file share as shown in the following example.

PS C:\> Register-ScheduledTask -Xml (get-content '\\myfileshare\tasks\DataKeeperAlerts.xml' 
| out-string) -TaskName "DataKeeper Service Alerts" -User datakeeper\dave 
-Password MyDomainP@55W0rd –Force

Finally, An Email Alert When Specific Windows Service Starts Or Stops

Hopefully what I have provided will give you everything you need to start receiving alert notification emails on whichever Windows Services keep you up at night.

This concludes my series on configuring email alerts. In this series I covered covered configuring alerts based on Perfmon counters, Event Log Entries and in this article Windows Service Start and Stop events. Of course you can extend these Powershell scripts described in these articles to do more than just send emails. Many alerts or unexpected service stoppages generally require some remediation. Why not just script out the recovery steps and let the triggered task take care of the issue for you?

Personally I recommend that you invest in SCOM , SolarWinds or some other Enterprise Management System, but if that is not in the cards where you work then these articles can help in a pinch.

To learn more tips about Email Alert When Specific Windows Service Starts Or Stops, contact us
Reproduced with permission from Clusteringformeremortals.com

Filed Under: Clustering Simplified Tagged With: email alert when specific windows service starts or stops, Windows Server 2016

Move SQL Server 2008 And 2008 R2 Clusters To Azure For Extended Support

November 16, 2018 by Jason Aw Leave a Comment

Move SQL Server 2008 And 2008 R2 Clusters To Azure For Extended Support

Move SQL Server 2008 And 2008 R2 Clusters To Azure For Extended Support

Earlier this year Microsoft announced extended support if you move SQL Server 2008 and 2008 R2 Clusters to Azure. For all the details, check out https://www.microsoft.com/en-us/sql-server/sql-server-2008. If you choose not to move, your extended support ends on July 9th, 2019.

Move SQL Server 2008 And 2008 R2 Clusters To Azure For Extended Support

If you are still running SQL Server 2008 R2, it’s probably because you never upgraded your application. Hence newer versions of SQL are not supported. Or perhaps, you decided not to fix what isn’t broken. Regardless of these reasons, you have just bought yourself another three years of support if you migrate to Azure.

Now migrating workloads to Azure is a pretty well documented procedure, using Azure Site Recovery. That process should be pretty seamless for you for your standalone instances of SQL Server.

But what about those clustered instances of SQL Server? You certainly don’t want to give up availability when you move to the Azure. Part of the beauty of Azure is that they have infrastructure that you can only dream of. However, it is incumbent upon the user to configure their applications to take full advantage of the infrastructure to ensure that your deployments are highly available.

With SQL Server 2008 and 2008 R2, high availability commonly means SQL Server Failover Clustering on either Windows Server 2008 R2 or Windows Server 2012 R2. If you are new to Azure, you will quickly discover that there is no native option that supports  shared storage clusters. Instead, you will need to look at a SANLess cluster solution such as SIOS DataKeeper. Microsoft list SIOS DataKeeper as the HA solution for SQL Server Failover Clustering in their documentation.

Move SQL Server 2008 And 2008 R2 Clusters To Azure For Extended Support
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/sql/virtual-machines-windows-sql-high-availability-dr

Getting Started

Let’s begin the move SQL Server 2008 And 2008 R2 Clusters To Azure For Extended Support. Here are the high level steps you will need to take.

  • Replace the Physical Disk Resource in your existing on premise SQL Server cluster with a DataKeeper Volume Resource. Do the same for MSDTC resources if you use MSDTC.
  • Remove your Disk Witness and replace it with a File Share Witness.
  • Use Azure Site Recovery to replicate your cluster nodes into Azure, making sure each replicated node resides in a different Fault Domain or in different Availability Zones in Azure
  • Recovery your replicate cluster nodes in Azure
  • Replace the File Share Witness with a File Share hosted in Azure
  • Configure the Internal Load Balancer in Azure for client redirection. This includes running the Powershell script on the local nodes to update the SQL Cluster IP resource to listen for the ILB probe
  • Assuming the IP addresses and subnet of the SQL Server cluster instances changed as part of this migration, you will also need to do some cleanup of the cluster IP address and the DataKeeper job endpoints to reflect the new IP addresses

I know I left out a lot of the details. But if you find yourself in the position of having to do a lift and shift of SQL Server to Azure, or any cloud for that matter, I’d be glad to get on the phone with you to answer any questions you may have. Keep in mind, the same steps apply for any version of SQL that you plan to migrate to Azure.

If you need to move SQL Server 2008 And 2008 R2 Clusters To Azure, get in touch with us.
Reproduced with permission from Clusteringformeremortals.com

Filed Under: Clustering Simplified Tagged With: 2008 R2 Clusters, Azure Site Recovery, move sql server 2008 and 2008 r2 clusters to azure, SQL Server 2008

Azure Site Recovery for Disaster Recovery

November 11, 2018 by Jason Aw Leave a Comment

Ensure Application Availability With Cloud-Based Disaster Recovery, Azure Site Recovery

#IGNITE2018 Session: Ensure Application Availability With Cloud-Based Disaster Recovery, Azure Site Recovery

I’m a big fan of Azure Site Recovery for Disaster Recovery  So, I was glad to attend the Ignite session today presented by Rochak Mittal and Ashish Gangwar

Ensure Application Availability With Cloud-Based Disaster Recovery, Azure Site Recovery

#IGNITE2018 Session: Ensure Application Availability With Cloud-Based Disaster Recovery, Azure Site Recovery

I’m a big fan of Azure Site Recovery for Disaster Recovery  So, I was glad to attend the Ignite session today presented by Rochak Mittal and Ashish Gangwar 

BRK3304 – Architecting mission-critical, high-performance SAP workloads on Azure

This session about ensuring Application Availability With Cloud-Based Disaster Recovery, Azure Site Recovery is particularly informative. In one of the architecture slides, they showed how an entire SAP deployment could be protected by Azure Site Recovery (ASR) and recovered in the event of a disaster in just a few minutes. Using Azure Recovery Plans allows you to have explicit control over recovery. It includes creating dependencies on resources as well as invoking scripts within a VM to help facilitate the complete recovery.

It seems like yesterday. But it was back in May of 2014 when I first started assisting Microsoft with providing a HA solution for SAP ASCS in Azure. That solution involves using DataKeeper to build a SANless cluster solution for ASCS. It still stands today as the only HA solution that also works with ASR for disaster recovery configurations such as the one shown in this demo at Ignite.

Ensure Application Availability With Cloud-Based Disaster Recovery, Azure Site Recovery 
Shared disks in Azure with SIOS DataKeeper

Want to know how to Ensure Application Availability With Cloud-Based Disaster Recovery, Azure Site Recovery, let us know and we’ll be glad to help.
Reproduced with permission from Clusteringformeremortals.com

Filed Under: Clustering Simplified Tagged With: Azure Site Recovery, disaster recovery, Microsoft

How To Trigger Email Alerts From Windows Performance Monitor

November 10, 2018 by Jason Aw Leave a Comment

Trigger Email Alerts From Windows Performance Monitor

Step-By-Step: How To Trigger Email Alerts From Windows Performance Monitor

Step-By-Step: How To Trigger Email Alerts From Windows Performance Monitor

Trigger Email Alerts From Windows Performance Monitor

Step-By-Step: How To Trigger Email Alerts From Windows Performance Monitor

Windows Performance Counter Alerts can be configured to be triggered on any Performance Monitor (Perfmon) Counter through the use of a User Defined Data Collector Set. However, if you wish to be notified via email when an Alert is triggered, you have to use a combination of Perfmon, Task Scheduler and good ol’ Powershell. Follow the steps below to Trigger Email Alerts From Windows Performance Monitor.

Step 1 – Write A Powershell Script

The first thing that you need to do is write a Powershell script that when run can send an email. While researching this I discovered many ways to accomplish this task. What I’m about to show you is just one way, but feel free to experiment and use what is right for your environment.

In my lab, I do not run my own SMTP server. I write a script that could leverage my Gmail account. You will see in my Powershell script, the password to the email account that authenticates to the SMTP server is in plain text. If you are concerned that someone may have access to your script and discover your password, then you will want to encrypt your credentials. Gmail requires and SSL connection. Your password should be safe on the wire, just like any other email client.

Here is an example of a Powershell script when used in conjunction with Task Scheduler and Perfmon. Together, it can send an email alert automatically when any user defined performance counter threshold condition is met. In my environment I set this to C:\Alerts\Alerts.ps1

$counter = $Args[0]
$dtandtime = $Args[1]
$ctr_value = $Args[2]
$threshold = $Args[3]
$value = $Args[4]
$FileName="$env:ComputerName"
$EmailFrom = "sios@medfordband.com"
$EmailTo = "dave@medfordband.com"
$Subject ="Alert From $FileName"
$Body = "Data and Time of Alert: $dtandtime`nPerfmon Counter: $ctr_value`nThreshold Value: $threshold `nCurrent Value: $value"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("sios@medfordband.com", "ChangeMe123");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

An example of an email generated from that Powershell script looks like this.

How To Trigger Email Alerts From Windows Performance Monitor

You probably noticed that this Powershell script takes four arguments. It also assigns them to variables used in the output. It saves the computer name to a variable which is used as part of the output. By doing this, the script can be used to send an email on any Perfmon Alerting Counter and on any server without additional customization.

Step 2 – Set Up A Scheduled Task

In Task Scheduler, we are going to Create a new Task as show in the following screen shots.

How To Trigger Email Alerts From Windows Performance Monitor

Give the Task a name, you will need to remember it for the next step.

How To Trigger Email Alerts From Windows Performance Monitor

Notice that there are no Triggers. This Task will actually be triggered through the Perfmon Counter Alert which we will set up in Step 3.

How To Trigger Email Alerts From Windows Performance Monitor

You want to define a new action on the Action tab. The action will be to Start a Program and use the following inputs,. Please adjust for your specific environment.

Program Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add Arguments: -File C:\Alerts\Alerts.ps1 $(Arg0)

How To Trigger Email Alerts From Windows Performance Monitor

How To Trigger Email Alerts From Windows Performance Monitor

How To Trigger Email Alerts From Windows Performance Monitor

How To Trigger Email Alerts From Windows Performance Monitor

Step 3 – Create The Performance Counter

Create a new Data Collector Set

How To Trigger Email Alerts From Windows Performance Monitor

How To Trigger Email Alerts From Windows Performance Monitor

How To Trigger Email Alerts From Windows Performance Monitor

Add whichever Performance Counters you would like to monitor and set the Alerting threshold.

How To Trigger Email Alerts From Windows Performance Monitor

How To Trigger Email Alerts From Windows Performance Monitor

Once you have created the Data Collector Set go into the Properties of it and make sure the Alerting threshold and Sample Interval is set properly for each Performance Counter. Keep in mind, if you sample every 10 seconds then you should expect to receive an email every 10 seconds as long as the performance counter exceeds the threshold you set.

How To Trigger Email Alerts From Windows Performance Monitor

If you select the Log an entry in the application event log don’t expect to see any entries in the normal Application event log. It will be written to the Microsoft-Windows-Diagnosis-PLA/Operational log in the Application and Services log directory.

How To Trigger Email Alerts From Windows Performance Monitor

And then finally we have to set an Alert Task that will trigger the Scheduled Task (EmailAlert) that we created in Step 2. You see that we also pass some of the Task arguments which are used by the Powershell script to customize the email with the exact error condition associated with the Alert.

How To Trigger Email Alerts From Windows Performance Monitor

Once the Data Collector is configured properly you will want to start it.

How To Trigger Email Alerts From Windows Performance Monitor

If you configured everything correctly you should start seeing emails any time an alert threshold is met.

If it doesn’t seem to be working, check the following…

  • Run the Powershell script manually to make sure it works. You may need to manually set some of the variables for testing purposes. In my case it took a little tweaking to get the Powershell script to work properly, so start with that.
  • Check the Task History to make sure the Alert Counter is triggering the Task.
    How To Trigger Email Alerts From Windows Performance Monitor
  • Run the Task manually and see if it triggers the Powershell.

Step 4 – Set The Performance Counter To Run Automatically

If you think you are all set to Trigger Email Alerts From Windows Performance Monitor, you have one more step. Whenever you reboot a server the Perfmon Counter Alert will not start automatically. In order to survive a reboot you must run the following at a command prompt. Note “Alerts” referenced in the script below is the name of my user defined Data Collector Set.

schtasks /create /tn Alerts /sc onstart /tr "logman start Alerts" /ru system

There are a few edge cases where you might have to create another Trigger to start the Data Collector set. For example, SIOS DataKeeper Perfmon Counters only collects data from the Source of the mirror. If you try to start the Data Collection Set on the Target Server you will see that it fails to start. However, if your cluster fails over, the old target now becomes the source of the mirror, so you will want to start monitoring DataKeeper counters on that new Source. You could create a Cluster Generic Script Resource that starts the Data Collector Set upon failover, but that is a topic for another time.

The easier way ensure the counter is running on the new Source is to set up a Scheduled Task that is triggered by an EventID that indicates the the server is becoming the source of the mirror. In this case I set up trigger on both Systems so that each time EventID 23 occurs the Trigger runs Logman to start the Data Collector Set. Every time a failover occurs Event ID 23 is logged on the new system when it becomes the source, so the Data Collector Set will automatically begin.

How To Trigger Email Alerts From Windows Performance MonitorHow To Trigger Email Alerts From Windows Performance Monitor

That’s it, you now can receive email Alerts directly from your server should any Perfmon counters you care about start getting out of hand.

Did you enjoy reading How To Trigger Email Alerts From Windows Performance Monitor? Click here to find out more.
Reproduced with permission from Clusteringformeremortals.com

Filed Under: Clustering Simplified Tagged With: trigger email alerts from windows performance monitor, Windows Performance Monitor

How To Trigger Email Alerts From Windows Event Using Windows Server 2016

November 9, 2018 by Jason Aw Leave a Comment

Trigger Email Alerts From Windows Event Using Windows Server 2016

Step-By-Step: How To Trigger An Email Alert From A Windows Event That Includes The Event Details Using Windows Server 2016

Introduction

Trigger Email Alerts From Windows Event Using Windows Server 2016 only requires a few steps. Specify the action that will occur when that Task is triggered. Since Microsoft has decided to deprecate the “Send an e-mail” option, the only choice we have is to Start a Program. In our case, that program will be a Powershell script to collect the Event Log information and parse it. This way, we can send an email that includes important Log Event details.

This work was verified on Windows Server 2016. But I suspect it should work on Windows Server 2012 R2 and Windows Server 2019 as well. If you get it working on any other platforms, please comment and let us know if you had to change anything.

Step 1- Write A Powershell Script

The first thing to do is write a Powershell script that when run can send an email. While researching this I discovered many ways to accomplish this task, so what I’m about to show you is just one way, but feel free to experiment and use what is right for your environment.

In my lab I do not run my own SMTP server, so I had to write a script that could leverage my Gmail account. You will see in my Powershell script that the password to the email account which authenticates to the SMTP server is in plain text. If you are concerned that someone may have access to your script and discover your password, do encrypt your credentials. Gmail requires and SSL connection. Your password should be safe on the wire, just like any other email client.

I have an example of a Powershell script. When used in conjunction with Task Scheduler, it will send an email alert automatically when any specified Event is logged in the Windows Event Log. In my environment, I saved this script to C:\Alerts\DataKeeper.ps1

$EventId = 16,20,23,150,219,220

$A = Get-WinEvent -MaxEvents 1  -FilterHashTable @{Logname = "System" ; ID = $EventId}
$Message = $A.Message
$EventID = $A.Id
$MachineName = $A.MachineName
$Source = $A.ProviderName


$EmailFrom = "sios@medfordband.com"
$EmailTo = "sios@medfordband.com"
$Subject ="Alert From $MachineName"
$Body = "EventID: $EventID`nSource: $Source`nMachineName: $MachineName `nMessage: $Message"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential
("sios@medfordband.com", "mySMTPP@55w0rd");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

An example of an email generated from that Powershell script looks like this.

Trigger Email Alerts From Windows Event Using Windows Server 2016

You probably noticed that this Powershell script uses the Get-WinEvent cmdlet to grab the most recent Event Log entry based upon the LogName, Source and eventIDs specified. It then parses the event and assigns EventID, Source, MachineName and Message to variables that will be used to compose the email. You will see that the LogName, Source and eventIDs specified are the same as the ones you will specify when you set up the Scheduled Task in Step 2.

Step 2 – Set Up A Scheduled Task

In Task Scheduler Create a Task as show in the following screen shots.

  1. Create Task
    Trigger Email Alerts From Windows Event Using Windows Server 2016Make sure the task is set to Run whether the user is logged on or not.
    Trigger Email Alerts From Windows Event Using Windows Server 2016
  2.  On the Triggers tab choose New to create a Trigger that will begin the task “On an Event”. In my example, I will be creating an event that triggers any time DataKeeper (extmirr) logs an important event to the System log.
    Trigger Email Alerts From Windows Event Using Windows Server 2016
    Create a custom event and New Event Filter as shown below…Trigger Email Alerts From Windows Event Using Windows Server 2016For my trigger I am triggering on commonly monitored SIOS DataKeeper (ExtMirr) EventIDs 16, 20, 23,150,219,220 . You will need to set up your event to trigger on the specific Events that you want to monitor. You can put multiple Triggers in the same Task if you want to be notified about events that come from different logs or sources.

    Trigger Email Alerts From Windows Event Using Windows Server 2016
    Create a New Event Filter

     

  3. Once the Event Trigger is configured, you will need to configure the Action that occurs when the event is run. In our case we are going to run the Powershell script that we created in Step 1.Trigger Email Alerts From Windows Event Using Windows Server 2016Trigger Email Alerts From Windows Event Using Windows Server 2016
  4. The default Condition parameters should be sufficient.
    Trigger Email Alerts From Windows Event Using Windows Server 2016
  5. And finally, on the Settings tab make sure you allow the task to be run on demand and to “Queue a new instance” if a task is already running.

    Trigger Email Alerts From Windows Event Using Windows Server 2016

Step 3 (If Necessary) – Fix The Microsoft Windows DistributedCOM Event ID: 10016 Error

In theory, if you did everything correctly, you should be able to Trigger Email Alerts From Windows Event Using Windows Server 2016. However, I ran into a weird permission issue on one of my servers. Here’s my fix to my problem. Hope it will help you too.

In my case when I manually triggered the event, or if I ran the Powershell script directly, everything worked as expected and I would receive an email. However, if one of the EventIDs being monitored was logged into the event log it would not result in an email being sent. The only clue I had was the Event ID: 10016. It was logged in my Systems event log every time I expected the Task Trigger to detect a logged event.

Log Name: System
Source: Microsoft-Windows-DistributedCOM
Date: 10/27/2018 5:59:47 PM
Event ID: 10016
Task Category: None
Level: Error
Keywords: Classic
User: DATAKEEPER\dave
Computer: sql1.datakeeper.local
Description:
The application-specific permission settings do not grant Local Activation permission 
for the COM Server application with CLSID 
{D63B10C5-BB46-4990-A94F-E40B9D520160}
and APPID 
{9CA88EE3-ACB7-47C8-AFC4-AB702511C276}
to the user DATAKEEPER\dave SID (S-1-5-21-25339xxxxx-208xxx580-6xxx06984-500) 
from address LocalHost 
(Using LRPC) running in the application container Unavailable SID (Unavailable). 
This security permission can be modified using the Component Services administrative tool.

Many of the Google search results for that error indicate that the error is benign. It included instructions on how to suppress the error instead of fixing it. However, I was pretty sure this error was the cause of my current failure. If I don’t fix it right, it would be difficult to Trigger Email Alerts From Windows Event Using Windows Server 2016.

After much searching, I stumbled upon this newsgroup discussion.  The response from Marc Whittlesey pointed me in the right direction. This is what he wrote…

There are 2 registry keys you have to set permissions before you go to the DCOM Configuration in Component services: CLSID key and APPID key.

I suggest you to follow some steps to fix issue:

1. Press Windows + R keys and type regedit and press Enter.
2. Go to HKEY_Classes_Root\CLSID\*CLSID*.
3. Right click on it then select permission.
4. Click Advance and change the owner to administrator. Also click the box that will appear below the owner line.
5. Apply full control.
6. Close the tab then go to HKEY_LocalMachine\Software\Classes\AppID\*APPID*.
7. Right click on it then select permission.
8. Click Advance and change the owner to administrators.
9. Click the box that will appear below the owner line.
10. Click Apply and grant full control to Administrators.
11. Close all tabs and go to Administrative tool.
12. Open component services.
13. Click Computer, click my computer, and then click DCOM.
14. Look for the corresponding service that appears on the error viewer.
15. Right click on it then click properties.
16. Click security tab then click Add User, Add System then apply.
17. Tick the Activate local box.

So use the relevant keys here and the DCOM Config should give you access to the greyed out areas:
CLSID {D63B10C5-BB46-4990-A94F-E40B9D520160}

APPID {9CA88EE3-ACB7-47C8-AFC4-AB702511C276}

I was able to follow Steps 1-15 pretty much verbatim. However, when I got to Step 16, I really couldn’t tell exactly what he wanted me to do. At first I granted the DATAKEEPER\dave user account Full Control to the RuntimeBroker, but that didn’t fix things. Eventually I just selected “Use Default” on all three permissions and that fixed the issue.

Trigger Email Alerts From Windows Event Using Windows Server 2016
I’m not sure how or why this happened. I figured I better write it all down in case it happens again because it took me a while to figure it out.

Step 4 – Automating The Deployment

If you need to enable the same alerts on multiple systems, export your Task to an XML file and Import it on your other systems.

Trigger Email Alerts From Windows Event Using Windows Server 2016Trigger Email Alerts From Windows Event Using Windows Server 2016

Or even better yet. Automate the Import as part of your build process through a Powershell script after making your XML file available on a file share as shown in the following example.

PS C:\> Register-ScheduledTask -Xml (get-content 
'\\myfileshare\tasks\DataKeeperAlerts.xml' | out-string) 
-TaskName "DataKeeperAlerts" -User datakeeper\dave 
-Password MyDomainP@55W0rd –Force

Trigger Email Alerts From Windows Event Using Windows Server 2016

In my next post, I will show you how to be notified when a specified Service either starts or stops. Of course you could just monitor for EventID 7036 from Service Control Monitor. But that would notify you whenever any service starts or stops. We will need to dig a little deeper to make sure we get notified only when the services we care about start or stop.

If you’re interested in our how-to articles like Trigger Email Alerts From Windows Event Using Windows Server 2016, click here.

Reproduced from Clusteringformeremortals.com

Filed Under: Clustering Simplified Tagged With: trigger email alerts from windows event using windows server 2016, Windows Server 2016

  • « Previous Page
  • 1
  • …
  • 92
  • 93
  • 94
  • 95
  • 96
  • …
  • 120
  • Next Page »

Recent Posts

  • With Great Power: Cluster Maintenance Best Practices
  • AI Is Moving Fast. Critical Applications Still Need to Stay Up.
  • What Is High Availability (HA)?
  • Surviving the Friday Night Crash: From Scrappy Bare Metal to Seamless Data Replication
  • Grounded: What Missing Percona Live Amsterdam Taught Me About HA

Most Popular Posts

Maximise replication performance for Linux Clustering with Fusion-io
Failover Clustering with VMware High Availability
create A 2-Node MySQL Cluster Without Shared Storage
create A 2-Node MySQL Cluster Without Shared Storage
SAP for High Availability Solutions For Linux
Bandwidth To Support Real-Time Replication
The Availability Equation – High Availability Solutions.jpg
Choosing Platforms To Replicate Data - Host-Based Or Storage-Based?
Guide To Connect To An iSCSI Target Using Open-iSCSI Initiator Software
Best Practices to Eliminate SPoF In Cluster Architecture
Step-By-Step How To Configure A Linux Failover Cluster In Microsoft Azure IaaS Without Shared Storage azure sanless
Take Action Before SQL Server 20082008 R2 Support Expires
How To Cluster MaxDB On Windows In The Cloud

Join Our Mailing List

Copyright © 2026 · Enterprise Pro Theme on Genesis Framework · WordPress · Log in