OpsMgr 2007 R2: Script Unit Monitor Comparison Problems!

 

While making my last Management Pack , I discovered a problem in the Operations Console of OpsMgr.

Problem:

 

When i created the Critical/Unhealthy/Healthy Expressions i had to compare to a Integer that was returned by the Script.

The problem was that when i compared 50 with 100, it acted like 50 was more than 100 !!

I was kind of baffled and did not know what was going on.

Solution:

So i exported the Management Pack to XML and took at closer look in the details:

This is a snippet from the XML, it is only one of the 3 expressions, the same has to be done with the  last 2.

     <ErrorExpression>
            <And>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='percentCoffee']</XPathQuery>
                  </ValueExpression>
                  <Operator>LessEqual</Operator>
                  <ValueExpression>
                    <Value Type="String">20</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="String">Property[@Name='percentCoffee']</XPathQuery>
                  </ValueExpression>
                  <Operator>GreaterEqual</Operator>
                  <ValueExpression>
                    <Value Type="String">0</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
            </And>
          </ErrorExpression>

As you can see in line 6, 10, 17 and 21, the datatype is configured as ”String”.

This means that the system is doing a string comparison on “50” and “100”, which results in 50 being more than 100.

To fix the problem, I knew i had to change the datatype, but i did not know which was allowed.

i tried to find some help on google, but without luck.

Then i looked into other MPs and figured that “Double” is supported, and this was the one i was hoping to use anyway.

So i changed all the “String” to “Double”

     <ErrorExpression>
            <And>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="Double">Property[@Name='percentCoffee']</XPathQuery>
                  </ValueExpression>
                  <Operator>LessEqual</Operator>
                  <ValueExpression>
                    <Value Type="Double">20</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
              <Expression>
                <SimpleExpression>
                  <ValueExpression>
                    <XPathQuery Type="Double">Property[@Name='percentCoffee']</XPathQuery>
                  </ValueExpression>
                  <Operator>GreaterEqual</Operator>
                  <ValueExpression>
                    <Value Type="Double">0</Value>
                  </ValueExpression>
                </SimpleExpression>
              </Expression>
            </And>
          </ErrorExpression>

and everything worked as it should!!

For some reason the Operations Console GUI, always use String comparison, but if you export the management pack, edit the XML, and import it again.

Of cause you could use the Authoring Console to make your Management Packs, and it has the possibility to write what type of data it is, instead of using string always.

Good luck with your MPs ;)





3 Responses to “OpsMgr 2007 R2: Script Unit Monitor Comparison Problems!”

  1. Vaibhav says:

    Nice post!

  2. I’m starting up a new internet website directory and was wondering if I can submit your website? I’m trying to grow my directory slowly by hand so that it maintains high quality. I will make sure and put your website in the best category and I’ll additionally use, “Coretech Blog » Blog Archive » OpsMgr 2007 R2: Script Unit Monitor Comparison Problems!” as your anchor text. Please make sure to let me know if this is alright with you by mailing me at: sarahhenel@live.fr. Bless you

  3. This may not be the ideal place to request this, but I am searching for a pest control provider in the pittsburgh region and have no method to find out who is the best. I located this company that’s truly close to me and wished to see if anybody has any critiques on them. Spectrum Pest Control, 3058 West Liberty Avenue, Dormont, PA 15216 – (412) 446-2802

Leave a Reply