Highlighted
Super Contributor.. Super Contributor..
Super Contributor..
107 views

Event customization groovy script not working

Hi Team,

We have created groovy script to add custom attributes in event but unfortunately it is not appeared on event .

below is the groovy script which takes data from external MS SQL database.We need your help to troubleshoot on urgent basis why event customization is not working.

 

 

 

import com.hp.opr.api.scripting.Event;
import groovy.sql.SQL;
import java.sql.Driver;


class EventProcess
{

def init()
{
def serverName = "sezvm4746p.xyz.net" // Examples: "localhost" "127.0.0.1"
def instance = "abc" // Example: "instance1"
def serverPort = "1433" //
def dbName = "OmiServiceNowSync"
def db = [url:"jdbc:sqlserver://" + serverName+ ":" + serverPort + ";instanceName=" + instance + ";databaseName=" + dbName , driver:"com.microsoft.sqlserver.jdbc.SQLServerDriver"]
def dbUsername="opsdsds"
def dbPassword="vcxsdf"
def dbDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
def sql = Sql.newInstance(db.url,dbUsername,dbPassword, db.driver)
}

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

def nodeHints = event.getNodeHints();
def nodeName = nodeHints.getDnsName();


def dbOut = sql.firstRow("SELECT * FROM OmiServiceNowSync where Name= '" + nodeName + "'" )
event.addCustomAttribute('usagearea', dbOut.Usagearea)
event.addCustomAttribute('usedfor', dbOut.Usedfor)
event.addCustomAttribute('status',dbOut.Status)
}



}

def destroy()
{
sql.close();
}

}

 

also attaching debug logs from pri DPS.

 

 

0 Likes
2 Replies
Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Re: Event customization groovy script not working

Can you guys help me here..
0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Event customization groovy script not working

@NileshX 

I see this (scripts.log): unable to resolve class groovy.sql.SQL

Do you need to add/upload (another) jar file?

 

The variables you define in init() are only local variables. You cannot access them in the process()

e.g. the sql

 

In addition I would check the "dbOut" return value for "null" (not sure if there is always something in your db)

def dbOut = sql.firstRow("SELECT * FROM OmiServiceNowSync where Name= '" + nodeName + "'" )

 

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.