DX Application Performance Management

 View Only
  • 1.  Shell command action problem

    Broadcom Employee
    Posted May 25, 2018 11:12 AM

    Hi all,

    I have a problem with a shell command action on windows server 2012 R2:

     

    (Alert->Action->file.bat, - alert passes 2 parameters to batch file, alert-name and alert-severity)

     

    The file.bat purpose is to run the following command:

     

    opcmsg msg_grp=Applicativi node=param1 application=param2 object=param3 severity=param4 msg_text="param5"

     

     

    The .bat file is now the following:

     

    -----------------------------------------------------------------------------------------------------

     

    @echo off

    setlocal ENABLEDELAYEDEXPANSION

    echo %1 %2 >>"D:\CA APM\ActionScript\action.log"

     

    REM Set a string with an arbitrary number of substrings separated by semi colons

    set teststring=%1

    set gravity=%2

        set n=0

    REM Do something with each substring

    :stringLOOP

                set /A n+=1

        REM Stop when the string is empty

        if "!teststring!" EQU "" goto END

     

        for /f "delims=." %%a in ("!teststring!") do set substring=%%a

     

            REM Do something with the substring -

            REM we just echo it for the purposes of demo

        REM    echo scrivo !substring! indice %n%

                            set vector[!n!]=!substring!

                           

    REM Now strip off the leading substring

    :striploop

               

        set stripchar=!teststring:~0,1!

        set teststring=!teststring:~1!

     

        if "!teststring!" EQU "" goto stringloop

     

        if "!stripchar!" NEQ "." goto striploop

     

        goto stringloop

    )

     

    :END

     

     

    set vector1=%vector[1]:"=%

    set vector2=%vector[2]%

    set vector3=%vector[3]%

    set vector4=%vector[4]:"=%

     

    echo %vector1% >>"D:\CA APM\ActionScript\action.log"

    echo %vector2% >>"D:\CA APM\ActionScript\action.log"

    echo %vector3% >>"D:\CA APM\ActionScript\action.log"

    echo %vector4% >>"D:\CA APM\ActionScript\action.log"

     

    REM if %2 EQU "1" (echo green)

    REM if %2 EQU "2" (echo yellow)

    REM if %2 EQU "3" (echo red) 

     

    if %2 EQU "1" (set alertgrav=normal)

    if %2 EQU "2" (set alertgrav=major)

    if %2 EQU "3" (set alertgrav=critical) 

     

     

    echo opcmsg msg_grp=Applicativi node=%vector1% application=%vector2% object=%vector3% severity=%alertgrav% msg_text="PROVA 2: La metrica oggetto di allarme : %vector4% " >"D:\CA APM\ActionScript\script.log"

     

    opcmsg msg_grp=Applicativi node=%vector1% application=%vector2% object=%vector3% severity=%alertgrav% msg_text="PROVA 2: La metrica oggetto di allarme : %vector4% "

     

    endlocal

     

    ------------------------------------------------------------------------------------------------------------------------

     

    The file D:\CA APM\ActionScript\script.log is written correctly, but the command opcmsg (opcmsg msg_grp=Applicativi node=%vector1% application=%vector2% object=%vector3% severity=%alertgrav% msg_text="PROVA 2: La metrica oggetto di allarme : %vector4% ") is not executed.

     

    If I copy the content of the script.log file on windows shell, the command is correctly executed. 

     

    Any suggestions?

     

    Thank You in advance.



  • 2.  Re: Shell command action problem
    Best Answer

    Broadcom Employee
    Posted May 25, 2018 02:21 PM

    If the opcmsg is a .exe file, then you would use the start command in the batch file.

     

    start "windowTitle" fullPath/file.exe

    Note: the first set of quotes must be there but you don't have to put anything in them, e.g.:

    start "" fullPath/file.exe


  • 3.  Re: Shell command action problem

    Broadcom Employee
    Posted May 28, 2018 04:40 AM

    Hi Matthew,

    thank You for aswer.

    I'll on site tomorrow, I'll keep you informed.

     

    Regards,

    Marco



  • 4.  Re: Shell command action problem

    Broadcom Employee
    Posted May 29, 2018 11:02 AM

    Hi all,

    I confirm You that including full path. the issue has been solved.

     

    Thank You

     

    Regards,

    Marco