Release 0.5.1 (#101)
* use netmiko_args * Add changes for 4.1.0 (#89) * Update requirements.txt * Typpo in requirements * _send_command has only two parameters * Adapt to stricter Unit tests --------- Co-authored-by: Anton Gridnev <anton@gridnev.pro> * Remove s350_base_interfaces custom map - it is allready in napalm base * Adapt Unit tests to canonical_interface_name() * Add format parameter to get_config() * Add badges * Tests for push are enought * update CD actions * add tests for device SG500-52 * Merge CI to develop (#95) * Simplify CI * CI update * CI update * Update CI from develop (#94) * Add format parameter to get_config() * Add badges * Tests for push are enought * update CD actions * add tests for device SG500-52 * fetch_command_output helper (#97) * fetch_command_output.sh tool * Update fetch_command_update from develop (#93) * adding read_timeout_override netmiko option --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Petr Klima <petr.klima@madeta.cz> Co-authored-by: Dave <davama@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Anton Gridnev <anton@gridnev.pro> * Set default command timeout (#98) * adding read_timeout_override netmiko option --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Petr Klima <petr.klima@madeta.cz> * Fetch command output - obfuscations (#99) * add IP and MAC obfuscation * Add obfuscate strings * Merge master changes back to develop (#100) * Lift version to 0.4.1 * Adapt to napalm 4.1 tests (#90) * use netmiko_args * Add changes for 4.1.0 (#89) * Update requirements.txt * Typpo in requirements * _send_command has only two parameters * Adapt to stricter Unit tests --------- Co-authored-by: Anton Gridnev <anton@gridnev.pro> * Remove s350_base_interfaces custom map - it is allready in napalm base * Adapt Unit tests to canonical_interface_name() --------- Co-authored-by: Dave <davama@gmail.com> Co-authored-by: Anton Gridnev <anton@gridnev.pro> * move version to 0.4.1.1 * Make it napalm 5 compliant (#92) * use netmiko_args * Add changes for 4.1.0 (#89) * Update requirements.txt * Typpo in requirements * _send_command has only two parameters * Adapt to stricter Unit tests --------- Co-authored-by: Anton Gridnev <anton@gridnev.pro> * Remove s350_base_interfaces custom map - it is allready in napalm base * Adapt Unit tests to canonical_interface_name() * Add format parameter to get_config() * Add badges --------- Co-authored-by: Dave <davama@gmail.com> Co-authored-by: Anton Gridnev <anton@gridnev.pro> * move version to 5.0.0 * move to version 0.5.0 --------- Co-authored-by: Dave <davama@gmail.com> Co-authored-by: Anton Gridnev <anton@gridnev.pro> * better obfuscation for fetch command output * better obfuscation for fetch command output * get rid of textFSM templates * get rid of textFSM templates * Add support and tests for SG250 * bump to version 0.5.1 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Dave <davama@gmail.com> Co-authored-by: Anton Gridnev <anton@gridnev.pro> Co-authored-by: Petr Klima <petr.klima@madeta.cz> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
77 files changed
+2720
-75
No files matched your search
Executable
+235
@@ -0,0 +1,235 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Defaults
|
||||
DEF_FORCE="n"
|
||||
#DEF_METHOD="cli" - nice with --method-kwargs "commands=['show ip interface']"
|
||||
# but output is JSON
|
||||
DEF_METHOD="_send_command"
|
||||
|
||||
# mocked data dir
|
||||
MDDIR="mocked_data"
|
||||
# command output dir
|
||||
CODIR="command_output"
|
||||
# config
|
||||
CMDIN="./$(basename $0 .sh ).cfg"
|
||||
|
||||
GETOPTS=":hu:p:ft:m:i:l:v:d:"
|
||||
function usage() {
|
||||
MSG="usage: $(basename $0) [-h] -u USERNAME -p PASSWORD [-f]\n"
|
||||
MSG+=" [-m METHOD] -i INTERFACE -l LLDP_INTERFACE\n"
|
||||
MSG+=" -t TYPE -v VENDOR -d DEVICE [SINGLE_COMMAND]\n"
|
||||
MSG+="\n"
|
||||
MSG+=" This utility helps to get output of commands from device.\n"
|
||||
MSG+=" Set of commands can be configured in '$CMDIN'\n"
|
||||
MSG+=" Command output is saved to '$CODIR/DEVICE_TYPE/command_out.txt'\n"
|
||||
MSG+=" and by default is not to be overwriten.\n"
|
||||
MSG+="\n"
|
||||
MSG+=" There is not any IP, MAC or names obfuscation or anonymizations!\n"
|
||||
MSG+=" Before using as a unit test files it is recommendet to protect\n"
|
||||
MSG+=" your privacy information yourself by editing output files\n"
|
||||
MSG+=" in '$CODIR/DEVICE_TYPE/command_out.txt'!\n"
|
||||
MSG+="\n"
|
||||
MSG+=" -h - this help\n"
|
||||
MSG+=" -u USERNAME - login username (or env DEVUSERNAME)\n"
|
||||
MSG+=" -p PASSWORD - login password (or env DEVPASSWORD)\n"
|
||||
MSG+=" -f - overwrite already downloaded output files\n"
|
||||
MSG+=" -t TYPE - device type\n"
|
||||
MSG+=" -m METHOD - what method sends command to device (def '$DEF_METHOD')\n"
|
||||
MSG+=" -i INTERFACE - interface for deailed info (see '$CMDIN')\n"
|
||||
MSG+=" -l INTERFACE - interface for deailed lldp info (see '$CMDIN')\n"
|
||||
MSG+=" -v VENDOR - vendor napalm driver\n"
|
||||
MSG+=" -d DEVICE - device to connect\n"
|
||||
|
||||
[[ -n $@ ]] && echo -e "\n### $@ ###\n" >&2
|
||||
|
||||
echo -e "$MSG" >&2
|
||||
exit 127
|
||||
}
|
||||
|
||||
|
||||
# Parse options
|
||||
# No run without options
|
||||
if ( ! getopts $GETOPTS opt); then # CLI bez options
|
||||
usage "Options needed !!!"
|
||||
fi
|
||||
OPTIND=1 # reset index
|
||||
|
||||
# Preset defaults
|
||||
FORCE="$DEF_FORCE"
|
||||
METHOD="$DEF_METHOD"
|
||||
|
||||
while getopts $GETOPTS opt; do
|
||||
#echo $opt;
|
||||
|
||||
case "$opt" in
|
||||
'u')
|
||||
DEVUSERNAME=$OPTARG ;;
|
||||
|
||||
'p')
|
||||
DEVPASSWORD=$OPTARG ;;
|
||||
|
||||
't')
|
||||
TYPE=$OPTARG ;;
|
||||
|
||||
'i')
|
||||
INTERFACE=$OPTARG ;;
|
||||
|
||||
'l')
|
||||
LLDPINTERFACE=$OPTARG ;;
|
||||
|
||||
'v')
|
||||
VENDOR=$OPTARG ;;
|
||||
|
||||
'm')
|
||||
METHOD=$OPTARG ;;
|
||||
|
||||
'd')
|
||||
DEVICE=$OPTARG ;;
|
||||
|
||||
'f')
|
||||
FORCE='y' ;;
|
||||
|
||||
'h')
|
||||
usage ;;
|
||||
|
||||
':')
|
||||
usage "Parameter '-$OPTARG' needs value."
|
||||
;;
|
||||
|
||||
'?'|*)
|
||||
usage "Unknown parameter '-$OPTARG' ."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
# read commands from file
|
||||
[ -f "$CMDIN" ] || usage "File '$CMDIN' does not exists."
|
||||
[ -r "$CMDIN" ] || usage "Can not read file '$CMDIN'."
|
||||
|
||||
[ -z "$INTERFACE" ] && usage "Parameter -i needed"
|
||||
[ -z "$LLDPINTERFACE" ] && usage "Parameter -l needed"
|
||||
|
||||
. "${CMDIN}"
|
||||
|
||||
# Get possible last arg and set it as only command
|
||||
shift $(($OPTIND - 1))
|
||||
[ -z "$1" ] || COMMANDS=("$1")
|
||||
|
||||
[ -z "$DEVUSERNAME" ] && usage "Parameter -u needed"
|
||||
[ -z "$DEVPASSWORD" ] && usage "Parameter -p needed"
|
||||
[ -z "$TYPE" ] && usage "Parameter -t needed"
|
||||
[ -z "$VENDOR" ] && usage "Parameter -v needed"
|
||||
[ -z "$DEVICE" ] && usage "Parameter -d needed"
|
||||
|
||||
# ensure directory structure exists
|
||||
[ -d "$CODIR" ] || usage "Output directory '$CODIR' does not exist."
|
||||
[ -w "$CODIR" ] || usage "Output directory '$CODIR' is not writeable."
|
||||
|
||||
mkdir -p "$CODIR/$TYPE" || usage "Can not make directory '$CODIR/$TYPE'"
|
||||
[ -w "$CODIR/$TYPE" ] || usage "Output directory '$CODIR/$TYPE' is not writeable."
|
||||
|
||||
echo "########## Generate output for type $TYPE ##########"
|
||||
# lets get commands outputs
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\t\n'
|
||||
for CMD in ${COMMANDS[@]}
|
||||
do
|
||||
IFS="$OLDIFS"
|
||||
|
||||
CMDSTR=${CMD// /_}
|
||||
CMDSTR=${CMDSTR//-/_}
|
||||
CMDSTR=${CMDSTR/\\/_}
|
||||
CMDSTR=${CMDSTR/./_}
|
||||
CMDSTR=${CMDSTR////_}
|
||||
CMDFILE="$CODIR/$TYPE/${CMDSTR}.txt"
|
||||
|
||||
# skip already fetched command outputs
|
||||
if [ -f "$CMDFILE" -a "$FORCE" = "n" ]; then
|
||||
echo "###### Skiping '$CMD'. File '$CMDFILE' exists (force run by -f)"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "## Fetching '$CMD' to '$CMDSTR.txt'"
|
||||
# --debug
|
||||
echo -e "$(napalm --user "$DEVUSERNAME" --password "$DEVPASSWORD" --vendor "$VENDOR" "$DEVICE" call --method-kwargs "command='$CMD'" "$METHOD" | sed 's/^"//;s/"$//;s/\\"/"/g')" > "$CMDFILE"
|
||||
done
|
||||
|
||||
echo "#### Preparing obfuscate script"
|
||||
echo "## IP addresses"
|
||||
IPs=$(cat "$CODIR/$TYPE/"*.txt \
|
||||
| sed -rn 's/.*[^0-9\.](([0-9]{1,3}\.){3}[0-9]{1,3})[^0-9\.]*.*/\1/gp' \
|
||||
| sort \
|
||||
| uniq
|
||||
)
|
||||
echo $IPs
|
||||
|
||||
for a in $IPs
|
||||
do
|
||||
oa=${a}
|
||||
oa=${oa//1/3}
|
||||
oa=${oa//2/3}
|
||||
oa=${oa//4/3}
|
||||
oa=${oa//5/3}
|
||||
oa=${oa//6/7}
|
||||
oa=${oa//8/7}
|
||||
oa=${oa//9/7}
|
||||
|
||||
oa=" -e s/$a/$oa/g "
|
||||
|
||||
oIPs="$oIPs$oa "
|
||||
done
|
||||
|
||||
echo "## MAC addresses"
|
||||
MACs=$(cat "$CODIR/$TYPE/"*.txt \
|
||||
| sed -rn -e 's/.*[^0-9\.:a-f-](([[:xdigit:]]{2}[:.-]?){5}[[:xdigit:]]{2})[^0-9\.:a-f-]*.*/\1/gp' \
|
||||
| sort \
|
||||
| uniq
|
||||
)
|
||||
echo $MACs
|
||||
|
||||
for m in $MACs
|
||||
do
|
||||
om=${m}
|
||||
om=${om//1/2}
|
||||
om=${om//3/2}
|
||||
om=${om//6/2}
|
||||
om=${om//8/2}
|
||||
om=${om//b/2}
|
||||
om=${om//e/2}
|
||||
om=${om//4/a}
|
||||
om=${om//5/a}
|
||||
om=${om//7/a}
|
||||
om=${om//9/a}
|
||||
om=${om//c/a}
|
||||
om=${om//d/a}
|
||||
|
||||
om=" -e s/$m/$om/g "
|
||||
|
||||
oMACs="$oMACs$om "
|
||||
done
|
||||
|
||||
echo "## Obfuscate IPs and MACs"
|
||||
echo oIPS=$oIPs
|
||||
echo oMACs=$oMACs
|
||||
set -x
|
||||
sed -r -i $oMACs $oIPs "$CODIR/$TYPE/"*.txt
|
||||
set +x
|
||||
|
||||
echo "## Obfuscate strings from OBFUSCATE config variable"
|
||||
|
||||
for s in "${OBFUSCATE[@]}"
|
||||
do
|
||||
f="${s%%&&&*}"
|
||||
t="${s##*&&&}"
|
||||
oSTR="${oSTR}s/$f/$t/g;"
|
||||
done
|
||||
|
||||
echo $oSTR
|
||||
sed -r -i -e "$oSTR" "$CODIR/$TYPE/"*.txt
|
||||
|
||||
echo "###################################################"
|
||||
echo "## Do not forget obfuscate other output: ##"
|
||||
echo "## passwords, secrets, keys, certificates ##"
|
||||
echo "## descriptions, names and other ... ##"
|
||||
echo "###################################################"
|
||||
Reference in new issue
Block a user