OpsMgr & External Services PT2
Continuing the series where i try to season Operations Manager with data from external sources. Where In part one I created a CSV file containing the name and url to yr.no’s open XML API. I created two classes and one relationship and discoveries for these. You can find part one of OpsMgr and External services here
In part two, I will continue with the weather management pack focusing on the Health Model by adding rules and monitors to Our location Objects. Full MP and VSAE Project will be included at the end of this post.
The rules are perf. Collection rules which collects the forecasted and observed temperature from yr.no. The monitor is added to alert when observed temperature is below what is set as alert temperature on each location (Object). For the configurable alert temperature I have added a New property to the weather location class.
<Property ID="LocationName" Key="true" Type="string" /> <Property ID="LocationURL" Key="false" Type="string" /> <Property ID="LocationAlertTemp" Key="false" Type="int" />
Which also means that Our discovery script has changed as well With the following line.
$instance.AddProperty("$MPElement[Name='TheWeatherSolution.WeatherLocation']/LocationAlertTemp$",$LocationAlertTemp)
Temperature (perf.) Collection rules
If you explore the API from yr, you will see that you get forecast for different periods. I noticed that when you Access the forecast XML node the first Object will always be for the period youre in right now which makes it easier to Write the script when we could just use the first Object.
An example of how the response:
from : 2016-10-16T21:00:00 to : 2016-10-17T00:00:00 period : 3 #comment : { Valid from 2016-10-16T21:00:00 to 2016-10-17T00:00:00 , Valid at 2016-10-16T21:00:00 } symbol : symbol precipitation : precipitation windDirection : windDirection windSpeed : windSpeed temperature : temperature pressure : pressure
As i mentioned in part one of this blog series I have gotten tips from Trond Hindenes for the MP it self and Kevin Holman for the VSAE fragments used in PowerShell rules and monitors. For this MP I created two collection rules for temperatures. Both observed and forcasted temp. (don’t ask, i know this data is available at www.yr.no).
The rules use the similar PS script, and after adding the OpsMgr Magic around it this is how it ended up.
param([string]$LocationURL, [string]$LocationName) # Add the SCOM API and Propertybag for output $api = New-Object -comObject "MOM.ScriptAPI" $bag = $api.CreatePropertyBag() $ScriptName = "GetTemperatureObservation.ps1" # Logging $api.LogScriptEvent($ScriptName,1234,0,"$ScriptName script is starting") [xml]$yr = Invoke-WebRequest -Uri $LocationURL #Getting the latest observation $Observation = $yr.SelectNodes("//observations").weatherstation | Select-Object -First 1 [int]$ObservationTemp = $Observation.temperature.value #Adding the value from the script into the propertybag $bag.AddValue("ObservationTemp",$ObservationTemp) #Logging $api.LogScriptEvent($ScriptName,1235,0,"$ScriptName script is complete") #Outputting the bag $bag ]]>
As you see, the script takes location URL as a parameter which needs to be added to the fragment by Kevin if you use it.
<Parameters> <Parameter> <Name>LocationURL</Name> <Value>$Target/Property[Type="TheWeatherSolution.WeatherLocation"]/LocationURL$</Value> </Parameter> </Parameters>
After a few days you hopefully have a graph like this With observed and forecasted temperature
Monitor
I don’t like having unmonitored Objects in SCOM so we needed to add a monitor to these locations, dont know why i need to be alerted by SCOM when it’s cold out, but now i can. Again, based on Kevins fragment created a two state PowerShell monitor which grabs the LocationAlertTemp parameter from each location and compares it to the observed temperature by yr.no. Anything less than Our Alert Temp will change the state and rase an alert. As you can imagine, no drastic changes to the PowerShell script we used in the rule, but some changes to the SCOM bits. This scipt/monitor takes two parameters that need to be added. First the location URL and the LocationAlertTemp.
param([string]$LocationURL,[string]$LocationName,[int]$LocationAlertTemp) # Load MomScript API and PropertyBag function $api = new-object -comObject 'MOM.ScriptAPI' $bag = $api.CreatePropertyBag() #Log script event that we are starting task $api.LogScriptEvent("TooCold.ps1",6789,0, "Starting toocold.ps1 script") [xml]$yr = Invoke-WebRequest -Uri $LocationURL #Getting the latest observation $Observations = $yr.SelectNodes("//observations").weatherstation | select-object -First 1 [int]$Obstemperature = $Observations.temperature.value $temperatureUnit = $Observations.temperature.unit if ($Obstemperature -lt $LocationAlertTemp){ $bag.AddValue("Result","BadCondition") #$bag.AddValue("Description", "It is freaking cold observed temperature" + "$obstemperature" + "$temperatureUnit") } else{ $bag.addvalue("Result","GoodCondition") } $bag
Below the script body I have added,
<Parameters> <Parameter> <Name>LocationURL</Name> <Value>$Target/Property[Type="TheWeatherSolution.WeatherLocation"]/LocationURL$</Value> </Parameter> <Parameter> <Name>LocationAlertTemp</Name> <Value>$Target/Property[Type="TheWeatherSolution.WeatherLocation"]/LocationAlertTemp$</Value> </Parameter> </Parameters>
If everything is working correctly you should have all Your locations monitored, and depending on observed temperature and the alert temp parameter it’s either healthy or in warning state
I have made my MP and VSAE Project available for download here – please note that i do not take any responsibility for this MP and it’s not something i would sell or add to Our Production environment before i have made more testing and cleaned all displaynames, alert text etc. Key file are also excluded.
2 COMMENTS
I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me? https://www.gate.io/de/signup/XwNAU
I may need your help. I’ve been doing research on gate io recently, and I’ve tried a lot of different things. Later, I read your article, and I think your way of writing has given me some innovative ideas, thank you very much.