A few weeks ago, I had a situation where I wanted to monitor a particular TCP Port across several different Servers. While the Authoring section within the SCOM 2012 Console provides the functionality for monitoring a single Port on a Server, there is no easy solution to provide the same type of monitoring across hundreds of different servers. After a couple of days of digging around, I wrote a Custom Management Pack Solution that is detailed below.
If you don't care to read anything below this point, the Management Pack has been attached to this post. (TCPPortCheck.xml)
Prerequisites
The SCOM 2007 R2 Authoring Console installed.
The following Libraries need to be available to the SCOM 2007 R2 Authoring Console and included in the Custom TCP Port MP.
Microsoft.SystemCenter.DataWarehouse.Library (Version: 6.1.7221.0)
Microsoft.SystemCenter.SyntheticTransactions.Library (Version: 6.1.7221.0)
The DataWarehouse Library is already included in the SCOM 2007 R2 Authoring Console. However, the version of the SyntheticTransactions Library that you need for this MP is only available in a SCOM 2007 R2 Installation. Unfortunately, the SyntheticTransactions Library that comes with SCOM 2012 is incompatible with the SCOM 2007 R2 Authoring Console as it requires as higher Base Version of the System Library to function. You have two options if you don’t already have an existing SCOM 2007 R2 Installation: Install an Evaluation Version of SCOM 2007 R2 to obtain the file or get the file from someone else in the community.
Make sure that both the DataWarehouse Library and the SyntheticTransactions Library are available in the System Center MP Authoring Console 2007 directory of your Authoring Console Installation.
Additional Documentation on the Synthetic Transactions Library can be found below:
http://msdn.microsoft.com/en-us/library/jj130214.aspx
Make sure you have a Custom Editor configured for the Authoring Console to use, as it will provide the necessary functionality to successfully complete this Management Pack. I recommend using Notepad++, but any custom text editor should suffice. In order to use the custom editor, you need to add a path for the Authoring Console to use it. You can do this by doing the following:
In the Authoring Console, go to Tools –> Options…
Under the General tab, click on the Browse… button under the Custom Editors heading.
Find the path to the executable of the custom editor you wish to use. Highlight the executable and click on Open when you are done.
Screenshot of what your final result should look like is below:
Create a New Management Pack
For this example, create a new Management Pack called TCPPortCheck. Make sure the Display Name is also called TCPPortCheck.
Add References to the Management Pack
Click on File –> Management Pack Properties.
Click on the References tab.
Click on the Add Reference… button.
Add the DataWarehouse and SyntheticTransactions Library’s into the Management Pack.
Change the Alias of the DataWarehouse Library to SCDW and the SyntheticTransactions Library to SCST to make them easier to identify later. When you are finished, it should like the Screenshot below. Click on Apply and OK.
Click on Apply and the OK.
Add a Computer Role Class in the Service Model section
Click on the Service Model section, go to Classes.
In the Classes Pane on the right, right-click and click on New –> Windows Server Role.
Name the Id: of the Class TCPPortCheck.TargetHost.
Set the Name: of the Class to TCP Port Check Target Host.
The Class should look like the Screenshot below when you are done.
Create a new Discovery in the Health Model section
Click on the Health Model section, go to Discoveries.
In the Discoveries Pane on the right, right-click and click on New –> Registry (Filtered).
Name the Id: of the Class TCPPortCheck.Discovery.
Set the Name: of the Class to TCP Port Check Discovery.
Set the Target: to Microsoft.Windows.Server.OperatingSystem. Click Next.
Configure the Schedule to run every hour (you can change this to a shorter or longer value). Click Next.
For the Computer: field type in $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$. Click Next.
Next, in Registry Probe Configuration, Click on Add.
Set the Object Type: to Key
Under Properties, set the Name: to TCPPortCheckRegKey; the Path to \SOFTWARE\SCOM\TCPPortCheck; the Attribute Type: to Check if exists. Click on OK. A Screenshot of what this should look like is below:
Click, Next.
In the Build Event Expression section, click on the Insert button.
The fields for the expression should be as follows:
Field
Value
ParameterName
Values/TCPPortCheckRegKey
Operator
Equals
Value
True
A Screenshot of what this should look like is below:
Click, Next.
In the Discovery Mapper section, set the Class ID: to be discovered to TCPPortCheck.TargetHost.
The fields for the Key Properties sections should be as follows:
Field
Value
Microsoft.Windows.Computer\PrincipalName
$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$
System.Entity\DisplayName
$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$
A Screenshot of what this should look like is below:
Click on Finish.
Create a new Probe Action in the Type Library section
Click on the Type Library section and click on Probe Actions.
In the Probe Actions Pane on the right, right-click and click on New –> Composite Probe Action…
Give this new Probe Action the ID of TCPPortCheck.TCPPortProbe.
Set the Name: to TCP Port Check TCP Port Probe.
Under the Member Modules tab, click on Add.
Look for and highlight Microsoft.SystemCenter.SyntheticTransactions.TCPPortCheckProbe. Name the Module ID: TCPPortProbe and click OK.
A Configuration page is going to pop-up; the fields should have the following values:
Field
Value
ServerName
$Config/ServerName$
Port
$Config/Port$
Click on OK.
Next, in the TCPPortProbe Module that you have created, click on the drop-down arrow in the NextModule field and select Module Output.
Next, Click on the Configuration Schema tab.
Under the Simple Configuration Schema section, change the Type value of the Port to Integer.
Next, click on the Overridable Parameters tab.
Click on Add –> ServerName. Name it ServerName.
Click on Add –> Port. Name it Port. Change the Configuration Element of Port from String to Integer.
Click on Apply and the OK.
Create a new Data Source in the Type Library section
In the Type Library section, click on Data Sources.
In the Data Sources Pane on the right, right-click and click on New –> Composite Data Source…
Give this new Data Source the ID of TCPPortCheck.TCPPortProbeDataSource.
Set the Name: to TCP Port Probe Data Source.
Click on the Member Modules tab and click on Add.
Look for and highlight TCPPortCheck.TCPPortProbe. Name the Module ID: TCPPortProbe and click OK.
A Configuration page is going to pop-up; the fields should have the following values:
Field
Value
ServerName
$Config/ServerName$
Port
$Config/Port$
Click on OK.
Next, in the Scheduler Module that you have created, click on the drop-down arrow in the NextModule field and select Module Output.
Click on the Member Modules tab and click on Add.
Look for and highlight System.SimpleScheduler. Name the Module ID: Scheduler and click OK.
A Configuration page is going to pop-up; the fields should have the following values:
Field
Value
IntervalSeconds
$Config/IntervalSeconds$
SyncTime
$Config/SyncTime$
Click on OK.
Next, in the Scheduler Module that you have created, click on the drop-down arrow in the NextModule field and select TCPPortProbe.
Click on the Configuration Schema tab.
Change the both Port and IntervalSeconds Types to Integer. Uncheck the Required box next to SyncTime.
Next, click on the Overridable Parameters tab.
Click on Add –> ServerName. Name it ServerName.
Click on Add –> Port. Name it Port. Change the Configuration Element of Port from String to Integer.
Click on Add –> IntervalSeconds. Name it IntervalSeconds. Change the Configuration Element of Port from String to Integer.
Click on Add –> SyncTime. Name it SyncTime.
Click on Apply and then OK.
Create Monitor Types in the Type Library section
Four Monitor Types have to created for the Four Different Conditions that can be returned back from a TCP Port Check. The conditions and the returned Status Code values are shown below:
Name
Status Code
Connection Refused
2147952461
DNS Resolution Failure
2147953401
Host Unreachable
2147952465
Timed Out
2147952460
Success
0
In the Type Library section, click on Monitor Types.
In the Monitor Types Pane on the right, right-click and click on New –> Composite Monitor Type…
Give this new Data Source the ID of TCPPortCheck.MonitorTypeTCPPortCheckConnectionRefused.
Set the Name: to Monitor Type TCP Port Check Connection Refused.
Click on the States tab and choose 2 State Monitor Type.
Set ID of State 1: to State_OK
Set ID of State 2: to State_CRITICAL
Next, click on the Member Modules tab and click on Add.
Look for and highlight TCPPortCheck.TCPPortProbeDataSource. Name the Module ID: DataSource and click OK.
A Configuration page is going to pop-up; the fields should have the following values:
Field
Value
ServerName
$Config/ServerName$
Port
$Config/Port$
IntervalSeconds
$Config/IntervalSeconds$
Click on Apply and then OK.
Next, click on the Member Modules tab and click on Add.
Look for and highlight System.ExpressionFilter. Name the Module ID: Status_OK and click OK.
A Configuration page is going to pop-up; Click on the Edit button.
Replace everything between the two Tags
and with the following:
StatusCode
NotEqual
2147952461
It Should look like the Screenshot below when you are finished:
Exit out of the Editor you are using when are finished and Save your changes when prompted.
Your Configuration page should look like the Screenshot below:
Click on Apply and then on OK.
Next, click on the Member Modules tab and click on Add.
Look for and highlight System.ExpressionFilter. Name the Module ID: Status_CRITICAL and click OK.
A Configuration page is going to pop-up; Click on the Edit button.
Replace everything between the two Tags
and with the following:
StatusCode
Equal
2147952461
It Should look like the Screenshot below when you are finished:
Exit out of the Editor you are using when are finished and Save your changes when prompted.
Your Configuration page should look like the Screenshot below:
Click on Apply and then on OK.
Click on the Member Modules tab and click on Add.
Look for and highlight TCPPortCheck.TCPPortProbe. Name the Module ID: Probe and click OK.
A Configuration page is going to pop-up; the fields should have the following values:
Field
Value
ServerName
$Config/ServerName$
Port
$Config/Port$
Click on OK.
Next, click on the Regular tab.
Highlight State_OK State and make sure it is configured as shown below:
Include
Member Module
Next Module
Checked
DataSource
Status_OK
Checked
Status_OK
Monitor State Output
Unchecked
Status_CRITICAL
Unchecked
Probe
Highlight State_CRITICAL State and make sure it is configured as shown below:
Include
Member Module
Next Module
Checked
DataSource
Status_CRITICAL
Unchecked
Status_OK
Checked
Status_CRITICAL
Monitor State Output
Unchecked
Probe
Next, click on the On Demand tab.
Put a check mark in the Use on Demand Detection box.
Highlight State_OK State and make sure it is configured as shown below:
Include
Member Module
Next Module
Checked
Status_OK
Monitor State Output
Unchecked
Status_CRITICAL
Checked
Probe
Status_OK
Highlight State_CRITICAL State and make sure it is configured as shown below:
Include
Member Module
Next Module
Unchecked
Status_OK
Checked
Status_CRITICAL
Monitor State Output
Checked
Probe
Status_CRITICAL
Next, click on the Configuration Schema tab.
Under the Simple Configuration Schema section, change both the Port Type and IntervalSeconds Type to Integer.
Next, click on the Overridable Parameters tab.
Click on Add –> ServerName. Name it ServerName.
Click on Add –> Port. Name it Port. Change the Configuration Element of Port from String to Integer.
Click on Add –> IntervalSeconds. Name it Port. Change the Configuration Element of IntervalSeconds from String to Integer.
Click on Apply and then OK.
The Monitor Type that was just created for the Connection Refused Status Code needs to be created for DNS Resolution Failure, Host Unreachable, and Timed Out. The directions at the top of this section can be repeated as there are only two values that need to be changed to create the other three Monitor Types:
The Respective Name of the Monitor Type
The Unsigned Integer Value of the Status_OK and Status_CRITICAL modules.
Just for Reference, here are what those values should be:
Monitor Type ID Name
Monitor Type Name
Unsigned Integer Value
TCPPortCheck.MonitorTypeTCPPortCheckConnectionRefused
Monitor Type TCP Port Check Connection Refused
2147952461
TCPPortCheck.MonitorTypeTCPPortCheckDNSResolutionFailure
Monitor Type TCP Port Check DNS Resolution Failure
2147953401
TCPPortCheck.MonitorTypeTCPPortCheckHostUnreachable
Monitor Type TCP Port Check Host Unreachable
2147952465
TCPPortCheck.MonitorTypeTCPPortCheckTimedOut
Monitor Type TCP Port Check Timed Out
2147952460
Create a new Rule in the Health Model section
In order to capture all Performance Metrics from this TCP Port Monitor, a Rule needs to be created.
In the Health Model section, click on Rules.
In the Rules Pane on the right, right-click and click on New –> Custom Rule…
Give this new Data Source the ID of TCPPortCheck.RuleTCPPortCheckConnectionTime.
Set the Name: to TCP Port Check Connection Time.
Set the Target: to TCPPortCheck.TargetHost.
Click on the Modules tab.
Under Data Sources, click on the Create… button.
Look for and highlight TCPPortCheck.TCPPortProbeDataSource. Name the Module ID: DataSource and click OK.
Next, highlight TCPPortCheck.TCPPortProbeDataSource and click on Edit.
On the Configuration page, make sure the fields have the following values:
Field
Value
ServerName
$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$
Port
3389
IntervalSeconds
300
Click on Apply and then OK.
Under Condition Detection click on the Create… button.
Look for and highlight System.Performance.DataGenericMapper. Name the Module ID: MapToPerf and click OK.
Highlight the MapToPerf module you just created and click on Edit.
On the Configuration page, make sure the fields have the following values:
Field
Value
ObjectName
TCP Port Check
CounterName
Connection Time
InstanceName
$Data/ServerName$:$Data/Port$
Value
$Data/ConnectionTime$
Click on Apply and then OK.
Under Actions click on the Create… button.
Look for and highlight Microsoft.SystemCenter.CollectPerformanceData. Name the Module ID: WriteToDB and click OK.
Under Actions click on the Create… button.
Look for and highlight Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData. Name the Module ID: WriteToDW and click OK.
Click on the Options tab.
Click on the Category [Value=’Custom’] item and change it to PerformanceCollection.
Click on Apply and then OK.
Create TCP Port Monitors in the Health Model section
First Create an Aggregate Monitor to contain all four of the Unit Monitors in:
In the Health Model section, click on Monitors.
In the Monitors Pane on the right, right-click and click on New –> Aggregate Monitor…
Give this new Data Source the ID of TCPPortCheck.TCPPortCheckHealth.
Set the Name: to TCP Port Health.
Set the Target: to TCPPortCheck.TargetHost.
Set the Parent Monitor: to System.Health.AvailabilityState
Click on Apply and then OK.
Next, We need to create the four Unit Monitors to test against the four possible failed TCP Port States.
In the Monitors Pane on the right, right-click and click on New –> Custom Unit Monitor…
Give this new Data Source the ID of TCPPortCheck.UnitMonitorTCPPortCheck3389ConnectionRefused.
Set the Name: to TCP Port Check 3389 - Connection Refused.
Set the Target: to TCPPortCheck.TargetHost.
Set the Parent Monitor: to TCPPortCheck.TCPPortCheckHealth
Next, click on the Configuration tab and click on Browse for a type…
Look for and highlight TCPPortCheck.MonitorTypeTCPPortCheckConnectionRefused and then click on OK.
In the fields that appear, make sure they are configured as shown below:
Name
Value
ServerName
$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$
Port
3389
IntervalSeconds
300
Next, Click on the Health tab and change the Health States to match what is shown below:
Monitor Condition
Operational State
Health State
State_OK
State_OK
Healthy
State_CRITICAL
State_CRITICAL
Critical
Next, click on the Alerting tab.
Put a check mark in the Generate alerts for this monitor checkbox.
Set Generate an alert when: to The monitor is in a critical health state.
Leave Automatically resolve the alert when the monitor returns to a healthy state checked.
Set the Alert Name: to TCP Port 3389 Check - Connection Refused.
Set the Alert Description: to The TCP Port 3389 Check Monitor on $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ returned back a Status Code of "Connection Refused".
Make sure that Priority: is set to Medium and Severity: is set to Critical.
Click on Apply.
Next, click on the Options tab.
Click on the Category [Value=’Custom’] item and change it to AvailabilityHealth.
Click on Apply and then OK.
Repeat this same process three more times for DNS Resolution Failure, Host Unreachable, and Timed Out.
The Monitor Types required when searching for a Custom Unit Monitor Type are listed below
Monitor Type ID Name
Monitor Type Name
TCPPortCheck.MonitorTypeTCPPortCheckConnectionRefused
Monitor Type TCP Port Check Connection Refused
TCPPortCheck.MonitorTypeTCPPortCheckDNSResolutionFailure
Monitor Type TCP Port Check DNS Resolution Failure
TCPPortCheck.MonitorTypeTCPPortCheckHostUnreachable
Monitor Type TCP Port Check Host Unreachable
TCPPortCheck.MonitorTypeTCPPortCheckTimedOut
Monitor Type TCP Port Check Timed Out
Create a Custom View for TCP Port Monitors and Port Performance in the Presentation section
To keep from having to dig to find the Monitors in the SCOM Console, we will create some Simple Custom View that will be available in the Monitoring section.
In the Presentation section, click on Views.
In the Views Pane on the right, right-click and click on New –> Folder…
Give this new Data Source the ID of TCPPortCheck.CustomViews.
Set the Name: to TCP Port Monitors.
Click on Apply then on OK.
Next, in the Views Pane on the right, right-click and click on New –> Alert View.
Give this new Data Source the ID of TCPPortCheck.TCPMonitorAlerts.
Set the Name: to TCP Monitor Alerts.
Set the Target: to TCPPortCheck.TargetHost.
Set the Category: to Alert.
In the Views Pane on the right-click on TCPPortCheck.TCPMonitorAlerts and click on properties.
Click on the Folder tab.
Deselect the Microsoft.SystemCenter.Monitoring.ViewFolder.Root
Select the TCPPortCheck.CustomViews
Click on Apply and then OK.
Next, in the Views Pane on the right, right-click and click on New –> Performance View.
Give this new Data Source the ID of TCPPortCheck.TCPPortPerformance.
Set the Name: to TCP Port Performance.
Set the Target: to TCPPortCheck.TargetHost.
Set the Category: to PerformanceCollection.
In the Views Pane on the right-click on TCPPortCheck.TCPPortPerformance and click on Properties.
Click on the Folder tab.
Deselect the Microsoft.SystemCenter.Monitoring.ViewFolder.Root
Select the TCPPortCheck.CustomViews
Click on Apply and then OK.
Next, in the Views Pane on the right, right-click and click on New –> Performance View.
Give this new Data Source the ID of TCPPortCheck.MonitoredServers.
Set the Name: to Monitored Servers.
Set the Target: to TCPPortCheck.TargetHost.
Set the Category: to Discovery.
In the Views Pane on the right-click on TCPPortCheck.MonitoredServers and click on Properties.
Click on the Folder tab.
Deselect the Microsoft.SystemCenter.Monitoring.ViewFolder.Root
Select the TCPPortCheck.CustomViews
Click on Apply and then OK.
Save the Management Pack and Import it into SCOM
From this point, if you haven’t done so several times already, go to File –> Save to save your Management Pack.
Next, Import the Management Pack into SCOM.
Note: The Export MP to Management Group… function in the Authoring Console doesn’t work for SCOM 2012.
Add the Registry Key HKLM\SOFTWARE\SCOM\TCPPortCheck to whichever Server you want to test this MP on. (Just make sure the SCOM Agent is running on it).
Depending on the scheduled interval you set in the Discovery Class earlier, you should start seeing results between a few minutes to an hour.
Screenshots of the Monitoring and Performance Views are below:
Console View:
Performance View:
Health Explorer View:
……