Absent Member.. Colin Yip Absent Member..
Absent Member..
1304 views

Accessing custom attributes in Logfile adapter Groovy script

Hi experts,

 

I have configured a connected server on localhost to invoke the sample logfile adapter groovy script, as what is demonstrated in the OMi extensibility guide.

 

Logging normal event properties works fine, but now I  need to customize this script to list out the custom attributes for all the events that are forwarded (either new or changed). I'm not sure how to access the custom attribute property from the main arg object. I have tried event.getCustomAttribute() but could not find a way to iterate through the differnt CMAs and print it out to the log file

 

Can anyone advise on how this could be done? Or even provide a code snippet to illustrate this?

 

Thank you!

0 Likes
7 Replies
Micro Focus Expert
Micro Focus Expert

Re: Accessing custom attributes in Logfile adapter Groovy script

you need to know the CMA name that you want to retrieve.

AFAIK, there is no way to get all CMA names from an event.

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Accessing custom attributes in Logfile adapter Groovy script

BTW, you can query for CMA name, and if it is not available for that event then you will get NULL. so you just need to know the union of all CMAs you might get for all your events.
0 Likes
Absent Member.. Colin Yip Absent Member..
Absent Member..

Re: Accessing custom attributes in Logfile adapter Groovy script

I do know the CMA name. But which method should I use to retrieve the CMA value?

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Accessing custom attributes in Logfile adapter Groovy script

you were using the right method (just provide the CMA name as parameter):

java.lang.String getCustomAttribute(java.lang.String key)

New Member.. Allan1
New Member..

Re: Accessing custom attributes in Logfile adapter Groovy script

I know this is an old thread, and perhaps it has already been posted elsewhere (but I coundn't find it). I have found a way to iterate through all of the Custom Attributes for events using an EPI script. I have posted the relevant code below - might not be the most elegant; but it get the job done... love to see other solutions if they are out there.

Allan

Most of the process(List<Event> events) method:

try
{
    Iterator it

for(event in events)
{
    it = event.iterateCustomAttributes()
    int cmaCount = it.size()
    int cmaIndex = 0

    while(event.iterateCustomAttributes().hasNext() && cmaIndex < cmaCount)
    {
        Map.Entry me = (event.iterateCustomAttributes().getAt(cmaIndex++)
        logger.info(x + " CMA <" + me.getKey() + ":" + me.getValue() + ">")
    }
}

}
catch(Exception e}
{
    // do some exception processing here if you like.
}

 

0 Likes
Wazr Frequent Contributor.
Frequent Contributor.

Re: Accessing custom attributes in Logfile adapter Groovy script

Thanks for that code snippet.  Has anyone by any chance figured out how to read custom attribute values while from the sample LogFileAdapter?  event.getCustomAttribute("myAttribute") doesn't work.  The same code works however in an EPI script.

0 Likes
Wazr Frequent Contributor.
Frequent Contributor.

Re: Accessing custom attributes in Logfile adapter Groovy script

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.