Unsolved

This post is more than 5 years old

21 Posts

142127

November 15th, 2012 14:00

How to bind alarm to Rule?

Hi,

I have a rule that consist of a script to pull events from vcenter and create alarm if it matches certain words.

My issue is that the rule has a script in the condition that uses the AlarmService to create the alarm in the Alarm dashboard but in fact the Rule it self never fires.

So in the rule management I see no alarm in the counter beside my rules and there is no way for me to add action since those rule never fire.

In the end, Im trying to add the email action to those rules.

Thank you

Alex

Here is the Rule condition:

import java.util.UUID;

alarmService = server.get("AlarmService");

// Severities for use in reportAlarm call

sevWarning = 2;

sevCritical = 3;

sevFatal = 4;

// Closure used to search events for matching text

testCls = { ev->

if(ev.get("message") ==~ /.*Network uplink redundancy.*changed from.*to Red.*/)

return true;

else

return false;

};

// Find the matching events

evnts = findObservationEntries(#events#,testCls);

evnts.each { evnt ->

          try

          {

                    if(evnt.get("relatedInstance"))

                    {

                              objId = evnt.get("relatedInstance").get("uniqueId");

                    }

                    else

                    {

                              objId = scope.get("uniqueId");

                    }

                    alarmService.reportAlarm(UUID.randomUUID().toString(),sevCritical,objId,evnt.get("message"));

          }

          catch (Exception e)

          {

                    println e.message;

          }

};

return false;

59 Posts

December 10th, 2012 16:00

I looks like your description of the condition is incomplete; the triggering policy and the definition of the closure is incomplete.

Even so, it looks like the closure block will return false or true before the block that triggers the alarmService.reportAlarm() is executed.

I would recommend debugging this script by adding logging statements to determine if alarmService.reportAlarm() is called and with what parameters.

You should also check the FMS log file to see if any other errors were generated while executing your rule.

Here' a code sample the creates a logger and writes a message to the FMS log:

import com.quest.common.log.*

final CAT = LogCategory.getInstance("example-rule")

StringBuffer aSB = new StringBuffer()

aSB.append ("my message = {" + "test information, OK?"+ "}")

CAT.log ("some message: " + aSB.toString())

Regards,

Brian Wheeldon

No Events found!

Top