Automation

 View Only
last person joined: yesterday 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Login scripts

    Posted 12-13-2023 17:52

    Hello all.

    I am trying to achieve that when an admin logs in,  they would see the result of the following commands:

    show system uptime all-members | find user
    show virtual-chassis status | except "new member|Chassis" with some blank line to make it pretty !

    with the chassis alarms already being  shown, this would give me a good indication if somethings is not right about the stack. For example, if a member rebooted or a member is actually down.

    I tried creating a first script by putting those commands in it. When I run it, I get the xml stuff without headers. Is there a way to just output  the result without having to  reinvent the wheel?

    On another subject, is scripting a thing of the past? I see examples of scripts from around 2010 that would be interesting to me but they no  longer work as the result format changed. But don't see anything recent. Any good location for script examples.

    Thanks.



    ------------------------------
    YVON LEDUC
    ------------------------------


  • 2.  RE: Login scripts

    Posted 12-14-2023 13:29

    Hi YVON,

    Have you thought about an op slax script?  You can create one and include both those commands with a separator and have the admins execute an ops command once they login. 

    Here is an example below with similar commands but not like for like but you should be able to adjust the commands to your supported commands. 

    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 $show_uptime = {
      <command> 'show system uptime';
      }
      
      var $show_chassis = {
      <command> 'show chassis alarm';
      }
      
      var $result0 = jcs:invoke($show_uptime);
      var $result1 = jcs:invoke($show_chassis);
     
      copy-of $result0;
      
     
      <output> "_________________________________________________________________________";

      
      copy-of $result1;
      
      
      }
    }



    ------------------------------
    JUAN RUIZ
    ------------------------------



  • 3.  RE: Login scripts

    Posted 12-14-2023 20:38

    Thanks for your answer Juan. 

    As a matter of fact, I did thought of a slax script but my result was the XML answer without the headers seen when running the command from the cli. Somehow the copy-of provides those headers. I really don't understand the "magic" of copy-of and why using it, provides the headers as if running the command manually.

     If you look at my original request, you will see that I am trying to display only specific lines by piping to find or except. any simple way to do that?

    Thanks again for your  time.



    ------------------------------
    YVON LEDUC
    ------------------------------



  • 4.  RE: Login scripts

    Posted 12-15-2023 16:45

    BEST WAY: Working with the XML is the best way to make your custom output. 

    EASIEST WAY: As easier but not as good looking of an option would be a "system login announcement" that prints out the two commands for them to copy and paste into the CLI themselves.

    YOUR WAY: I don't know the SLAX stuff well, but I do know that for PyEZ, the CLI command that you could use doesn't support the pipe feature because it translates to RPC and RPC doesn't work with pipe.  So you could definitely do the entire command using an op script but then you have to write code to manipulate the cli response.  And at this point, with this level of effort, the case could be made to just work with the XML. 



    ------------------------------
    .
    ------------------------------