Automation

 View Only

IMPORTANT MODERATION NOTICE

This community is currently under full moderation, meaning  all posts will be reviewed before appearing in the community. Please expect a brief delay—there is no need to post multiple times. If your post is rejected, you'll receive an email outlining the reason(s). We've implemented full moderation to control spam. Thank you for your patience and participation.



  • 1.  How to write SLAX result tree to STDOUT in XML format?

    Posted 09-16-2015 07:18

    I work with the following slax op script:

    ---snip---

    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 / {
      <op-script-results> {
        var $ping-target = "10.1.1.1";
        call pinger($ping-target);
            }  
        
    }

    template pinger($ping-target) {

       /* ping the target   */  
        var $ping-rpc = {
            <ping> {
                   <host> $ping-target;
                   <count> "1";
                   }
        }

            var $ping := jcs:invoke($ping-rpc);
        <output> $ping;

    }

    ---snap---

     

    When running it as "op ping.slax", I get the following output:

    user@juniper> op ping2                 
    10.1.1.1
    10.1.1.1
    56

    1
    0
    100

    no response

    {master:0}
    user@juniper>

     

    Even when running it as "op ping2 | display xml", I'm just getting

    user@juniper> op ping2 | display xml   
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.3R6/junos">
        <output>
            10.1.1.1
            10.1.1.1
            56
           
            1
            0
            100
           
            no response
        </output>
        <cli>
            <banner>{master:0}</banner>
        </cli>
    </rpc-reply>

    {master:0}
    user@juniper>

     

    How can I get the output in XML format?

     

    Thanks,

    Stefan

     


    #result
    #xml
    #Slax
    #output
    #Tree


  • 2.  RE: How to write SLAX result tree to STDOUT in XML format?

    Posted 09-16-2015 08:11

    If you want the raw XML, use

      copy-of $ping

    instead of

      <output> $ping

     

     



  • 3.  RE: How to write SLAX result tree to STDOUT in XML format?

    Posted 09-16-2015 08:26

    For some reason copy-of does not seem to work for me.

    ---snip---

    % vi ping1.slax
    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 / {
      <op-script-results> {
        var $ping-target = "10.1.1.1";
        <output> "Vorher";
        call pinger($ping-target);
        <output> "Nachher";
            }

    }

    template pinger($ping-target) {
       /* ping the target   */
        var $ping-rpc = {
            <ping> {
                   <host> $ping-target;
                   <count> "1";
                   }
        }

    /*    var $ping := jcs:invoke($ping-rpc);   */
          copy-of jcs:invoke($ping-rpc);
    /*    <output> $ping;   */
    /*    expr jcs:output( $ping );   */
    /*      copy-of $ping;   */

    }

    ---snap---

     

    I tried both "copy-of $ping;" as well as "copy-of jcs:invoke($ping-rpc);".

     

    What am I missing?

     

    Thx,

    Stefan



  • 4.  RE: How to write SLAX result tree to STDOUT in XML format?

    Posted 09-16-2015 08:33

    Add-on: Actually I get no output at all when using copy-of...



  • 5.  RE: How to write SLAX result tree to STDOUT in XML format?
    Best Answer

    Posted 09-16-2015 08:50

    Works for me:

    Here's my edited version:

    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 / {
      <op-script-results> {
        var $ping-target = "192.168.131.2";
        <output> "Vorher";
        call pinger($ping-target);
        <output> "Nachher";
      }
    }
    template pinger($ping-target) {
       /* ping the target   */
        var $ping-rpc = {
            <ping> {
                   <host> $ping-target;
                   <count> "1";
                   }
        }
        var $ping := jcs:invoke($ping-rpc);
        copy-of jcs:invoke($ping-rpc);
    }

    I had to edit to test on my vsrx.  Here's what I got when I ran::

    regress@vsrx-3> op url /var/db/scripts/op/pinger.slax | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.1X47/junos">
        <output>
            Vorher
        </output>
        <ping-results xmlns="http://xml.juniper.net/junos/12.1X47/junos-probe-tests">
            <target-host>
                192.168.131.2
            </target-host>
            <target-ip>
                192.168.131.2
            </target-ip>
            <packet-size>
                56
            </packet-size>
            <probe-result date-determined="1442418373">
                <probe-index>
                    1
                </probe-index>
                <probe-success/>
                <sequence-number>
                    0
                </sequence-number>
                <ip-address>
                    192.168.131.2
                </ip-address>
                <time-to-live>
                    128
                </time-to-live>
                <response-size>
                    64
                </response-size>
                <rtt>
                    9905
                </rtt>
            </probe-result>
            <probe-results-summary>
                <probes-sent>
                    1
                </probes-sent>
                <responses-received>
                    1
                </responses-received>
                <packet-loss>
                    0
                </packet-loss>
                <rtt-minimum>
                    9905
                </rtt-minimum>
                <rtt-maximum>
                    9905
                </rtt-maximum>
                <rtt-average>
                    9905
                </rtt-average>
                <rtt-stddev>
                    0
                </rtt-stddev>
            </probe-results-summary>
            <ping-success/>
        </ping-results>
        <output>
            Nachher
        </output>
        <cli>
            <banner></banner>
        </cli>
    </rpc-reply>
    
    regress@vsrx-3>
    

    As a practical note: consider specifying a time-out on the ping, else your script will appear to hang...

     

    /doug

     



  • 6.  RE: How to write SLAX result tree to STDOUT in XML format?

    Posted 09-16-2015 08:54

    Hi doug,

     

    stupid me... I was missing the "| xml". Thanks for your additional hint as well.

     

    Thx,

    stefan



  • 7.  RE: How to write SLAX result tree to STDOUT in XML format?

    Posted 11-03-2017 08:28

    Can this be done via python also?