SCSM – How to create Custom Connectors via SC Orchestrator – SCOM Monitored Server Connector
When it comes to synchronizing data into SCSM there are several default connectors which are available to you;
- Active Directory
- SCCM
- SCOM (CI and Alert Connector)
- SCVMM
- Orchestrator
Though these are available, there are various CI objects in which we may want to add to its CMDB such as bespoke applications or even such as SCOM information.
You have the SCOM CI connector which can synchronize all of the CI data from its management packs, but one thing you cannot actually synchronize is the SCOM agent statues and health statuses of each of the monitored CI’s within SCOM.
Reason being is because SCSM uses the same engine as SCOM and is essentially SCOM to itself, and various tables within the SCSM database are duplicates of the SCOM database but will only hold objects which are local to the SCSM CI synchronization and its management Servers.
In this case I wanted to pull the information from SCOM so I can see the following;
- SCOM Agent is Installed
- Current Health State
- Is Available
- Last Available Date
These attributes are occupied within the SCSM database with the management server values and the default connectors are unable to bring this in even with allowing the appropriate classes using the “Add-SCSMAllowListClass” command or adding more SCOM management packs.
Create the Management Pack
So, the first thing we need to do is create a custom management pack which will contain these classes for us, as they maybe available within SCSM as an existing class but you will be unable to create any additional objects with them so we will need to create our own.
The SCSM Authoring tool will be first choice to build this, I do have a script which can actually build the SCSM management pack from Scratch using PowerShell & XML which I will make another blog for separately.
- Open the SCSM Authoring Tool
- Right click file and choose New
- Type a name for the Management Pack and click save
- Right click “Classes” and choose to Create Configuration Item Class.
- Type in a name for the class which doesn’t contain any spaces
- Click the Class you have just created and go to the Details pane and locate the “Name” field. This is where you can add a space in between the words of your class name if wanting a better-looking display name.
- Now right click inside the “Class Properties and Relationships” window and choose “Create Property”.
- Type in the name of the properties you wish to create in this case it would be the SCOM attributes listed above and do the same for each accepting the default data type being a “String”.
- Go to the “Name” value and make sure that the Display Name is done how you want it to show.
- If there is a property called “Property” with some numbers next to it then delete this. This is placed as a default to establish a key property. You may get a warning message once this bit has been done.
- Go to any one of the properties which you have created that you want to be the key value, then go into the details pane and change the “Key” attribute from false to true.
- Save the management pack. If you want to seal it then right click the Management Pack name in the top left-hand pane in the “Management Pack Explorer” and choose “Seal Management Pack”. (Note: You would need to have an encryption key already created to seal it which you can do from the Visual Studio command tools)
Import into SCSM
Once created perform the following
- Open the Service Manager Console
- Go to Administration – Management Packs and choose the Import Management Pack button
- Select the Management Pack in which you had just created. Then click OK to import.
- Once completed go to the Configuration Items tab.
- Right click anywhere you see appropriate and choose to “Create View”.
- Type in a name for the View, and select the management pack which you wish to store the view in (Note: Best practice would be to store them in a New Management pack which you can click the New button to do as you don’t want to get into any habit of just storing every single custom made object into any default unsealed packs as this can cause huge issues in the future).
- Click the Browse button in the Criteria section. Then change the drop-down list from “Frequently used basic classes” to “All Basic Classes” and search for the class which you have just created.
- Click OK to accept the view.
- This will be the view which you will see all of the CI objects show in once we get the actual connector created.
Creation of the Connector
The main prerequisites for this would be the following
- Microsoft System Center Orchestrator
- Microsoft System Center Service Manager Integration Pack
- SQL Management Studios + Client SDK + Command Line Tools
The first two are what you will need to formulate the connector logic and the SQL management studios is needed for us to write the PowerShell logic to open a connection to the SCOM Database Server.
So here are the pieces in which you need to create the runbook. First you will need to do the following;
- Open the runbook designer
- Right click the Runbooks folder and create a new runbook
- Make sure the runbook is checked out so you can edit it
- Use the following boxes below to create the activity steps
Step Number |
1 |
|
Step Name |
Schedule Daily at (Specify Time) |
|
Integration Pack |
Scheduling |
|
Activity Name |
Monitor Date/Time |
|
Functionality |
This step will be the initial start point triggered by a specific amount of time. Similar to the connectors within the SCSM console |
|
How to Create |
Open the scheduling tab in the Runbook Designer application. Drag to the empty space and right click it to show properties. In the details section edit what time interval you want the runbook to run at. |
Step Number |
2 |
|
Step Name |
Get SCOM Agents |
|
Integration Pack |
System |
|
Activity Name |
Run .NET Script |
|
Functionality |
This step will grab all of the SCOM Agents which are monitored. |
|
How to Create |
Drag the Run .NET Script to the runbook and create a link between the “Schedule Daily At” step to this activity. Make sure the script connection is “PowerShell”. The following script will need to be constructed. The following script below creates a connection to the SCOM Database Server and runs the query which will grab all of the monitored SCOM agents and then grabs the information from all of the columns from the Variables. (Note: Make sure to create the variables again in the “Published Data” tab in the properties of the Run .NET Script” step) You will need to enter values for the following variables
$servername = “<Database Server Name>” $Databasename = “<Database Name>” $Query = "Use OperationsManager select distinct * from dbo.ManagedEntityGenericView Where FullName LIKE '%HealthServiceWatcher%' AND MonitoringClassId = 'A4899740-EF2F-1541-6C1D-51D34B739492'" $user = "<Domain\Username>” $QueryTimeout = 120 $Connectiontimeout = 30 $Connection = New-Object System.Data.SqlClient.SqlConnection $Connectionstring = "Server=$servername;uid=$user;pwd=$pwd;Database=$database;Integrated Security=True" $connection.ConnectionString = $Connectionstring $connection.open() $command = $connection.CreateCommand() $Command.CommandText = $Query $result = $command.ExecuteReader() $Agents = New-Object "System.Data.DataTable" $Agents.Load($result) $Name = $Agents | ForEach-Object {$_.DisplayName} $HealthState = $Agents | ForEach-Object {$_.HealthState} $IsAvailable = $Agents | ForEach-Object {$_.IsAvailable} $AvailabilityLastModified = $Agents | ForEach-Object {$_.AvailabilityLastModified} $BaseManagedEntityId = $Agents | ForEach-Object {$_.BaseManagedEntityId} Go into the published data option and create the variables which you see in the script which are
This will allow you to pass the variable data across to the other activities. |
Step Number |
3 |
|
Step Name |
Find SCOM CI Agent |
|
Integration Pack |
SC 2016 Service Manager |
|
Activity Name |
Get Object |
|
Functionality |
This will check to see any of the SCOM agents actually exist within the Service Manager Database |
|
How to Create |
Drag the Get Object activity from the SC 2016 Service Manager integration pack and into the runbook creating a link between “Get SCOM Agents” and this activity. Open the activity and make sure to select the class for which you created within the management pack for the SCOM agents. And add a filter for the displayname to use the “Name” published data from the “Get SCOM Agents” step |
Step Number |
4 |
|
Step Name |
Add SCOM CI Agent |
|
Integration Pack |
SC 2016 Service Manager |
|
Activity Name |
Create Object |
|
Functionality |
Creates the SCOM CI within Service Manager |
|
How to Create |
Drag the Create Object activity from the SC 2016 Service Manager integration pack and into the runbook creating a link between “Find SCOM CI agent” and this activity. Edit the link properties between them both and make sure to set it as “Display Name from Find SCOM Agent CI matches pattern ^$” which means if this property is blank. Again edit the properties of the activity and select the custom class you created and add the following fields
And then right click each one and map the published data from the “Get SCOM Agents” to the appropriate fields |
Step Number |
5 |
|
Step Name |
Update SCOM Agent |
|
Integration Pack |
SC 2016 Service Manager |
|
Activity Name |
Update |
|
Functionality |
If the SCOM CI already exists in Service Manager then it will update the property with the new information from SCOM |
|
How to Create |
Drag the Update Object activity from the SC 2016 Service Manager integration pack and into the runbook creating a link between “Find SCOM CI agent” and this activity. Edit the link properties between them both and make sure to set it as “Display Name from Find SCOM Agent CI doesn’t match pattern ^$” which means if this property is blank. Again, edit the properties of the activity and select the custom class you created and add the following fields
And then right click each one and map the published data from the “Get SCOM Agents” to the appropriate fields |
This runbook should now be complete.
So, run the runbook (can test with the runbook tester) and when finished we can check the SCSM console, and go into the view you created earlier and you should now see a list of all of the SCOM CI agents inside now.
Future Reference
Any and every part of this process can be edited or tailored and doesn’t have to specifically apply to SCOM but can be to any products or applications in which you support that doesn’t have a connector to support it.