Use the eval command to calculate the value of an expression and display the value in a new field.
Note
While the stats command calculates statistics based on
existing fields, the eval command creates new fields by
using existing fields and arbitrary expressions.
String processing functions like indexof and
substr are resource intensive. Due to this, running
the eval command with these functions against large
number of log records, or large field values is not recommended.
Instead, extract these values using the Extended Field Definitions (EFD)
or Labels in your Log Source. See Use Extended Fields in Sources and Use Labels in Sources.
Ensure that the field name used in the eval
command does not contain the characters [ and
].
dateset(date, property, value [,
property, value])
formatdate(date
[,format])
now()
Similar to where command, you can use human
readable string to manipulate time in the query. For example, to
create a new field named 10mins Later that's 10 minutes
ahead of the value in the Time field:
Note: md5 and sha
functions currently operate on the lower case field values.
Note
For the concat() function, you can input
numeric data types like integer, float, or long. The numeric fields with
be automatically converted to the corresponding string values.
You can use || to concatenate n
number of inputs. Here too, you can input numeric data types which will
be automatically converted to the corresponding string values.
Parameters
The following table lists the parameters used in this command, along
with their descriptions.
Parameter
Description
new_field_name
Specify the name of the field where the calculated
value of the expression is to be displayed.
expression
Specify the expression for which the value needs to
be calculated.
For examples of using this command in typical scenarios, see:
You can use the md5, sha1, sha256, and sha512 hash functions with the
eval command to filter log data. The following example sets the value of the field
user with the value sha1("jane").
*|eval user = sha1("jane")
The following example converts a hex to a decimal and n evaluates to 255:
* | eval n = toNumber('0xFF')
The following example converts an octal number to a decimal and n evaluates to
10:
* | eval 'Disk Read Time' = unit('Disk Read Time (millis)', ms) | stats avg('Disk Read Time') as 'Avg Disk Read Time'
Run the above three queries on Tile visualization with the option
Format Number checked, for the best results.
A field with a size or duration type unit would be used to format
the values in the Link Analyze chart, addfields histograms, Link Table, and Tile
visualization:
'Log Source' = 'FMW WebLogic Server Access Logs'
| link span = 5minute Time, Server
| stats avg('Duration') as 'Raw Avg. Duration'
avg('Content Size') as 'Raw Avg. Transfer Size'
| eval 'Average Duration' = unit('Raw Avg. Duration', ms)
| eval 'Average Transfer Size' = unit('Raw Avg. Transfer Size', byte)
| classify 'Start Time', 'Average Duration',
'Average Transfer Size' as 'Response Time vs. Download Sizes'
Mark a field as containing US Dollars, thousands of US Dollars, millions
of US Dollars, or billions of US Dollars, respectively:
| eval 'Amount in USD' = unit('Sales Price', currency_usd)
| eval 'Amount in Thousands (USD)' = usd('Quarterly Sales', currency_usd_thousand)
| eval 'Amount in Millions (USD)' = usd('Annual Profit', currency_usd_million)
| eval 'Amount in Billions (USD)' = usd('Annual Sales', currency_usd_billion)
Supported Types for the
unit Function
🔗
Unit Names:
PERCENT | PCT
Data size:
BYTE
KILOBYTE | KB
MEGABYTE | MB
GIGABYTE | GB
TERABYTE | TB
PETABYTE | PB
EXABYTE | EB
Time:
MILLISECOND | MS
S | SEC | SECS | SECOND | SECONDS
M | MIN | MINS | MINUTE | MINUTES
H | HR | HRS | HOUR | HOURS
D | DAY | DAYS
W | WEEK | WEEKS
MON | MONTH | MONTHS
Y | YR | YRS | YEAR | YEARS
MICRO | µs
Power:
WATT
KILOWATT | kW
MEGAWATT | MW
GIGAWATT | GW
TERAWATT | TW
PETAWATT | PW
EXAWATT | EW
Temperature:
KELVIN | K
CELSIUS | C
FAHRENHEIT | F
Frequency:
HERTZ | Hz
KILOHERTZ | kHz
MEGAHERTZ | MHz
GIGAHERTZ | GHz
TERAHERTZ | THz
PETAHERTZ | PHz
EXAHERTZ | EHz
Supported Currency Types in the
unit Function
🔗
You can use this function for eval command only under the
link command. See eval command example links for using
the function in typical scenarios.
Specify the currency unit using the following format:
The suffixes _k, _m and
_b are used to indicate the currency in thousands, millions or
billions, respectively. For a full list of currency codes, see ISO Standards.
NLS_Territory
Currency
AFGHANISTAN
AFN
ALBANIA
ALL
ALGERIA
DZD
AMERICA
USD
ANGOLA
AOA
ANTIGUA AND BARBUDA
XCD
ARGENTINA
ARS
ARMENIA
AMD
ARUBA
AWG
AUSTRALIA
AUD
AUSTRIA
EUR
AZERBAIJAN
AZN
BAHAMAS
BSD
BAHRAIN
BHD
BANGLADESH
BDT
BARBADOS
BBD
BELARUS
BYN
BELGIUM
EUR
BELIZE
BZD
BERMUDA
BMD
BOLIVIA
BOB
BOSNIA AND HERZEGOVINA
BAM
BOTSWANA
BWP
BRAZIL
BRL
BULGARIA
BGN
CAMBODIA
KHR
CAMEROON
XAF
CANADA
CAD
CAYMAN ISLANDS
KYD
CHILE
CLP
CHINA
CNY
COLOMBIA
COP
CONGO BRAZZAVILLE
XAF
CONGO KINSHASA
CDF
COSTA RICA
CRC
CROATIA
HRK
CURACAO
ANG
CYPRUS
EUR
CZECH REPUBLIC
CZK
DENMARK
DKK
DJIBOUTI
DJF
DOMINICA
XCD
DOMINICAN REPUBLIC
DOP
ECUADOR
USD
EGYPT
EGP
EL SALVADOR
SVC
ESTONIA
EUR
ETHIOPIA
ETB
FINLAND
EUR
FRANCE
EUR
FYR MACEDONIA
MKD
GABON
XAF
GEORGIA
GEL
GERMANY
EUR
GHANA
GHS
GREECE
EUR
GRENADA
XCD
GUATEMALA
GTQ
GUYANA
GYD
HAITI
HTG
HONDURAS
HNL
HONG KONG
HKD
HUNGARY
HUF
ICELAND
ISK
INDIA
INR
INDONESIA
IDR
IRAN
IRR
IRAQ
IQD
IRELAND
EUR
ISRAEL
ILS
ITALY
EUR
IVORY COAST
XOF
JAMAICA
JMD
JAPAN
JPY
JORDAN
JOD
KAZAKHSTAN
KZT
KENYA
KES
KOREA
KRW
KUWAIT
KWD
KYRGYZSTAN
KGS
LAOS
LAK
LATVIA
EUR
LEBANON
LBP
LIBYA
LYD
LIECHTENSTEIN
CHF
LITHUANIA
EUR
LUXEMBOURG
EUR
MACAO
MOP
MALAWI
MWK
MALAYSIA
MYR
MALDIVES
MVR
MALTA
EUR
MAURITANIA
MRU
MAURITIUS
MUR
MEXICO
MXN
MOLDOVA
MDL
MONTENEGRO
EUR
MOROCCO
MAD
MOZAMBIQUE
MZN
MYANMAR
MMK
NAMIBIA
NAD
NEPAL
NPR
NEW ZEALAND
NZD
NICARAGUA
NIO
NIGERIA
NGN
NORWAY
NOK
OMAN
OMR
PAKISTAN
PKR
PANAMA
PAB
PARAGUAY
PYG
PERU
PEN
PHILIPPINES
PHP
POLAND
PLN
PORTUGAL
EUR
PUERTO RICO
USD
QATAR
QAR
ROMANIA
RON
RUSSIA
RUB
SAINT KITTS AND NEVIS
XCD
SAINT LUCIA
XCD
SAUDI ARABIA
SAR
SENEGAL
XOF
SERBIA
RSD
SIERRA LEONE
SLL
SINGAPORE
SGD
SLOVAKIA
EUR
SLOVENIA
EUR
SOMALIA
SOS
SOUTH AFRICA
ZAR
SOUTH SUDAN
SSP
SPAIN
EUR
SRI LANKA
LKR
SUDAN
SDG
SURINAME
SRD
SWAZILAND
SZL
SWEDEN
SEK
SWITZERLAND
CHF
SYRIA
SYP
TAIWAN
TWD
TANZANIA
TZS
THAILAND
THB
THE NETHERLANDS
EUR
TRINIDAD AND TOBAGO
TTD
TUNISIA
TND
TURKEY
TRY
TURKMENISTAN
TMT
UGANDA
UGX
UKRAINE
UAH
UNITED ARAB EMIRATES
AED
UNITED KINGDOM
GBP
URUGUAY
UYU
UZBEKISTAN
UZS
VENEZUELA
VES
VIETNAM
VND
YEMEN
YER
ZAMBIA
ZMW
ZIMBABWE
ZWL
indexof Function
Details
🔗
The syntax for the index0f function:
indexof (String, String [,int])
indexof (String, String [,start_pos]): Index count begins with 0,
returns the index of match starting from the start_pos (if provided), and returns
-1 if no match.
The following example sets the value of the field newField
with the position of .com in the uri string.
*|eval newField = indexOf(uri, '.com')
Use Case: Extract the relevant portion of the API path from OCI Audit
Logs, Path field
The Path field contains a value like
/apis/coordination.k8s.io/v1/namespaces/default/leases/oracle.com-oci.
You can extract the value coordination.k8s from the above field by
following these steps:
Find the position of the first and second / using the
indexOf() function.
Find the position of the third /.
Extract the values after the second /, up to the third
/, using the substr() function.
lastindexof (String, String [, end_pos]): Index count begins with 0,
returns index of last occurrence of substring before the end_pos (if provided),
and returns -1 if no match. The end_pos argument is optional.
Some examples for using lastindexof function:
*|eval n = lastindexof(uri, '.com')
Use Case: Extract the Area from the Type field in OCI Audit Logs
The Type field contains a value like
com.oraclecloud.computeApi.GetInstance.
To extract computeAPI from the above value, you could use the following
scheme:
Identify the position of the last . using
lastIndexOf().
From this offset, identify the position of the previous ., using
another lastIndexOf(), but by providing the offset from where to
search back.
Extract the value between these two positions using substr().
substr(String, start_pos, end_pos - 1): index count begins with
start_pos and ends with the end_pos - 1.
In the following example, newField is the substring of
aabbcc where the start index (inclusive) is 2 and
end index (exclusive) is 4. Note that for strings, the index count
begins with 0. So the resulting substring is bb.