proc
Executes a user-defined procedure. When you pass arguments matching the parameter types defined in the procedure, the arguments are set as query parameters and the predefined query runs.
Command properties
| Item | Description |
|---|---|
| Command type | Driver query |
| Required permission | Procedure owner or user granted execution permission |
| License usage | Licensed command |
| Parallel execution | Not supported |
| Distributed execution | Not supported |
Syntax
Target
PROC_NAME(ARGS, ...)- Procedure name and argument list. Pass expressions that can be evaluated as constants as arguments, matching the parameter types defined in the procedure. The parameter types supported by procedures are as follows:
string: Stringint: 32-bit integerdouble: 64-bit floating-pointbool: Booleandate: Date. Pass a string in"yyyy-MM-dd"format or a date value; the time is truncated to00:00:00.datetime: Date and time. Pass a string in"yyyy-MM-dd HH:mm:ss"format or a date value.ip: IP address
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 11000 | The procedure cannot be found. | A procedure with the specified name does not exist |
| 11001 | The procedure variable type does not match. | The type of the passed argument differs from the procedure parameter type |
| 11002 | The procedure owner cannot be found. | The procedure owner account does not exist |
| 11003 | The number of procedure arguments does not match. | The number of passed arguments differs from the number of procedure parameters |
| 11004 | You do not have permission to execute the procedure. | You are not the procedure owner and have not been granted execution permission |
Runtime errors
N/A
Description
The proc command executes a previously registered procedure. A procedure consists of a query string and parameter definitions. When a procedure is called, the passed arguments are set as query parameters and the query defined in the procedure runs.
Only the procedure owner or a user granted execution permission can call the procedure. The internal query of the procedure runs with the procedure owner's permissions. This allows fine-grained control over access to specific queries.
You can reference parameter values in the procedure's internal query string using the $() function.
Examples
-
Calling a procedure
Register the following query as a procedure named
cpu_overloadin the web console.table duration=1d sys_cpu_logs | search kernel + user >= $("threshold")Then call the procedure as follows:
proc cpu_overload(90)The value
90is passed to thethresholdparameter, querying records where CPU usage is 90% or more. -
Calling a procedure with multiple parameters
Register the following query as a procedure named
search_logs. This procedure takessrc(string type) andmin_bytes(int type) as parameters.table duration=1d web_logs | search src_ip == $("src") and bytes >= $("min_bytes")Call it as follows:
proc search_logs("192.0.2.1", 1024)Queries records where
src_ipis192.0.2.1andbytesis 1,024 or more.