はじめに
このドキュメントでは、vManageで使用可能なAPIコールの一部を使用する方法と、スクリプトを使用して実行するようにAPIコールを調整する方法について説明します。
問題
オーバーレイに数百または数千のCiscoエッジルータが含まれている場合、vManageから必要な情報を収集することは必ずしも容易ではありません。
例:
単一のCiscoエッジルータの実行コンフィギュレーションを取得する最も簡単な方法は、Configuration > Devices > Wan Edge Listの順に移動し、省略記号(...)をクリックして、Running Configurationをクリックすることです。次に、すべての設定を選択してコピーし、.txt形式などの別のファイルに保存する必要があります。ただし、複数のCiscoエッジルータの設定を取得しようとすると、この問題が発生し、時間と労力がかかります。


API呼び出しの概要
次の手順は、簡単なAPI呼び出しを使用して、必要なすべての情報を取得する方法の例です。
ステップ 1:
URLまたはIPアドレスを使用して、通常どおりvManageにログインします。

ステップ 2:
新しいタブブラウザを開き、vManageのURL(https://172.18.121.103:15256/apidocs)をコピーアンドペーストし、/apidocsというサフィックスを追加します。

ステップ 3:
検索ボックスに「Monitoring - Device Details」と入力します。

ステップ 4:
1つのデバイスの設定を取得するには、/device/config APIコールを試す必要があります。

ステップ 5:
1台のCiscoエッジルータのSystem-IPを入力し、APIコールを実行します。


スクリプトでのCurlの使用
スクリプトでAPIコールを使用してCiscoエッジルータのコンフィギュレーションファイルを生成する方が適切です。
ステップ 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エッジルータのすべてのシステム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 %
ファイルに「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 %