Solved

QCommand API response issues

  • 16 March 2021
  • 9 replies
  • 424 views

Userlevel 1
Badge +6

Hi, I have a strange issue, I use same call for two different commcells. One commcell returns data as requested with no issues, second commcell simply returns very ‘informative’ error:


Response code: <Response [200]>
{'CVGui_GenericResp': {'@errorMessage': 'Operation failed', '@errorCode': '2'}}


I am sending the following URL:

http://mycommcell.NET:81/SearchSvc/CVWebService.svc/ExecuteQCommandcommand=qoperation execscript -sn QS_DataProtectionJobSummary -si '2020-1-1' -si '2021-3-16'

 

Code snippet:

 

    def commcell_authentication(self):
"""This method is used to get token for comcells"""

for auth in self.cs_api:
pwd = self.cs_creds['password']
pwd = bytes(pwd, encoding='utf8')
pwd = str(base64.b64encode(pwd), encoding='utf-8')
username = 'dbadmin\\' + self.cs_creds['username']
self.cs_login_api = self.cs_login_api.replace("<<username>>", username)
self.cs_login_api = self.cs_login_api.replace("<<password>>", pwd)

response = requests.post(auth['url'] + 'Login', data = self.cs_login_api)
if response.status_code == 200:
root = ET.fromstring(response.text)
token = root.attrib['token']
headers = {'Accept': 'application/json', 'Authtoken': token, 'Content-Type': 'application/x-www-form-urlencoded'}
auth['headers'] = headers


def get_commvault_clients(self):
"""This method is used to get history of all clients backups from past year, in both comcells"""

todays_date = datetime.datetime.today()
todays_date = "{}-{}-{}".format(todays_date.year, todays_date.month, todays_date.day)
last_year_date = datetime.datetime.today() - datetime.timedelta(days = 365)
last_year_date = "{}-1-1".format(last_year_date.year)

self.commvault_servers = []
for api in self.cs_api:
jobs_request = api['url'] + 'ExecuteQCommand'
jobs_response = requests.post(jobs_request, headers = api['headers'], data = "command=qoperation execscript -sn QS_DataProtectionJobSummary -si " + "'" + str(last_year_date) + "'" + " -si " + "'" +str(todays_date) + "'")
if jobs_response.status_code == 200:
jobs = jobs_response.json()
for job in jobs['ExecScriptOutput']['FieldValue']:
self.commvault_servers.append(job)

return self.commvault_servers



Where is the problem and what does the error code ‘2’ means?

icon

Best answer by Mike Struening RETIRED 12 April 2021, 22:47

View original

9 replies

Badge +1

you are missing something in your URL, the API “ExecuteQCommand” is not separated from the param “command=qoperation”

 

http://mycommcell.NET:81/SearchSvc/CVWebService.svc/ExecuteQCommandcommand=qoperation execscript -sn QS_DataProtectionJobSummary -si '2020-1-1' -si '2021-3-16'

i guess there should be a “?” inbetween? 

Userlevel 1
Badge +6

you are missing something in your URL, the API “ExecuteQCommand” is not separated from the param “command=qoperation”

 

http://mycommcell.NET:81/SearchSvc/CVWebService.svc/ExecuteQCommandcommand=qoperation execscript -sn QS_DataProtectionJobSummary -si '2020-1-1' -si '2021-3-16'

i guess there should be a “?” inbetween? 

 

Nah, that’s just print() output to show you what I am sending, ‘+’ sign will not show space when printing out.. Not a problem here, also - as mentioned before - same works on first commcell.

Badge +1

Figured it wouldn’t hurt to ask just be sure.   Per the documentation, the api response output would vary depending on the command being run

https://documentation.commvault.com/commvault/v11/article?p=48618.htm

sadly the documentation for this particular script does not mention anything about a “2” error code

https://documentation.commvault.com/commvault/v11/article?p=features/cli/qscripts/CommServ.QS_DataProtectionJobSummary.Readme.html

 

 

Userlevel 1
Badge +6

Figured it wouldn’t hurt to ask just be sure.   Per the documentation, the api response output would vary depending on the command being run

https://documentation.commvault.com/commvault/v11/article?p=48618.htm

sadly the documentation for this particular script does not mention anything about a “2” error code

https://documentation.commvault.com/commvault/v11/article?p=features/cli/qscripts/CommServ.QS_DataProtectionJobSummary.Readme.html

 

 


Documentation about Commvault’s ‘generic’ response codes sucks to be frank 🙂 I would not call that a documentation, just an observarion more like it.

Now, regarding the issue, some more focus on the issue that after going from SP16 to SP20 something somewhere now changed..And I can’t find where..



 

[{'url': 'http://mycommcell.NET:81/SearchSvc/CVWebService.svc/', 'headers': {'Accept': 'application/json', 'Authtoken': 'QSDK deletedforsecurityreasons', 'Content-Type': 'application/x-www-form-urlencoded'}}]


Response code: <Response [200]>
{'CVGui_GenericResp': {'@errorMessage': 'Operation failed', '@errorCode': '2'}}
Traceback (most recent call last):
File "xxxxx", line 117, in <module>
clients = server_data.get_commvault_clients()
File "xxxxx", line 99, in get_commvault_clients
for job in jobs['ExecScriptOutput']['FieldValue']:
KeyError: 'ExecScriptOutput'

 

Userlevel 1
Badge +6

I can see some stuff in WebServer.log

 

I’ve raised a ticket Incident 210316-330.

Userlevel 7
Badge +23

Thanks for sharing the case number @Benjis (and thanks for referring to the forum in the details!).

I’ll follow and update back here once we have a resolution (barring you beating me to it).

Userlevel 3
Badge +4

@Benjis  Code looks fine. The user with which you’re trying to call the API probably doesn’t have necessary permissions. Check the user permissions between your two commcells. I tried this internally from a user without any permissions and hit the same error you mentioned.

Userlevel 1
Badge +6

@Benjis  Code looks fine. The user with which you’re trying to call the API probably doesn’t have necessary permissions. Check the user permissions between your two commcells. I tried this internally from a user without any permissions and hit the same error you mentioned.

Hi @Yash My user is in master group, so I doubt that there are permission issues.

Userlevel 7
Badge +23

Hey @Benjis !

 

I see the great @Brian Bruno  solved this one, so I’m copying the resolution down for posterity:

- Customer has been using automation to pull job history for the past year via REST API.
- Specifically, the QS_DataProtectionJobSummary stored procedure is being executed via REST API (qoperation execscript -sn QS_DataProtectionJobSummary)
- After upgrading to FR20, this is no longer working.

- The underlying cause was due to the size of the JSON response - it's generating over 250 MB of data, where our theoretical limit on response size is ~64 MB.

- Although it was suggested that this functioned previously on SP16, we tested internally on an SP16 database and got the same issue.
- The customer has instead opted to use the GET Job API with a completedJobLookupTime of 7 days, and this will run weekly.
- This is giving them the data that is required.

Reply