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 😉