Skip to content

Commit fc2d3ba

Browse files
author
Ashutosh Mangalekar
committed
Merge branch 'master' of https://github.com/VeritasOS/netbackup-api-code-samples into feature/alert_api
2 parents 3b9536f + 723c5a9 commit fc2d3ba

File tree

21 files changed

+957
-100
lines changed

21 files changed

+957
-100
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.linting.enabled": false
3+
}

README.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,13 @@ Contains code samples to invoke NetBackup REST API using different programming l
55
#### Disclaimer
66
These scripts are only meant to be used as a reference. Please do not use these in production.
77

8-
#### Executing the snippets in PowerShell
9-
Pre-requisites:
10-
- NetBackup 8.1.1 or higher
11-
- Powershell 5.0 or higher
12-
13-
Use the following commands to run the powershell samples.
14-
- `.\Get-NB-Images.ps1 -nbmaster <masterServer> -username <username> -password <password>`
15-
- `.\Get-NB-Jobs.ps1 -nbmaster <masterServer> -username <username> -password <password>`
16-
- `.\Get-NB-Alerts.ps1 -nbmaster <masterServer> -username <username> -password <password>`
17-
18-
#### Executing the snippets in Python
19-
Pre-requisites:
20-
- NetBackup 8.1.1 or higher
21-
- python 3.5 or higher
22-
- python modules: `requests, texttable`
8+
#### Executing the snippets for different programming languages
239

24-
Use the following commands to run the python samples.
25-
- `python -W ignore get_nb_images.py -nbmaster <masterServer> -username <username> -password <password>`
26-
- `python -W ignore get_nb_jobs.py -nbmaster <masterServer> -username <username> -password <password>`
27-
- `python -W ignore get_nb_alerts.py -nbmaster <masterServer> -username <username> -password <password>`
10+
The `snippets` folder contains code samples to invoke NetBackup REST API using different programming languages.
2811

29-
#### Executing the snippets in Perl
3012
Pre-requisites:
3113
- NetBackup 8.1.1 or higher
32-
- See script README for perl requirements and usage
33-
34-
#### Executing the snippets using curl
35-
Pre-requisites:
36-
- NetBackup 8.1.1 or higher
37-
- curl 7.51.0 or higher
38-
- jq command-line parser (https://github.com/stedolan/jq/releases)
39-
40-
Use the following commands to run the curl samples.
41-
- `./get_nb_jobs.sh -master <master_server> -username <username> -password <password>`
42-
- `./get_nb_images.sh -master <master_server> -username <username> -password <password>`
14+
- See the script's README for the corresponding requirements and usage
4315

4416
#### Tools
4517
The `tools` folder contains utilities that have proven useful in the development of projects using

snippets/curl/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### NetBackup API Code Samples for curl
2+
3+
This directory contains code samples to invoke NetBackup REST APIs using curl.
4+
5+
#### Disclaimer
6+
7+
These scripts are only meant to be used as a reference. If you intend to use them in production, use it at your own risk.
8+
9+
#### Pre-requisites:
10+
11+
- NetBackup 8.1.1 or higher
12+
- curl 7.51.0 or higher
13+
- jq command-line parser (https://github.com/stedolan/jq/releases)
14+
15+
#### Executing the snippets in curl
16+
17+
Use the following commands to run the curl samples.
18+
- `./get_nb_jobs.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>`
19+
- `./get_nb_images.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>`

snippets/curl/get_nb_images.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#####################n#####################################################
44

5-
# This script demonstrates the usage of netbackup REST API for listing
5+
# This script demonstrates the usage of netbackup REST API for listing
66
# the backup images
77

8-
# This script requires jq command-line JSON parser
8+
# This script requires jq command-line JSON parser
99
# if your system does not have jq installed, this will not work
1010
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
1111

@@ -23,7 +23,7 @@ showHelp()
2323
echo ""
2424
echo "Invalid command parameters"
2525
echo "Usage:"
26-
echo "./get_nb_images.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
26+
echo "./get_nb_images.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
2727
echo ""
2828
exit 1
2929
}
@@ -33,10 +33,10 @@ parseArguments()
3333
if [ $# -lt 6 ]; then
3434
showHelp
3535
fi
36-
36+
3737
while [ "$1" != "" ]; do
3838
case $1 in
39-
-master)
39+
-nbmaster)
4040
master_server=$2
4141
;;
4242
-username)
@@ -57,7 +57,7 @@ parseArguments()
5757
esac
5858
shift 2
5959
done
60-
60+
6161
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
6262
showhelp
6363
fi
@@ -98,4 +98,3 @@ curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth
9898
jq '[.data[]|{IMAGE_ID: .id, POLICY: .attributes.policyName, CLIENT: .attributes.clientName, BACKUP_TIME: .attributes.backupTime}]'
9999

