SD-WAN

 View Only
last person joined: 4 days ago 

Ask questions and share experiences with SD-WAN and Session Smart Router (formerly 128T).
  • 1.  Historical Changes or Configuration "Diff"

    Posted 01-08-2019 15:18
    Was looking for a quick way to answer the question "What changes were made to the configuration?" and found myself writing a  script to perform a comparison of historical data store configurations found in /var/lib/128technology. 

    Here is a semi-useful script to display recent configuration changes.  Probably would not have chosen bash, in hindsight, but it does the trick if you don't mind the XML-diff output.  A useful enhancement would be to convert the XML to "show config flat" format before the diff.   Just paste the text below into a file such as "config-diff.sh" and make it executable.

    #!/bin/bash
    # Script to diff configuration history

    LIB=/var/lib/128technology
    TMP=/var/lib/128technology/cfgtmp

    if [ ! -d $TMP ]; then
    mkdir -p $TMP;
    fi;

    echo "----------------------------------------------------------------------------------------------------------------"
    echo "Comparing files current to 1"
    echo "---------------------------------------------------------------------------"
    echo "Configuration file $((num)): $LIB/t128-running.xml"
    diff "$LIB/t128-running.xml" "$LIB/t128-running.1.xml" | grep datastore | awk '/datastore/{i++}i==1' > $TMP/date1
    date1="$(cut -d '"' -f2 < $TMP/date1)"
    date1="$((date1 / 1000))"
    echo "Created:"
    date -d "@$((date1))"

    echo "---------------------------------------------------------------------------"
    echo "Configuration file $((num + 1)): $LIB/t128-running.$((num + 1)).xml"
    diff "$LIB/t128-running.xml" "$LIB/t128-running.1.xml" | grep datastore | awk '/datastore/{i++}i==2' > $TMP/date2
    date2="$(cut -d '"' -f2 < $TMP/date2)"
    date2="$((date2 / 1000))"
    echo "Created:"
    date -d "@$((date2))"
    echo "---------------------------------------------------------------------------"
    diff "$TMP/1.xml" "$TMP/2.xml" | grep -v datastore
    echo "----------------------------------------------------------------------------------------------------------------"


    for (( num=1; num<=8; num++ )); do
    echo "Comparing files $num to $((num + 1))"
    echo "---------------------------------------------------------------------------"
    echo "Configuration file $((num)): $LIB/t128-running.$num.xml"
    diff "$LIB/t128-running.$num.xml" "$LIB/t128-running.$((num + 1)).xml" | grep datastore | awk '/datastore/{i++}i==1' > $TMP/date1
    date1="$(cut -d '"' -f2 < $TMP/date1)"
    date1="$((date1 / 1000))"
    echo "Created:"
    date -d "@$((date1))"

    echo "---------------------------------------------------------------------------"
    echo "Configuration file $((num + 1)): $LIB/t128-running.$((num + 1)).xml"
    diff "$LIB/t128-running.$num.xml" "$LIB/t128-running.$((num + 1)).xml" | grep datastore | awk '/datastore/{i++}i==2' > $TMP/date2
    date2="$(cut -d '"' -f2 < $TMP/date2)"
    date2="$((date2 / 1000))"
    echo "Created:"
    date -d "@$((date2))"
    echo "---------------------------------------------------------------------------"
    diff "$LIB/t128-running.$num.xml" "$LIB/t128-running.$((num + 1)).xml" | grep -v datastore
    echo "----------------------------------------------------------------------------------------------------------------"
    echo "----------------------------------------------------------------------------------------------------------------"
    done

    rm $TMP/date1 $TMP/date2
    rmdir $TMP

    ------------------------------
    Don Troshynski
    CTO - Global Sales

    ------------------------------


  • 2.  RE: Historical Changes or Configuration "Diff"

     
    Posted 04-20-2019 11:25
    Along the same lines, I use gitwatch to watch for changes to t128-running.xml, and commit the file to a git repo whenever it changes. This way I have full traceability through all configuration changes, forever.

    One of these days I'll write it up, in the offchance anyone may find it useful.

    ------------------------------
    pt.
    ------------------------------



  • 3.  RE: Historical Changes or Configuration "Diff"

    Posted 07-11-2019 16:47
    Hi Patrick,
    Do you mind to share your solution?
    I have something similar in mind. 
    Whenever the XML config file changes,
    then get the flat config file and add and commit it into a GIT Repository. 
    But im not a programmer. 
    Any hint would be welcome. 
    Thanks 
    Marcel

    ------------------------------
    Marcel Reuter
    Network Eng.
    ------------------------------



  • 4.  RE: Historical Changes or Configuration "Diff"

    Posted 07-11-2019 16:57
    We just grab the output of:

    /bin/pcli show config running flat​


    We save that to a file "config" then use git/github to diff for us, and github sends us a notification on a MS Teams chat channel.



    ------------------------------
    --
    Jessie Bryan | jbryan@impulse.net
    VP Engineering |
    ------------------------------



  • 5.  RE: Historical Changes or Configuration "Diff"

    Posted 07-11-2019 23:53
    Hi Jessie, et al,

    exactly this is it:

    /bin/pcli show config running flat​​

    The only thing is, I like this to be automatically done, every time the xml config file changes.

    Any one has an example of how to do this?



    ------------------------------
    Marcel Reuter
    Network Eng.
    ------------------------------



  • 6.  RE: Historical Changes or Configuration "Diff"

     
    Posted 07-12-2019 07:33
    Hi Marcel, I haven't written this up as I'd hoped to do. I'll put something together in the coming weeks and circulate it here.

    ------------------------------
    pt.
    ------------------------------



  • 7.  RE: Historical Changes or Configuration "Diff"

     
    Posted 04-26-2020 06:33
    I hacked around on this over the weekend and came up with a better way than using gitwatch: using a native systemd path service! (Very powerful stuff.)

    Here's a blog post on how I got it working.

    ------------------------------
    pt.
    ------------------------------



  • 8.  RE: Historical Changes or Configuration "Diff"

    Posted 07-12-2019 09:46
    I like Jesse and Marcel's approach much better than mine so modified my Conductor with the following (there are lots of ways to automate):

    # Just run this all as root to restrict access
    sudo su
    -----------------
    # Ensure root can execute PCLI
    sudo usermod -a -G 128t-admin root
    -----------------
    ​# Install file monitoring tool (and epel-release as necessary)
    yum install inotify-tools​​
    -----------------
    # ssh-keygen with defaults to enable scp without password (I've opted to save these files to an ssh server but you can be creative with git/slack/Teams, etc)
    ssh-keygen
    -----------------
    # Copy output of /root/.ssh/id_rsa.pub into your backup host /home/admin/authorized_users file
    cat ​​/root/.ssh/id_rsa.pub
    # Use vi to add output to the end of /home/admin/authorized_users on your target host
    -----------------
    # Using your favorite editor, create a quick script to transfer the file to your scp server when it changes
    [root@lab1-conductor1 ~]# cat /root/config-watch.sh
    #!/bin/sh

    inotifywait -m --timefmt '%d%m%y%H%M' --format '%T' /var/lib/128technology/t128-running.xml | while read time ; do
    config="/var/lib/128technology/config"
    /bin/pcli show config running flat > $config
    scpfile="admin@192.168.1.7:/readynas/128T/Configs/Conductor-lab1/config$time"
    echo "Sending $config to $scpfile"
    # This is where you can be creative with the operation you wish to execute on the new config file
    scp $config $scpfile
    done
    -----------------
    # Execute this script upon reboot

    /root/config-watch.sh &

    At this point, the file should be transferred to your file server using scp (ssh must be running) with a timestamp for each config.  These can be diffed as required using the "diff" command, for comparison.



    ​​​​​​

    ------------------------------
    Don Troshynski
    CTO - Global Sales
    ------------------------------