Impersonating an alarm from the sending probe using raw-alarms

Discussion created by carstein.seeberg on Feb 14, 2009
Latest reply on Jul 2, 2010 by carstein.seeberg
Now and then the question comes up if it is possible to associate an existing alarm generated by a probe or the infrastructure components.  This post shows how this is done by the use of generating a "raw" alarm message onto the bus.   The NAS will use elements like the domain, robotname, source and
suppression key to tie messages.  The nimbus.alarm sent from the NAS has a different "footprint" than the ones generated by the probes.  The following code contains one function to generate a unique key (the nimid) and the actual 'rawalarm' function. 

Please use this knowledge with care :-)


-- Generates a nimid
function unique_id()
   key = ""
key = mid(base,math.random(1,26),1) .. mid(base,math.random(1,26),1) ..
sprintf("%07d", math.random(1,100000000)) .. "-" ..
   return key

-- rawalarm (source,severity,subsystem,message ]]]])
-- returns 0 - ok, rest error
function rawalarm (source,severity,subsystem,message,suppkey,domain,origin,robot,probe)
   -- expect following parameters
   if type(severity) ~= "number" then return 1 end
   if type(message) ~= "string" then return 1 end
   if type(subsystem) ~= "string" then return 1 end
   if type(source) ~= "string" then return 1 end

   -- set default values for optional parameters.
   if type(domain) ~= "string" then domain="lua-domain" end
   if type(origin) ~= "string" then origin="lua-origin" end
   if type(robot) ~= "string" then robot="lua-robot" end
   if type(probe) ~= "string" then probe="lua-probe" end
   if type(suppkey) ~= "string" then suppkey="lua-suppkey" end
   msg = pds.create ()
   nimid = unique_id()
   -- Create message header
   pds.putString (msg,"nimid",nimid)
   pds.putInt    (msg,"nimts", )
   pds.putString (msg,"subject","alarm")
   pds.putInt    (msg,"pri",1)
   pds.putString (msg,"source",source)
   pds.putString (msg,"origin",origin)
   pds.putString (msg,"domain",domain)
   pds.putString (msg,"robot",robot)
   pds.putString (msg,"prid",probe)
   pds.putString (msg,"suppression","y+000000000#" .. suppkey)
   pds.putString (msg,"supp_key",suppkey)
   -- Add raw alarm data
   udata = pds.create()
   pds.putInt    (udata,"level",severity)
   pds.putString (udata,"subsys",subsystem)
   pds.putString (udata,"message",message)
   pds.putPDS (msg,"udata",udata)
   -- Post the message to the hub-spooler
   t,rc = nimbus.request ("spooler","hubpost",msg)

   pds.delete (udata)
   pds.delete (msg)
   return rc,nimid

-- initialize the random generator

rc,id = rawalarm ("",3,"1.2.3","This is a simple test...")
printf ("rawalarm: %s, %d",id,rc)

rc,id = rawalarm ("",NIML_CRITICAL,"1.2.3","This is an advanced test...","mykey","mydomain","myorigin","myrobot","myprobe")
printf ("rawalarm: %s, %d",id,rc)