AnsweredAssumed Answered

Connecting to External SQL DB with LUA, executing Query, modifying alarm variables with Query Values

Question asked by steveternes on Jan 17, 2013
Latest reply on Jan 18, 2013 by steveternes

What I am attempting is to integrate the Footprints ticketing systems with my NMS instance.  Currently, there is no gateway, and Footprints is unable to send or respond to snmp.  I am able to open a ticket within Footprints by sending the alarms via email.  I am also able to close the alarm, but I have to send the FootPrints incident number in the subject of the email.  That step I have figured out, by creating a custom variable and using it in the emailgtw for the footprints incident number.  What I would like to do is to write a lua script that will query the Footprints SQL database and find the alarm by the NIMID; as added that field and are pushing it into the Footprints ticket informaiton; then take that value/incident number and add it to the alarm.  This is what I have so far..."Provider=SQLNCLI10;Server=iccmsql;Database=Footprints_2;User Id=sa;Password=password;")


FPID =database.query("SELECT top 1 [mrID] FROM [Footprints_2].[dbo].[MASTER2] where [mrSTATUS]= 'Open' and [NIMID] = $NIMID'")




local a = alarm.get()

local updates = {}

updates.nimid = a.nimid

updates.custom_1 = $FPID



I am very new to Lua and I broke it into two parts 1) making the connecting to the SQL DB and executing the query and 2) adding the "custom_1" variable to the alarm.  When I run the database portion of the code; this is the output I recieve:


In the NAS Scripting:

----------- Executing script at 1/16/2013 1:37:03 PM ----------

Error in line 5: '=' expected near '<eof>'


In SciTE Lua tool:

>lua -e "io.stdout:setvbuf 'no'" "NBimFPInt.Lua"
lua: NBimFPInt.Lua:1: attempt to index global 'database' (a nil value)
stack traceback:
 NBimFPInt.Lua:1: in main chunk
 [C]: ?
>Exit code: 1


Any assistance would be appraciated.