Novell Operations Center - Example using server side global variables.

Novell Operations Center - Example using server side global variables.

From time to time there is a need to open a ticket, send an email, run a commandline utility, etc either based on a user issuing a right-click and/or an automation. For this blog I will go over the skeleton of the script(s) to get you headed in the right direction.

For the first part, the thought is that we want the commandline util or the ticket opened to occur in the context of the actual Operations Center server. Sometimes due to limited apps installed on the client PC and/or traversing firewalls, it makes more sense for the actual "action" to happen from the Operations Center server as opposed to the client PC.

For this requirement, I leveraged an adapter setting to start up my main script. Each adapter has a property such as Script.onStarted, Script.onStopped. The idea is, when the adapter "starts", it will run whatever is in the Script.onStarted setting. While there are several other options for starting and running the script, I used the Script.onStarted as an example. For my example, on the adapter I used, I had the following in Script.onStarted:
load( "SOS.fs" );

Next I needed to put together a script that does the work. I need a way for a script to run on the server, but I need to be able to add/pass things from a right-click and/or an automation. The first part of the script leverages a server side global variable feature in Operations Center called "state variables". For my state variable, I created a LinkedList, essentially a way that I can add things to this queue and then pull them off the queue. There are several ways this can be done, I just used LinkedList for this example.

The next section of code is a for-loop that runs forever. I'd like the script to check the queue (LinkedList) for work, sleep a bit, then check for more work. In case I need to make changes to my script, since it runs forever regardless of the adapter running or not, I also made the for-loop leverage the adapter status (running vs stopped) to end my script.

Attached below is the Script.onStarted script. The script is only the skeleton of setting up the state variable and the for-loop to process items, it only logs items to the log file for now. Add your code to expand functionality such as inserting rows into a database.
/* Script On Started for an adapter */

if( !state.myQueue )
{
// If the state (server side global) variable does not exist, create it
var myQueue = new java.util.LinkedList();
state.myQueue = myQueue
}

// Grab the current status of the adapter, ie: running, stopped, reconnecting.
// Keep in mind that status may be different per adapter
var adapterStatus = adapter.status();

// While loop that runs forever... mostly
while( !adapterStatus.equals( "stopped" ) ){

// re-grab adapter status, want the script to stop/end if the
// adapter is stopped.
adapterStatus = adapter.status();

formula.log.info( "myQueue size: " + state.myQueue.size() );

// if there is something in the queue, process it
if( state.myQueue.size() > 0 )
{
var item = state.myQueue.remove();
formula.log.info( "item: " + item );

// Add code here to update a database, send email, run a commandline util, etc
}

// sleep for 10 seconds before looping again
try{

java.lang.Thread.sleep( 10000 )
}catch( Exception ) {
}
}
formula.log.info( "ending SOS.fs" );

Next to test my script on started script, I created a right-click that runs as a serverscript. Since I need access to the state variable to add things to the queue, the right-click must run in context of serverscript. Below is the script associated to the serverscript operation.

The script first ensures that the state variable exists, if it does, it adds the "element" to the queue and adds the element name to the queue. Typically you would only add one item such as the element name or even the entire element, I was just trying to fill the queue quicker and showing multiple examples.
if( state.myQueue ){

state.myQueue.add( element );

state.myQueue.add( element.name );

formula.log.info( "myQueue size: " + state.myQueue.size() );
}

That pretty much covers it. There are many ways that this can be done, but this is a common approach we have done over the years. Hopefully this will be of use to you and as always... develop and test these on a Dev/QA system and NOT production 🙂

- Tobin

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2011-11-02 16:40
Updated by:
 
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.