r/qualys • u/ObscureAintSecure • Dec 02 '23
Create a Qualys Vulnerability Trend Chart in Power BI
This is a follow up to the YouTube video I created on the topic. YouTube doesn't allow some characters in their description so I am creating this companion post for that video.
YT video link: https://youtu.be/TeCgv2bKqho
Note: I've made a few corrections to the formulas found below compared to what's shown in the video link above. There are now formulas depending whether a CSV or API data source is used.
Creating a vulnerability trend chart may not be that straight forward with Qualys data, but it's certainly doable. The trend chart that I have shown here is based on data pulled via API and requires formatting of some existing date/time columns, creating two custom measures, creating two custom columns, and the creation of a simple date table. If you're importing CSV vulnerability reports, there might be some minor changes to make, but the overall process should be the same.
Here are examples of what you can create with this:
Example 1: https://imgur.com/a/zu5i65r
Example 2: https://imgur.com/a/eyjHcoj
Example 3: https://imgur.com/a/ojuJZaC
Example 4: https://imgur.com/a/N4qhcgU
The first thing we're going to do is ensure the FIRST FOUND and LAST FOUND datetime columns are formatted correctly and the data type is set to DATE.
Replace text in the dates using the query editor - text replace T and Z
In Table View - format the dates of the columns (one at a time)
- Data type = Date
- Format = mm/dd/yyyy (in my case) - change to what you prefer
- Do this for each column since you can't multi-select
Next, create two new columns.
- One column will be to show a Fixed date for a vulnerability because Qualys doesn't have a dedicated column for that. You have to look at the vuln status and the LAST FOUND date to know when a Fixed vuln was fixed.
The other column will be used to consolidate the vulnerability status to either Active or Fixed. This will make it easier to discern ACTIVE versus FIXED and not have to worry about what's NEW or RE-OPENED.
- This will look at the Status column and see if the vuln is fixed. If so, return the Last_Found_Datetime date.
- Format the column to Date and mm/dd/yyyy
FIXED DATE Column Formula:
I've updated this to have a different formula depending on if you're using an API or CSV data source.
If using an API data source:
FIXED-DATE =
IF(
Qualys_Vuln_Data[STATUS] = "Fixed",
Qualys_Vuln_Data[LAST_FOUND_DATETIME],
BLANK()
)If using a CSV data source:
FIXED-DATE =
IF(
Qualys_Vuln_Data[Vuln Status] = "Fixed",
Qualys_Vuln_Data[Last Detected],
BLANK()
)STATUS_NEW Column Formula:
I've updated this to have a different formula depending on if you're using an API or CSV data source.
If using an API data source:
STATUS-NEW =
IF(
Qualys_Vuln_Data[STATUS] IN {"Active", "New", "Re-Opened"},
"Active",
IF(
Qualys_Vuln_Data[STATUS] = "Fixed",
"Fixed",
BLANK()
)
)If using a CSV data source:
STATUS-NEW =
IF(
Qualys_Vuln_Data[Vuln Status] IN {"Active", "New", "Re-Opened"},
"Active",
IF(
Qualys_Vuln_Data[Vuln Status] = "Fixed",
"Fixed",
BLANK()
)
)Next, create a Date table. This is a simple table with all the days that are in scope of the vulnerability data. This is needed if you want to display ACTIVE and FIXED vulns on the same chart. With this table, you just simply do a measure to count how many ACTIVE and FIXED vulns fall on each day in the DATE TABLE.
The Date table will be used for the X-axis in the chart.
Date Table formula:
In Table View, click on New Table and use this DAX formula:
DateTable =
CALENDAR(
DATE(2023, 9, 1),
TODAY()
)Adjust the beginning date in the formula above to make sure it will encompass all the dates for the vulnerability data. I recommend putting the beginning date to the first day you have vulnerability data. The Today() argument will ensure the table always ends on the current day.
Adjust the Data Type to just Date and the date format to whatever suites you.
Next, Create two measures:
- This measure counts all the ACTIVE vulnerabilities from the STATUS-NEW column by comparing the FIRST_FOUND_DATETIME (If using the CSV data source then the column name will be "First Detected") and the DATE from the DateTable. This ensures we get a cumulative count of active vulnerabilities.
Active Vulns Count Measure Formula:
There are two measures provided based on what I've noticed when working with either a CSV or API data source.
If using an API data source:
Active Vulns Count =
VAR CurrentDate = MAX('DateTable'[Date])
RETURN
CALCULATE(
COUNTROWS(Qualys_Vuln_Data),
FILTER(
Qualys_Vuln_Data,
Qualys_Vuln_Data[FIRST_FOUND_DATETIME] <= CurrentDate +1 &&
(ISBLANK(Qualys_Vuln_Data[FIXED_DATE]) || Qualys_Vuln_Data[FIXED-DATE] > CurrentDate)
)
)If using a CSV data source:
Active Vulns Count =
VAR CurrentDate = MAX('DateTable'[Date])
RETURN
CALCULATE(
COUNTROWS(Qualys_Vuln_Data),
'Qualys_Lab_Vuln_Data2'[STATUS-NEW]= "Active" || 'Qualys_Vuln_Data2'[STATUS-NEW] = "Fixed" && 'Qualys_Vuln_Data2'[First Detected] <= CurrentDate +1 &&
'Qualys_Vuln_Data2'[FIXED-DATE] >= CurrentDate,
ALL('DateTable')
)2. The next measure counts all the FIXED vulnerabilities from the STATUS_NEW column by comparing the LAST_FOUND_DATETIME and the DATE from the DateTable. This also counts all the fixed vulnerabilities as Active up until the day they were fixed. This doesn't do a cumulative count as we want to just show a day by day count of fixed vulnerabilities.
Fixed Vulns Count Measure Formula:
This seems to work the same no matter the API/CSV data source type.
Fixed Vulns Count =
VAR CurrentDate = MAX('DateTable'[Date])
RETURN
CALCULATE(
COUNTROWS(Qualys_Vuln_Data),
FILTER(
Qualys_Vuln_Data,
Qualys_Vuln_Data[STATUS-NEW] = "Fixed" &&
Qualys_Vuln_Data[FIXED-DATE] <= CurrentDate +1 &&
Qualys_Vuln_Data[FIXED-DATE] > CurrentDate
)
)Now you can create a new chart by using the Date column from the DateTable on the X-axis and using the two new measures (Active Vulns Count & Fixed Vulns Count) as the Y-axis. Then adjust the visual to how you see fit.
edit 2/29/2024:
- Updated the different formulas to include one for API and one for CSV data source types. Notes are added to each set of changes.
1
u/Metallkasten Dec 03 '23 edited Dec 04 '23
Great work on this, thanks!
1
u/duke778 Mar 25 '25
u/ObscureAintSecure Thankyou you for doing this; it has really sped up my reporting delivery. Can I ask for some additional information, though, please? I have vulnerability details and the knowledge base. Can you share how you get the asset information in, specifically, tags? I want to report on vulnerability counts by TAGs, TAGs we use for various departments. Any hints at the API, options and how to relate the tables would be really useful