cancel
Showing results for 
Search instead for 
Did you mean: 

Prognosis REST API and SECONDS

Guillaume
05 Base Camper

Prognosis REST API and SECONDS

Hi,

I'm trying to create a REST API dataset to return the alarms opened in the last X seconds.
This X should be a parameter defined by the dataset consumer upon request.

In the "\Prognosis\WebUI\IIS\Administration\Config\RestApiDataSets.xml" file, I've added the following code.
The forum automatically gets rid of XML tags so I had to cheat.
Same thing for the "greater than or equal to" part, the original code is "& gt;", if I don't use a space or replace the & sign the forum would replace the character with a ">", which AFAIK cannot be used in the RestAPI file.

«dataSet»
«id»getCustomerProbsum2«/id»
«query»SELECT * FROM ProbSum WHERE OpenTime $gt;== Now() - @LookBackSeconds SECONDS NODE ALL ORDER BY opentime DESC, problemnumber ASC«/query»
«/dataSet»

The issue is, it's not working, I get the following error : "Failed to get response from PQL: Syntax error near 'SECONDS'. Token: SECONDS." when accessing the following URL:
/Prognosis/rest/v1/data/getCustomerProbsum2?LookBackSeconds=300


If I hardcode a value instead of the @LookBackSeconds parameter, the dataset works properly.

How can I achieve this?

Thanks!
2 REPLIES 2

Re: Prognosis REST API and SECONDS

Guillaume,

I can confirm that it seems like a bug or unsupported feature. I'll reach out to R&D and get a confirmation.

In the meanwhile, another way to approach the same problem is that you create a base view that also calculates 'ElapsedSeconds' for you. Then in your rest view, you can use that field as a regular field, instead of doing time manipulation.


C:\Prognosis\Server\Configuration>..\irpqlcli "Create View MyProblems as Select *, DateDiff(Second, OpenTime, Now()) as ElapsedSeconds FROM PROBSUMC"

C:\Prognosis\Server\Configuration>..\irpqlcli "Start MyProblems"

C:\Prognosis\Server\Configuration>..\irpqlcli "Select TOP 10 OpenTime, ProblemNumber FROM MyProblems where ElapsedSeconds > @lookbackseconds" -r -b lookbackseconds=60
OpenTime | ProblemNumber |
___________________________________________________
2018-01-24T06:40:00.007867-07:00 | 200233 |
2018-01-24T08:20:00.004423-07:00 | 200234 |
2018-01-17T01:20:00.005010-07:00 | 200129 |
2018-01-17T03:00:00.009549-07:00 | 200130 |
2018-01-17T04:40:00.014087-07:00 | 200131 |
2018-01-17T06:20:00.003026-07:00 | 200132 |
2018-01-17T08:00:00.007564-07:00 | 200133 |
2018-01-17T09:40:00.014103-07:00 | 200134 |
2018-01-17T11:20:00.003041-07:00 | 200135 |
2018-01-17T13:00:00.023180-07:00 | 200136 |


C:\Prognosis\Server\Configuration>

Let me know if this works for you.


pql001.png


If my reply answered your question please click on the 'Accept as Solution' button to help others find the answer.
Thanks,
Shoaib
Guillaume
05 Base Camper

Re: Prognosis REST API and SECONDS

Hi Shoaib,

Thanks, this looks promising, I didn't think about doing the seconds calculation in a view but it would definitely work.

Thanks for the tip, I'll test ASAP Smiley Happy