UK CA Unified Infrastructure Management User Group

LUA/Regex query returning nothing - how to alert on nothing

  • 1.  LUA/Regex query returning nothing - how to alert on nothing

    Posted 03-10-2017 12:00 PM

    I have a script that will query a database and return a value if the thing I am looking for is present, that works fine.

    If the thing I am looking for is not present then it returns nothing.

    I'm looking for some regex that will detect nothing if this is possible? I've tried all sorts of variations but not getting anywhere with it..

    Script: rc = database.open("provider=nis;database=nis;driver=none")

    query = "SELECT * from nas_transaction_summary where created > DATE_SUB(CURRENT_TIMESTAMP(),INTERVAL 140 MINUTE) and message like 'LIVE - STRMIGSCH%' limit 1;"

    alarms, rc = database.query(query)

    for _, al in pairs (alarms) do print (al.message)

    if regexp (al.message,"STRMIGSCH")

    then print ("Everything is fine")

    else nimbus.alarm(1,"TEST ALERT")

    database.close()

    end

    end

    I think this is the problem line:

    if regexp (al.message,"STRMIGSCH")

    If there is no text at all, then it doesn't move on.

    Does anyone have any suggestions?

    Thanks in advance,