Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pushing the Envelope;.NET Code in SCOM Management Packs Nathan Jonathan

Similar presentations

Presentation on theme: "Pushing the Envelope;.NET Code in SCOM Management Packs Nathan Jonathan"— Presentation transcript:

1 Pushing the Envelope;.NET Code in SCOM Management Packs Nathan Foreman @Nate_Foreman Jonathan Almquist @jtalmquist

2 #MMSMOA @Nate_Foreman Solutions Engineer 10+ years in IT Nathan Foreman

3 #MMSMOA @jtalmquist Consultant, blogger, author, speaker TechNet Forum Blogging since 2007 16 years experience in IT, past 10 years focused on Operations Manager Jonathan Almquist

4 Overview and Agenda Theory Why.NET? What’s.Net Modules Pros (& Cons) Functionality Microsoft Examples Elastic Search DW Development Concepts Threading Batching Persistence Acknowledgments/Notification s Module Lifecycle Implementation Making the Library (.dll) Create VS Project Signing the Builds References Class Construction Required Methods SyncLock Data & Control Flow Get the Module in SCOM Create Library MP Add Deployable Assembly Create & Use Module

5 Why.NET?Why.NET? It’s not quicker or easier, so what can we gain by going this route?

6 What are.NET modules? One of three Module Implementation [3,4] Native Managed Composite They’ve been around for a while SCOM 2007 [4] “Creation or modification of native modules and managed modules is not supported...” SCOM 2012 [5] Only create them, when provided modules “are insufficient for your needs”

7 Advantages Persisted State Compiled.NET code can work faster [1] Harder to Tamper/Reverse Engineer Full Featured IDE Leverage.NET Coding Professionals Disadvantages More Complicated than Scripted Alternatives Additional Knowledge required to write Code Requires additional Steps for Distribution Updates to Code take longer to deploy than scripts. Why.NET? – Pros and Cons

8 Functionality & Examples Microsoft Examples PowershellProbeBase PowershellProbe PowershellDiscoveryProbeBa se PowershellDiscoveryProbe SystemCenter.GroupPopulat or SystemCenter.EventWriter.DiscoveryDataWriter.PerformanceDataWriter Elastic Search DW High Speed Logging 4,000 items Per Second Perf Collection Every 2 Seconds Reduce Database Size Smaller OpsDB Extended DW Retention Fast Searching and Reporting

9 Demo.NET Elastic Search DW (Frontend)

10 Development ConceptsDevelopment Concepts To get the most from your.NET modules there are a few things to keep in mind. Design and Development notes from Microsoft:

11 Development Concepts Threading Not a Unique concern to.NET Health Service is a Shared Environment IO Bound: Use Async Methods CPU Bound: Perform work Synchronously Batching [6] Allows Multiple Items per Execution Not relevant for composite module types Consolidation Modules with multiple Items

12 Development Concepts Persistence Save State between Executions Module Host handles data Cleared on Module Change Acknowledgments Transactional Data Flow not Supported [5] Responsible until Acknowledgment Completion Notifications Notifies Health Service work is Complete Must Notify Completion before next Request

13 Development Concepts Startup and Shutdown Constructor Start Called After Constructor Completes Must be Thread Safe with NotifyStop NotifyStop Notifies of a graceful shutdown Shutdown About to be Unloaded, time to save State Engine may Unload without Notice Module must not corrupt threads

14 Making the LibraryMaking the Library Implementation is where the fun really is.

15 New Visual Studio Project Create a Class Library Project Sign the Build Set the Namespace Strong Named Assemblies Required us/library/ms227566(v=vs.80).aspx Handle Required References Are they on the Target? Embed Resources you may Need Embedded-Resource

16 Class Definition Attributes MonitoringModule(ModuleType.WriteAction) ModuleOutput (True/False) Inherits ModuleBase Of DataItemBase Global Variables SyncLock Object Shutdown in Progress Boolean

