Morning all
So, am writing a front-end querying module for a hardware inventory with a CosmosDB REST backend. However, I’m trying to make it so it’ll be easy for non-technical users to use to query the results.
For those unaware, you can query CosmosDB (basically, a NoSQL Mongo sort of thing, schemaless, with documents posted in JSON format) with a SQL-alike language.
Sample queries:
SELECT f.hostname, c.Name, c.Installed
FROM Computers f
JOIN c IN f.FeaturesAndRoles
WHERE f.hostname = ‘HH-HOST-BETA’ and c.Installed and c.Name = ‘Hyper-V’
SELECT f.hostname, c.Name, c.Installed
FROM Computers f
JOIN c IN f.FeaturesAndRoles
WHERE c.Installed and c.Name = ‘Hyper-V’
SELECT f.hostname, c.Name, c.Installed
FROM Computers f
JOIN c IN f.FeaturesAndRoles
WHERE c.Installed and contains(c.Name, ‘Active’)
Now, traditionally if it were me, I’d provide the likes of a -Query parameter to my Query-Cosmos command, and pass in my own SQL command in there. But, I want my non-technical users instead not to have to do that.
I’d thought of (in the above examples) enabling them to somehow run queries like:
Query-Cosmos -Hostname 'HH-HOST-BETA' -FeaturesIncludes 'Hyper-V' | Select HostName, Name, Installed
Query-Cosmos -Hostname 'HH-HOST-BETA' -FeaturesIncludes 'Hyper-V' -KBInstalled '937576' -SoftwareInstalled "Acrobat"
and having my code do all the heavy lifting of assembling the SQL in the background, all nice and friendly.
But I can’t help but think there’s some other better way that means I don’t have to take care of all the different use cases (I built my database using this script) and added some more classes to it, removed some, added FeaturesAndRoles, such like. So I don’t want to have to try and skin-up a parameter for each and every one of those potential combinations.
A VERY cut-down sample of the data created by that script is linked here.
So, from that sample, you can see the sort of queries I might like to contrive to make could include “Get all servers in <domain> where active directory feature is installed, the spooler is not running and KB925673 is installed”.
Does anyone have any suggestions on the best method to approach to handle this? Like I say, I can write the queries no issue - it’s a best-method to approach the assembling of such things, maybe there’s some technique I’m unaware of. The only two ideas I’ve had are either getting them to make a legible query (and CosmosDB just returns a 400 with no hints as to what’s wrong if it doesn’t like it, so that’s out), or to have a parameter list that will go a long way towards my back-end code then turning that into a legit query. There must be another option I’ve not thought of (or more likely, a simple way to code the second option), I hope?
Appreciate this might be a tall order, but hey - you never know… !
Thanks!