Skip navigation
All Places > CA Unified Infrastructure Management > Blog > 2013 > September
2013
carl

Tutorial Requests

Posted by carl Sep 3, 2013

Promising to make more time to create these articles and tutorials, I might even ask for help and advice from you guys that are intrested in contributing? Any takers?

Feel free to post comments to this thread for requests or vote up other requests by giving kudos.

Open the NAS configuration GUI and navigate to "Auto-Operator" -> "Scripts" tab -> Right-Click and NEW -> Script

 

 

 

Image 001.png

 

 

We now have a new window with a script editor:

 

 

Image 002.png

 

 

Attached to this guide is the "NAS WHITEPAPER" PDF you might like to have this open while we discuss some of the functions we will use.

 

The first job it to get the alarm. When we put this script to work in production the NAS will be used to find the NIMID of an alarm. The NIMID is a unique identifier used to select a specific single alarm or chain of alarms. While we develop this script however we will need to have a NIMID of an existing alarm we can play with. 

 

Lets create a test alarm so as not to change any of our existing alarms that might cause confusion for other users.

 

Navigate to the NAS status tab and find the "Send test alarm" icon: Image 004.png 

 

This will open a new window where we can create a test alarm.

 

Image 003.png

 

Now in our IM alarm console we can see the new alarm:

 

Image 005.png

 

You might need to drap the first column a little wider to see the NIMID:

 

Image 006.png

 

 

 

So back to our script window. We will get this alarm and store it in a LUA table.

 

a = alarm.get("VF69259077-26007")

 

 

This will create a table called "a" and store the alarm details in there. Again while developing we pass the NIMID as a string so be sure to wrap in "". Later we will just use alarm.get() and the NAS will pass the NIMID.

 

 

I have some pre-written code that provides us with a small function to human readable print to screen the content of a table, add the follow to the top of your script.

 

--Table Dumper - Used in table  function tdump(t)       local function dmp(t, l, k)         if type(t) == "table" then           print(string.format("%s%s:", string.rep(" ", l*2), tostring(k)))           for k, v in pairs(t) do             dmp(v, l+1, k)           end         else           print(string.format("%s%s:%s", string.rep(" ", l*2), tostring(k), tostring(t)))         end       end     dmp(t, 1, "root")             end --End Table dumper code

 

Now we can use this function to print out the table:

 

tdump(a)

 

We pass the name of our table "a" to the function, in the code - as this is a table there is no need to wrap in "".

 

Our script should now look like this:

 

--Table Dumper - Used in table  function tdump(t)       local function dmp(t, l, k)         if type(t) == "table" then           print(string.format("%s%s:", string.rep(" ", l*2), tostring(k)))           for k, v in pairs(t) do             dmp(v, l+1, k)           end         else           print(string.format("%s%s:%s", string.rep(" ", l*2), tostring(k), tostring(t)))         end       end     dmp(t, 1, "root")             end --End Table dumper code  a = alarm.get("VF69259077-26007")  tdump(a)

 

Go ahead an execute this script using the "play" icon top of the script editor: Image 007.png

 

Below is the output:

 

----------- Executing script at 02/09/2013 09:33:48 ----------      root:       robot:cloud       i18n_dsize:0       source:10.0.0.1       origin:cloud.teknetik.co.uk       time_origin:2013-09-02 09:26:47       arrival:1378110412       supp_key:123456       hostname:10.0.0.1       level:4       nimid:VF69259077-26007       aots:0       change_id:10778ADF18D41BE15F3F52FA26179BC5       time_arrival:2013-09-02 09:26:52       domain:teknetik.co.uk       visible:1       severity:major       hub:cloud.teknetik.co.uk       nimts:1378110407       subsys:NMS       message:Testmessage       tz_offset:-3600       nas:cloud.teknetik.co.uk       user_tag1:newznab       suppcount:0       supp_id:smileyvery-happy:E98D080A00476F2C0FFEDF5DFD44502       event_type:1       sid:1

 

Now we can see the makeup of the alarm as a key/value table. 

 

Lets go ahead and change the alarm message. I am not going into too much detail on tables here as there is a seperate tutorial 

 

a.message = "New Alarm Message"

 

Add the above line just above the tdump function and run the script again.

 

The tdump output will now show this has been updated:

 

message:New Alarm Message

 

Before we resend this edited alarm I want to quickly cover concatination as I feel this will be a common request. 

 

Say we want to just append some text to the alarm message:

 

a.message = a.message.." +my text"

 

This line states that a.message should be updates with the original contents of a.message and the double dot ".." concatinates our new string to the end. Dont for get to wrap string with "" and add your formatting spaces.

 

We can also use combinations of existing table strings or other variables:

 

myVar = "source" a.message = a.message.." "..myVar.." "..a.source

 

Here we create a new variable with the string "source" and use the key value for s.source. Notice the extra conactination and strings added to insert spaces for formatting. 

 

Here is the result:

 

message:Testmessage source 10.0.0.1

 

Page 21 of the attached NAS Whitepaper discusses all the available fields you can edit or add.

 

Once we have the changes we want to make in place we need to send the alarm back onto the NIMBUS:

 

alarm.set(a)

 Will send the alarm back to the NIMBUS and the NAS will update your alarm console:

 

Image 008.png

 

 

Full script now looks like this:

 

--Table Dumper - Used in table  function tdump(t)       local function dmp(t, l, k)         if type(t) == "table" then           print(string.format("%s%s:", string.rep(" ", l*2), tostring(k)))           for k, v in pairs(t) do             dmp(v, l+1, k)           end         else           print(string.format("%s%s:%s", string.rep(" ", l*2), tostring(k), tostring(t)))         end       end     dmp(t, 1, "root")             end --End Table dumper code  a = alarm.get("VF69259077-26007")  myVar = "source" a.message = a.message.." "..myVar.." "..a.source alarm.set(a)  tdump(a)

 

GREAT! We can now manipulate alarms based on auto-operator profiles. Lets take a quick look at how to create that profile, if your familiar with auto-operator profiles you might want to spik this part and start having fun with LUA :smileyhappy:

Follow this link for creating NAS auto operator rules [coming soon!]