Junos OS

last person joined: 7 days ago 

Ask questions and share experiences about Junos OS.
  • 1.  Executing CLI commands with event-options

    Posted 07-21-2009 01:30

    Hello!

    I need to modify config of my M10i  router at certain time of day.

    I have following configuration:

     

    minotaur@br1-gdr.ki# show event-options
    generate-event {
    Start-Business-Time time-of-day "12:07:00 +0300";
    }
    policy Modify-Speeds-to-World {
    events Start-Business-Time;
    then {
    execute-commands {
    commands {
    configure;
    "set firewall filter Speed-to-World term Colo-Olimpia then policer pol-2Mbit";
    "commit and-quit";
    }
    output-filename bbb;
    destination FTP;
    output-format text;
    }
    }
    }
    destinations {
    FTP {
    archive-sites {
    ftp://ftp/incoming;
    }
    }
    }

     

    CLI commands is executed, but with errors. The output uploaded to FTP looks like:

     

    root@br1-gdr.ki> configure Entering configuration mode root@br1-gdr.ki> set firewall filter Speed-to-World term Colo-Olimpia then policer pol-2Mbit error: unknown command: set root@br1-gdr.ki> commit and-quit error: unknown command: commit

     

     Why does not "configure" command work? Thanks in advance.

     

     

    Message Edited by Minotaur on 07-21-2009 02:34 AM


  • 2.  RE: Executing CLI commands with event-options
    Best Answer

    Posted 07-21-2009 05:33
    To alter the configuration you need to use an event script, not just an event policy, and a minimum of JUNOS 9.3.  I am attaching an example event script which shows you how it is done.


  • 3.  RE: Executing CLI commands with event-options

    Posted 07-21-2009 07:01
    It looks strange for me that such siple task is solved with scripts only... Anyway, thank you for proposed solution!


  • 4.  RE: Executing CLI commands with event-options

    Posted 07-21-2009 07:37

    Here is an example script that should make the configuration change you want (I didn't test it so there might be typos):

     

    version 1.0;

    ns junos = "http://xml.juniper.net/junos/*/junos";
    ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
    ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

    import "../import/junos.xsl";


    match / {
       
        /* Create the configuration change */
        var $change = {
            <configuration> {
                <firewall> {
                    <filter> {
                        <name> "Speed-to-World";
                        <term> {
                            <name> "Colo-Olimpia";
                            <then> {
                                <policer> "pol-2Mbit";
                            }
                        }
                    }
                }
            }
           
        var $connection = jcs:open();
       
        var $results := { call jcs:load-configuration( $connection, $configuration=$change ); }
           
        expr jcs:close( $connection );
    }

     

    And if you later want to remove the policer:

     

    version 1.0;

    ns junos = "http://xml.juniper.net/junos/*/junos";
    ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
    ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

    import "../import/junos.xsl";


    match / {
       
        /* Create the configuration change */
        var $change = {
            <configuration> {
                <firewall> {
                    <filter> {
                        <name> "Speed-to-World";
                        <term> {
                            <name> "Colo-Olimpia";
                            <then> {
                                <policer delete="delete"> "pol-2Mbit";
                            }
                        }
                    }
                }
            }
           
        var $connection = jcs:open();
       
        var $results := { call jcs:load-configuration( $connection, $configuration=$change ); }
           
        expr jcs:close( $connection );
    }

     

    Requires 9.3...



  • 5.  RE: Executing CLI commands with event-options

    Posted 09-30-2011 06:59

    Hi,

     

    I would like to use "match" criteria in the execute-commands in event policy. It seems that it does not work.

    Using "display set" is O.K. but "match" "except" not 😞

     

    Do you have any idea?

    Thank you very much for your help in advance!

     

    Best regards,

    Bela Doczi

    JNCIP-M/T #1201

     

    [edit]
    kapsch@MVM-PE1# show event-options
    policy 1 {
        events ui_commit;
        then {
            execute-commands {
                commands {
                    "show configuration|match KD";
                }
                output-filename LALA;
                destination HP;
            }
        }
    }
    destinations {
        HP {
            transfer-delay 5;
            archive-sites {
                "scp://dbela@10.1.0.254:2279/home/dbela" password "$9$8B4XdbYgoGjHvWX-VwaJfTz3nC"; ## SECRET-DATA
            }
        }
    }
    traceoptions {
        file EVENTPOL;
        flag all;
    }