NetIQ Operations Center - Using fscript utility

over 7 years ago
Customers routinely create custom scripts (Right clicks, Automations, Jobs, etc) to send out emails, bring up element/alarm data, open a helpdesk ticket, etc. While parts of the java script are NOC related, most of the scripting is around java. For instance, sending an email or adding a row to a database is a java exercise, not a NOC exercise. I start by using the java doc's on Oracle's website to look up the classes and methods. From there, since it is documented for use inside of a java compiler, I then sometimes need to test the java script version. Googling "javascript" stuff can be useful, but nearly every example is how to use java script in side of a jsp/html/etc webpage. Since we aren't doing that, I find them less useful. I search for things like: java example read file While it provides examples that are compile java examples, it is very close to what you would use in javascript inside of NOC.

Javascript and java are close, but not exactly the same. One of the common differences is declaring variables.

In java script, you use the word "var" and it figures out from there for some data types

var x = 1

var y = 'abc'

Java script understands one is a string and the other is a number. For other cases, where you need to a specific data type, you can specify the specific "java" type (not javascript) var type. For that, you need to know the full package name. In the java docs, most data types are under java.lang such as Float.

var z = new java.lang.Float( 45 )

The point of the blog is not to teach you java or javascript, it is to show you ways to test script fragments. Sometimes you can create a right-click operation and test it there, but I find it is easier to test it via the commandline utility called fscript locationed in the "bin" directory. You can pass parms to it to run predefined scripts, of you can just type fscript and hit enter and you are in a interactive javascript session.

After you start fscript, you are sitting at a js> prompt. You can type pretty much any valid javascript, such as the example above where we created a float variable.

js> var z = new java.lang.Float( 45 )
js> z

As you can see, you can declare a variable, you can then check it afterwards.

I find this useful to test java classes/methods. When you look up things in the java docs, there is some translation you have to do, so as I did above

Java Example;
float myVar = 41.4;

java script
var myVar = new java.lang.Float( 41.4 );

Other examples are declaring classes (contructors). Suppose you want to open a file to read from it. A common way is to use the class. In order to declare it, you use one of the constructors. For instance:

js> var fis = new "c:/errorlog.txt" );
js> fis
js> fis.available();

You can even do while loops, for loops, etc, etc, etc.

js> for( var i=0; i<10; i )
writeln( "printing line: " i );

 printing line: 0
printing line: 1
printing line: 2
printing line: 3
printing line: 4
printing line: 5
printing line: 6
printing line: 7
printing line: 8
printing line: 9

You can even run predefined scripts via a parm when you start up fscript or load the script on the fly...

js> load( "../database/scripts/util/adapters.fs" );

Novell Operations Center(r) Copyright 2010 Novell, Inc.

Enter web server host [buzz] :

Now, on to the limitations. You are able to access NOC type stuff, but you are limited. For instance, when you run the adapters.fs script, it logs into NOC and it allows you to interact with NOC, but... you can't use the findElement() method and access an element or alarm. Limit your use of fscript to the core java stuff like accessing files, email, databases or basic interaction with NOC such as adapters.fs. If you need to interact at the level you need to access real elements and alarms, you need to either use the Web2Connect interface, or be within a Job, Automation or Right-click. I know, I don't design (code) this stuff, I just use it.

The other option to test out script fragments is to launch the client or server debugger. When you create a right-click operation, if the first line is as below, an interactive script debugger comes up and in the bottom right hand window, you can type in all the stuff we did above, plus you can also interact with elements and alarms.

// @debug on

writeln( "test" );

That pretty much covers fscript. Again, I find it most useful to start up real quick and test out some JavaScript syntax. Other times I may use the debugger, just really depends. Read up on some of the methods in the java docs and try some of them out in the fscript utility. Remember, don't play on production systems, people tend to get mad

- Tobin

Comment List
Related Discussions