November 4, 2016 By Mutaz Alsallal 3 min read

QRadar uses Ariel Query Language (AQL), a structured query language that can be used to manipulate event and flow data from the Ariel database.

To retrieve events in QRadar, for example, you can execute the following simple AQL query in the QRadar log activity tab: Select * from events. In addition, user-defined functions are very useful when a custom function is required to perform complex calculations or specific formatting before the data is available for a report.

Importing User-Defined AQL Functions in QRadar

AQL features several built-in functions to perform calculations and formatting on data, such as MIN, MAX, AVG, SUM, REPLACEALL, SUBSTRING, LOWER, UPPER, CONCAT and more. These functions can be called within your AQL query statement. The following query, for example, will return the usernames in lowercase text:

SELECT LOWER(username) from events

For more complex endeavors, however, it can be beneficial to import user-defined AQL functions in QRadar and use them in the query statements. You can call it like this:

User/Custom Defined Functions

Stored/Local Procedures

These functions are very useful when you need to perform complex calculations or are formatting data retrieved from the Ariel databases. They can be written using JavaScript.

Below are two simple examples to show you how to import user-defined AQL functions in QRadar and how to use them within AQL queries.

Example One: A Simple Function

Let’s say I want a function to add two numbers — just a simple function. Below is the function written in JavaScript. We have to import it intro QRadar using the following XML structure:

Save the above XML as CustomFunctionAdd.xml and compress it as a ZIP file, like so: RegExTextExtractor.zip.

To add any custom AQL functions to QRadar, you can use the Extensions Management tool from the admin tab in QRadar or the Content Management Tool (CMT). From the admin tab, open the Extensions Management tool, click “add button” in the top right corner and choose the ZIP file as follows. Don’t forget to check “Install immediately.”

After that, the function will be imported into QRadar to be used with our AQL queries. We can call the function like this:

select MYCUSTOM::ADDNUMBERS(2,8,90,1) As “Add operation result” from events limit 1

Example Two: Extracting Text That Matches a RegEx

Let’s say I need a function to extract the text that matches a regular expression (RegEx) from the event payload. Below is the XML structure and the JavaScript function to extract the text with the capture group number:

To add the above function, as with the previous example, save the XML structure as RegExTextExtractor.xml, then compress it as RegExTextExtractor.zip. After that, you can import it into QRadar using the Extensions Management tool in the admin tab.

Example Three: Putting It All Together

The following is an AQL example that shows how to use the above user-defined function to extract a text that matches a RegEx. Let’s say, for example, I have the following string in an event payload: “Without data you’re just another person with an opinion 437199.” I want to extract the numbers at the end and return them using AQL query:

Select MYCUSTOM::REGEXTEXTEXTRACTOR(‘Without data youre just another person with an opinion 437199’, ‘[a-zA-Z ]+(\d*)’, ‘1’) As “ExtractedNumber” from events limit 1

To learn more, check out this video that explains how to add and use custom AQL functions, prepared by our security architect, Jose Bravo.

Special thanks to Colin Hay.

More from Intelligence & Analytics

New report shows ongoing gender pay gap in cybersecurity

3 min read - The gender gap in cybersecurity isn’t a new issue. The lack of women in cybersecurity and IT has been making headlines for years — even decades. While progress has been made, there is still significant work to do, especially regarding salary.The recent  ISC2 Cybersecurity Workforce Study highlighted numerous cybersecurity issues regarding women in the field. In fact, only 17% of the 14,865 respondents to the survey were women.Pay gap between men and womenOne of the most concerning disparities revealed by…

Protecting your data and environment from unknown external risks

3 min read - Cybersecurity professionals always keep their eye out for trends and patterns to stay one step ahead of cyber criminals. The IBM X-Force does the same when working with customers. Over the past few years, clients have often asked the team about threats outside their internal environment, such as data leakage, brand impersonation, stolen credentials and phishing sites. To help customers overcome these often unknown and unexpected risks that are often outside of their control, the team created Cyber Exposure Insights…

X-Force Threat Intelligence Index 2024 reveals stolen credentials as top risk, with AI attacks on the horizon

4 min read - Every year, IBM X-Force analysts assess the data collected across all our security disciplines to create the IBM X-Force Threat Intelligence Index, our annual report that plots changes in the cyber threat landscape to reveal trends and help clients proactively put security measures in place. Among the many noteworthy findings in the 2024 edition of the X-Force report, three major trends stand out that we’re advising security professionals and CISOs to observe: A sharp increase in abuse of valid accounts…

Topic updates

Get email updates and stay ahead of the latest threats to the security landscape, thought leadership and research.
Subscribe today