how to get a session token in a discovery pattern for REST discovery

RolandW1
Tera Expert

I would like to discover the HPE Oneview Global Dashboard appliance to retrieve hardware information using the REST API.

I need to get an authorization session token but I am unsure if this is possible using the OOTB pattern steps. Or how else this could be accomplished. I could not find any good documentation on this subject.

https://servername/rest/login-sessions/

To get a  token I need to send this:

Content-Type: Specifies the content type of the request body and should be set to application/json.
X-Api-Version: integer [ 2 .. 300 ] Required

 

I can query the version needed with the following url:

https://servername/rest/version 

which returns:

{

"minimumVersion": 2,
"currentVersion": 300

}

The request body should contain the following:

{

"authLoginDomain": "local",
"password": "secret",
"userName": "sarah"

}

I need to get an answer like this:

{

"token": "NTAxMjQzNDc2NzIyR2yWViDr0ENEJvM1cu7IJap7h_UmkDSj",
"user":

{

"domain": "local",
"user_roles":

[],
"userName": "administrator"

}

I need the token to be able to query the data from the appliance.

 

What kind of pattern step(s) can I use to accomplish this? I could not find an example in the OOTB patterns.

Can we use "basic authentication credentials here without hardcoding them?

Any help will be greatly appreciated!

Best regards,

Roland

 

 

 

 

4 REPLIES 4

VivekSattanatha
Mega Sage
Mega Sage

Hi Roland,

 

Create a custom pattern operation (sa_custom_operation) where you can write scripts. Once it's been created you can use them in your patterns. You can have a look at the existing examples in that table for reference.

 

Regards,

Vivek

Hi Vivek,

 

Thanks, I have looked at that but could not find a good example. I am not a scripting god so maybe I overlooked it. Do you have the name/specific example from the existing examples? I don't see any doing something with posting for a session token?

 

Best regards,

 

Roland

Hi Roland, Were you able to achieve this ?

i am facing similar issue.

I know this is an old thread but... still trying to get a Pattern for our newer HPE Synergy gear that now uses REST API unlike the really old stuff that the ServiceNow Discovery Pattern is for...

 

Have a Custom Operation written, but...

End up with an issue with scopes

Script calls RESTmessageV2 which is scoped sn_ws

     var restMessage = new sn_ws.RESTMessageV2();
     ....

When called in the Discovery Pattern returns an error = sn.ws is not defined