17 [MonitoringModule(ModuleType.WriteAction)] [ModuleOutput(false)] public sealed class WriteToES : ModuleBase { //Shared objects, accessible from all instances static P2PLogging Logger; static bool ShutdownInProgress; //Global object, controls activity via SyncLocks private object shutdownLock; //Making Global, reducing instantiation cost private ElasticSearchConnector ESConnector; private DataItemProcessor DataItemCollection; _ Public NotInheritable Class WriteToES 'Inherit the ModuleBase we will be working off of Inherits ModuleBase(Of DataItemBase) 'Shared objects are accessible from all instances Shared Logger As P2PLogging Shared ShutdownInProgress As Boolean 'Global object, controls activity via SyncLocks Private shutdownLock As Object 'Making Global, reducing instantiation cost Private ESConnector As ElasticSearchConnector Private DataItemCollection As DataItemProcessor Class Construction: Code VB.NETC# VB.NE T

18 Required Methods - New Signature moduleHost As ModuleHost(Of DataItemBase) configuration As XmlReader previousState As Byte() Setup your Module Logging Libraries Configuration Parsing

19 public WriteToES(ModuleHost moduleHost, XmlReader configuration, byte[] previousState) : base(moduleHost) { //Verify we Have everything we need if (configuration == null) { throw (new Exception("configuration is nothing")); } //Add the Additional Libraries to our instantiation LibraryLoader LibraryLoader = new LibraryLoader(Assembly.GetExecutingAssembly(), false); LibraryLoader.LoadLibrariesFromResources(); //Extract from Config what we need and initiate the connections. ParsedConfigData InstanceConfig = new ParsedConfigData(); InstanceConfig = ExtractConfigData(configuration); //Create the Classes we will use throughout the life of this module Logger = new P2PLogging(); DataItemCollection = new DataItemProcessor(Logger); shutdownLock = new object(); Public Sub New(moduleHost As ModuleHost(Of DataItemBase), configuration As XmlReader, previousState As Byte()) 'Call the Base Constructor MyBase.New(moduleHost) 'Verify we Have everything we need If configuration Is Nothing Then Throw New Exception("configuration is nothing") 'Add the Additional Libraries to our instantiation Dim LibraryLoader As New LibraryLoader(Assembly.GetExecutingAssembly(), False) LibraryLoader.LoadLibrariesFromResources() 'Extract from Config what we need and initiate the connections. Dim InstanceConfig As ParsedConfigData InstanceConfig = ExtractConfigData(configuration) 'Create the Classes we will use throughout the life of this module Logger = New P2PLogging DataItemCollection = New DataItemProcessor(Logger) shutdownLock = New Object() New Method: Code VB.NETC# VB.NE T

20 Required Methods - Start Empty Signature Check for Shutdown Lock ModuleHost.RequestNextDataItem()

21 public override void Start() { lock(shutdownLock) { //We don't need to continue if Shutdowns are starting. if (ShutdownInProgress) { return ; } //Request the first data batch. //The ME keyword unambiguously refers to this instance this.ModuleHost.RequestNextDataItem(); } Public Overrides Sub Start() SyncLock shutdownLock 'We don't need to continue if Shutdowns are starting. If ShutdownInProgress Then Return End If 'Request the first data batch. 'The ME keyword unambiguously refers to this instance Me.ModuleHost.RequestNextDataItem() End SyncLock End Sub Start Method: Code VB.NETC# VB.NE T

22 Required Methods - OnNewDataItems Denote Input Stream Number [InputStream(0)] Signature dataItems As DataItemBase() logicallyGrouped As Boolean acknowledgedCallback As DataItemAcknowledgementCallback acknowledgedState As Object completionCallback As DataItemProcessingCompleteCallback completionState As Object Do work with the DataItems() Lock ModuleHost.RequestNextDataItem()

23 [InputStream(0)] public void OnNewDataItems(DataItemBase[] dataItems, bool logicallyGrouped, DataItemAcknowledgementCallback acknowledgedCallback, object acknowledgedState, DataItemProcessingCompleteCallback completionCallback, object completionState) { // If we have been shutdown stop processing. if (ShutdownInProgress) { Logger.WriteInformation("Shutdown in Progress"); return ; } // This is where you will do your work, code has been removed for Space lock(shutdownLock) { this.ModuleHost.RequestNextDataItem(); } _ Public Sub OnNewDataItems(dataItems As DataItemBase(), logicallyGrouped As Boolean, acknowledgedCallback As DataItemAcknowledgementCallback, acknowledgedState As Object, completionCallback As DataItemProcessingCompleteCallback, completionState As Object) ' If we have been shutdown stop processing. If ShutdownInProgress Then Logger.WriteInformation("Shutdown in Progress") Return End If ' This is where you will perform you work with the DataItems() SyncLock shutdownLock Me.ModuleHost.RequestNextDataItem() End SyncLock End Sub OnNewDataItems Method: Code VB.NETC# VB.NE T

24 Required Methods - Shutdown Empty Signature Lock Mark Global Shutdown in Progress Cleanup as Needed Finalize()

25 public override void Shutdown() { //Lock to prevent other operations during Shutdown lock(shutdownLock) { ShutdownInProgress = true; //Cleanup Here } Public Overrides Sub Shutdown() 'Lock to prevent other operations during Shutdown SyncLock shutdownLock ShutdownInProgress = True Me.Finalize() End SyncLock End Sub Shutdown Method: Code VB.NETC# VB.NE T

26 Getting The Module in SCOMGetting The Module in SCOM It’s time to get back into familiar territory

27 Creating a Library Management Pack DeployableAssembly Fully Qualified Assembly Name <DeployableAssembly ID="P2P.ManagedScomModules" Accessibility="Public" FileName="ManagedSCOMModules.dll" HasNullStream="false" QualifiedName="ManagedSCOMModules, Version=, Culture=neutral, PublicKeyToken=d49ecc768c087c65"/> DLL in Management Pack Project Set Build Action = Embedded Resource

28 Create the Write Action Module P2P.ManagedScomModules ManagedSCOMModules.WriteToES System!System.BaseData

29 Create a Pack with Actions PerformanceCollection. % Processor Time Process true 2 SCOMWinEvents SCOMDataItems true

30 Demo Putting Everything Together.

31 References 1. performance-comparison-compiled-code-cmdlet-or-net- call performance-comparison-compiled-code-cmdlet-or-net- call 2. us/library/7k989cfy(v=vs.90).aspx us/library/7k989cfy(v=vs.90).aspx 3. 15219.operations-manager-management-pack- authoring-module-implementations.aspx 15219.operations-manager-management-pack- authoring-module-implementations.aspx 4. us/library/ff381347.aspx us/library/ff381347.aspx 5. 6. module-to-rule-them-all-a-custom-scom-managed- module-sysctr/ module-to-rule-them-all-a-custom-scom-managed- module-sysctr/

32 Evaluations: Please provide session feedback by clicking the EVAL button in the scheduler app (also download slides). One lucky winner will receive a free ticket to the next MMS! Session Title: Pushing the Envelope;.NET Code in SCOM Management Packs Discuss… Ask your questions-real world answers! Plenty of time to engage, share knowledge. SPONSORS


Download ppt "Pushing the Envelope;.NET Code in SCOM Management Packs Nathan Jonathan"

Similar presentations

Ads by Google