SCOM MP Authoring Example: Generate alerts based on entries from SQL Database (Part 1 of 2)
This is probably going to be a bit too long for one single blog post. I’ll separate this topic into 2 articles:
- Part 1 includes the background and overview of the rule and it’s workflow
- Part 2 documents all the steps to create all the module types and the rule itself.
This article is the first part of the 2-part series.
Recently, I’ve been writing a SCOM management pack for a new application that my employer is implementing. This application logs any application related alarms into a SQL express database. One of the requirement for the MP is to catch these alarms from the database and generate alerts based on these alarms.
In the database, I’m interested in any records that has the value of “Alarm triggered” in “EventTypeCaption” column.
The the record is added to the database, the application also adds the time stamp in UTC to the “EventDate” field.
Below is a snapshot of a subset of the database. I’ve highlighted the records that I’m interested in:
To achieve this goal, I’ve written some custom modules and created a rule using these modules.
As usual, the rule contains 3 modules:
- Data Source
- Condition Detection
Below is the flow chat for the entire workflow:
To explain the workflow in details:
- The workflow takes 3 inputs:
- IntervalSeconds – how frequent does the rule run
- SQLInstance – Name of the SQL instance
- Database – Name of the database
- The data source member module system.simple.scheduler runs according to the intervalseconds
- The Probe Action member module (a PowerShell script) takes all 3 inputs:
- connect to the database in the SQL instance as specified from the input
- calculate the earliest time (current time minus intervalseconds from the input then convert to UTC). store the earliest time in a datetime variable $starttime
- Build the SQL query: “Select * from <table name> Where EventTypeCaption LIKE ‘Alarm triggered’ AND EventDate >= ‘$StartTime'”
- Execute the SQL query.
- If returned any data:
- Property Bag value “GenerateAlert” = True
- For each record, convert the EventDate from UTC time to local time.
- combine all records from the record set to a multi line string that include converted event date and event description. return this string as Property Bag value “LogEntry”
- return Property Bag Value “LogEntryCount”
- Condition Detection module detects Property Bag value “GenerateAlert” = True
- If passed Condition Detection Module, the Write Action module generates alert with LogEntry and LogEntryCount in alert description field.
Note: I’m using PowerShellPropertyTriggerOnlyProbe rather than VBscript because I found it’s easier to convert UTC and local time back and forth as I can simply use .NET class System.TimeZoneInfo and powershell datetime object ToUTC() method to do the conversion. if we are to use VBScript, there is no equivalent trigger only probe for VBScript. I’ll try to cover this in a separate blog post.
I’ll go through how to create each module types and the rule itself in part 2 of this series.
To be continued…
- Active Directory (1)
- Azure (25)
- DNS (1)
- Hyper-V (5)
- Microsoft Exchange (1)
- MVP (3)
- OMS (48)
- Others (30)
- Power BI (7)
- PowerShell (109)
- SC Orchestrator (4)
- SCCM (44)
- SCDPM (1)
- SCOM (180)
- SCSM (3)
- SCVMM (5)
- SharePoint (1)
- SMA (31)
- SQL Server (1)
- TY Consulting (1)
- Uncategorized (2)
- VBScript (1)
- Visual Studio (1)
- Windows (5)
Blogs I Follow
- Adin Ermie
- Aidan Finn
- Alexandre Verkinderen
- Bob Cornelissen
- Cameron Fuller
- Christopher Keyaert
- Damian Flynn
- Daniele Grandini
- David O’Brien
- Dieter Wijckmans
- Flemming Riis
- Jakob Gottlieb Svendsen
- James Bannan
- James Van Den Berg
- Lee Berg
- Kevin Greene
- Kristian Nese
- Marcel Zehner
- Marnix Wolf
- Raymond Chou
- Pete Zerger
- Stanislav Zhelyazkov
- Stefan Roth
- Steve Beaumont
- Steve Buchanan
- Thomas Maurer