Home
  • RapidInsight
  • RapidInformer
  • Support
  • About Us
Home » Blogs » berkay's blog

Groovy4Netcool script example: updating an event field

Posted October 24th, 2007 by berkay
in
  • groovy
  • Groovy4Netcool
  • howto
  • Netcool
  • opensource
  • scripting

In the previous post, I'd announced the Groovy4Netcool project. In this follow up post, I'll go through a simple script as an example to demonstrate how it can be used. The objective is to work with an event in the Netcool server, to get the value of a field and update that value.

First, I should highlight the files in this project are NOT required to use groovy to work
with Netcool server. Groovy language has inherent support to work with database via jdbc. The files in this project provide an infrastructure to make it easier to work with Netcool so that one does not have to know or deal with JDBC and SQL,
although they are available.

 

First, I need to set the connection parameters for the Netcool server in the NetcoolDataSource.groovy file.

static def datasourceParams = [

"netcool": ["url":"jdbc:sybase:Tds:host:port?LITERAL_PARAMS=true", "username":"nameoftheuser", "password":"passwordoftheuser"]

];

Now we can start writing our script. In our script we will use the NetworkAdapter class (defined in NetworkAdapter.groovy) file.

ncAdapter  = new NetworkAdapter()

The events in the Netcool server can be identified using the Serial or the Identifier fields of the event. I'll use the getEvent method of the ncEvent class to get the event. getEvent method takes the Serial of the event as a parameter.

myEvent = ncAdapter.getEvent(898)

If I had the Identifier of the event but not the Serial, I could have used the getSerial method to get the serial (ncAdapter.getSerial("Router1Down"))

The event fields are now accessible in the script as properties of the myEvent object. myEvent.severity, myEvent.summary, etc. The event field names are used as all small letters. Let's print the identifier, summary and severity for the field.

println("Identifier: " + myEvent.identifier + " Summary: " + myEvent.summary)

We can also set the values of the event fields similarly.

myEvent.severity = 4

myEvent.summary = "summary set by example script"

Setting the value of the myEvent object properties update the event in the Netcool server immediately.  

 

That's it! This script is available in the project wiki as UpdateEventFieldsExample

Trackback
  • Login or register to post comments

 Social Bookmark

  • Using groovy scripting to work with Netcool Omnibus
  • Standing on the shoulders of giants: say no to proprietary languages, welcome to Groovy and salute JVM
  • Automated acceptance test example for Netcool event enrichment solution
  • RapidInsight: what is it good for? - Integration in the presentation layer
  • How to integrate an RSSFeed into Smarts

  • Create new account
  • Request new password