CA Service Management

 View Only
  • 1.  How can I use Notification Method do a curl HTTP POST

    Posted Dec 11, 2016 08:22 PM

    I am have problem doing a HTTP POST batch script when Variable from Notification NX_SUMMARY contain (Quotations marks"") ,(hyphen -) ,(ampersand &) (space ) data.
    When I copy the context of the notification and try to pass it to a cmd variable myecho (" " Some - in 'missing' & "Value" not 'right') to the cmd prompt, it display error message'"Value"' is not recognized as an internal or external command, operable program or batch file.

     

     

    How can I use the use the notification context in curl.exe to do a HTTP POST with C:\Curl.exe http://myserver/cmd/system/api/sendsms.cgi?tar_num=555^&tar_msg=%NX_SUMMARY%

     

    Update on notification method with curl.exe.

    When using direct notification to do http post the receiving server was unable to handle the load of about ( 100 per second)

    To limit the amount of post to the server, I change the notification method to write to file only.Then using batch file to run the curl posting sequentially with the extracted NX variable from each file.

    But after having email service available, have switch to email notification for simplicity management.



  • 2.  Re:  How can I use Notification Method do a curl HTTP POST

    Posted Dec 12, 2016 03:40 AM

    Hi Guan,

     

    I think you need to find a way to escape the characters that cause an issue. For example try passing additional quotes "" for every variable

     

    Hope this helps?

     

    Kind Regards,

    Brian



  • 3.  Re:  How can I use Notification Method do a curl HTTP POST

    Posted Dec 12, 2016 07:34 AM

    Hi,

    this is not exacly answer to your question but you can append intermediate script on perl, in my example I call this script directly as Notification Method: pdm_perl SDMMailProc.pl

     

    It generates unique files in specified folder, but you can use it to pass through data next to executable file.

     

    Code:

    use IO::File;

    my $path = "../SDMMailProcessor/queue";
    my $syf = 0;
    my $nixtime = time;
    my $FILE_NAME;

    while ( (-e $FILE_NAME) || ($FILE_NAME eq '') ) {
         $FILE_NAME = $path . "/" . $nixtime . "." . $syf;
         $syf++;
    }

    print $FILE_NAME;

    my $fh = IO::File->new($FILE_NAME, O_RDWR|O_CREAT|O_EXCL);

    $summary = $ENV{"NX_NTF_SUMMARY"};
    $summary =~ s/[\r\n]+/ /g;
    $msg = $ENV{"NX_NTF_MESSAGE"};
    $msg =~ s/[\r\n]+/\\n/g;
    $email = $ENV{"NX_NTF_EMAIL_ADDRESS"};

    print $fh "NX_NTF_SUMMARY=$summary\n";
    print $fh "NX_NTF_EMAIL_ADDRESS=$email\n";
    print $fh "NX_NTF_MESSAGE=$msg\n";

    close $fh;

     

    Regards,

    cdtj



  • 4.  Re:  How can I use Notification Method do a curl HTTP POST

    Posted Dec 14, 2016 02:26 PM

    Hi cdtj,

     

    Thanks for the information. Current I do not understand perl language will take note of these alternative.

    I am still using batch file below is what I came up with.

     

     

    I am using batch files to run below commands.
    It seem to be able to redirect all context of the notitification (" " Some - in 'missing' & "Value" not 'right') to a file
    and later use curl to encode first before sending HTTP POST.

    Still waiting for chance of some form of stress test.

     

    Setlocal enableDelayedExpansion
    echo !NX_NTF_SUMMARY! > C:\notification.txt
    cd C:\
    C:\Curl.exe --data-urlencoded tar_msg@notification.txt -d tar_num=555 http://myserver/cmd/system/api/sendsms.cgi

     

    I need some opinion if these can work on heavy load test.

    Or if anyone can advice to point out flaws in these way of usage.

     

     

    Thanks



  • 5.  Re:  How can I use Notification Method do a curl HTTP POST

    Posted Dec 14, 2016 03:12 PM

    Hi,

     

    Sorry seem I got typo errors on the command.

    Below is the correct commands when I look at the man page.

     

    SETLOCAL EnableDelayedExpansion
    echo !NX_NTF_SUMMARY! > C:\notification.txt
    cd C:\
    C:\Curl.exe --progress-bar --data-urlencode tar_msg@notification.txt -d tar_num="555" tar_mode='text' http://myserver/cmd/system/api/sendsms.cgi



  • 6.  Re:  How can I use Notification Method do a curl HTTP POST

    Posted Dec 16, 2016 02:13 AM

    Hi,

    having static file name could cause problems, currently we are testing something similiar and outgoing notification's queue can rise up to 30 messages per second.

     

    Firstly we have used batch file with followed code (code by CA, used in CA Spectrum Integration):

    @echo off
    for /f "delims=" %%a in ('pdm_perl writeNotifDataToFile.pl') do @set FILE_NAME=%%a
    "d:\Program Files (x86)\CA\SC\JRE\1.6.0_30\\bin\java.exe"  -DFILE_NAME="%FILE_NAME%" -jar OCNotify.jar
    del %FILE_NAME%

    But I'm bad in batching so I switched to perl but this code could be a useful example how to generate unique temporary files, pass it to executable and then delete.

     

    Also here is one of my other projects where I have used perl script (Im not good at perl too  but as it distributing with CA SDM I think that every SDM admin should use it for their needs ):

    use pdm_perlext;
    use pdm_misc;
    use strict;
    use utf8;
    use Encode;

    binmode(STDOUT, ":utf8");          #treat as if it is UTF-8
    binmode(STDIN, ":encoding(utf8)"); #actually check if it is UTF-8

    $summary = $ENV{"NX_NTF_SUMMARY"};
    $summary =~ s/[\r\n]+/ /g;
    $msg = $ENV{"NX_NTF_MESSAGE"};
    $msg =~ s/[\r\n]+/ /g;
    $email = $ENV{"NX_NTF_EMAIL_ADDRESS"};

    my $appPath = "\"D:\\Program Files (x86)\\CA\\Service Desk Manager\\site\\mods\\integration\\someapp.exe\"";
    my $javaCmd = $appPath . " -email $email -msg $msg -summary $summary";
    my $out = `$javaCmd`;

     

    Hope this example helps you to build stable solution for your needs.

     

    Regards,

    cdtj



  • 7.  Re:  How can I use Notification Method do a curl HTTP POST

    Posted Dec 22, 2016 09:56 AM

    Something to consider too on large system if you are using the write to file to get additional value is that you may encounter performance issue due to all the extra I/O you will generate.

    Will mostly only impact system heavely used but to be consider.

    My 2 cents

    /J