Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Luis_Miguel_Mig
Advisor
Jump to solution

gaia api run-script

api command show-licenses shows you the licenses, but is there any way to get the contract coverage via the api?

2 Solutions

Accepted Solutions
Amir_Senn
Employee
Employee

It doesn't bring it as part of the answer at the moment but I found a work around to succeed in getting the contract.

Instead of using "show-licenses" I use "run-script" and the script I'm running is "cplic print".

The answer is only task-id but then you can run "show-task" and you will get the whole output of cplic print command in base64.

After quick decode you will have licenses + contract.

 

Kind regards, Amir Senn

View solution in original post

PhoneBoy
Admin
Admin

To use run-script, you have to have full admin rights.
I believe this applies to both the Management and Gaia API.

View solution in original post

23 Replies
the_rock
Legend
Legend

I dont know how that command worked for you. I tried in on 3 different mgmt servers, all R81.20 jumbo 38 and no luck.

Andy

Luis_Miguel_Mig
Advisor

yeah, this works for me "https://$fwhost/gaia_api/v1.6/show-licenses" but I only get the licenses.

I would like to get the "contracts" information that you get when you run "cplic print"

the_rock
Legend
Legend

Would you mind sharing exact command you ran? I tried mgmt_cli show-licenses and its not working

Andy

Luis_Miguel_Mig
Advisor

I am not using mgmt_cli, it is just a http request https://host/gaia_api/v1.6/show-licenses>
My original question: Is it possible to get the contract information via api request?

Amir_Senn
Employee
Employee

It doesn't bring it as part of the answer at the moment but I found a work around to succeed in getting the contract.

Instead of using "show-licenses" I use "run-script" and the script I'm running is "cplic print".

The answer is only task-id but then you can run "show-task" and you will get the whole output of cplic print command in base64.

After quick decode you will have licenses + contract.

 

Kind regards, Amir Senn
Luis_Miguel_Mig
Advisor

Do I need anything special in terms of authorization to run-scripts?
I don't have any issue to run query commands through the api via web or mgmt_cli with a monitor user.

However I get this error when I try to run-script and then try to see the task-details output even if I configure the user as adminRole.
No issue If I try with the admin user


mgmt_cli run-script script "show version" --context gaia_api
Username: userapi
Password:
code: generic_err_no_permissions
errors: User doesn't have permission to perform this action
message: No Permission


add rba user userapi roles adminRole
mgmt_cli run-script script "show version" --context gaia_api
Username: userapi
Password:
task-id: 83f4a31d-94a0-4bd2-a83f-bbfb7f7985bc

mgmt_cli show task task-id "83f4a31d-94a0-4bd2-a83f-bbfb7f7985bc" --context gaia_api
Username: userapi
Password:
tasks:
- execution-time: '0.02'
last-update-time: 2023-12-27T16:03+0.00.0
progress-description: succeeded
progress-percentage: 100
start-time: 2023-12-27T16:03+0.00.0
status: succeeded
status-code: 200
task-details:
- error: L2Jpbi9zaDogL3Jlc3RfYXBpLy9ydW5TY3JpcHRUZW1wLnNoLTgzZjRhMzFkLTk0YTAtNGJkMi1hODNmLWJiZmI3Zjc5ODViYzogUGVybWlzc2lvbiBkZW5pZWQ=
output: ''
return-value: 126
task-id: 83f4a31d-94a0-4bd2-a83f-bbfb7f7985bc
task-name: /run-script
time-spent-in-queue: '0.26'




Luis_Miguel_Mig
Advisor

I had only tried with  gaia api v1.6 and v1.7 and I got the error I reported

PhoneBoy
Admin
Admin

To use run-script, you have to have full admin rights.
I believe this applies to both the Management and Gaia API.

Luis_Miguel_Mig
Advisor

I got the error with gaia api and full admin rigthts

add rba user userapi roles adminRole

Amir_Senn
Employee
Employee

a. Please make sure you ran gaia_api access --user <admin>--enable true

b. I noticed this works only when the UID of the user is 0, and not between 103 and 65533.

Kind regards, Amir Senn
Luis_Miguel_Mig
Advisor

Thanks Amir,
a. yeah, It was already configured, I have never had any issue with readonly type of api queries
b.  I have set uid to 0 and now I get a different error

[Expert@dc1fwo2a:0]# mgmt_cli show task task-id "c50b12b9-db35-4f2e-80ad-6223b4b2e237" --context gaia_api
Username: userapi
Password:
tasks:
- execution-time: '0.03'
last-update-time: 2023-12-28T10:26+0.00.0
progress-description: succeeded
progress-percentage: 100
start-time: 2023-12-28T10:26+0.00.0
status: succeeded
status-code: 200
task-details:
- error: c2hvdzogY29tbWFuZCBub3QgZm91bmQ=
output: ''
return-value: 127
task-id: c50b12b9-db35-4f2e-80ad-6223b4b2e237
task-name: /run-script
time-spent-in-queue: '0.21'

Amir_Senn
Employee
Employee

Use this syntax:

mgmt_cli run-script script "cplic print" --context gaia_api

