소개
이 문서에서는 vManage에서 사용할 수 있는 일부 API 호출을 사용하는 방법 및 스크립트를 사용하여 실행하도록 조정하는 방법에 대해 설명합니다.
문제
오버레이에 수백 또는 수천 개의 Cisco Edge 라우터가 포함된 경우 vManage에서 요구할 수 있는 정보를 수집하기가 항상 쉽지는 않습니다.
예:
단일 Cisco Edge Router의 실행 중인 컨피그레이션을 가져오는 가장 간단한 방법은 Configuration(컨피그레이션) > Devices(디바이스) > Wan Edge List(Wan 에지 목록)로 이동하여 생략 부호(...)를 클릭하고 Running Configuration(실행 중인 컨피그레이션)을 클릭하는 것입니다. 그런 다음 모든 컨피그레이션을 선택하여 복사하고 .txt 형식 같은 다른 파일에 저장해야 합니다. 하지만 여러 Cisco Edge Router의 컨피그레이션을 받기를 원하기 때문에 시간이 많이 소요되고 소모적인 문제가 발생합니다.


API 호출 개요
이 절차는 간단한 API 호출을 사용하여 필요한 모든 정보를 가져오는 방법의 예입니다.
1단계.
URL 또는 IP 주소를 사용하여 vManage에 정상적으로 로그인합니다.

2단계.
새 탭 브라우저를 연 다음 vManage의 URL을 복사하여 붙여 넣고 접미사 /apidocs(https://172.18.121.103:15256/apidocs)를 추가합니다.

3단계.
검색 상자에 Monitoring - Device Details를 입력합니다.

4단계.
한 디바이스의 컨피그레이션을 가져오려면 /device/config API 호출을 시도해야 합니다.

5단계.
Cisco Edge Router 하나의 System-IP를 입력하고 API 호출을 실행합니다.


스크립트에서 컬 사용
더 좋은 방법은 스크립트에서 API 호출을 사용하여 Cisco Edge Router의 컨피그레이션 파일을 생성하는 것입니다.
1단계.
먼저 셸 또는 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 %
2단계.
백업이 필요한 Cisco Edge Router의 모든 시스템 IP 주소로 .txt 파일을 생성합니다. vManage에서 가져오고 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 %
6단계.
/.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 %
파일에 시스템 IP가 vManage에 없음을 의미하는 "No device found for system IP(시스템 IP에 대해 디바이스를 찾을 수 없음)"가 표시되는 경우 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 %