Einleitung
In diesem Dokument wird beschrieben, wie einige der in vManage verfügbaren API-Aufrufe verwendet werden und wie Sie diese anpassen können, um sie mithilfe eines Skripts auszuführen.
Problem
Informationen, die Sie von vManage anfordern können, lassen sich nicht immer leicht erfassen, wenn das Overlay Hunderte oder Tausende von Cisco Edge-Routern enthält.
Beispiel:
Die einfachste Möglichkeit, die aktuelle Konfiguration eines einzelnen Cisco Edge-Routers zu erhalten, besteht darin, zu Configuration > Devices > Wan Edge List (Konfiguration > Geräte > WAN-Edge-Liste) zu navigieren und auf Ellipse (...) und Running Configuration (Konfiguration ausführen) zu klicken. Anschließend müssen Sie die gesamte Konfiguration auswählen und kopieren und in einer anderen Datei wie dem TXT-Format speichern. Das Problem tritt jedoch auf, wenn Sie mehrere Cisco Edge-Router konfigurieren möchten, was diese Aufgabe anstrengend und zeitaufwendig macht.


Übersicht über API-Aufrufe
Dieses Verfahren ist ein Beispiel dafür, wie Sie einen einfachen API-Aufruf verwenden können, um alle erforderlichen Informationen abzurufen.
Schritt 1:
Melden Sie sich wie gewohnt mit der URL oder der IP-Adresse bei vManage an.

Schritt 2:
Öffnen Sie einen neuen Browser, kopieren Sie die URL von vManage und fügen Sie das Suffix /apidocs (https://172.18.121.103:15256/apidocs) hinzu.

Schritt 3:
Geben Sie im Suchfeld Monitoring - Device Details (Überwachung - Gerätedetails) ein.

Schritt 4:
Um die Konfiguration eines Geräts zu erhalten, müssen Sie /device/config API-Aufruf ausprobieren.

Schritt 5:
Geben Sie die System-IP-Adresse eines Cisco Edge-Routers ein, und führen Sie den API-Aufruf aus.


Curl in Skript verwenden
Eine bessere Option ist die Verwendung eines API-Aufrufs in einem Skript zum Generieren von Konfigurationsdateien von Cisco Edge-Routern.
Schritt 1:
Erstellen Sie zunächst in der Shell- oder CLI-Befehlszeile einen Ordner, in dem alle Sicherungsdateien gespeichert sind.
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 %
Schritt 2:
Erstellen Sie eine TXT-Datei mit allen System-IP-Adressen der Cisco Edge-Router, die gesichert werden müssen. System-IP-Adressliste, die Sie von vManage erhalten und die CSV-Datei exportieren können.
Es ist erforderlich, die Datei als System-IPs.txt zu benennen und in demselben Verzeichnis zu speichern, das zuvor erstellt wurde (Backup_cedges).


Schritt 3:
Bestätigen Sie, dass die Datei gespeichert ist.
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 %
Schritt 4:
Fahren Sie mit der Erstellung des Skripts fort. Es ist möglich, vi oder ein beliebiges Notizblock zu verwenden, nur vorsichtig sein, um es im .sh-Format zu speichern.
#!/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"
Schritt 5:
Ändern der Berechtigungen der Datei, sodass sie ausgeführt werden kann.
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 %
Schritt 6:
Führen Sie das Skript mit dem Befehl /.config_backup_script.sh aus. Je nach Anzahl der Geräte kann dies einige Zeit in Anspruch nehmen.
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 %
Schritt 7.
Zum Schluss überprüfen Sie die Dateien mit dem Befehl 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 %
Überprüfen Sie die Konfigurationsdatei.
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
Wenn Dateien leer sind oder die Fehlermeldung "Bad request" (Fehlerhafte Anforderung) angezeigt wird, überprüfen Sie bitte den Benutzernamen und das Passwort für die Authentifizierung.
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % more 30.30.30.1.txt
Bad Request
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
Wenn in der Datei "No device found for system IP" (Kein Gerät für System-IP gefunden) angezeigt wird, bedeutet dies, dass die System-IP in vManage nicht vorhanden ist. Sie müssen System-IPs.txt korrigieren und die falsche System-IP löschen.
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 %