Highlighted
Absent Member.. Absent Member..
Absent Member..
967 views

Groovy Script API for custom attribute.

Hi Team,

 

 

I have a sceario where I need to add custom attribute to event and use this custom attribute for a decision making.


Current scenario :
We are adding custom attribute named "Customer_name" = "Test" using below script in 1st BSM server

 

import java.util.List;
import com.hp.opr.api.scripting.Event;
import com.hp.opr.api.scripting.Severity;

class GroovyScriptSkeleton
{
  def init()
  {

  }

  def destroy()
  {

  }

def process(List<Event> events)
{
  events.each 
  {
    event -> modifyEvent(event);
  }
}

def modifyEvent(Event event)
{
  if(event.getSeverity() == Severity.MAJOR)
  {
    event.addCustomAttribute("Customer_Name", "Test")
            
  }
  
  if(event.getSeverity() == Severity.CRITICAL)
  {
    event.addCustomAttribute("Customer_Name", "Test")
          
  }
}
}

 

 

In our MOM BSM, we can see the Customer Name as Test in events Custom attribute TAB .

 

Now in MOM BSM I need a decision making condition based on "Customer_Name". I coudn't find any API for it like get.omServiceid().

 

May I know if there are any APIs available for custom attribute

 

 

-Vishnu BV

0 Likes
3 Replies
Highlighted
Absent Member.. Absent Member..
Absent Member..

event.getCustomAttribute("Customer_Name")

 

Should work? What version is this?

 

//ludvig

Highlighted
Absent Member.. Absent Member..
Absent Member..

Hi ludvig,

 

Thanks for your response.

 

We are using ver.9.24.

 

So does that mean, if I want to make a decision based on customer_name attribute using an 'if' condition, will it work ? - code as shown below

if(event.getcustomAttribute("Customer_Name").contains("Test"))             #Customer master condition 
                { 
                  event.addCustomAttribute("Tier1", "xyz")
                }

 

 

We are yet to test this, but I just thought of confirming it.

 

-Vishnu BV

0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

That is correct! 

 

edit: except "#" is not valid groovy comment-syntax, should use "//" 🙂

 

//ludvig

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.