Automation

 View Only
last person joined: 6 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  How to change-configuration with the variable in policy-event ?

    Posted 06-08-2020 07:12

    Hi everyone,

    I have the issue with change-configuration action. I want to push the FPC slot from chassisd_snmp_trap10 event to the command action (chassisd_snmp_trap10.value7 is the slot variable). I tested with below configuration, but it did not work. There is no configuration change although the event trigger the policy (i checked the trace_option).

    Is there any idea ? 

    Thank a alot :D.

     

    policy test_1 {
    events chassisd_snmp_trap10;
    attributes-match {
    chassisd_snmp_trap10.trap matches "^Fru Offline$";
    chassisd_snmp_trap10.value5 matches "^FPC*";
    }
    then {
    change-configuration {
    commands {
    "set chassis fpc chassisd_snmp_trap10.value7 power off";
    }
    commit-options {
    log down_fpc_script;
    }
    }
    }
    }

    traceoptions {
    file trace_script size 50m;
    flag all;
    }

     


  • 2.  RE: How to change-configuration with the variable in policy-event ?

    Posted 06-08-2020 09:00

    Hello,

     

    Please try this:

     

    policy test_1 {
    events chassisd_snmp_trap10;
    attributes-match {
    chassisd_snmp_trap10.trap matches "^Fru Offline$";
    chassisd_snmp_trap10.value5 matches "^FPC*";
    }
    then {
    change-configuration {
    commands {
    "set chassis fpc {$$.value7} power off";
    }
    commit-options {
    log down_fpc_script;
    }}}}
    

     

     

    HTH

    Thx

    Alex



  • 3.  RE: How to change-configuration with the variable in policy-event ?

    Posted 06-08-2020 09:13

    Hi TuanAnhVu, 

     

    Greetings, 

    I believe the below output and the configuration statement will help you understand the steps in achieving this.

    For our reference considering the below trap output: 

     

    CHASSISD_SNMP_TRAP10: SNMP trap generated: FRU power off (jnxFruContentsIndex 8, jnxFruL1Index 1, 
    jnxFruL2Index 1, jnxFruL3Index 0, jnxFruName node0 PIC: 8x 1GE-TX 4x 1GE-SFP @ 0/0/*, jnxFruType 11, jnxFruSlot 0, 
    jnxFruOfflineReason 8, jnxFruLastPowerOff 2519258, jnxFruLastPowerOn 89379)
    >> The highlight value is value7 as per trap

    The command can be referenced as follows:

     

     then {
                  change-configuration {
                      commands {
                          "set chassis fpc {$$.value7} power off";
                      }
    Here the value to be used is FRUSLOT which can be referenced based on the event i.e. CHASSISD_SNMP_TRAP10's value 7 and hence we need to use $$ > represents the event that triggered policy and value 7 references the variable FPC# to use.

     

     

     

    For more details , the reference link that explains the event variable usage: https://www.juniper.net/documentation/en_US/junos/topics/reference/configuration-statement/commands-edit-event-options.html

     

    Hope this helps. Smiley Happy

     

    Please mark "Accept as solution" if this answers your query. 

     

    Kudos are appreciated too! 

     

    Regards, 

    Sharat Ainapur



  • 4.  RE: How to change-configuration with the variable in policy-event ?

    Posted 06-08-2020 09:42

    Hi,

    I tried with that configuration, but it does not help, the policy is trigger but no configuration change. When i try with the python script, it works perfectly. I dont want to use the script because i need to push the script file to the router. :D. (Just imagining that you have a hundred boxes @@)

    Any idea for this case ?

     

    # show event-options
    Jun 08 23:34:33
    policy test {
    events chassisd_snmp_trap10;
    attributes-match {
    chassisd_snmp_trap10.trap matches "^Fru Offline$";
    chassisd_snmp_trap10.value5 matches "^FPC*";
    chassisd_snmp_trap10.argument8 matches "^jnxFruOfflineReason$";
    chassisd_snmp_trap10.value8 matches "^7$";
    }
    then {
    change-configuration {
    commands {
    "set chassis fpc {$$.value7} power off";
    }
    commit-options {
    log down_fpc_script;
    }}
    inactive: event-script down_fpc.py {
    arguments {
    fpc_slot "{$$.value7}";
    }}}}
    event-script {
    file down_fpc.py;
    }
    traceoptions {
    file trace_script size 50m;
    flag all;
    }

     


  • 5.  RE: How to change-configuration with the variable in policy-event ?

    Posted 06-08-2020 09:54

    Hi TuanAnhVu, 

     

    I guess when the event is triggered the FPC is already under transition and would not take up this command. 

    Here, the concerned FPC will be already in transition phase as it is showing up FRU power off log as per the trap, It will not accept the power off command that we are trying to achieve.

    I suppose that is the reason why we are unable to perform that action. Ideally, I would recommend you to run this after it comes up online, say set a delay timer <after it comes up online>  and then execute this command.

     

    Hope this helps. 🙂 

     

    Please mark "Accept as solution" if this answers your query. 

     

    Kudos are appreciated too! 

     

    Regards, 

    Sharat Ainapur

     



  • 6.  RE: How to change-configuration with the variable in policy-event ?
    Best Answer

    Posted 06-08-2020 22:31

    Hello,

    Yeah. looks like there is a problem with variable substitution under "change-configuration" stanza, You may want to open a JTAC case.

    Anyway, here is the workaround for You, I tested it:

     

    policy test_1 {
        events chassisd_snmp_trap10;
        attributes-match {
            "{$$.trap}" matches "Fru Offline";
    	"{$$.value5}" matches "FPC";
        }
        then {
            execute-commands {
                commands {
                    "request routing-engine execute command \"cli -c 'edit; set chassis fpc {$$.value7} power off;commit comment down_fpc_script'\"";
                }
            }
        }
    }

     

    The single|double quotes and backslash escapes are important!

     

    Verification:

     

    regress@agg3> request chassis fpc slot 2 offline    
     Offline initiated, use "show chassis fpc" to verify
    
    regress@agg3> show system commit 
    Jun 09 08:21:17
    0   2020-06-09 08:21:12 AST by root via cli
        down_fpc_script

    regress@agg3> show system rollback compare 1 0
    Jun 09 08:21:36
    [edit chassis fpc 2]
    + power off;

     

    HTH

    Thx

    Alex



  • 7.  RE: How to change-configuration with the variable in policy-event ?

    Posted 06-09-2020 19:53

    Thank you for your workaround.

    I will open the JTAC for the variable for change-configuration. Your workaround looks good to try.

    Thank again 😄 !