Tuesday, October 16, 2012

SCOM 2007/2012 Cheat Sheet

What I'm about to cover is not located on anyone elses site.  And if it is, they just ripped it off from here.

Cheat Sheet #1: The poor man's managementpack working environment using SCOM 2007.

Thought you had to have the SCOM Console or SCOM Authoring Console installed and working correctly just to create a ManagementPack? You thought wrong.

Manually install an SCOM 2007 agent on your computer. Copy the SDK binaries into the agent's folder, bring up a copy of Visual Studio, create a project and then add a reference to them by browsing over to the agent's folder and selecting each one of the binaries.  You only need the application one.

Then, add the namespaces to your form or module or class:

VB.Net:
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Configuration.IO

C#.Net:
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Configuration.IO;

C++.Net:
using namespace Microsoft::EnterpriseManagement::Configuration;
using namespace Microsoft::EnterpriseManagement::Configuration::IO;

Cheat Sheet #2: The poor man's managementpack working environment using SCOM 2012.

Manually install an SCOM 2012 agent on your computer. Copy the SDK binaries into the agent's folder, bring up a copy of Visual Studio, create a project and then add a reference to them by browsing over to the agent's folder and selecting each one of the binaries.  You only need the core one.

Then, add the namespaces to your form or module or class:

VB.Net:
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Configuration.IO

C#.Net:
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Configuration.IO;

C++.Net:
using namespace Microsoft::EnterpriseManagement::Configuration;
using namespace Microsoft::EnterpriseManagement::Configuration::IO;

This one is a bit trickier in that you have to change the compiler option from .Net Framework 4 Client Profile to .Net Framework 4. See picture below:




Cheat Sheet #3: Both sealed and unsealed Managementpacks are MPs as far as Managmentpacks are concerned. When you make reference to an mp either format is accepted by the following call:

Dim mp as New ManagementPack(mpFilename)
Dim mp as New ManagementPack(xmlFilename)

Cheat Sheet #4: Covert an unsealed SCOM 2007 mp to an unsealed SCOM 2012 mp in just two lines of code but you have to use the 2012 SDK binaries. Use only a copy of your original SCOM 2007 mp (sealed or unsealed). Place it into a new folder. Below is an example of how to do this using a sealed mp:

Dim OpenFileDialog As New OpenFileDialogOpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocumentsOpenFileDialog.Filter =
"Sealed Managementpack (*.mp)|*.mp"If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) ThenDim FileName As String = OpenFileDialog.FileName
Dim mp As New ManagementPack(FileName)
Dim xmlWriter As New ManagementPackXmlWriter(Application.StartupPath)
Dim xmlFilename As String = xmlWriter.WriteManagementPack(mp)mp =
New mp(xmlFilename)mp.AcceptChanges()
End If
If you try doing the code below, you will get an error:

Dim OpenFileDialog As New OpenFileDialogOpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocumentsOpenFileDialog.Filter =
"Sealed Managementpack (*.mp)|*.mp"If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) ThenDim FileName As String = OpenFileDialog.FileName
Dim mp As New ManagementPack(FileName)mp.AcceptChanges()End If

The image below proves it is trying to write to disk:



Here's an example of doing the same thing using the unsealed xml file:

Dim OpenFileDialog As New OpenFileDialogOpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocumentsOpenFileDialog.Filter =
"Unsealed Managementpack (*.xml)|*.xml"If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) ThenDim FileName As String = OpenFileDialog.FileName
Dim mp As New ManagementPack(FileName)mp.AcceptChanges()End If

Cheat Sheet #5: You can't verify your xml.  You have to use the Authoring Console. Wanna bet?


Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "Unsealed Managementpack (*.xml)|*.xml"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileNameDim mpStore as new ManagementFileStore
'I'm using SCOM 2012 as an example
mpStore.AddDirectory("C:\SC2012OMRTM\ManagementPacks")

Dim mp As New ManagementPack(FileName, mpStore)mp.Verify()End If

NOTE: This assumes you're using the standard out of the box libaray mps

Cheat Sheet #6: You don't have to have hard code every library and other referenced managementpacks.

When dynamically adding librarys and other referenced mamagmentpacks, create an a array of mps instead.
This way, your libraries can be dynamically driven by the design of your ManagementPack.




 




No comments:

Post a Comment