squaredup / Community.PowerShellMonitoring.MP

The PowerShell Monitoring Management Pack extends the System Center Operations Manager (SCOM) console with the ability to create PowerShell based monitoring and automation workflows, including Monitors, Rules, Agent tasks, Diagnostics and Recoveries.
GNU General Public License v3.0
23 stars 4 forks source link

Returning Multiple PropertyBags possible with Performance Rules ? #5

Open MrDibbley opened 6 years ago

MrDibbley commented 6 years ago

with the following code snippet:

` foreach ($omnistackhost in $omnistackcluster.members) {

$uri = "https://" + $ovc + "/api/hosts/" + $omnistackhost 
$hostresponse = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get

$propertyBag = $scomAPI.CreatePropertyBag()
$propertyBag.AddValue("Instance", $hostresponse.host.name)
$propertyBag.AddValue("Counter", "Used")
$propertyBag.AddValue("Value", $hostresponse.host.used_capacity)
$propertyBag

$propertyBag = $scomAPI.CreatePropertyBag()
$propertyBag.AddValue("Instance", $hostresponse.host.name)
$propertyBag.AddValue("Counter", "Total")
$propertyBag.AddValue("Value", $hostresponse.host.allocated_capacity)
$propertyBag

}`

mapped in the performance mapper as:

Object - OmnistackCapacity Counter - $Data/Property[@Name='Counter']$ Instance - $Data/Property[@Name='Instance']$ Value - $Data/Property[@Name='Value']$

when results are returned the countername does not get updated, so Countername = UsedBytes for both bags?

from DW db - 2018-02-15 11:21:39.833 265672542208 hh-hpe-i03.diti.lr.net UsedBytes 2018-02-15 11:21:39.833 6091815282278 hh-hpe-i03.diti.lr.net UsedBytes 2018-02-15 11:21:39.520 265151482880 hh-hpe-i04.diti.lr.net UsedBytes 2018-02-15 11:21:39.520 6091815282278 hh-hpe-i04.diti.lr.net UsedBytes

when i was hoping for:

2018-02-15 11:21:39.833 265672542208 hh-hpe-i03.diti.lr.net UsedBytes 2018-02-15 11:21:39.833 6091815282278 hh-hpe-i03.diti.lr.net TotalBytes 2018-02-15 11:21:39.520 265151482880 hh-hpe-i04.diti.lr.net UsedBytes 2018-02-15 11:21:39.520 6091815282278 hh-hpe-i04.diti.lr.net TotalBytes

is it possible to return multiple bags this way or will i need to create two separate collectors?

Thanks

shadeon commented 6 years ago

You can return multiple property bags from a script - the issue you are seeing here is that SCOM does not support returning more than one Object or Counter value from a single performance collection rule.

Regardless you will need to create two performance collection rules, but if you are worried about the performance overhead of your script running twice and making two sets of requests, you could utilise SCOM's cookdown feature.

Here you have the script return multiple property bags, but run in two different rules. As the script will be exactly the same, SCOM will just run it once and replay the data to any subsequent modules in the workflow. You'd just need to insert a System.ExpressionFilter module after the script to filter out the property bag you don't want, based on counter.

Sadly the PS MP doesn't support this directly, as adding an expression filter to the rule wizard would be unnecessary in most cases and just make an already confusing UI even worse. It would also rely on you keeping the scripts in both collection rules exactly the same, or it will then switch to running the script twice.

If you are up to the challenge though you could create the rules using the MP (leave disabled by default), export the MP and then manually add an Expression Filter to each in the Condition Detection section, to pass through only the appropriate counter for the rule. Enable the rules and re-import and you'll be good to go.

shadeon commented 6 years ago

Sorry, didn't mean to close. I'll tag this with enhancement and we can look at adding an additional template that exposes an expression filter for this. You'll still have to manually keep the scripts in sync, but at least it will make it easier.