Blog Entry

tisenberg's picture
blog
Reads:

4079

Score:
2
2
2
 
Comments:

0

Novell Operations Center – Copy selected item to Clipboard

(View Disclaimer)

From time to time we run across situations where the end user needs to grab a piece of information from within Novell Operations Center and add it to an email, a change request or some other application. While Operations Center can be customized to do some of these tasks in a more automated manner, there are some adhoc situations where the user would just like to grab the details and use it.

One way to accomplish this is to add custom right-clicks to copy specific details to the clipboard. A couple of examples of this I have seen customers use are copying the selected elements dname to the clipboard as well as copying the highlighted alarm(s) to the clipboard.

var selection = new java.awt.datatransfer.StringSelection( element.dname ); 
var clip = java.awt.datatransfer.Clipboard; 
clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); 
clip.setContents( selection, null );

In the code above the only item that is unique to Operations Center is the “element.dname” on the first line. The rest of the code is the java way to place a string into the clipboard, there are probably other ways, but this is the one I found.

In order to test this script out follow the steps below.

  • Log into the Operations Console
  • Navigate to Administration\Server\Operations Definitions
  • Right-click on Operations Definitions and select Create Operation
  • Operation Name and Menu Text, enter: Tools|Copy Element DName to Clipboard
  • Context set to: element
  • Match By: name expression and place a .* (period asterisk) in the next box
  • Permission: View
  • Type: Client Script
  • For Operation, copy and paste code above
  • After you save this new operation, you can then select an element, right-click on it and use the newly created operation to copy the element’s dname to the clipboard. You could update the script to do pretty much any element property such as element.name. If the element has additional attributes that are unique to the data source or added via customizations, you could access those using the same manner such as element.ipAddress.

    In order to make the script above work for an alarm instead, you would need to do some additional coding to either grab the specific alarm columns (fields) or just access the specific field directly.

    When creating an alarm operation, by default the script is provided an array object called “alarms”. The idea is that the end user could have selected one alarm or several alarms. The first part of the script would need to traverse through the selected alarms.

    for( var i=0; i<alarms.length; i++)
    {
    	… some more code specific to one alarm….
    }
    

    Below is an example of the script that would copy the selected alarms to the clipboard. It will copy not only all the selected alarms, but it will also copy all of the individual alarm columns (fields).

    // variable to hold the alarm information
    var results = ' ';
    
    // a wacky way to create a variable that is a carriage return and line feed
    var cr = new java.lang.String( new java.lang.Character( 0x0d ) ) + java.lang.String( new java.lang.Character( 0x0a ) );
    
    // for loop to go through all highlighted alarms
    for( var i=0; i<alarms.length; i++ ){
    	results += cr
    	results += 'Alarm ID: ' + alarms[i].ID + cr;
    
    	// for loop to go through all of the alarm properties for the current alarm
    	for( p in alarms[i].properties ) { 
    		// place the alarm field name and value into the results string
    		results += p + ': ' + alarms[i][p] + cr;
    	}
    }
    
    // place the results string into the clipboard
    var selection = new java.awt.datatransfer.StringSelection( results );
    var clip = java.awt.datatransfer.Clipboard;
    clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    clip.setContents( selection, null );
    

    In order to try this script out, follow the instructions above to create another right-click operation, just use a different name and menu text, something like: Tools|Copy Alarms to Clipboard

    I'm sure there are some additional coding options that can be done in order to make a single right click accomplish multiple types of copy/paste as well as updating the script to copy other types of things such as relationships, maybe you can take on that challenge. Remember, work through your scripts on development systems before putting them into production. Enjoy!


    Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).

    It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.




    User Comments

    © 2013 Novell