Operations Center sample code - exporting configuration on the server, and sending it to the client

  • 7011909
  • 11-Mar-2013
  • 11-Mar-2013

Environment

NetIQ Operations Center
Novell Operations Center 5.0

Situation

Operations Center suite provides frameworks and tools for highly sophisticated and highly customizable solutions. One of these tools is fscript. Fscripting on the Operations Center (NOC) server can be done either on the server side, or on the client side. Sometimes it is useful to combine both these approaches, and pass data between server-side script and client-side script.  This sample code wants to present exactly this featue - it shows how to export NOC configuration on the server side, and how to send it as the parameter to the client side.

Resolution

Our script below is triggered by the server-side operation. It works basically in four steps:
a) it locates "server" elements and exports selected configuration to the temporary file,  using 'Config|ExportSilent' method
b) it reads temporary file, and copies the data into new string array
c) it passes the string array to the client-side, as a part of client-side script invocation
d) invoked client-side script writes then the data to the file on the Java client PC

The code is designed to work for relatively small configurations, but it would for sure cause problems and crash if you would try to send this way huge configuration data.

Here is the operations definition, it needs to be added to the operations.ini file:
[Export configuration to the client]
command=
context=element
description=Export configuration to the client
operation=load("support/exportConfigToClient.fs")
permission=view
target=namematch:.*
type=serverscript










Here is our script "support/exportConfigToClient.fs":
// @debug off
// Adjust to suit.
var filename = 'C:\\Temp\\tempExport.xml';
var exportRelationships = 'true';
var exportedRelated = 'true';
var propertyPatterns = '';

var clientScript = "\
    //@debug on   \
    var out = new java.io.FileWriter('C:\\\\Temp\\\\clientSide.xml');    \
    var bw = new java.io.BufferedWriter(out);     \
    for (var i=0; i<xmlConfig.length; i++)    \
    {   \
        bw.write(xmlConfig[i]);    \
        bw.newLine();    \
    }    \
    bw.flush();    \
    bw.close();    \
";
// Here is where our server script starts
// First, we locate our "server" element, and delegate configuration export operation to it.
var serverElem = formula.Administration.findElement( 'formulaServer=Server' );
serverElem.perform( session, 'Config|ExportSilent', [], [ element.dname, filename, exportRelationships, exportedRelated, propertyPatterns ] );

// Next, we have to read our temporary file into string array
try
{
   var br = new java.io.BufferedReader(new java.io.FileReader(filename));
   var lines = new java.util.ArrayList();
   var line = null;
   while ((line = br.readLine())!= null) { lines.add(line) };
   br.close();
   var xmlConfig = lines.toArray();
}
catch(ex) { formula.log.warn('We have problem: '+ ex); }

// Third, we invoke the client-side script, and pass our String array as a parameter
session.invokeScript('Export save', clientScript,[xmlConfig],['xmlConfig']);

// Finally, we send the notification to the client
session.sendMessage( 'Congratulations, you successfully passed our test in fscript programming !');