Skip to content
This repository has been archived by the owner on Oct 11, 2020. It is now read-only.

04. JSNAPy command line tool

Khelil Sator edited this page Jun 3, 2017 · 1 revision

Documentation

https://github.com/Juniper/jsnapy/wiki/3.-Command-Line-Tool

Help:

jsnapy -h

Snapcheck:

Use this subcommand to compare the current configuration or the current operational states against pre-defined criteria.

Syntax:

The default snapshot name is snap_temp:

jsnapy --snapcheck -f <config_file>
ls snapshots/*snap_temp* -l

You can define a snapshot name:

jsnapy --snapcheck <snap_file_name> -f <config_file>
ls snapshots/*<snap_file_name>* -l
Examples
Compare the current operational states against pre-defined criteria:
  • Alarms:

JSNAPy files details:

sublime-text cfg_file_snapcheck_alarms.yml 
sublime-text testfiles/devices.yml 
sublime-text testfiles/test_file_snapcheck_alarms.yml

Usage with default snapshot name:

jsnapy --snapcheck -f cfg_file_snapcheck_alarms.yml 
ls -l snapshots/*_snap_temp_*

Usage with another snapshot name:

jsnapy --snapcheck -f cfg_file_snapcheck_alarms.yml snapshot_name
ls -l snapshots/*_snapshot_name_*
  • Interfaces:

JSNAPy files details:

sublime-text cfg_file_snapcheck_intf_states.yml
sublime-text testfiles/devices.yml 
sublime-text test_file_snapcheck_intf_states.yml

Usage with default snapshot name:

jsnapy --snapcheck -f cfg_file_snapcheck_intf_states.yml
  • BGP:

JSNAPy files details:

sublime-text cfg_file_snapcheck_bgp_states.yml 
sublime-text testfiles/test_file_snapcheck_bgp_states.yml 

Usage with default snapshot name:

jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states.yml 
Compare the current configuration against pre-defined criteria:
  • LLDP:

JSNAPy files details:

sublime-text cfg_file_snapcheck_lldp_cfg.yml 
sublime-text testfiles/devices.yml 
sublime-text testfiles/test_file_snapcheck_lldp_cfg.yml

Usage with default snapshot name:

jsnapy --snapcheck -f cfg_file_snapcheck_lldp_cfg.yml 
  • Name-servers:

JSNAPy files details:

sublime-text cfg_file_snapcheck_name_servers_cfg.yml 
sublime-text testfiles/devices.yml 
sublime-text testfiles/test_file_snapcheck_name_servers_cfg.yml

Usage with default snapshot name:

jsnapy --snapcheck -f cfg_file_snapcheck_name_servers_cfg.yml 
ls -l snapshots/*_snap_temp_*

Using another snapshot name:

jsnapy --snapcheck -f cfg_file_snapcheck_name_servers_cfg.yml snapshot_name
ls -l snapshots/*_snapshot_name_*
  • Various topics:

JSNAPy files details:

sublime-text cfg_file_snapcheck_cfg.yml 
sublime-text testfiles/devices.yml 
sublime-text testfiles/test_file_snapcheck_cfg.yml

Usage with default snapshot name:

jsnapy --snapcheck -f cfg_file_snapcheck_cfg.yml
Verbosity:

The default console logging level is info:

/etc/jsnapy/logging.yml 

You can set the verbosity to debug level messages using -v

jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states.yml  -v 
Optional arguments:

You can use optional arguments.
Run this command to discover the optional arguments:

jsnapy -h
Examples:

It is not required 172.30.179.73 exists in the config file config.snapcheck.states.yml:

jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states.yml -v -t 172.30.179.73 -l pytraining -p Poclab123 -P 830

Jsnapy will prompt you to provide the username and password:

jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states.yml -v -t 172.30.179.73
Local snapcheck using the --local option

Presence of --local option runs the tests on stored snapshot.
To use this command one has to first create snapshot using --snap command.

Documentation

https://github.com/Juniper/jsnapy/wiki/3.-Command-Line-Tool#optional-arguments

Syntax:
jsnapy --snapcheck <snap_name> -f <config_file> --local
Examples:
jsnapy --snap -f cfg_file_snapcheck_bgp_states.yml snapshot_name
ls snapshots/*snapshot_name* -l
jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states.yml --local -v snapshot_name

snap_temp is the default snapshot name, so these 2 commands do the same thing:

jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states.yml --local -v 
jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states.yml --local -v snap_temp
Local snapcheck using the key local in the configuration file

Use the key local in the configuration file if you want to run snapcheck on stored snapshots.
Works with --snapcheck command only.
For exemple in cfg_file_snapcheck_bgp_states_on_local_snapshots.yml, STORED is being used.

sublime-text cfg_file_snapcheck_bgp_states_on_local_snapshots.yml

So we might have already done a snap.

jsnapy --snap STORED -f cfg_file_snapcheck_bgp_states_on_local_snapshots.yml
ls snapshots/*STORED* -l
jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states_on_local_snapshots.yml
Custom jsnapy lookup directory

You can specify custom jsnapy lookup directory (--folder).

Documentation:

https://github.com/Juniper/jsnapy/wiki/3.-Command-Line-Tool#optional-arguments

Examples:
ls other_jsnapy_folder/ -l
ls other_jsnapy_folder/testfiles -l
jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states.yml --folder other_jsnapy_folder
jsnapy --snap -f cfg_file_snapcheck_bgp_states_on_local_snapshots.yml --folder other_jsnapy_folder STORED
jsnapy --snapcheck -f cfg_file_snapcheck_bgp_states_on_local_snapshots.yml --folder other_jsnapy_folder

Snap:

Use this subcommand to take a snapshot.

Syntax:
jsnapy --snap <file_name> -f <config_file>
Examples:
  • BGP operational states:
sublime-text cfg_file_check_bgp_states.yml
sublime-text testfiles/test_file_check_bgp_states.yml

jsnapy --snap pre -f cfg_file_check_bgp_states.yml -v
ls snapshots/*_pre_*

jsnapy --snap post -f cfg_file_check_bgp_states.yml
ls snapshots/*_post_*

Check:

Use this subcommand to compare two snapshots based on tests.
So you first need to take 2 snapshots (snap).

Syntax:
jsnapy --check <pre_snap> <post_snap> -f <config_file>
Examples:
  • BGP operational states:
jsnapy --snap pre -f cfg_file_check_bgp_states.yml 
jsnapy --snap post -f cfg_file_check_bgp_states.yml
jsnapy --check pre post -f cfg_file_check_bgp_states.yml -v
  • Interfaces configurations:
sublime-text cfg_file_check_intf_cfg.yml
sublime-text testfiles/devices.yml 
sublime-text testfiles/test_file_check_intf_cfg.yml
jsnapy --snap pre -f cfg_file_check_intf_cfg.yml
ls snapshots/*_pre_*
jsnapy --snap post -f cfg_file_check_intf_cfg.yml
ls snapshots/*_post_*
jsnapy --check pre post -f cfg_file_check_intf_cfg.yml -v

Diff:

Use this subcommand to compare two snapshots (either in xml or text format) character by character.
So you first need to take 2 snapshots (snap).
Supported only in command line mode.

Syntax:
jsnapy --diff <pre_snap> <post_snap> -f <config_file>
Examples:
sublime-text cfg_file_diff.yml
sublime-text testfiles/devices.yml 
sublime-text testfiles/test_file_diff.yml 
jsnapy --snap pre -f cfg_file_diff.yml
ls snapshots/*_pre_*
jsnapy --snap post -f cfg_file_diff.yml
ls snapshots/*_post_*
jsnapy --diff pre post -f cfg_file_diff.yml