Jump to content

Nhardel

Active Members
  • Posts

    49
  • Joined

  • Last visited

Profile Information

  • Location
    Carmel, Indiana

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Nhardel's Achievements

Seeker

Seeker (1/7)

1

Reputation

  1. Bump
  2. @argumentum So I will be the first to admit I don't understand dll structure and converting back to readable data. I have been toying with your listusersessions array trying to understand it and get it to pull the data I want. But I need two additional columns of info. WTSLogonTime & WTSIdleTime. Here are the changes I have made to your base code but I don't think I am converting things correctly. If you could help me understand what I am doing wrong and where I can find the different structures for each property. I believe I want to create an array that list all the properties for all sessions. I made no changes to the function _WTSQuerySessionInformation Func ListUserSessions() ; mod. of https://www.autoitscript.com/forum/topic/139774-dllcall-and-returned-pointers/?do=findComment&comment=980850 Local $_Self_SessionId = _WTSQuerySessionInformation(-1, 4) ; -1 = current user ; 4 = WTSSessionId Local Enum $e_IsSelf_SessionId, $e_SessionName, $e_UserName, $e_SessionId, $e_StateName, $e_StateInt, $e_ClientName, $e_ClientIp, $e_Domain, $e_IdleTime, $e_LogonTime, $e_UBound Local Const $tagWTS_SESSION_INFO = 'dword SessionId;ptr WinStationName;uint State' Local $aResult = DllCall('wtsapi32.dll', 'int', 'WTSEnumerateSessionsW', 'ptr', 0, 'dword', 0, 'dword', 1, 'ptr*', 0, 'dword*', 0) If @error Or $aResult[0] = 0 Then Return SetError(1, 0, "") ; https://docs.microsoft.com/en-us/windows/desktop/api/wtsapi32/ne-wtsapi32-_wts_connectstate_class Local $aConnectionState = StringSplit("Active,Connected,ConnectQuery,Shadow,Disconnected,Idle,Listen,Reset,Down,Init", ",", 2) Local $tInfo, $Offset = 0, $c = 0, $aReturn[$aResult[5] + 1][$e_UBound] ; $e_UBound is the last enumerator, just to determine the size of the array $aReturn[0][$e_SessionId] = "ID" $aReturn[0][$e_SessionName] = "SessionName" $aReturn[0][$e_StateInt] = "StateInt" $aReturn[0][$e_StateName] = "State" $aReturn[0][$e_UserName] = "UserName" $aReturn[0][$e_ClientName] = "ClientName" $aReturn[0][$e_ClientIp] = "ClientIp" $aReturn[0][$e_Domain] = "Domain" $aReturn[0][$e_IdleTime] = "IdleTime" $aReturn[0][$e_LogonTime] = "LogonTime" For $i = 1 To $aResult[5] $tInfo = DllStructCreate($tagWTS_SESSION_INFO, $aResult[4] + $Offset) $Offset += DllStructGetSize($tInfo) $c += 1 $aReturn[$c][$e_SessionId] = DllStructGetData($tInfo, 'SessionId') $aReturn[$c][$e_SessionName] = DllStructGetData(DllStructCreate('wchar[1024]', DllStructGetData($tInfo, 'WinStationName')), 1) $aReturn[$c][$e_StateInt] = DllStructGetData($tInfo, 'State') If UBound($aConnectionState) > $aReturn[$c][$e_StateInt] Then $aReturn[$c][$e_StateName] = $aConnectionState[$aReturn[$c][$e_StateInt]] $aReturn[$c][$e_UserName] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 5) ; WTSUserName $aReturn[$c][$e_ClientName] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 10) ; WTSClientName $aReturn[$c][$e_ClientIp] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 14) ; WTSClientAddress $aReturn[$c][$e_Domain] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 7) ; WTSDomainName $aReturn[$c][$e_IdleTime] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 17) ; WTSIdleTime $aReturn[$c][$e_LogonTime] = _WTSQuerySessionInformation($aReturn[$c][$e_SessionId], 18) ; WTSLogonTime $aReturn[0][$e_IsSelf_SessionId] = $c If $_Self_SessionId = $aReturn[$c][$e_SessionId] Then $aReturn[$c][$e_IsSelf_SessionId] = 1 Else $aReturn[$c][$e_IsSelf_SessionId] = 0 EndIf Next DllCall('wtsapi32.dll', 'none', 'WTSFreeMemory', 'ptr', $aResult[4]) Return $aReturn EndFunc ;==>ListUserSessions
  3. Well that seem to do it. I made all of the changes that you suggested but then got a 401 unauthorized response. I jacked around with the username and password but didnt work. put that line back in the header and then everything worked. $sHeader = 'Authorization: Basic YWRtaW46' & @CRLF & _ 'Content-Type: application/json' $sTarget = "/SolarWinds/InformationService/v3/Json/Create/Orion.Nodes" $orion_QueryResponse = _WinHttpSimpleSSLRequest($hConnect,"Post", $sTarget, Default, $sDta, $sHeader, True, Default, Default, Default, 1) Response received: HTTP/1.1 200 OK Date: Fri, 01 Sep 2017 18:51:30 GMT Content-Length: 60 Content-Type: application/json Server: Microsoft-HTTPAPI/2.0 Verified that node was created on server.
  4. Download links seem to be dead. Where might I get this UDF and all supporting files?
  5. Okay, so I cleaned up the header as @trancexx suggested. That did help. I now get the following response. <HTML><HEAD><TITLE>Bad Request</TITLE> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD> <BODY><h2>Bad Request - Invalid Hostname</h2> <hr><p>HTTP Error 400. The request hostname is invalid.</p> </BODY></HTML> So that makes me assume that my I do need to push json array with my request. So I need a json udf. Here are my options: JSON_UDF Library (fully RFC4627-compliant) by Gabriel13 & A Non-StrictJSON &nbsp;UDF (JSMN) by Ward I am currently looking into the UDF by Gabriel13. It however seems very outdated and not much support on that thread if I do run into problems. Maybe it is just that easy, so don't flame me yet. I am looking into it. The second one by Ward seems to be the better option but by all accounts looks to be a dead project. The first post has all dead download links. Hoping someone might have a copy or could point me to something else that would work. No real question here, just looking for thoughts or ideas. Or the occasional "hey dumbass, the answer is right in front of you" comments.
  6. @trancexx Please do confuse me How else am I going to get better, if I don't get critical feedback.
  7. 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
  8. #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
  9. 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.
  10. Needing some clarification. I am using _winhttpsimplesslrequest with post. the requirements of the api state that I must use a json array in the body tags of my request. I thought this was $sdta of the function but I am not getting the expected result. I am getting a 500 error. Could this be because I am not actually sending a JSON array? Or am I missing a function that I should be using to input the data into the body. ;solarwinds.au3 #Region Includes #include-once #include <log4a.au3> #include <Array.au3> #include <WinHttp.au3> #EndRegion #Region Logging ; Enable logging and don't write to stderr _log4a_SetEnable() _log4a_SetMinLevel($LOG4A_LEVEL_TRACE);Possible levels: $LOG4A_LEVEL_TRACE ; $LOG4A_LEVEL_DEBUG ; $LOG4A_LEVEL_INFO ; $LOG4A_LEVEL_WARN ; $LOG4A_LEVEL_ERROR ; $LOG4A_LEVEL_FATAL _log4a_SetErrorStream(False) _log4a_SetFormat("${shortdate} | ${host} | ${level} | ${message}") _log4a_SetLogFile(@ScriptFullPath & ".log");Sets the path of the log file (Default: "<ScriptFullPath>.log") _log4a_SetCompiledOutput($LOG4A_OUTPUT_BOTH);Possible outputs: $LOG4A_OUTPUT_CONSOLE = Direct output to the console ; $LOG4A_OUTPUT_FILE = Direct output to the log file. ; $LOG4A_OUTPUT_BOTH = Direct output to both the console and the log file. #EndRegion Global $debug =0 Global $host = "usandl0213" Global $hOpen,$hConnect,$hRequest _orionConnect($host) $response = _orionNew() _orionDisconnect() 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 _orionNew() Local $sHeader = _ 'Authorization: Basic YWRtaW46, ' & _ 'Accept: */*, ' & _ 'User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3, ' & _ 'Host: usandl0213:17778, ' & _ 'Content-Type: application/json ' _log4a_trace($sHeader) Local $sDta = '{' & _ '"EntityType":"Orion.Nodes", ' & _ '"IPAddress":"127.0.0.1", ' & _ '"Caption":"Test - Test", ' & _ '"DynamicIP": false, ' & _ '"EngineID": 1, ' & _ '"Status": 1, ' & _ '"UnManaged": false, ' & _ '"Allow64BitCounters": false, ' & _ '"SysObjectID": "", ' & _ '"MachineType": "", ' & _ '"VendorIcon": "", ' & _ '"ObjectSubType": "SNMP", ' & _ '"SNMPVersion": 2, ' & _ '"Community":"public"' & _ '}' _log4a_trace($sDta) Local $orion_QueryResponse = _WinHttpSimpleSSLRequest($hConnect,"Post" ,"/SolarWinds/InformationService/v3/Json/Create/Orion.Nodes",Default , $sDta, $sHeader, True , Default, Default, Default, 1) ;~ _WinHttpSimpleSSLRequest($hConnect, $sType, $sPath , $sReferrer, $sDta, $sHeader, $fGetHeaders, $iMode, $sCredName, $sCredPass, $iIgnoreCertErrors) 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]) if $debug = 1 then _arraydisplay($orion_QueryResponse) return $orion_QueryResponse EndFunc Func _orionDisconnect() _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) EndFunc If I use a Rest client here are my results: POST /SolarWinds/InformationService/v3/Json/Create/Orion.Nodes HTTP/1.1 Authorization: Basic YWRtaW46 Accept: */* User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3 Content-Length: 296 Host: usandl0213:17778 Content-Type: application/json {"EntityType":"Orion.Nodes", "IPAddress":"127.0.0.1", "Caption":"Test - Test", "DynamicIP": false, "EngineID": 1, "Status": 1, "UnManaged": false, "Allow64BitCounters": false, "SysObjectID": "", "MachineType": "", "VendorIcon": "", "ObjectSubType": "SNMP", "SNMPVersion": 2, "Community":"public"} HTTP/1.1 200 OK Content-Length: 60 Content-Type: application/json Server: Microsoft-HTTPAPI/2.0 Date: Fri, 25 Aug 2017 16:27:39 GMT "swis://USANDL0213.nestle.com/Orion/Orion.Nodes/NodeID=1287"
  11. Sorry JLogan3o13 I only have very basic things at this point so I did not think it was complete enough to be in that forum. If that is where I should be then yes, please move post.
  12. 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.
  13. Holy crap, I got the expected response back. Thanks so much Inververs. Let me go play with this for a while and now that I can actually talk to the server see if I can figure out how to do the POST verb and understand JSON arrays. Again, thanks a lot. I did have to drop the '& @CRLF' to get this to work.
  14. Okay so I made a few changes and I am getting something out of it again but I am still back to an authorization issue. However I can see that it is not using the credentials correctly now. Here is new code: ;solarwinds.au3 #Region Includes #include-once #include <log4a.au3> #include <Array.au3> #include "WinHttp.au3" #EndRegion ;~ GET https://localhost:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+Uri+FROM+Orion.Pollers+ORDER+BY+PollerID+WITH+ROWS+1+TO+3+WITH+TOTALROWS HTTP/1.1 ;~ Authorization: Basic YWRtaW46 ;~ User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3 ;~ Host: localhost:17778 ;~ Accept: */* ;~ Row|Col 0 ;~ [0]|https ;~ [1]|2 ;~ [2]|usandl0213 ;~ [3]|17778 ;~ [4]| ;~ [5]| ;~ [6]|/SolarWinds/InformationService/v3/Json/Query ;~ [7]|?query=SELECT+NodeID+FROM+Orion.NODES Global $sAddress = "https://usandl0213:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+NodeID+FROM+Orion.NODES" Global $array_URL = _WinHttpCrackUrl($sAddress) ;~ _ArrayDisplay($array_url) Global $hOpen = _winhttpOpen() If @error Then _log4a_Fatal("Error intializing the usage of WinHTTP functions") Exit 1 EndIf Global $hConnect = _winhttpConnect($hOpen, "usandl0213","17778") If @error Then _log4a_Fatal("Error specifying the initial target server of an HTTP request.") _WinHttpCloseHandle($hOpen) Exit 2 EndIf Global $aRequest = _WinHttpSimpleSSLRequest($hConnect,"GET" ,$array_url[6]&$array_url[7],Default , Default, Default, True , Default, "Admin", Default, 1) ;~ _WinHttpSimpleSSLRequest($hConnect, $sType, $sPath , $sReferrer, $sDta, $sHeader, $fGetHeaders, $iMode, $sCredName, $sCredPass, $iIgnoreCertErrors) consolewrite(@error&@crlf) 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 _arraydisplay($aRequest) Close_request() Func Close_request() ; Close open handles and exit ;~ _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) EndFunc And here is what the array spits out now Row|Col 0 [0]|HTTP/1.1 401 Unauthorized Date: Wed, 02 Aug 2017 15:38:38 GMT Content-Length: 0 Server: Microsoft-HTTPAPI/2.0 WWW-Authenticate: Basic realm="" [1]| [2]|https://usandl0213:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+NodeID+FROM+Orion.NODES I had made the most basic user possible within the Solarwinds site "Admin" with no password just to try to get this working.
  15. I tried using _WinHTTPSimpleSSLRequest() but I get no response. Still fuzzy if I am using it correctly. Code I used. #Region Includes #include <log4a.au3> #include <Array.au3> #include "WinHttp.au3" #EndRegion ;~ Row|Col 0 ;~ [0]|https ;~ [1]|2 ;~ [2]|usandl0213 ;~ [3]|17778 ;~ [4]| ;~ [5]| ;~ [6]|/SolarWinds/InformationService/v3/Json/Query ;~ [7]|?query=SELECT+NodeID+FROM+Orion.NODES Global $sAddress = "https://usandl0213:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+NodeID+FROM+Orion.NODES" Global $array_URL = _WinHttpCrackUrl($sAddress) ;~ _ArrayDisplay($array_url) Global $hOpen = _winhttpOpen() If @error Then _log4a_Fatal("Error intializing the usage of WinHTTP functions") Exit 1 EndIf Global $hConnect = _winhttpConnect($hOpen, $sAddress) If @error Then _log4a_Fatal("Error specifying the initial target server of an HTTP request.") _WinHttpCloseHandle($hOpen) Exit 2 EndIf Global $aRequest = _WinHttpSimpleSSLRequest($hConnect,"GET",$sAddress,Default,Default,Default,True,Default) 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 _arraydisplay($aRequest) Close_request() Func Close_request() ; Close open handles and exit _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) EndFunc
×
×
  • Create New...