컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
strings.coalesce
strings.coalesce(a, b, c, ...)
설명
이 함수는 인수를 무제한으로 사용하고 빈 문자열로 평가되지 않는 첫 번째 표현식의 값을 반환합니다(예: '0이 아닌 값'). 모든 인수가 빈 문자열로 평가되면 함수 호출에서 빈 문자열을 반환합니다.
인수는 리터럴, 이벤트 필드 또는 함수 호출일 수 있습니다. 모든 인수는 STRING
유형이어야 합니다. 인수가 이벤트 필드인 경우 속성은 동일한 이벤트에서 생성되어야 합니다.
매개변수 데이터 유형
STRING
반환 유형
STRING
코드 샘플
예 1
다음 예시에는 문자열 변수를 인수로 포함합니다. (1) $e.network.email.from
이 suspicious@gmail.com
이거나 (2) $e.network.email.from
이 비어 있고 $e.network.email.to
가 suspicious@gmail.com
이면 조건이 True로 평가됩니다.
"suspicious@gmail.com" = strings.coalesce($e.network.email.from, $e.network.email.to)
예 2
다음 예시에서는 인수가 3개 이상 있는 coalesce
함수를 호출합니다. 이 조건은 $e
이벤트에서 null이 아닌 첫 번째 IP 주소를 참조 목록 ip_watchlist
의 값과 비교합니다. 이 호출에서 인수가 병합되는 순서는 규칙 조건에 열거되는 순서와 같습니다.
$e.principal.ip
가 먼저 평가됩니다.
$e.src.ip
가 다음에 평가됩니다.
$e.target.ip
가 다음에 평가됩니다.
- 마지막으로, 이전
ip
필드가 설정되지 않은 경우 'No IP' 문자열이 기본값으로 반환됩니다.
strings.coalesce($e.principal.ip, $e.src.ip, $e.target.ip, "No IP") in %ip_watchlist
예 3
다음 예시에서는 이벤트 $e1
및 이벤트 $e2
의 principal.hostname
을 병합하려고 시도합니다. 인수가 서로 다른 이벤트 변수이므로 컴파일러 오류가 반환됩니다.
// returns a compiler error
"test" = strings.coalesce($e1.principal.hostname, $e2.principal.hostname)
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-29(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-29(UTC)"],[[["\u003cp\u003e\u003ccode\u003estrings.coalesce\u003c/code\u003e returns the first non-empty string from a list of arguments, or an empty string if all arguments are empty.\u003c/p\u003e\n"],["\u003cp\u003eThe function accepts an unlimited number of \u003ccode\u003eSTRING\u003c/code\u003e arguments, which can be literals, event fields, or function calls, as long as they are all of \u003ccode\u003eSTRING\u003c/code\u003e type.\u003c/p\u003e\n"],["\u003cp\u003eWhen using event fields as arguments, all attributes must originate from the same event.\u003c/p\u003e\n"],["\u003cp\u003eThe order of argument evaluation is sequential, as shown in the second example, with the first non-empty string being returned, and if none are met, the last option is returned.\u003c/p\u003e\n"],["\u003cp\u003eThe function is compatible with both Rules and Search functionalities.\u003c/p\u003e\n"]]],[],null,["### strings.coalesce\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search) \n\n strings.coalesce(a, b, c, ...)\n\n#### Description\n\nThis function takes an unlimited number of arguments and returns the value of the first expression that does not evaluate to an empty string (for example, \"non-zero value\"). If all arguments evaluate to an empty string, the function call returns an empty string.\n\nThe arguments can be literals, event fields, or function calls. All arguments must be of `STRING` type. If any arguments are event fields, the attributes must be from the same event.\n\n#### Param data types\n\n`STRING`\n\n#### Return type\n\n`STRING`\n\n#### Code samples\n\n##### Example 1\n\nThe following example includes string variables as arguments. The condition\nevaluates to true when (1) `$e.network.email.from` is `suspicious@gmail.com` or\n(2) `$e.network.email.from` is empty and `$e.network.email.to` is\n`suspicious@gmail.com`. \n\n \"suspicious@gmail.com\" = strings.coalesce($e.network.email.from, $e.network.email.to)\n\n##### Example 2\n\nThe following example calls the `coalesce` function with more than two\narguments. This condition compares the first non-null IP address from event `$e`\nagainst values in the reference list `ip_watchlist`. The order that the\narguments are coalesced in this call is the same as the order they are\nenumerated in the rule condition:\n\n1. `$e.principal.ip` is evaluated first.\n2. `$e.src.ip` is evaluated next.\n3. `$e.target.ip` is evaluated next.\n4. Finally, the string \"No IP\" is returned as a default value if the previous `ip` fields are unset.\n\n strings.coalesce($e.principal.ip, $e.src.ip, $e.target.ip, \"No IP\") in %ip_watchlist\n\n##### Example 3\n\nThe following example attempts to coalesce `principal.hostname` from event\n`$e1` and event `$e2`. It will return a compiler error because the arguments are\ndifferent event variables. \n\n // returns a compiler error\n \"test\" = strings.coalesce($e1.principal.hostname, $e2.principal.hostname)"]]