CA Service Management

 View Only
  • 1.  Create a new notification method to SMS e EMAIL messages

    Posted Apr 27, 2015 03:32 PM

    I need to create a new notification method in SDM tool that runs a BATCH file within that batch file are fired two actions simultaneously: Send an EMAIL and SMS via PDM_MAIL command and another executable that sends text messages to cell . This new method would be called " Email & SMS" .

    The problem is that I do not know how to reference the message parameters related to the object in question (cr , chg , iss, etc.) in the batch file.

    To use the command manually PDM_MAIL you must specify the following parameters: pdm_mail -s -i " email title " -and email@address.com -q < message.txt If anyone can help ,

    I appreciate it .



  • 2.  Re: Create a new notification method to SMS e EMAIL messages

    Broadcom Employee
    Posted Apr 27, 2015 04:14 PM

    Daniel, I think you can use the NX_NTF vaiables written to a flat txt

    file in the TEMP folder. Please take a look at the SDM Impl Guide,

    chapter "Customizing", where you will see some info about these

    variable. Here is an example from one such file:

    SECTION=cr

    NX_NTF_ID=400019

    NX_NTF_PRODUCER_ID=cr

    NX_NTF_PERSISTENT_ID=cr:400019

    NX_NTF_NEW_DELAY_LOG=

    NX_NTF_REF_NUM=70

    NX_NTF_SUMMARY=my-summary-here

    NX_NTF_DESCRIPTION=my-description-here

    NX_NTF_OPEN_DATE=04/15/2015 17:11:56

    NX_NTF_LAST_MOD_DT=04/27/2015 15:43:09

    NX_NTF_TIME_SPENT_SUM=14 seconds

    NX_NTF_CLOSE_DATE=(NULL)

    NX_NTF_RESOLVE_DATE=(NULL)

    NX_NTF_CHARGE_BACK_ID=(NULL)

    NX_NTF_EXTERN_REF=(NULL)

    NX_NTF_EXTERN_TOKEN=(NULL)

    NX_NTF_EVENT_TOKEN=(NULL)

    NX_NTF_TICKET_AVOIDED=(NULL)

    NX_NTF_WEB_URL=http://server-name-here/CAisd/pdmweb.exe?OP=SEARCH+FACTORY=cr+SKIPLIST=1+QBE.EQ.id=400019

    NX_NTF_CAWF_PROCID=(NULL)

    NX_NTF_BASED_ON_KD=(NULL)

    ...

    X_NTF_STATUS.SYM=Open

    NX_NTF_ACTIVE.SYM=YES

    NX_NTF_LAST_MOD_BY.COMBO_NAME=Administrator

    NX_NTF_ROOTCAUSE.SYM=(NULL)

    NX_NTF_RESOLUTION_CODE.SYM=(NULL)

    NX_NTF_RESOLUTION_METHOD.SYM=(NULL)

    NX_NTF_AFFECTED_RESOURCE.NAME=(NULL)

    NX_NTF_LOG_AGENT.COMBO_NAME=Administrator

    NX_NTF_ASSIGNEE.COMBO_NAME=Administrator

    NX_NTF_CUSTOMER.COMBO_NAME=Administrator

    NX_NTF_GROUP.COMBO_NAME=

    ...

    SECTION=cnt

    NX_NTF_ID=8BBCC117211335498F5850AC32FADD9F UUID String

    NX_NTF_PRODUCER_ID=cnt

    NX_NTF_PERSISTENT_ID=cnt:8BBCC117211335498F5850AC32FADD9F

    NX_NTF_LAST_MOD_DT=04/27/2015 15:39:28

    NX_NTF_CREATION_DATE=(NULL)

    NX_NTF_LAST_NAME=Administrator

    NX_NTF_FIRST_NAME=(NULL)

    NX_NTF_MIDDLE_NAME=(NULL)

    NX_NTF_ALIAS=Administrator

    ....

    SECTION=notification
    NX_NTF_CONTACT=cnt:8BBCC117211335498F5850AC32FADD9F
    NX_NTF_MESSAGE=Incident 70 Manual Notify.
    Assigned to: Administrator
    Customer: Administrator
    Description:

    please send to:
    abc.cdv@yee.com


    Click on the following URL to view:
    http://server-name-here/CAisd/pdmweb.exe?OP=SEARCH+FACTORY=cr+SKIPLIST=1+QBE.EQ.id=400019


    NX_NTF_SUMMARY=Incident 70 Manual Notify
    NX_NTF_ACK_BY=
    NX_MAILUSER=ServiceDesk
    NX_NTF_EMAIL_ADDRESS=xxxxx@yyyyy.com
    NX_NTF_USERID=Administrator
    NX_NTF_COMBO_NAME=Administrator
    NX_NTF_URGENCY=2
    NX_NTF_TRANSITION=28

    ///////////////////////////////////////////////////////////////

    This list is long and you can see your script can get a lot of info from

    this file. Hope this helps a bit. Thanks _Chi



  • 3.  Re: Create a new notification method to SMS e EMAIL messages
    Best Answer

    Posted Apr 27, 2015 05:55 PM

    Notification section also available as run-time environment variables. You can create custom notification method that will execute batch file with the following command

    set NX_NTF >tmp

    to get all available environment variables for this section



  • 4.  Re: Create a new notification method to SMS e EMAIL messages

    Posted Apr 28, 2015 04:55 PM

    Thanks Guti e Chi.

    Thanks to you I have developed a new method of reporting that gives me the possibility to send EMAIL and SMS simultaneously and very quickly. Attached the code. !

     

    @ECHO OFF

    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    :: Programa:        Enviador de SMS e EMAIL

    :: Autor:            Daniel Becker Bighelini

    :: Criado em:        25/04/2015

    :: Modificado por:    Daniel Becker Bighelini

    :: Modificado em:    28/04/2015

    :: Descricao:        Envia SMS e EMAIL.

    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

     

    :: Habilita a expansao das variaveis de ambiente

    SETLOCAL ENABLEDELAYEDEXPANSION

     

    :: Salva pasta atual

    PUSHD "%~dp0"

     

    :: Verifica os parametros

    SET batargc=0

    FOR %%? IN (%*) DO (

        IF DEFINED batdebug ECHO %DATE% %TIME%    DEBUG        #ARG !batargc!: %%?

        SET /A batargc+=1

        FOR %%f IN (debug help log confirm email sms) DO (

            IF [%%f]==[%%?] (

                SET batparameters=!batparameters!%%?;

                SET bat%%?=1

            )

        )

    )

    IF DEFINED batdebug ECHO %DATE% %TIME%    DEBUG        Quant. de parametros informados: %batargc%

    ECHO.

     

    :inicio

    :: Define variaveis globais

    IF DEFINED batdebug ECHO %DATE% %TIME%    DEBUG        Declarando variaveis...

    CALL:atualiza_data_hora

    SET batauthor=Daniel Becker Bighelini

    SET batfunction=Enviador

    SET batversion=1.0

    SET batdescription=Envia SMS e EMAIL para destinatarios da USD

    SET batstart=%DATE% %TIME%

    SET batuser=%USERNAME%

    SET batname=%~n0

    SET batext=%~x0

    SET batfile=%batname%%batext%

    SET batpath=%~dp0

    SET battemp="%TEMP%\%batname%%agoraf%.tmp"

    SET batpathfull="%batpath%%batname%%batext%"

    SET batcfgpathfull="%batpath%%batname%.cfg"

    SET batlogname=%batname%.log

    SET batlognameold=%batlogname%.old

    :: Define variaveis personalizaveis

    SET batemailexec=pdm_mail -H ISO-8859-1

    SET batsmsexec=sms

    :: Fim das variaveis personalizaveis

    IF DEFINED NX_ROOT (

        IF DEFINED batdebug ECHO %DATE% %TIME%    DEBUG        Definindo local para armazenamento de logs na USD...

        SET batlogpath="%NX_ROOT%\log\%batlogname%"

        SET batlogpathold="%NX_ROOT%\log\%batlognameold%"

        :: Substitui a barra por contrabarra no path do servicedesk

        SET batfindbar=/

        SET batreplacebar=\

        CALL SET batlogpath=%%batlogpath:!batfindbar!=!batreplacebar!%%

        CALL SET batlogpathold=%%batlogpathold:!batfindbar!=!batreplacebar!%%

    ) ELSE (

        IF DEFINED batdebug ECHO %DATE% %TIME%    DEBUG        Definindo local para armazenamento de logs na pasta do script...

        SET batlogpath="%batpath%%batlogname%"

        SET batlogpathold="%batpath%%batlognameold%"

    )

    IF DEFINED batdebug CALL:logmsg DEBUG "Arquivo de logs utilizado: %batlogpath%"

    IF DEFINED NX_LOGFILE_LIMIT (

        SET batlogsizemax=%NX_LOGFILE_LIMIT%

    ) ELSE (

        SET batlogsizemax=5000000

    )

    IF DEFINED batdebug CALL:logmsg DEBUG "Tamanho maximo do log: %batlogsizemax% bytes."

    IF EXIST %batlogpath% CALL:verifica_log

    FOR %%? IN (%batpathfull%) DO SET batdate=%%~t?

     

    CALL:exibe_cabecalho

    CALL:bloco_inicio

     

    :: Aborta script se nao forem informados parametros

    IF [%argc%]==[0] GOTO erro1

     

    :: Exibe a ajuda

    IF DEFINED bathelp GOTO exibe_ajuda

     

    :: Exibe a confirmacao de execucao do programa

    IF DEFINED batconfirm (

        ECHO.

        CHOICE /C SN /M "Deseja continuar com a execucao"

        IF ERRORLEVEL 2 GOTO cancelar

    )

     

    IF DEFINED batdebug (

        :: Capturando variaveis de ambiente do SCRIPT

        IF DEFINED batname (

            CALL:logmsg DEBUG "Capturando variaveis utilizadas pelo SCRIPT..."

            FOR /F "tokens=1-2 delims==" %%a IN ('SET bat') DO (

                ECHO %DATE% %TIME%    DEBUG        %%a=%%b>>%batlogpath%

            )

        ) ELSE (

            CALL:logmsg ERROR "AVISO: As variaveis de ambiente do script nao puderam ser coletadas."

        )

     

        :: Capturando variaveis de ambiente NTF utilizadas para o envio

        IF DEFINED NX_NTF_CONTACT (

            CALL:logmsg DEBUG "Capturando variaveis NTF da USD utilizadas para o processo de notificacao..."

            :: Somente captura as variaveis NTF se ao menos a obrigatoria NX_NTF_CONTACT existir

            :: E isso soh ocorre quando este script eh executado a partir de um metodo de notificacao da USD

            FOR /F "tokens=1-2 delims==" %%a IN ('SET NX_NTF') DO (

                ECHO %DATE% %TIME%    DEBUG        %%a=%%b>>%batlogpath%

            )

        ) ELSE (

            CALL:logmsg WARNING "AVISO: As variaveis de ambiente NTF da USD nao puderam ser coletadas."

        )

    )

     

    :: Envia o EMAIL

    IF DEFINED batemail (

        IF NOT DEFINED NX_NTF_EMAIL_ADDRESS GOTO erro2

        IF DEFINED batdebug CALL:logmsg DEBUG "Enviando EMAIL atraves do comando '%batemailexec%'..."

        CALL:logmsg SIGNIFICANT "Notificando por EMAIL o contato '%NX_NTF_COMBO_NAME%' ('%NX_NTF_EMAIL_ADDRESS%')..."

        %batemailexec%

        IF NOT "%ERRORLEVEL%"=="0" (

            CALL:erro "%batemailexec%"

        ) ELSE (

            CALL:logmsg SIGNIFICANT "EMAIL enviado com SUCESSO para o contato '%NX_NTF_COMBO_NAME%' ('%NX_NTF_EMAIL_ADDRESS%')."

        )

    )

     

    :: Envia o SMS

    IF DEFINED batsms (

        IF NOT DEFINED NX_NTF_VOICE_PHONE GOTO erro3

        IF DEFINED batdebug CALL:logmsg DEBUG "Enviando SMS atraves do comando '%batsmsexec%'..."

        CALL:logmsg SIGNIFICANT "Notificando por SMS o contato '%NX_NTF_COMBO_NAME%' ('%NX_NTF_VOICE_PHONE%')..."

        %batsmsexec% %NX_NTF_VOICE_PHONE% "%NX_NTF_MESSAGE%"

        IF NOT "%ERRORLEVEL%"=="0" (

            CALL:erro "%batsmsexec%"

        ) ELSE (

            CALL:logmsg SIGNIFICANT "SMS enviado com SUCESSO para o contato '%NX_NTF_COMBO_NAME%' ('%NX_NTF_VOICE_PHONE%')."

        )

    )

     

    :: Encerra execucao

    GOTO fim

     

    :logmsg

    SET batmsgtype=%1

    SET batmsgtype=%batmsgtype:"=%

    SET batmsgtext=%2

    SET batmsgtext=%batmsgtext:"=%

    SET batmsg=%DATE% %TIME%    %batmsgtype%        %batmsgtext%

    IF "%batmsgtype%"=="SIGNIFICANT" SET batmsg=%DATE% %TIME%    %batmsgtype%    %batmsgtext%

    ECHO %batmsg%

    IF DEFINED batlog ECHO %batmsg%>>%batlogpath%

    GOTO:EOF

     

    :erro

    SET baterror_code=%ERRORLEVEL%

    SET baterror_msg=%1

    SET baterror_msg=%baterror_msg:"=%

    CALL:logmsg ERROR "ERRO [%baterror_code%] ao executar rotina '%baterror_msg%'."

    EXIT /B %baterror_code%

    GOTO:EOF

     

    :erro1

    SET baterror_code=1

    CALL:logmsg ERROR "ERRO [%baterror_code%] ao iniciar rotina: Nenhum parametro foi informado."

    CALL:bloco_fim

    EXIT /B %baterror_code%

    GOTO:EOF

     

    :erro2

    SET baterror_code=2

    CALL:logmsg ERROR "ERRO [%baterror_code%] ao enviar EMAIL: Nenhum endereco de email foi informado."

    CALL:bloco_fim

    EXIT /B %baterror_code%

    GOTO:EOF

     

    :erro3

    SET baterror_code=3

    CALL:logmsg ERROR "ERRO [%baterror_code%] ao enviar SMS: Nenhum numero de telefone foi informado."

    CALL:bloco_fim

    EXIT /B %baterror_code%

    GOTO:EOF

     

    :sucesso

    CALL:logmsg SIGNIFICANT    "Operacao CONCLUIDA com sucesso."

    GOTO fim

     

    :cancelar

    CALL:logmsg SIGNIFICANT    "Operacao CANCELADA pelo usuario."

    GOTO fim

     

    :atualiza_data_hora

    :: Consultando data atual

    FOR %%A IN (%DATE%) DO (

        FOR /F "tokens=1-3 delims=/-" %%B in ("%%~A") DO (

            SET batdataf=%%D%%C%%B

            SET batdatas=%%B/%%C/%%D

        )

    )

    :: Consultando hora atual

    FOR /F "tokens=1-3 delims=:.," %%A IN ("%TIME%") DO (

        SET bathoraf=%%A%%B%%C

        SET bathoras=%%A:%%B:%%C

    )

    :: Concatenando data e hora

    SET batagoraf=%batdataf%%bathoraf%

    SET batagoras=%batdatas% %bathoras%

    GOTO:EOF

     

    :verifica_log

    :: Verifica se o arquivo de log atingiu o limite de tamanho definido

    :: E em caso positivo, rotaciona o log.

    IF DEFINED batdebug CALL:logmsg DEBUG "Verificando tamanho do arquivo de log..."

    FOR /F "usebackq" %%A IN ('%batlogpath%') DO set batlogsize=%%~zA

    IF DEFINED batdebug CALL:logmsg DEBUG "Tamanho atual do arquivo de log: %batlogsize%"

    IF %batlogsize% GEQ %batlogsizemax% (

        IF DEFINED batdebug CALL:logmsg DEBUG "O arquivo de log ATINGIU o limite de tamanho de %batlogsizemax% bytes."

        IF DEFINED batdebug CALL:logmsg DEBUG "Removendo logs antigos e rotacionando log..."

        IF EXIST "%batlognameold%" DEL "%batlognameold%"

        IF EXIST "%batlogname%" IF NOT EXIST "%batlognameold%" REN "%batlogname%" "%batlognameold%"

    )

    GOTO:EOF

     

    :exibe_ajuda

    :: Exibe a ajuda do programa

    ECHO.

    ECHO AJUDA DO SCRIPT

    ECHO.

    ECHO Sintaxe: %batfile% email^|sms [debug] [log] [help] [confirm]

    ECHO.

    ECHO          email   = Envia um EMAIL ao contato.

    ECHO          sms     = Envia um SMS ao contato.

    ECHO          debug   = Exibe detalhadamente o funcionamento do script.

    ECHO          log     = Registra em log o funcionamento do script.

    ECHO          help    = Ajuda do script.

    ECHO          confirm = Solicita confirmacao antes de executar o script.

    ECHO.

    ECHO Comandos atualmente configurados:

    ECHO          email   = %batemailexec%

    ECHO          sms     = %batsmsexec%

    ECHO.                 

    GOTO fim

     

    :exibe_cabecalho

    :: Exibe o cabecalho do programa

    ECHO *************************************************************

    ECHO %batfunction% %batversion% [%batfile%]

    ECHO Desenvolvido por %batauthor% em %batdate%

    ECHO Descricao: %batdescription%

    ECHO *************************************************************

    GOTO:EOF

     

    :bloco_inicio

    :: Exibe o bloco de inicio do programa

    CALL:logmsg SIGNIFICANT "INICIO"

    IF DEFINED batparameters (

        IF DEFINED batdebug (

            CALL:logmsg DEBUG "Linha de comando utilizada: %CMDCMDLINE%"

            CALL:logmsg DEBUG "Parametros validos: %batparameters%"

        )

    )

    GOTO:EOF

     

    :bloco_fim

    :: Exibe o bloco de fim do programa

    CALL:logmsg SIGNIFICANT "FIM"

    GOTO:EOF

     

    :fim

    :: Reseta variaveis

    CALL:bloco_fim

    POPD

    ENDLOCAL

    :EOF



  • 5.  Re: Create a new notification method to SMS e EMAIL messages

    Posted Apr 28, 2015 05:39 PM

    Thank you for sharing. Creating a document and sharing it with community may be good idea.



  • 6.  Re: Create a new notification method to SMS e EMAIL messages

    Posted Feb 19, 2018 09:06 AM

    Hi Daniel

     

    this all code we need to put in  notification method box??



  • 7.  Re: Create a new notification method to SMS e EMAIL messages

    Posted Feb 19, 2018 09:43 AM

     

    Yes. Create a new method referencing this batch file.