Searching the Help
To search for information in the Help, type a word or phrase in the Search box. When you enter a group of words, OR is inferred. You can use Boolean operators to refine your search.
Results returned are case insensitive. However, results ranking takes case into account and assigns higher scores to case matches. Therefore, a search for "cats" followed by a search for "Cats" would return the same number of Help topics, but the order in which the topics are listed would be different.
Search for | Example | Results |
---|---|---|
A single word | cat
|
Topics that contain the word "cat". You will also find its grammatical variations, such as "cats". |
A phrase. You can specify that the search results contain a specific phrase. |
"cat food" (quotation marks) |
Topics that contain the literal phrase "cat food" and all its grammatical variations. Without the quotation marks, the query is equivalent to specifying an OR operator, which finds topics with one of the individual words instead of the phrase. |
Search for | Operator | Example |
---|---|---|
Two or more words in the same topic |
|
|
Either word in a topic |
|
|
Topics that do not contain a specific word or phrase |
|
|
Topics that contain one string and do not contain another | ^ (caret) |
cat ^ mouse
|
A combination of search types | ( ) parentheses |
|
Create EPI and custom action scripts
This section describes how to create EPI and custom action scripts.
Learn more
A script requires a script definition, and for this you must specify script definition attributes.
A script definition consists of the following attributes:
-
Name: The internal script name (not the file name of the script).
-
Classpath / JAR files: One or more JAR files can be uploaded together with the script. The content of the JAR file is available on the classpath during execution of the script. The order of the jar files on the classpath can be changed by moving jar files in the UI up or down.
-
Filter: Optional, EPI scripts only. A filter can be referenced by name. Only events that match the filter are passed to the script.
-
Read-only: Optional. Scripts specified with the read-only attribute do not modify events. These scripts are executed asynchronously to read/write scripts. This asynchronous execution speeds up overall event processing, so it is recommended as a best practice to set the read-only attribute for scripts that are not intended to modify events.
-
Active: Enables or disables the script for execution. When a script is enabled, the
init()
function is called. Similarly, when a script is disabled, thedestroy()
function is called. -
Timeout: Optional. The maximum time for each script invocation. This is independent of the number of events. The default value for the timeout is 0, which means that the script execution will never timeout.
For synchronous scripts, if the timeout is reached, script execution is aborted, and all changes made to the events are rolled back.
For asynchronous scripts, if the timeout is reached, script execution is aborted.
If you intend to create your own EPI or custom action scripts, you must implement a Groovy script that at a minimum contains calls to the init()
, process()
, and destroy()
functions. The Groovy script API with full documentation of all arguments and types can be found in the Java API Documentation delivered with the product. For more information about developing and deploying Groovy scripts, see Groovy scripts.
The Java API Documentation includes the following information needed for creating scripts:
- Event class: this is the main interface
- Complete list of event attributes that are available for modification
You can find the Java API Documentation at the following location:
<OMi_HOME>/opr/api/doc/opr-external-api-javadoc.zip
The basic format of a script definition for EPI scripts and custom action scripts looks like this:
import com.hp.opr.api.scripting.Event;
def init() { // This method is called when the script is loaded (for example, // when OMi is started, when the script is enabled, or when the // script has been modified). }
def destroy() { // This method is called when the script is unloaded (for example, // if it is disabled in the configuration user interface). }
def process(List<EpiEvent> events) { // This method is called when events are processed. The list is of
// type java.util.List. // In this method, properties of the events can be changed. If the // script is in read-only mode, the UnsupportedOperationException is // thrown. // See the Java API documentation for opr-external-api.jar for a // list of event attributes that are available for modification. }
This section contains the sample EPI Groovy scripts shipped with the product.
You can find the EPI Groovy script examples in the following directory:
<OMi_HOME>/opr/examples/epi-scripts
SimpleExampleEPI.groovy
This is a simple example that sets all possible event attributes to some sample values.
import java.util.Date; import java.util.List; import com.hp.opr.api.scripting.Action; import com.hp.opr.api.scripting.Event; import com.hp.opr.api.scripting.EventActionFlag; import com.hp.opr.api.scripting.LifecycleState; import com.hp.opr.api.scripting.MatchInfo; import com.hp.opr.api.scripting.NodeInfo; import com.hp.opr.api.scripting.PolicyType; import com.hp.opr.api.scripting.Priority; import com.hp.opr.api.scripting.ResolutionHints; import com.hp.opr.api.scripting.Severity; /* * This example set all possible event attribute to some example values. */ class SimpleExample { def init() { } def destroy() { } def process(List<Event> events) { events.each { event -> modifyEvent(event); } } def modifyEvent(Event event) { String application = event.getApplication(); event.setApplication("Modified by EPI: " + application); def groupId = event.getAssignedGroupId(); event.setAssignedGroupId(groupId); def assignedUserId = event.getAssignedUserId(); event.setAssignedUserId(assignedUserId); Action autoAction = createSampleAction(); event.setAutoAction(autoAction); String assignedGroupName = event.getAssignedGroupName(); event.addCustomAttribute(“ASSIGNED_GROUP_NAME”, assignedGroupName); String assignedUserLogin = event.getAssignedUserLogin(); event.addCustomAttribute("ASSIGNED_USER_LOGIN", assignedGroupName); String category = event.getCategory(); event.setCategory("Modified by EPI: " + category); String correlationKeyPattern = event.getCloseKeyPattern(); event.setCloseKeyPattern("Modified by EPI: " + correlationKeyPattern); String description = event.getDescription(); event.setDescription("Modified by EPI: " + description); String etiDisplayName = event.getEtiDisplayName(); event.addCustomAttribute("ETI_DISPLAY_NAME", etiDisplayName); String etiName = event.getEtiName (); event.addCustomAttribute ("ETI_NAME", etiName); String etiStateDisplayName = event.getEtiStateDisplayName (); event.addCustomAttribute("ETI_STATE_DISPLAY_NAME", etiStateDisplayName); String etiStateName = event.getEtiStateName(); event.addCustomAttribute("ETI_STATE_NAME", etiStateName); String etiInfo = event.getEtiHint(); event.setEtiHint(etiInfo); String correlationKey = event.getKey(); event.setKey("Modified by EPI: " + correlationKey); MatchInfo matchInfo = createSampleMatchInfo(); event.setMatchInfo(matchInfo); event.setNoDedup(true); ResolutionHints hints = createSampleResolutionHints(); event.setNodeHints(hints); String object = event.getObject(); event.setObject("Modified by EPI: " + object); String omServiceId = event.getOmServiceId(); event.setOmServiceId(omServiceId); String omUser = event.getOmUser(); event.setOmUser(omUser); String originalText = event.getOriginalData(); event.setOriginalData("Modified by EPI: " + originalText); String originalId = event.getOriginalId(); event.setOriginalId(originalId); event.setPriority(Priority.HIGHEST); String ciInfo = event.getRelatedCiHint(); event.setRelatedCiHint("Modified by EPI: " + ciInfo); event.setSeverity(Severity.CRITICAL); String solution = event.getSolution(); event.setSolution("Modified by EPI: " + solution); ResolutionHints sourceCiHints = createSampleResolutionHints(); event.setSourceCiHints(sourceCiHints); event.setState(LifecycleState.IN_PROGRESS); String subCategory = event.getSubCategory(); event.setSubCategory("Modified by EPI: " + subCategory); event.setTimeReceived(new Date()); String title = event.getTitle(); event.setTitle("Modified by EPI: " + title); String type = event.getType(); event.setType("Modified by EPI: " + type); Action userAction = createSampleAction(); event.setUserAction(userAction); /* * Calling isReceivedOnCiDowntime should be done after CI/ETI resolution, * at which point the CI is identified. */ Boolean receivedDuringDowntime = isReceivedOnCiDowntime(); event.addCustomAttribute(“RECEIVED_ON_DOWNTIME”, receivedDuringDowntime); } def ResolutionHints createSampleResolutionHints() { ResolutionHints hints = new ResolutionHints(false); hints.setCoreId("CoreId"); hints.setDnsName("mydqdn.com"); hints.setHint("My Hint"); hints.setIpAddress("0.0.0.0"); return hints; } def MatchInfo createSampleMatchInfo() { MatchInfo matchInfo = new MatchInfo(false); matchInfo.setConditionId("conditionId"); matchInfo.setPolicyName("policyName"); matchInfo.setPolicyType(PolicyType.CONSOLE); return matchInfo; } def Action createSampleAction() { NodeInfo actionNodeInfo = new NodeInfo(false); Action action = new Action(false); actionNodeInfo.setCoreId("CoreId"); actionNodeInfo.setDnsName("myfqdn.com"); actionNodeInfo.setIpAddress("0.0.0.0"); action.setCall("Call"); action.setNode(actionNodeInfo); action.setStatus(EventActionFlag.AVAILABLE); return action; } }
RegExample.groovy
This example script flips every second word with its previous word.
import java.util.Date; import java.util.List; import com.hp.opr.api.scripting.Action; import com.hp.opr.api.scripting.Event; import com.hp.opr.api.scripting.EventActionFlag; import com.hp.opr.api.scripting.LifecycleState; import com.hp.opr.api.scripting.MatchInfo; import com.hp.opr.api.scripting.NodeInfo; import com.hp.opr.api.scripting.PolicyType; import com.hp.opr.api.scripting.Priority; import com.hp.opr.api.scripting.ResolutionHints; import com.hp.opr.api.scripting.Severity; /* * This script flips every second word with its previous word. */ class RegExpExample { def init() { } def destroy() { } def process(List<Event> events) { events.each { event -> event.setTitle(event.getTitle().replaceAll(/(\w+)\s+(\w+)/, '$2 $1')); } } }
ResolveLocationFromDB.groovy
This script matches an IP address to a node name to resolve a location from the database.
To make this example work with a MS SQL Server, you must do the following:
-
Create a new DB
asset_db
(or adjust the name below). -
Create a new table
LocationMapping
(or adjust the name below) with the following attributes:ip (varchar(50), primary key)
location (varchar(50))
phone (varchar(50))
contact (varchar(50))
-
Add rows to the table for each IP address that matches the node hint of your events.
-
Adjust the database parameters in
Sql.newInstance
below. -
Add this script as an EPI script. Upload a JTDS driver. You can find a JTDS driver at http://jtds.sourceforge.net.
import groovy.sql.Sql; class ResolveLocationFromDB { def connection; void init() { def properties = new Properties(); // Create Properties object def properties = new Properties(); // Set user ID for connection properties.put("user", "sa"); // Set password for connection properties.put("password", "installed"); def driver = new net.sourceforge.jtds.jdbc.Driver (); def conn = driver.connect("jdbc:jtds:sqlserver://localhost/asset_db", properties); connection = Sql.newInstance(conn); } void process(eventList) { try { for (event in eventList) { def nodeHints = event.getNodeHints(); def nodeName = nodeHints.getDnsName(); if(nodeName != null) { def ipaddress = InetAddress.getByName(nodeName).hostAddress connection.eachRow('select * from LocationMapping', { if (it.ip == ipaddress) { if (event.getDescription() == null) event.setDescription("CI located in building: " + it.location) else event.setDescription(event.getDescription() + "\nCI located in building: " + it.location) event.addCustomAttribute('phone', it.phone) event.addCustomAttribute('contact', it.contact) event.addCustomAttribute('location', it.location) } }); } } } finally { } } void destroy() { connection.close(); } }
This section contains a Groovy script example for custom actions.
You can find the custom actions Groovy script example in the following directory:
<OMi_HOME>/opr/examples/ca_scripts
SimpleExample.groovy
Here is a simple example of a custom actions script that modifies an event:
import com.hp.opr.api.scripting.Event; import com.hp.opr.api.scripting.Priority; import com.hp.opr.api.scripting.Severity; class SimpleExample { def init() { // Nothing to initialize } def destroy() { // Nothing to destroy } def process(List<Event> events) { events.each { event -> modifyEvent(event); } } def modifyEvent(Event event) { event.addCustomAttribute("CA_SCRIPT", "MODIFIED"); event.setSeverity(Severity.CRITICAL); event.setPriority Priority.HIGHEST; } }
We welcome your comments!
To open the configured email client on this computer, open an email window.
Otherwise, copy the information below to a web mail client, and send this email to ovdoc-asm@hpe.com.
Help Topic ID:
Product:
Topic Title:
Feedback: