Solved

API call to show failed backup jobs

  • 25 November 2021
  • 6 replies
  • 1059 views

Userlevel 4
Badge +13

Hi all,

 

I need to display failed backup jobs from yesterday using a script. In REST Webservice API Sandbox I am able to create API call - see below.

Is it possible to run this API call as part of the script from Linux shell (as a curl command) or from Powershell? Or are API calls executable only as part of /from C#, Python, Ruby or Postman?

 

Your help will be much appreciated!

 

GET SearchSvc/CVWebService.svc/Job HTTP/1.1
Host: win-cv-new.listopad.local:81
Accept: application/xml
Cookie2: QSDK 3c6ff3754c98e6b114bac8d6f751e1338d6ed01fb5a0dcf1abae25a51ddbf94bc8663b0b17632c829925b4447467b33075c9b41b52f765a7a1361f1ecffbd228e55980d2dcb805798d652cd364c0e64cc9ed6c0ce6af6e6c8b43c63b1a5791f04cdcde6a7f61db3827e9ae400eea2d6d971493994686d96c2f17b8bd959b8fe864f330e2a2503ee3e96b67b8f568462ac4ca2f9d20112401c80fe055bcee5c35b06f2744a83f76443fa25aa7f9c965625a33ab72a7f4ab3fdcfbf85df3d292ce67f3f7843e5f817a04163838fb982db422306577c98ffae3c254db77b7f8d28a083f3bcab1af341a55c1e67e3eb952dfbe89c52663d922f1a79a14db15132fb3fb4d41804257e544346f6e92c9a45a624

icon

Best answer by Stuart Painter 30 November 2021, 06:48

View original

6 replies

Userlevel 7
Badge +15

Hi @drPhil 

There are many ways to invoke REST APIs, the interface is provided so that any such tool can connect to the endpoint to invoke API calls and receive responses over http.

We have several options explained in Commvault, please take a look at:

Getting Started with the Commvault REST API which shows the options we have documented.

But there are many other options available to you:

Microsoft PowerShell Invoke-RestMethod

A quick Google search for “rest api in linux shell” shows where people have used curl:

APIacademy: DevOps: REST API Execution Through Bash Shell Scripting

Thanks,

Stuart

 

 

Userlevel 4
Badge +13

Hi @Stuart Painter , thank you so much for your input.

In fact, I did not know, how to build such a script. Fortunately, using Postman I was able to create something like that.

 

#!/bin/bash
auth=$(curl --location --request POST 'http://win-cv-new.listopad.local:81/SearchSvc/CVWebService.svc/Login' --header 'Accept: application/json' --header 'Content-Type: application/json' --data-raw '{
  "password": "********",
  "username": "admin"
}' | jq -r .token)
curl --location --request GET 'http://win-cv-new.listopad.local:81/SearchSvc/CVWebService.svc//Job?completedJobLookupTime=30000' --header 'Accept: application/json' --header 'Authtoken: '"$auth"''

 

*password is encoded with Base64 encoded password

 

I have just a  question. Are there any parameters that can display only failed jobs? I did not see something similar here.

https://documentation.commvault.com/11.24/essential/47608_rest_api_get_job.html

So, the solution is only to parse json output using jq or with whatsoever tool?

And is it possible to somehow display only failed VMs, that are of course a part of a subclient. So, the subclients report, that backup was partially succesfull, but some of the VMs could failed. Can I using API find only these failed VMs?

 

Cheers!

 

 

 

Userlevel 7
Badge +15

Hi @drPhil 

I have checked GET Job and GET JobDetails, but neither provide any parameters to filter on job status.

You would - as you suggest - need to collect and parse the json output to perform the filter on the response data.

I will check internally to see if there are any other ways to do this with REST API.

Thanks,

Stuart

Userlevel 7
Badge +15

Hi @drPhil 

I’ve checked internally with Development and had a suggestion to use a slightly different approach, with POST Jobs API.

Please take a look at: https://api.commvault.com/#17736755-e86f-9a27-75c5-6c5e999bec80

You can specify different job statuses for a specific client, for example:

{
"pagingConfig": {
"sortDirection": 1,
"offset": 0,
"sortField": "jobStartTime",
"limit": 10
},
"jobFilter": {
"completedJobLookupTime": 1637370018,
"statusList": [
"Failed"
],
"jobTypeList": [
4
],
"entity": {
"clientId": 34
}
}
}

Where jobTypeList:4 is for Backup jobs.

For a full list of JobTypeList options:
https://documentation.commvault.com/11.24/essential/105923_jobfilter_parameter_values.html

Thanks,

Stuart

Userlevel 7
Badge +15

Hi @drPhil 

Checking this a little further, Development have also confirmed as an alternative to clientId, you can also use subclientId within “entity:”

{
"pagingConfig": {
"sortDirection": 1,
"offset": 0,
"sortField": "jobStartTime",
"limit": 10
},
"jobFilter": {
"completedJobLookupTime": 1637370018,
"statusList": [
"Failed"
],
"jobTypeList": [
4
],
"entity": {
"subclientId": 202
}
}
}

Thanks,

Stuart

Userlevel 4
Badge +13

Hi @Stuart Painter! Thank you so much for your suggestion with putting focus on specific clients and then listing its jobs. It’s an creative option how to display only failed jobs using API calls. What made me troubles in my testing environment was that I was not able to list more clients associated in my commserver server, which could be caused by connectivity in my lab environment. Neverthless, even using API calls, it is possible to display failed backup jobs.

Reply