简介
本文档介绍如何使用vManage中提供的某些API调用,以及如何调整它以使用脚本运行它。
问题
如果重叠包含数百或数千台思科边缘路由器,则从vManage收集所需信息并非总是很容易收集的。
示例:
要获得单台Cisco Edge路由器的运行配置,最简单的方法是导航到Configuration > Devices > Wan Edge List,然后点击省略号(...)和Running Configuration。然后,您必须选择并复制所有配置,然后保存为其他文件,如.txt格式。但是,当您想要配置多个思科边缘路由器时,问题就会出现,导致此任务耗时且耗时。


API调用概述
此过程是一个示例,说明如何使用简单的API调用获取所需的所有信息。
步骤1:
使用URL或IP地址正常登录vManage。

Step 2.
打开新的选项卡浏览器,然后复制并粘贴vManage的URL,并添加后缀/apidocs(https://172.18.121.103:15256/apidocs)。

第 3 步:
在搜索框中,键入Monitoring - Device Details。

第 4 步:
要获取一个设备的配置,您必须尝试/device/config API调用。

第 5 步:
输入一个Cisco Edge路由器的System-IP并运行API调用。


在脚本中使用Curl
更好的选择是在脚本中使用API调用生成思科边缘路由器的配置文件。
步骤1:
首先,在shell或CLI命令行中,创建一个存储所有备份文件的文件夹。
lufrias@LUFRIAS-M-P9Q2 Desktop % mkdir Backup_cedges
lufrias@LUFRIAS-M-P9Q2 Desktop % cd Backup_cedges
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % pwd
/Users/lufrias/Desktop/Backup_cedges
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
Step 2.
使用需要备份的云翼路由器的所有系统IP地址创建一个.txt文件。您可以从vManage和export CSV文件获取的系统IP地址列表。
需要将该文件命名为System-IPs.txt,并将其保存在先前创建的同一目录(Backup_cedges)中。


第 3 步:
确认文件已保存。
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ls -l
total 8
-rw-r--r--@ 1 lufrias staff 77 Aug 27 12:20 System-IPs.txt
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
第 4 步:
继续创建脚本。可以使用vi或任何记事本,请注意将其保存为.sh格式。
#!/bin/bash
#Define your variables
echo "Please type vManage URL in following format"
echo "https://172.18.121.103:15256 or https://vmanage.cisco.com"
read VMANAGE
echo "Please enter username to access vmanage"
read USER
echo "Password:"
read PASSWORD
#DEFINING THE API CALLS TO LOGIN AND BODY
security_url="$VMANAGE/j_security_check"
credentials="j_username=$USER&j_password=$PASSWORD"
#EXECUTE THE API CALL TO LOGIN TO THE VMANAGE.
curl --request POST --silent --insecure -c cookies.txt --url $security_url --data $credentials
#EXECUTE THE API CALL TO GET A TOKEN
TOKEN=$(curl "$VMANAGE/dataservice/client/token" -X GET -b cookies.txt -s --insecure)
arr_csv=()
while IFS= read -r line
do
arr_csv+=("$line")
curl --insecure -b cookies.txt -H "accept: text/plain" -H "X-XSRF-TOKEN: $TOKEN" -X GET "$VMANAGE/dataservice/device/config?deviceId="$line > $line.txt
echo $line
done < System-IPs.txt
echo "Running config was collected from following System_IPs:"
index=0
for record in "${arr_csv[@]}"
do
echo "Record at index-${index} : $record"
((index++))
done
curl "$VMANAGE/logout" -b cookies.txt --silent --insecure -H "X-XSRF-TOKEN: $TOKEN"
echo "Check files, if they are empty or with message "Bad request" check user and password"
第 5 步:
更改文件的权限,使其可以运行。
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ls -l
total 16
-rw-r--r--@ 1 lufrias staff 77 Aug 27 12:20 System-IPs.txt
-rw-r--r-- 1 lufrias staff 1174 Aug 27 12:47 config_backup_script.sh
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % chmod +x config_backup_script.sh
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ls -l
total 16
-rw-r--r--@ 1 lufrias staff 77 Aug 27 12:20 System-IPs.txt
-rwxr-xr-x 1 lufrias staff 1174 Aug 27 12:47 config_backup_script.sh
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
第六步:
使用/.config_backup_script.sh命令运行脚本。考虑完成此操作需要一些时间,具体取决于设备的数量。
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ./config_backup_script.sh
Please type vManage URL in following format
https://172.18.121.103:15256 or https://vmanage.cisco.com
https://172.18.121.103:15256
Please enter username to access vmanage
admin
Password:
qwerty1234Q
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7238 0 7238 0 0 1133 0 --:--:-- 0:00:06 --:--:-- 1761
10.10.10.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7218 0 7218 0 0 1799 0 --:--:-- 0:00:04 --:--:-- 1800
20.20.20.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 1978 0 --:--:-- 0:00:03 --:--:-- 1978
30.30.30.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 1491 0 --:--:-- 0:00:04 --:--:-- 2031
40.40.40.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 2717 0 --:--:-- 0:00:02 --:--:-- 2718
50.50.50.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 1610 0 --:--:-- 0:00:04 --:--:-- 1641
60.60.60.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 1668 0 --:--:-- 0:00:04 --:--:-- 1668
70.70.70.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 40 0 40 0 0 108 0 --:--:-- --:--:-- --:--:-- 107
80.80.80.1
Running config was collected from following System_IPs:
Record at index-0 : 10.10.10.1
Record at index-1 : 20.20.20.1
Record at index-2 : 30.30.30.1
Record at index-3 : 40.40.40.1
Record at index-4 : 50.50.50.1
Record at index-5 : 60.60.60.1
Record at index-6 : 70.70.70.1
Record at index-7 : 80.80.80.1
ErrorMethod Not AllowedCheck files, if they are empty or with message Bad request check user and password
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
第 7 步:
最后,使用ls -l命令检查文件存在。
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ls -l
total 152
-rw-r--r-- 1 lufrias staff 7238 Sep 11 10:06 10.10.10.1.txt
-rw-r--r-- 1 lufrias staff 7218 Sep 11 10:06 20.20.20.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:06 30.30.30.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:06 40.40.40.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:06 50.50.50.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:06 60.60.60.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:07 70.70.70.1.txt
-rw-r--r-- 1 lufrias staff 40 Sep 11 10:07 80.80.80.1.txt
-rw-r--r--@ 1 lufrias staff 88 Sep 10 11:48 System-IPs.txt
-rwxr-xr-x 1 lufrias staff 1352 Sep 11 09:49 config_backup_script.sh
-rw-r--r-- 1 lufrias staff 288 Sep 11 10:06 cookies.txt
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
检查配置文件。
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % more 10.10.10.1.txt
system
system-ip 10.10.10.1
overlay-id 1
site-id 101
no transport-gateway enable
port-offset 0
control-session-pps 300
admin-tech-on-failure
sp-organization-name CISCORTPLAB
organization-name CISCORTPLAB
port-hop
track-transport
track-default-gateway
console-baud-rate 9600
no on-demand enable
on-demand idle-timeout 10
vbond 192.168.51.117 port 12346
如果文件为空或显示错误消息“Bad request”,请检查身份验证用户名和密码。
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % more 30.30.30.1.txt
Bad Request
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
如果文件显示“No device found for system IP”,表示系统IP在vManage中不存在。您必须更正System-IPs.txt并删除错误的System-IP。
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % more 80.80.80.1.txt
No device found for system IP 80.80.80.1
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %