Contents

Introduction

Problem

Overview of API Call

Using Curl in Script

Introduction

This document describes how to use some of the API calls available in vManage and how you can adapt it to run it using an script.

Problem

Information that you can require from vManage is not always easy to collect if the overlay contains hundreds or thousands of Cisco Edge Routers.

Example:

Most simple way to get running configuration of single Cisco Edge Router is navigate to Configuration > Devices > Wan Edge List click ellipsis (…) and Running Configuration. Then you have to select and copy all the configuration and save in another file like .txt format. However, the problem comes up when you want to get the configuration of multiple Cisco Edge Routers making this task exhausting and time consuming.

Overview of API Call

This procedure is an example of how you can use a simple API call to get all the information required.

Step 1.

Log in to vManage as normal using the URL or IP address.

Step 2.

Open a new tab browser and then copy and paste the URL of vManage and add the suffix /apidocs (https://172.18.121.103:15256/apidocs).

Step 3.

In the search box, type Monitoring - Device Details.

Step 4.

In order to get the configuration of one device you have to try out /device/config API call.

Step 5.

Enter the System-IP of one Cisco Edge Router and run the API call.

Using Curl in Script

A better option is to use an API call in a script to generate configuration files of Cisco Edge Routers.

Step 1.

First, in the shell or CLI command line, create a folder where all backup files are stored.

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.

Create a .txt file with all the system-IP addresses of the Cisco Edge Routers that backup is required. System-IP address list you can get from vManage and export CSV file.

It is needed to name the file as System-IPs.txt and save it in the same directory that was previously created (Backup_cedges).

Step 3.

Confirm that file is saved.

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 %

Step 4.

Proceed to create the script. It is possible to use vi or any notepad, just be careful to save it with .sh format.

#!/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"

Step 5.

Change privilege of the file so that it can be run.

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 %

Step 6.

Run the script using /.config_backup_script.sh command. Consider that this takes some time to be completed depending on quantity of devices.

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

<html><head><title>Error</title></head><body>Method Not Allowed</body></html>Check files, if they are empty or with message Bad request check user and password

lufrias@LUFRIAS-M-P9Q2 Backup_cedges %

Step 7.

Finally, check files are there with ls -l command.

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 %

Check configuration file.

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

If files are empty or with an error message “Bad request” please check the authentication username and password.

lufrias@LUFRIAS-M-P9Q2 Backup_cedges % more 30.30.30.1.txt

Bad Request

lufrias@LUFRIAS-M-P9Q2 Backup_cedges %

If file shows "No device found for system IP" that means the system IP does not exist in vManage. You must correct System-IPs.txt and delete wrong 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 %