DX Unified Infrastructure Management

  • 1.  Send Alarm message via SMS URL

    Posted Nov 14, 2018 10:59 PM

    Hi,

     

    My customer requests us to send the UIM alarm to sms gateway through the provided SMS URL.

    Here is the SMS URL:

    http://***.***.***.***/cauim_dev/Sendsms?param="..cmd1.."^&toNumber=0812800XXXX^&apiKey=X******

     

    I have created a script in NAS alarm like this:

    function space(s)
    return s:gsub("","+")
    end

    function equals(s)
    return s:gsub("=",":")
    end

    a = alarm.get()

    cmd1 = equals(a.hostname.."("..a.source.."), Severity:"..a.severity..", Message:"..a.message)
    cmd2 = "start "..space("http://***.***.***.***/cauim_dev/Sendsms?param="..cmd1.."^&toNumber=0812800XXXXX^&apiKey=ShinhANnegaBaro")

    action.command(cmd2)

     

    After I executed that script, there was an activity was logged in Activity Log like this:

    http://***.***.***.***/cauim_dev/Sendsms?param=Severity:+Testmajor,+Message:QOS_INTERFACE_UTILIZATION+=+1176110.94+from+source+JAKARTA+targeting+eix0(eix0)+has+crossed+the+major+static+threshold+of+>95.0^&tonumber=0812800XXXX^&apiKey=X******

     

    Waiting for more than 5 minutes, but I was not receiving a SMS from the executed script.

     

    Then, I tried to run the activity value  in browser and here is the return value:

    Once I executed it from browser, I received the SMS as expected.

     

    Can somebody advise me, why the alarm was not sending SMS once I executed it from NAS alarm? What I missed in my script?

     

    Regards

    Rio



  • 2.  Re: Send Alarm message via SMS URL

    Broadcom Employee
    Posted Nov 15, 2018 10:05 AM

    My suspicion is that this is failing becaue you are calling a url and not a windows command.

    I would suggest creating a batch file that you can pass parameters to that will send this.

    in the batch file you will need to call curl or ie or some other application that can handle the http request properly.

     

    as the lua is not running in a user context I do not believe the START command will work as it does in a user session.

     

     



  • 3.  Re: Send Alarm message via SMS URL

    Posted Nov 15, 2018 10:50 AM

    Hi Gene,

     

    Do you mean that the NAS is not allowing the START command?

    From the script I created, can you advise how to convert it into batch file? I use 2 functions to remove "space" and "=". Without those functions the URL will not show full message. The URL do not allow space and = characthers.

     

    Regards,

    Rio



  • 4.  Re: Send Alarm message via SMS URL

    Broadcom Employee
    Posted Nov 15, 2018 11:41 AM

    personally, I would not try and use start.

    I would use the curl.exe

    How do I install and use curl on Windows? - Stack Overflow 

     

    I do not believe the start command can be run in a service context but you would have to check with MS on that.

     

    if you use curl or ieexplorer.exe instead of start I think it should work for you.



  • 5.  Re: Send Alarm message via SMS URL

    Posted Nov 15, 2018 10:39 PM

    Ok, let me try it by today.

     

    thanks

    Rio



  • 6.  Re: Send Alarm message via SMS URL

    Posted Nov 15, 2018 11:58 PM

    Hi Gene,

     

    I just tried it using curl.exe but it is fail.

    See the result below:

    1. Install curl.exe.

    2. Create a script:

    function space(s)
    return s:gsub("","+")
    end

    function equals(s)
    return s:gsub("=",":")
    end

    a = alarm.get()

    cmd1 = equals(a.hostname.."("..a.source.."), Severity:"..a.severity..", Message:"..a.message)
    cmd2 = "curl.exe "..space("http://***.***.***.***/cauim_dev/Sendsms?param="..cmd1.."^&toNumber=0812800XXXXX^&apiKey=*********")

    action.command(cmd2)

    3. Result in Activity Log

    Result was error

     

    4. Use the Activity Result and execute it from Command Prompt

    the return value is success. 

     

    So, it is seems the NAS is still not working properly. Any advise?

     

    Regards

    Rio



  • 7.  Re: Send Alarm message via SMS URL

    Broadcom Employee
    Posted Nov 16, 2018 01:05 PM

    please add a print statement to your script to print out the command to nas to make sure the final result is what you are expecting.

    print("Full Curl Command")

    print(cmd2)

    action.command(cmd2)

     

    then test and check your nas.log and see what the command looks like



  • 8.  Re: Send Alarm message via SMS URL

    Posted Nov 16, 2018 01:15 PM

    Really, check the nas.log file. That return status 1 is typically a coding error - concatenation of a nil value is my guess.

     

    You also have no error checking in your code. You should validate that alarm.get() worked by testing if a is nil or not. 

     

    And that curl.exe is in your path. As it is, you are making the assumption it is in your current directory or system path. Neither may be true for the nas. AO profiles will have the nas directory as the current dir, not the directory where your script is (unless they are the same of course)

     

    And finally when running commands like this, I prefer to use "cmd.exe /c" to run them. That way you'll get a fresh environment as opposed to using what the nas inherited on startup.

     

    -Garin



  • 9.  Re: Send Alarm message via SMS URL

    Posted Nov 18, 2018 10:41 PM

    Hi Garin,

     

    Below is the Nas log. I did save this log after I executed the script

    Nov 15 13:43:21:719 [21844] nas: SqliteExecuteCallback: sqlite3_finalize returned:0
    Nov 15 13:43:21:719 [21844] nas: _processEvents 1 of 1000 in 6 ms.
    Nov 15 13:43:21:719 [21844] nas: Event-Processor: published 1 messages in 6ms, 0 in queue.
    Nov 15 13:43:21:759 [7504] nas: Trigger state changed to TRUE , '__INTERNAL:SMS URL'
    Nov 15 13:43:21:759 [7504] nas: ExecEvent: IMMEDIATE rule='SMS URL', nimid=CF89430803-74045, ACTION:script
    Nov 15 13:43:21:760 [19612] nas: [0xBD417000] Database provider is 'SQLITE3', database 'database.db'
    Nov 15 13:43:21:765 [21508] nas: dbBeginTransaction tlogRun, OK - rc:0
    Nov 15 13:43:21:765 [19612] nas: SqliteExecuteCallback: sqlite3_finalize returned:0
    Nov 15 13:43:21:771 [21508] nas: dbCommitTransaction tlogRun, OK - rc:0
    Nov 15 13:43:21:797 [22232] nas: SREQUEST: post ->10.97.244.253/48001
    Nov 15 13:43:21:797 [22232] nas: RREPLY: status=OK(0) <-10.97.244.253/48001 h=37 d=28
    Nov 15 13:43:21:837 [7504] nas: ExecEvent: Rule='SMS URL' on nimid='CF89430803-74045' with ACTION:script, age:0s, status:OK
    Nov 15 13:43:21:841 [22504] nas: dbBeginTransaction dbsRun, OK - rc:0
    Nov 15 13:43:21:847 [22504] nas: dbCommitTransaction dbsRun, OK - rc:0
    Nov 15 13:43:21:847 [22504] nas: dbsRun committed 1 requests. 0 remaining in queue...
    Nov 15 13:43:21:848 [22232] nas: SREQUEST: post ->10.97.244.253/48001
    Nov 15 13:43:21:848 [22232] nas: RREPLY: status=OK(0) <-10.97.244.253/48001 h=37 d=28
    Nov 15 13:43:21:856 [21580] nas: dbBeginTransaction actLogRun, OK - rc:0
    Nov 15 13:43:21:862 [21580] nas: dbCommitTransaction actLogRun, OK - rc:0
    Nov 15 13:43:21:932 [18232] nas: NiS bridge: NTS INSERTED: nimid='CF89430803-74045' rc: 0 took 1ms
    Nov 15 13:43:21:934 [18232] nas: NiS bridge: NA INSERTED: nimid='CF89430803-74045' rc: 0 took 1ms
    Nov 15 13:43:21:934 [18232] nas: SqliteExecuteCallback: sqlite3_finalize returned:0
    Nov 15 13:43:21:991 [18232] nas: SqliteExecuteCallback: sqlite3_finalize returned:0
    Nov 15 13:43:22:204 [6380] nas: RREQUEST: get_info <-10.97.244.253/55324 h=297 d=15
    Nov 15 13:43:22:204 [6380] nas: (get_info) - called from 10.97.244.253/55324
    Nov 15 13:43:22:204 [6380] nas: [0xBCD21B10] Database provider is 'SQLITE3', database 'database.db'
    Nov 15 13:43:22:210 [6380] nas: SqliteExecuteCallback: sqlite3_finalize returned:0
    Nov 15 13:43:22:210 [6380] nas: SREPLY: status = 0(OK) ->10.97.244.253/55324
    Nov 15 13:43:22:210 [6380] nas: RREQUEST: _close <-10.97.244.253/55324 h=295 d=0
    Nov 15 13:43:22:210 [6380] nas: sockClose:000001EFBD7EFEC0:10.97.244.253/48015
    Nov 15 13:43:22:992 [18232] nas: SqliteExecuteCallback: sqlite3_finalize returned:0
    Nov 15 13:43:23:993 [18232] nas: SqliteExecuteCallback: sqlite3_finalize returned:0

     

    From the log I did not see the trace of execution script. It just shown the Script Name (SMS URL).

    Even though the script was not in the nas.log, but the result was logged in the Activity log.

    See the Time between Nas.log and Activitiy Log in the same time 13:43

     

    Can I understand what do you mean about your statement on this one:

    AO profiles will have the nas directory as the current dir, not the directory where your script is (unless they are the same of course)

    For your information, my NAS and AO are in the same directory

     

    Regards

    Rio



  • 10.  Re: Send Alarm message via SMS URL
    Best Answer

    Posted Nov 21, 2018 01:44 AM

    Hi,

     

    It's work now after I added a full path of curl.exe in my script.

    The script become like this:

    function space(s)
    return s:gsub("","+")
    end

    function equals(s)
    return s:gsub("=",":")
    end

    a = alarm.get()

    cmd1 = equals(a.hostname.."("..a.source.."), Severity:"..a.severity..", Message:"..a.message)
    cmd2 = "C:\\curl-7.62.0-win64-mingw\\bin\\curl.exe "..space("http://***.***.***.***/cauim_dev/Sendsms?param="..cmd1.."^&toNumber=0812800XXXXX^&apiKey=xxxxxxxxxx")

    action.command(cmd2)

     

    With this script, NAS able to work properly to trigger a provided URL SMS and I can receive SMS as expected.

    Here is the one of the successful received SMS:

     

    Regards

    Rio