if operator と
Sumo Logic のクエリで使用できる三項式には 2 つの形式があります。1 つは IF operator を使用し、もう 1 つは疑問符 (?) operator を使用して式を組み立てます。式は少し異なりますが、結果は同じです。使いやすい構文を使用してください。
これらの式は、条件を true または false で評価します。値は各結果に割り当てられます。if-else 条件を簡単に表現するための方法です。テストに基づき、条件が真であれば式全体は value_if_true を返し、偽であれば value_if_false を返します。2 つのサブ式 (value_if_true と value_if_false) は同じ型でなければなりません。
構文
if(<condition>, <value_if_true>, <value_if_false>) as <field>
例
| if(status_code matches "5*", 1, 0) as serverError
| if(status_code matches "2*", 1, 0) as success
- | if(!(status_code matches "2*"), 1, 0) as failure
- | if(status matches "WARN" or status matches "ERROR", 1, 0) as status
- | if(alpha > 1 and beta > 5, "true", "false") as conditionState
ネスト化 if ステートメント (if...elseif...else)
ネスト化 if ステートメントを作成するには、クエリで次の構文を使用します。
| if(message matches "*/schedule?*","Alert Scheduled",
if(message matches "*/update?*","Alert Updated",
if(message matches "*/cancel?*","Alert Canceled","N/A"))) as problem
疑問符 (?) operator の使用
構文
| <field> = <condition> ? <value_if_true> : <value_if_false>
例
disk_usage > threshold ? "disk full" : "OK" as status
!(disk_usage > threshold) ? "disk full" : "OK" as status
a < b ? a : b // This is the same as min(a, b)
null 値の処理については isNull operator を参照してください。