Kind regards, Amir Senn
the_rock
Legend
Legend

Hey Amir,

I just tested that command in my mgmt R81.20 jumbo 41 lab and got below, not sure if that looks right?

Best,

Andy

 

[Expert@CP-management:0]# mgmt_cli run-script script "cplic print" --context gaia_api
Username: admin
Password:
task-id: 8d6634bc-86b4-48d1-90cc-2cc5f0f8bc06

[Expert@CP-management:0]#

the_rock
Legend
Legend

Never mind, appears its good based on the task ID

Best,

Andy

 

[Expert@CP-management:0]# mgmt_cli run-script script "cplic print" --context gaia_api
Username: admin
Password:
task-id: 8d6634bc-86b4-48d1-90cc-2cc5f0f8bc06

[Expert@CP-management:0]# ^C
[Expert@CP-management:0]# mgmt_cli show task task-id "8d6634bc-86b4-48d1-90cc-2cc5f0f8bc06" --context gaia_api
Username: admin
Password:
tasks:
- execution-time: '0.21'
last-update-time: 2023-12-28T08:22+19.00.0
progress-description: succeeded
progress-percentage: 100
start-time: 2023-12-28T08:22+19.00.0
status: succeeded
status-code: 200
task-details:
- error: ''
output: SG9zdCAgICAgICAgICAgICBFeHBpcmF0aW9uICBGZWF0dXJlcyAgICAgICAgICAgIAoxNzIuMTYuMTAuMjUyICAgIDEwSmFuMjAyNCAgIENQU00tQy1VIENQU0ItTlBNIENQU0ItRVBNIENQU0ItTE9HUyBDUFNCLU1OVFIgQ1BTQi1QUlZTIENQU0ItVURJUiBDUFNCLVdLRkwtMTAwIENQU0ItV1MgQ1BTQi1NUFRMIENQVlAtU05YLVUtTkdYIENQU0ItU1dCIENQU0ItQUROQy1NIENQU0ItUlBSVC1VIENQU0ItRVZDUi1VIENQU0ItU1NMVlBOLU1PQk1BSUwrNTAwMCBDUFNCLUNPTVAtMTUwIENLLUZGQjI0NzE2REZCOAoKQ29udHJhY3QgQ292ZXJhZ2U6CgogIyAgIElEICAgICAgICAgIEV4cGlyYXRpb24gICBTS1UgICAgICAgICAgICAgICAgIAo9PT0rPT09PT09PT09PT0rPT09PT09PT09PT09Kz09PT09PT09PT09PT09PT09PT09Cj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ogICAgIENQU00tQy1VIENQU0ItTlBNIENQU0ItRVBNIENQU0ItTE9HUyBDUFNCLU1OVFIgQ1BTQi1QUlZTIENQU0ItVURJUiBDUFNCLVdLRkwtMTAwIENQU0ItV1MgQ1BTQi1NUFRMIENQVlAtU05YLVUtTkdYIENQU0ItU1dCIENQU0ItQUROQy1NIENQU0ItUlBSVC1VIENQU0ItRVZDUi1VIENQU0ItU1NMVlBOLU1PQk1BSUwrNTAwMCBDUFNCLUNPTVAtMTUwIENLLUZGQjI0NzE2REZCOAo9PT0rPT09PT09PT09PT0rPT09PT09PT09PT09Kz09PT09PT09PT09PT09PT09PT09
return-value: 0
task-id: 8d6634bc-86b4-48d1-90cc-2cc5f0f8bc06
task-name: /run-script
time-spent-in-queue: '0.26'

[Expert@CP-management:0]#

Luis_Miguel_Mig
Advisor

Sure, no problem with the admin user

Luis_Miguel_Mig
Advisor

That is the syntax I use and that is how I get the error I reported

Amir_Senn
Employee
Employee

From earlier comments I saw you used this:
"mgmt_cli run-script script "show version" --context gaia_api"

If we translate error field output from base64 we get: "show: command not found"

If you fixed the syntax, please send new syntax + response and I'll try to figure out further.

Kind regards, Amir Senn
Luis_Miguel_Mig
Advisor

Ah, okay. Yeah, you are right. So if the uid = 0, it works. 
So in the end this user has a User ID of 0, and therefore has all of the privileges of a root user.

It would be nice if the output of "cplic print" was in the api directly and therefore we didn't need to run a query with full admin rights.

Amir_Senn
Employee
Employee

Based on this post I created an improvement request and if nothing goes wrong I think it will be implemented in one of upcoming versions.

Kind regards, Amir Senn
Luis_Miguel_Mig
Advisor

Thanks very much Amir
What main version do you think? I guess no R80.40, right?
Is there any way to know more details of this improvement and track it maybe in the release notes? Does it have an ID or something?

PhoneBoy
Admin
Admin

By upcoming, it will likely mean a future (unreleased) version.
The next major release is R82. 

MattElkington
Contributor

API scripts run in the bash context.  If  you need  it to run a clish command you need to run the command:

mgmt_cli -run-script script "clish -c 'show version all'" --context gaia_api

Tested this working:


Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events