Jump to content

Recommended Posts

I have been working on trying to develop some scripts to interface with the REST/JSON API from the Orion SDK.  This is where I will ask my questions and hopefully get some community responses that could help benefit others. 

https://github.com/solarwinds/OrionSDK

I am trying to create examples of how to interface with the API from autoit.  This should be a knowledge dump for this task. 

Link to comment
Share on other sites

  • Moderators

@nhardel do you have a specific question on how to complete a task, or are you looking to create a library of some sort with help from the community? If it is the latter then I will move this thread to the Projects and Collaboration forum.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

The API is a basic web server listening on localhost:17778, it uses REST API... which uses JSON to communicate back and fro'. A good starting point would be to check out the WinHTTP UDF to place requests to the server and a JSON UDF to interpret the responses.

I am personally not familiar working with JSON in AutoIt so I can't give you more advice on that part.

Some reference material: https://github.com/solarwinds/OrionSDK/wiki/REST

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

I have looked at the reference material already.  My hope is to find some others that have access to solarwinds products and come up with practical wrappers or a UDF.  I am using the winhttp udf and have had success with the query command.  The JSON part is where I am having some issues.

Link to comment
Share on other sites

#include <log4a.au3>

Func _orionConnect($orion_host)
    $hOpen = _winhttpOpen()
    If @error Then
        _log4a_Fatal("Error intializing the usage of WinHTTP functions")
        Exit 1
    EndIf
    $hConnect = _winhttpConnect($hOpen, $orion_host,"17778")
    If @error Then 
        _log4a_Fatal("Error specifying the initial target server of an HTTP request.") 
        _orionDisconnect() 
        Exit 2 
    EndIf 
EndFunc

Func _orionDisconnect()
    _WinHttpCloseHandle($hRequest) 
    _WinHttpCloseHandle($hConnect) 
    _WinHttpCloseHandle($hOpen)
EndFunc

log4a.au3

Link to comment
Share on other sites

Func _orionQuery($orion_query)
    Local $sHeader = 'Authorization: Basic YWRtaW46'
    Local $orion_QueryResponse = _WinHttpSimpleSSLRequest($hConnect,"GET","/SolarWinds/InformationService/v3/Json/Query?query="&$orion_query,Default,Default,$sHeader,True,Default,Default,Default,1)

    If @error Then 
        Switch @error
            Case 1
                _log4a_Fatal("could not open request.") 
            Case 2
                _log4a_Fatal("could not send request.") 
            Case 3
                _log4a_Fatal("could not receive response.") 
            Case 4
                _log4a_Fatal("$iMode is not valid.") 
        EndSwitch
    EndIf
    _log4a_trace(@crlf & $orion_QueryResponse[0])
    _log4a_trace($orion_QueryResponse[1])
    _log4a_trace($orion_QueryResponse[2])
    return $orion_QueryResponse
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...