Highlighted
Absent Member.. Absent Member..
Absent Member..
510 views

Groovy Script Reference Manual

Is there a reference manual somewhere that might help me with coding in the EPI groovy scripts?  Something to let me know the name of the methods that are exposed and possible examples?

Labels (1)
0 Likes
8 Replies
Highlighted
Absent Member.
Absent Member.

Please take a look at the "BSM Extensiblity Guide" which is part of the BSM documentation manual set.

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Edward, "Possible methods" are described in OPR docs:

look in \HPBSM\opr\api\doc\opr-external-api-javadoc.zip

Please start index.html, look at 'com.hp.opr.api.scripting.Event' class.

 

Examples can be found at \HPBSM\opr\examples\epi-scripts\

 

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Hello There,

 

I installed the groovy console and testing out my first script and it fails.

 

import com.hp.opr.api.scripting.Event;
import org.apache.commons.logging.LogFactory
import org.apache.commons.logging.Log


class ListEvent {

  private static Log s_log = LogFactory.getLog("com.hp.opr.epi.ListEvent")

  def init() {
    s_log.info("Initialized.")
  }

  def destroy() {
    s_log.info("Destroyed.")
  }

  def process(List<Event> events) {

    for (Event event in events) {
        println "EventDetails:" + event.getTitle();
    }         
  }
}

 

 

it fails with below error

 

 groovy.lang.GroovyRuntimeException: This script or class could not be run.
It should either:
- have a main method,
- be a JUnit test or extend GroovyTestCase,
- implement the Runnable interface,
- or be compatible with a registered script runner. Known runners:
  * <none>

 

Could someone assist with this?

 

-KAKA-

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

Below is a shell I use for my scripts.  Maybe this will help?  I put my logic in the modifyEvent method.

 

import java.util.List;
import java.lang.*;
import com.hp.opr.api.scripting.Event;
import com.hp.opr.api.*;
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)
  {
  }
}

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Thanks for your response. and where do you test it? i am using an programm called Groovy Console as mentioned in HP OMi's extensibility guide.

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

I have been unable to get the groovy console to work.  I put the changes in and check out the log below (path is where we have it - your location might be different).  This log will help identify errors and might help in your current situation.

 

D:\HPBSM\log\opr-scripting-host/opr-scripting-host.log

Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

So i think it is a Groovy Script problem. i used piece of codes which you sahred and created a script to modify the severity of event which worked well.

 

but wondering then how people are testing thier work?

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

The method recommended to me was using the groovy console.  I have not been able to get it to work but have not spent large amount of time, either.  You can put comments - what I do is use the Additional Info tab description field.  Every one of my scripts has the method, below - which I call to insert messages (having a common method simplifies my updating process).  I note when I start the script the name of the script running as well as when it ends.  I include original text when doing an update.  You could use this for debugging, also, by putting various debug statements as desired.  This may not be the best method of testing but it works for me.  By including the start and end of the script I am able to tell, all of the time, the exact scripts that were used on the event should any questions arise about why something did, or did not, apply.

 

  def updateDesc(Event event, String strTxt)
  {
    //get current description
     String strDesc = event.getDescription();
    
    //adjust description - prepend the new text at the top of the description field
    strDesc = strTxt + strDesc;
    
    //replace description with the new value
    event.setDescription(strDesc);
 }

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.