100100
exit 0
101-

snippets/curl/get_nb_jobs.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# This script demonstrates the usage of netbackup REST API for listing the jobs
77

8-
# This script requires jq command-line JSON parser
8+
# This script requires jq command-line JSON parser
99
# if your system does not have jq installed, this will not work
1010
# jq can be downloaded from here: https://github.com/stedolan/jq/releases
1111

@@ -23,7 +23,7 @@ showHelp()
2323
echo ""
2424
echo "Invalid command parameters"
2525
echo "Usage:"
26-
echo "./get_nb_jobs.sh -master <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
26+
echo "./get_nb_jobs.sh -nbmaster <master_server> -username <username> -password <password> -domainname <dname> -domaintype <unixpwd/nt>"
2727
echo ""
2828
exit 1
2929
}
@@ -33,10 +33,10 @@ parseArguments()
3333
if [ $# -lt 10 ]; then
3434
showHelp
3535
fi
36-
36+
3737
while [ "$1" != "" ]; do
3838
case $1 in
39-
-master)
39+
-nbmaster)
4040
master_server=$2
4141
;;
4242
-username)
@@ -57,7 +57,7 @@ parseArguments()
5757
esac
5858
shift 2
5959
done
60-
60+
6161
if [ -z "$master_server" ] || [ -z "$username" ] || [ -z "$password" ] || [ -z "$domainname" ] || [ -z "$domaintype" ]; then
6262
showhelp
6363
fi
@@ -97,4 +97,3 @@ curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth_
9797
| \
9898
jq '[.data[]|{JOBID: .id, TYPE: .attributes.jobType, STATE: .attributes.state, STATUS: .attributes.status}]'
9999
exit 0
100-

snippets/nodejs/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### NetBackup API Code Samples for Node.js
2+
3+
This directory contains code samples to invoke NetBackup REST APIs using node.js.
4+
5+
#### Disclaimer
6+
7+
These scripts are only meant to be used as a reference. If you intend to use them in production, use it at your own risk.
8+
9+
#### Pre-requisites:
10+
11+
- NetBackup 8.1.1 or higher
12+
- node.js v8.9.4 or higher
13+
- node.js modules: `https, fs, stdio, pem`
14+
- openssl and openssl path should be configured in system path.
15+
16+
* To install node.js module, Run `npm install <module_name>`.
17+
18+
#### Executing the snippets in Node.js
19+
20+
Before running API samples, run following command to store CA certificate.
21+
- `node get_ca_cert.js --nbmaster <master_server> [--port <port_number>] [--verbose]`
22+
or
23+
- `node get_ca_cert.js -n<master_server> [-pr <port_number>] [-v]`
24+
25+
Use the following commands to run the node.js samples.
26+
- `node get_nb_images.js --nbmaster <master_server> [--port <port_number>] --username <username> --password <password> [--domainname <domain_name>] [--domaintype <domain_type>] [--verbose]`
27+
or
28+
- `node get_nb_hosts.js -n<master_server> [-pr <port_number>] -u <username> -p <password> [-d <domain_name>] [-t <domain_type>] [-v]`

snippets/nodejs/get_ca_cert.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var netbackup = require("./netbackup-module/netbackup.js");
2+
// including stdio just for creating help
3+
var stdio = require('stdio');
4+
var parms = stdio.getopt({
5+
'nbmaster' : { key: 'n', args: 1, description: 'Master server name', mandatory: true },
6+
'port' : { key: 'pr', args: 1, default: '1556', description: 'Port number' },
7+
'verbose' : { key: 'v', args: 1, description: 'Verbose statements' }
8+
});
9+
10+
var contentType = "application/vnd.netbackup+json;version=1.0";
11+
var verbose;
12+
13+
function main() {
14+
verbose = (parms.verbose === undefined) ? false: true;
15+
16+
netbackup.printOnConsole('\nDeploying CA certificate...', verbose);
17+
netbackup.getCACertificate(parms.nbmaster, parms.port, contentType, verbose);
18+
19+
}
20+
21+
main();

