AnsweredAssumed Answered

Shell command action problem

Question asked by annma01 Employee on May 25, 2018
Latest reply on May 29, 2018 by annma01

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.

Outcomes