Am trying to create a datatable in canvas , but Iam not sure how to execute this condition. I have a fields hostname and risk_factor (critical, high, medium, low ) and Iam trying to create a datable on top hosts basedon the count of risk factor like my picture for last 7 days, but am not sure how to implement it .Please help me to fix it .
SELECT fname, count() as total from "nessus-" where risk_factor = 'Critical' GROUP BY fname HAVING count(*) > 0 ORDER BY total DESC
But with this I can list only risk factor = critical but I would like to include other risk factor like High and medium in the same data table , but i dont how to do it . Same like my screenshot above.
So do an initial query that returns the hostnames and maybe the total count if they want that.
Then mapColumn to get the count for each severity level:
Some pseudocode:
| filters
| essql 'SELECT host from index'
| mapColumn name='Critical' fn={filters | essql 'SELECT host, count( <em>) from index where severity='CRITICAL'}
| mapColumn name='High' fn={filters | essql 'SELECT host, count(</em> ) from index where severity='HIGH'}
| mapColumn name='Medium' fn={filters | essql 'SELECT host, count( <em>) from index where severity='MEDIUM'}
| mapColumn name='Low' fn={filters | essql 'SELECT host, count(</em> ) from index where severity='LOW'}
| render
"name" is an actual argument to mapColumn so it should be name='Critical' not risk_factor='Critical' as the first argument to mapColumn.
Other than that you have some quotation problems in your query. In your WHERE clause use double quotes for risk_factor='Critical' and then remember to close out the query string with a single quote.
query="SELECT "@timestamp" + INTERVAL '1' HOURS as ABATime, "fname" as fname, "risk_factor" as risk_factor FROM "nessus-" WHERE "@timestamp" > NOW() - INTERVAL '7' DAYS ORDER BY ABATime DESC"
| mapColumn name='Critical' fn={filters | essql 'SELECT fname, count(*) FROM "nessus-" WHERE "risk_factor='CRITICAL'"}
| mapColumn name='High' fn={filters | essql 'SELECT fname, count(*) FROM "nessus-" WHERE "risk_factor='HIGH'"}
| mapColumn name='Medium' fn={filters | essql 'SELECT fname, count(*) FROM "nessus-" WHERE "risk_factor='MEDIUM'"}
| mapColumn name='Low' fn={filters | essql 'SELECT fname, count() FROM "nessus-" WHERE "risk_factor='LOW'"}
I've spent some time on this and the problem is that you can't hang on to the context at the individual row level, so in this case the sub-expression won't return the data you need. The best way to do this is to use ply so you can at least split out and group the numbers into unique rows.
Here's an example: filters | essql 'SELECT hostname, risk_factor, count(*) as "count" from secscan_sample_data group by hostname, risk_factor' | ply by="risk_factor" | render
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.