Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error for Copy Query As / curl (cmd || bash) #334

Open
kmsigma opened this issue Mar 29, 2023 · 0 comments
Open

Syntax error for Copy Query As / curl (cmd || bash) #334

kmsigma opened this issue Mar 29, 2023 · 0 comments

Comments

@kmsigma
Copy link
Contributor

kmsigma commented Mar 29, 2023

When a query is copied using the Edit / Copy Query As / Curl (Cmd) or Edit / Copy Query As / Curl (Bash), it does not contain surrounding quotes. This is necessary for any query that contains parenthesis. For this example, I've seen issues with functions like GETUTCDATE() or parenthetical clauses WHERE ( This AND THAT )

Query Used

SELECT TOP 10 Caption
      , IP
      , CONCAT(Caption,'"/"',IP) AS [ComboName]
      , GETUTCDATE() AS [RightNow]
FROM Orion.Nodes
WHERE IP LIKE '192.168.%.%'

As Produced

Copy Query As / Curl (cmd)

curl.exe -k -u MyUsername:MyC0mpl3xP@ssw0rd https://solarwinds.domain.local:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+TOP+1+Caption%2c+IP%2c+CONCAT(Caption%2c+%27%22%2f%22%27%2c+IP)+AS+%5bComboName%5d%2c+GETUTCDATE()+AS+%5bRightNow%5d+FROM+Orion.Nodes+WHERE+IP+LIKE+%27192.168.%25.%25%27

Copy Query As / Curl (bash)

curl -k -u MyUsername:MyC0mpl3xP@ssw0rd curl -k -u MyUsername:MyC0mpl3xP@ssw0rd https://solarwinds.domain.local:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+TOP+1+Caption%2c+IP%2c+CONCAT(Caption%2c+%27%22%2f%22%27%2c+IP)+AS+%5bComboName%5d%2c+GETUTCDATE()+AS+%5bRightNow%5d+FROM+Orion.Nodes+WHERE+IP+LIKE+%27192.168.%25.%25%27

Results when executed in selected shell

Copy Query As / Curl (cmd)

Using Command Prompt as Shell (cmd.exe)

C:\Users\LocalUser> curl.exe -k -u MyUsername:MyC0mpl3xP@ssw0rd https://solarwinds.domain.local:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+TOP+1+Caption%2c+IP%2c+CONCAT(Caption%2c+%27%22%2f%22%27%2c+IP)+AS+%5bComboName%5d%2c+GETUTCDATE()+AS+%5bRightNow%5d+FROM+Orion.Nodes+WHERE+IP+LIKE+%27192.168.%25.%25%27
{"results":[{"Caption":"KMS-NAS","IP":"192.168.21.200","ComboName":"KMS-NAS\"/\"192.168.21.200","RightNow":"2023-03-29T16:22:28.5000000"}]}

Returns results as expected.

Using Windows PowerShell as Shell (powershell.exe)

PS C:\Users\LocalUser> curl.exe -k -u MyUsername:MyC0mpl3xP@ssw0rd https://solarwinds.domain.local:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+TOP+1+Caption%2c+IP%2c+CONCAT(Caption%2c+%27%22%2f%22%27%2c+IP)+AS+%5bComboName%5d%2c+GETUTCDATE()+AS+%5bRightNow%5d+FROM+Orion.Nodes+WHERE+IP+LIKE+%27192.168.%25.%25%27
At line:1 char:152
+ ... v3/Json/Query?query=SELECT+TOP+1+Caption%2c+IP%2c+GETUTCDATE()+AS+%5b ...
+                                                                  ~
An expression was expected after '('.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedExpression

Generates a parsing error.

Using PowerShell as Shell (pwsh.exe on Windows) and (pwsh on *NIX)

PS C:\Users\LocalUser> curl.exe -k -u MyUsername:MyC0mpl3xP@ssw0rd https://solarwinds.domain.local:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+TOP+1+Caption%2c+IP%2c+CONCAT(Caption%2c+%27%22%2f%22%27%2c+IP)+AS+%5bComboName%5d%2c+GETUTCDATE()+AS+%5bRightNow%5d+FROM+Orion.Nodes+WHERE+IP+LIKE+%27192.168.%25.%25%27
ParserError:
Line |
   1 |  … v3/Json/Query?query=SELECT+TOP+1+Caption%2c+IP%2c+GETUTCDATE()+AS+%5b …
     |                                                                 ~
     | An expression was expected after '('.

Generates a parsing error.

Copy Query As / Curl (bash)

username@LINUXHOST:~ $ curl -k -u curl -k -u MyUsername:MyC0mpl3xP@ssw0rd https://solarwinds.domain.local:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+TOP+1+Caption%2c+IP%2c+CONCAT(Caption%2c+%27%22%2f%22%27%2c+IP)+AS+%5bComboName%5d%2c+GETUTCDATE()+AS+%5bRightNow%5d+FROM+Orion.Nodes+WHERE+IP+LIKE+%27192.168.%25.%25%27
-bash: syntax error near unexpected token `('

Generates a parsing error.

Possible Solution

Surround the entire URI with single quotes (') or double-quotes (") so that the native parser reads it as a single element. This should not be an issue with the query converter because the query has already been URL enocoded which strips ' and ".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant