DX Infrastructure Management

Expand all | Collapse all

e2e Scripting help for generating an alarm

  • 1.  e2e Scripting help for generating an alarm

    Posted 03-20-2017 05:23 AM

    Hi All,

     

    Good day

     

    I am new to e2e_appmon scripting. I have a question about generating an alarm for each of the transaction when it fails alone.Need an alarm post failing each steps.

     

    I have a script which does the following

     

    1. Open the website

    2.log on to the website

    3.click on the page within a website post logon

    4.Some steps

    5.Some steps

    6.Logoff

     

    I have if condition for step1 to generate an alarm. It works fine. However would like to know how i can generate the alarm for each of the other steps from step2. I dont know where and how to put the condition for other steps. Below is the sample script.

     

     

     

    dim qos$(10) 'Ten qos names should do for most cases? The first is normally blank!

    ' Required for NimBUS system calls (like sending QoS'es)
    include "Nimbus-functions.src"

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' close_communicator - closes the Microsoft Lync App if it appears

    function close_communicator()
    if existw("COMMUNICATOR.EXE|CommunicatorMainWindowClass|Microsoft Lync ",1) = 0 then 'Window does not exist, exit function!
    exitfunction
    endif
    'If we get here we need to do some controlled closing of windows etc. Add code as appropriate
    'for your application! Some examples:

    CloseWindow("COMMUNICATOR.EXE|CommunicatorMainWindowClass|Microsoft Lync ",1)

    endfunction

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' close_communicator - closes the Microsoft Lync App if it appears

    function close_explorer()

    if IsRunning("IEXPLORE.EXE") = 0 then 'Internet Explorer not running so we exit
    exitfunction
    endif

    killApp("IEXPLORE.EXE",1)
    ' MsgBox ("Ran Kill Ex")

    endfunction

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' prepare - makes sure the app is not already running and sets up the NimBUS connections.
    function prepare()
    '#ignoreerrors=0 'we are running automatically, so no one sees the error message anyway!
    'MsgBox("Running Prepare")
    close_communicator()
    close_explorer()
    nimInit()
    endfunction

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' cleanup - checks the rc code and sends NULLs where appropriate. Calls close_app, closes the
    ' connections to NimBUS and exits the script (returning rc)
    function cleanup(rc)
    if rc > 0 then
    if rc <= 1 then
    nimQoSSendNull(qos$(1))
    endif
    if rc <= 2 then
    nimQoSSendNull(qos$(2))
    endif
    if rc <= 3 then
    nimQoSSendNull(qos$(3))
    endif
    if rc <= 4 then
    nimQoSSendNull(qos$(4))
    endif
    if rc <= 5 then
    nimQoSSendNull(qos$(5))
    endif
    if rc <= 6 then
    nimQoSSendNull(qos$(6))
    endif
    endif

    close_explorer() 'Make sure everything is closed up nice and tight!

    nimEnd()
    end(rc)
    endfunction

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Set your variables that you will need later on
    #IgnoreErrors = 0

    'Get the profile name from the Probe's environment or default to Manual Run.

    script$ = nimGetEnv$("APPMON_PROFILE_NAME","KPN-Annet-v1")

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Uncomment next line to create log file
    LogFile("C:\Program Files\Nimsoft\e2e_scripting\Logs\" + script$ + ".log",1,0)

    ' Fill in your qos targets. You might want to use the script name here as well, to make finding the
    ' QoS entries easier! Needs to be set up early, since these qos targets are used to send NULLs in
    ' the cleanup function.
    qos$(1) = script$ + " - Open Annet"
    qos$(2) = script$ + " - Login"
    qos$(3) = script$ + " - Search Customer"
    qos$(4) = script$ + " - Open Fiber"
    qos$(5) = script$ + " - Open Client"
    qos$(6) = script$ + " - Logoff"

    'Used to enumerate the different steps your scripts takes. Every step which has a QoS target associated
    'with it should have an entry in the qos$ array! This approach lets you have enumerated steps, but if
    'you decide to add a step between two existing steps you will not have to change all the step numbers
    'in your script. You WILL have to change the qos$ array however!!
    step = 1

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' This is where the "real" work begins
    prepare() 'Gotta prepare ourselves

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Step1 Open the Annet


    nimQoSStart()

    ret=StartBrowser("IE", "http://annet.kpn.org/", 3)

     

    If ret<>0 then

    supp$ = script$
    subsys$ = "e2e_appmon"
    msg$ = "Failed to open Annet"
    nimAlarm(5,msg$,supp$,subsys$)
    nimQoSStop()
    nimQoSSendTimer(qos$(step))

    End If

    'Step1 is completed


    'Step2 Login to Annet

     

    step = step + 1
    nimQoSStart()

    UsePage("Annet Login - r01")
    WriteHTML("INPUT TEXT[NAME= 'loginForm:userName']", "UIM6")
    WriteHTML("INPUT TEXT[NAME= 'loginForm:organizati']", "SERVICE")
    WriteHTMLEncrypted("INPUT PASSWORD[NAME= 'loginForm:password']", "FTNsS6GHWjK211wpZylaTGNhmm")
    ClickHTMLElement("A[INNERTEXT= 'Meld aan']")

    supp$ = script$
    subsys$ = "e2e_appmon"
    msg$ = "Failed to login to Annet"
    nimAlarm(5,msg$,supp$,subsys$)
    nimQoSStop()
    nimQoSSendTimer(qos$(step))

    'Step2 is completed

     

    'Step3 Search the customer

    step = step + 1
    nimQoSStart()

    UsePage("Annet Zoek Klant - r01")
    WriteHTML("INPUT TEXT[ID= 's_zipcode']", "7559BS")
    WriteHTML("INPUT TEXT[ID= 's_housenr']", "53")
    ClickHTMLElement("A[INNERTEXT= 'Zoek',INDEX='2']")

    supp$ = script$
    subsys$ = "e2e_appmon"
    msg$ = "Failed to search the customer on Annet"
    nimAlarm(5,msg$,supp$,subsys$)
    nimQoSStop()
    nimQoSSendTimer(qos$(step))

    'Step3 is completed

     

     

    Any help is appreciated.

     

    Thanks,

    Regards,

    Murugesh



  • 2.  Re: e2e Scripting help for generating an alarm

    Posted 03-20-2017 12:30 PM

    Here are two examples:

     

    script extract:

     

    1)
    'Subroutine is called for all failure code.
    Sub Failure(target$, id$, OP_REF$, message$)
        errormsg$= TargetAppName$ + ":  " + message$ + " during step:  " + target$ + ".  " + OP_REF$
        nimQoSStop()
        nimQoSSendNull(target$)
        nimAlarm(4, errormsg$, target$, id$)    '*****Uncomment this line to enable alarming*****
        nimEnd()
        MsgFrame(errormsg$, 1)
        Print_Screen()
        RemoveFrame(1)
        Clean_Up()
    EndSub

     

    2) Examples within a full script
    Include "NimBUS-functions.src"

     

    Sub Clean_up()
        KillApp("IEXPLORE.EXE",1)
    EndSub

     

    'Below is a generic error handling routine
    Sub Process_Error()
    local buffer$
     
    'If within this proc, an error occurs too, it generates an infinite loop as
    'the call to the error proce causes an error. To avoid that, we disable OnAction Error within this proc.
    disable(Error)
    'Take a screenshot of the desktop
    file_path$="C:\"+#ErrorScript$+"_error"
    ret=Hardcopy(file_path$+".jpg",1,1)
     
    'Here a part for writing in a txt file where we were in the script, the error code, the error message when the error occurred.
    buffer$="------ "+Date$()+ " - "+Time$()+" -------"
    write(file_path$+".txt",buffer$,crlf)
    buffer$="Error in : "+#ErrorScript$
    write(file_path$+".txt",buffer$,crlf)
    buffer$="Error line : "+str$(#LastErrorLine)
    write(file_path$+".txt",buffer$,crlf)
    buffer$="Error Code : "+str$(#Errorcode)
    write(file_path$+".txt",buffer$,crlf)
    buffer$="Error Function : "+#ErrorFunction$
    write(file_path$+".txt",buffer$,crlf)
    buffer$="Error message : "+#ErrorMsg$
    write(file_path$+".txt",buffer$,crlf)

     

    'Add here other lines for what to do in case of an error.
    '......
    nimQoSStop() 'Stops the QoS timer.
    nimQoSSendNull(target$) 'Send the response time measurement- timeout value per customer
    nimSetVariable("suppression_id",#ErrorScript$+"-Script error")
    nimAlarmSimple (5,"Error in : "+#ErrorScript$+" at line : "+str$(#LastErrorLine)+" Error Function: "+#ErrorFunction$+"Error message : "+#ErrorMsg$) ' Sends a major alert that the script did not run. The number 5 is critical 4 is major, etc
    nimEnd()
    Clean_up()
    End

     

    Endsub

     

    OnAction error
    dosub Process_Error
    endaction

     


    #PauseTimeout = 30 'Default for Pause until statements is a 2 minute/120 secs timeout
    #HideTrayIcon = 1
    '#ActionTimeout= 10 'The default value for #ActionTimeout is 30 seconds
    #IgnoreErrors = 1 'This is required to use a custom error handling routine
    #SendKeysDelay = 3

     


    niminit()

     

    nimSetVariable("subsystem", "MSPetSHop")

     

    target$= "MSPetShop-Launch 1"
    nimSetVariable("suppression_id", target$)
    nimQOSStart()

     

    StartBrowser("IE", "http://localhost/Default.aspx",3)

     


        Pause  until
            WinStatus(Active)
            InWindow("IEXPLORE.EXE|IEFrame|Welcome to .NET Pet Shop - Microsoft Internet Explorer",1)
        PauseFalse
            nimAlarmSimple(4, "MSPetShop-Launch failed")
            nimQOSStop()
            nimQOSSendNull(target$)
            nimend()
            Clean_up()
            End
        EndPause
        nimAlarmSimple(0, "MSPetShop-Launch succeeded")
            nimQOSStop()
            nimQOSSendTimer(target$)

     


    target$= "MSPetShop-Login 2"
    nimSetVariable("suppression_id", target$)
    nimQOSStart()

     

    UsePage("Welcome to .NET Pet Shop")
        ClickHTMLElement("A[INNERTEXT= 'sign in']")

     

        Pause  until
            WinStatus(Active)
            InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Sign In - Microsoft Internet Explorer",1)
        PauseFalse
            nimAlarmSimple(4, "MSPetShop-Login: Sign in page failed to load")
            nimQOSStop()
            nimQOSSendNull(target$)
            nimend()
            Clean_up()
            End
        EndPause
    nimAlarmSimple(0, "MSPetShop-Login: Sign in page success")
    'Read in a single encrypted password to use for login
    file$ = "password_encrypt.txt"
    Read(file$,pwd$,CRLF) ' puts the first line of file$ in pwd$

     

    UsePage(".NET Pet Shop :: Sign In")
        WriteHTML("INPUT TEXT[NAME= 'ctl00$cphPage$Login$']", "RobYoung")
        WriteHTMLEncrypted("INPUT PASSWORD[NAME= 'ctl00$cphPage$Login$']", pwd$)
        ClickHTMLElement("INPUT SUBMIT[VALUE= 'Sign In']")

     

    PAUSE 10 secs  until
        Bitmap("C:\Program Files\NimBUS\e2e_scripting\Scripts\demo_sign_out.bmp")
        InWindow("IEXPLORE.EXE|Internet Explorer_Server|Welcome to .NET Pet Shop - Microsoft Internet Explorer|1",1)
        InArea( 705, 3, 202, 388 )
    PauseFalse
        nimAlarmSimple(4, "MSPetShop-Login: Failed")
        nimQOSStop()
        nimQOSSendNull(target$)
        nimend()
        Clean_up()
        End
    EndPause
        nimAlarmSimple(0, "MSPetShop-Login: Success")

     

    nimQOSStop()
    nimQOSSendTimer(target$)

     

    UsePage("Welcome to .NET Pet Shop")
        ClickHTMLElement("A[INNERTEXT= 'Endangered']")

     

    PAUSE  until
        Bitmap("C:\Program Files\NimBUS\e2e_scripting\scripts\MSPetShop_skeleton_pic.bmp")
        InWindow("IEXPLORE.EXE|Internet Explorer_Server|.NET Pet Shop :: Endangered - Microsoft Internet Explorer|1",1)
        InArea( 369, 184, 182, 219 )
    PauseFalse
        MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
        End
    EndPause

     

    UseWindow( "IEXPLORE.EXE|Internet Explorer_Server|.NET Pet Shop :: Endangered - Microsoft Internet Explorer|1",1 )
    ClickOnBitmap( "C:\Program Files\NimBUS\e2e_scripting\scripts\MSPetShop_Pet.bmp", left, single,
        InArea( 384, 282, 208, 162 ) )

     

    PAUSE  until
        Bitmap("C:\Program Files\NimBUS\e2e_scripting\scripts\MSPetShop_rover.bmp")
        InWindow("IEXPLORE.EXE|Internet Explorer_Server|.NET Pet Shop :: Pet - Microsoft Internet Explorer|1",1)
        InArea( 366, 170, 296, 363 )
    PauseFalse
        MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
        End
    EndPause

     


    UsePage(".NET Pet Shop :: Pet")
        ClickHTMLElement("A[INNERTEXT= 'Add to Shopping Cart']")

     


        Pause  until
            WinStatus(Active)
            InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Shopping Cart - Microsoft Internet Explorer",1)
        PauseFalse
            MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
            End
        EndPause

     


    UsePage(".NET Pet Shop :: Shopping Cart")
        ClickHTMLElement("A[INNERTEXT= 'Continue Shopping']")

     

    PAUSE  until
        Bitmap("C:\Program Files\NimBUS\e2e_scripting\Scripts\MSPetShop_rover.bmp")
        InWindow("IEXPLORE.EXE|Internet Explorer_Server|.NET Pet Shop :: Pet - Microsoft Internet Explorer|1",1)
        InArea( 366, 170, 296, 363 )
    PauseFalse
        MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
        End
    EndPause

     


    UsePage(".NET Pet Shop :: Pet")
        ClickHTMLElement("A[INNERTEXT= '< Back to list']")

     

     

     

        Pause  until
            WinStatus(Active)
            InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Endangered - Microsoft Internet Explorer",1)
        PauseFalse
            MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
            End
        EndPause

     

     

     

    UsePage(".NET Pet Shop :: Endangered")
        ClickHTMLElement("A[HREF= 'http://localhost/Items.aspx?p']")

     


        Pause  until
            WinStatus(Active)
            InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Skeleton - Microsoft Internet Explorer",1)
        PauseFalse
            MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
            End
        EndPause

     


    UsePage(".NET Pet Shop :: Skeleton")
        ClickHTMLElement("A[INNERTEXT= 'Add to Shopping Cart']")

     


        Pause  until
            WinStatus(Active)
            InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Shopping Cart - Microsoft Internet Explorer",1)
        PauseFalse
            MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
            End
        EndPause

     


    UsePage(".NET Pet Shop :: Shopping Cart")
        ClickHTMLElement("INPUT IMAGE[NAME= 'ctl00$cphPage$Shoppi']")
        ClickHTMLElement("INPUT IMAGE[NAME= 'ctl00$cphPage$Shoppi']")
        ClickHTMLElement("A[INNERTEXT= 'sign out']")

     


    UseWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Shopping Cart - Microsoft Internet Explorer",1)
        Sendkeys("<Alt> f")
        Sendkeys("c")
        
    nimEnd()