snippets/nodejs/get_nb_hosts.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var netbackup = require("./netbackup-module/netbackup.js");
2+
// including stdio just for creating help
3+
var stdio = require('stdio');
4+
var parms = stdio.getopt({
5+
'nbmaster' : { key: 'n', args: 1, description: 'Master server name', mandatory: true },
6+
'port' : { key: 'pr', args: 1, default: '1556', description: 'Port number' },
7+
'username' : { key: 'u', args: 1, description: 'User name', mandatory: true },
8+
'password' : { key: 'p', args: 1, description: 'Password of a user', mandatory: true },
9+
'domainname' : { key: 'd', args: 1, default: '', description: 'Domain name (empty by default)' },
10+
'domaintype' : { key: 't', args: 1, default: '', description: 'Domain type (empty by default)' },
11+
'verbose' : { key: 'v', args: 1, description: 'Verbose statements' }
12+
});
13+
14+
var contentType = "application/vnd.netbackup+json;version=1.0";
15+
var jwt;
16+
var verbose;
17+
18+
function main() {
19+
verbose = (parms.verbose === undefined) ? false: true;
20+
21+
netbackup.printOnConsole('\nMaking call to login API...', verbose);
22+
netbackup.loginWithUser(parms.nbmaster, parms.port, parms.username, parms.password,
23+
parms.domainname, parms.domaintype, contentType, verbose, loginResponse);
24+
}
25+
26+
function loginResponse(data) {
27+
if (typeof data.errorCode != 'undefined') {
28+
console.info("\nError:\n " + JSON.stringify(data, null, 4));
29+
} else {
30+
netbackup.printOnConsole('\nLogin completed!', verbose);
31+
jwt = data.token;
32+
netbackup.printOnConsole('\nJWT token : ' + jwt, verbose);
33+
34+
netbackup.getHostDetails(parms.nbmaster, parms.port, jwt, contentType, verbose, hostsListResponse);
35+
}
36+
}
37+
38+
function hostsListResponse(data) {
39+
if (typeof data.errorCode != 'undefined') {
40+
console.info("\nError:\n " + JSON.stringify(data, null, 4));
41+
} else {
42+
console.info("\nHosts:\n " + JSON.stringify(data, null, 4));
43+
netbackup.printOnConsole('\nDone!!!');
44+
}
45+
}
46+
47+
main();

snippets/nodejs/get_nb_images.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var netbackup = require("./netbackup-module/netbackup.js");
2+
// including stdio just for creating help
3+
var stdio = require('stdio');
4+
var parms = stdio.getopt({
5+
'nbmaster' : { key: 'n', args: 1, description: 'Master server name', mandatory: true },
6+
'port' : { key: 'pr', args: 1, default: '1556', description: 'Port number' },
7+
'username' : { key: 'u', args: 1, description: 'User name', mandatory: true },
8+
'password' : { key: 'p', args: 1, description: 'Password of a user', mandatory: true },
9+
'domainname' : { key: 'd', args: 1, default: '', description: 'Domain name (empty by default)' },
10+
'domaintype' : { key: 't', args: 1, default: '', description: 'Domain type (empty by default)' },
11+
'verbose' : { key: 'v', args: 1, description: 'Verbose statements' }
12+
});
13+
14+
var contentType = "application/vnd.netbackup+json;version=1.0";
15+
var jwt;
16+
var verbose;
17+
18+
function main() {
19+
verbose = (parms.verbose === undefined) ? false: true;
20+
21+
netbackup.printOnConsole('\nMaking call to login API...', verbose);
22+
netbackup.loginWithUser(parms.nbmaster, parms.port, parms.username, parms.password,
23+
parms.domainname, parms.domaintype, contentType, verbose, loginResponse);
24+
}
25+
26+
function loginResponse(data) {
27+
if (typeof data.errorCode != 'undefined') {
28+
console.info("\nError:\n "+ JSON.stringify(data, null, 4));
29+
} else {
30+
netbackup.printOnConsole('\nLogin completed!', verbose);
31+
jwt = data.token;
32+
netbackup.printOnConsole('\nJWT token : ' + jwt, verbose);
33+
34+
netbackup.getNBImages(parms.nbmaster, parms.port, jwt, contentType, verbose, nbImages);
35+
}
36+
}
37+
38+
function nbImages(data) {
39+
if (typeof data.errorCode != 'undefined') {
40+
console.info("\nError:\n "+ JSON.stringify(data, null, 4));
41+
} else {
42+
console.info("\nNB Images:\n "+ JSON.stringify(data, null, 4));
43+
netbackup.printOnConsole('\nDone!!!');
44+
}
45+
}
46+
47+
main();

0 commit comments

Comments
 (0)