<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 一、前言 Logstash的配置文件支持各種條件判斷語法,條件查看和行為與編程語言中的條件相同。詳情可看[官方文檔](https://www.elastic.co/guide/en/logstash/7.x/event-dependent-configuration.html#conditionals) ## 二、條件語法 條件支持if,else if和else語句并且可以嵌套,語法如下: ~~~ if EXPRESSION { ... } else if EXPRESSION { ... } else { ... } ~~~ ### 2.1. 比較操作 * 相等:`==`,`!=`,`<`,`>`,`<=`,`>=` * 正則:`=~`(匹配正則),`!~`(不匹配正則) * 包含:`in`(包含),`not in`(不包含) ### 2.2. 布爾操作 * `and`(與),`or`(或),`nand`(非與),`xor`(非或) ### 2.3. 一元運算符 表達式可能很長且很復雜。表達式可以包含其他表達式,您可以使用!來取反表達式,并且可以使用括號(...)對它們進行分組。 * `!`(取反) * `()`(復合表達式),`!()`(對復合表達式結果取反) ## 三、案例 ### 3.1. 如若`action`的值是`login`,則通過`mutate`filter刪除`secret`字段: ~~~ filter { if [action] == "login" { mutate { remove_field => "secret" } } } ~~~ ### 3.2. 若是需要通過正則匹配(即,當if的表達式為正則時),匹配成功后添加自定義字段: ~~~ filter { if [message] =~ /\w+\s+\/\w+(\/learner\/course\/)/ { mutate { add_field => { "learner_type" => "course" } } } } ~~~ ### 3.3. 在一個條件里指定多個表達式: ~~~ output { # Send production errors to pagerduty if [loglevel] == "ERROR" and [deployment] == "production" { pagerduty { ... } } } ~~~ ### 3.4. 在in條件,可以比較字段值: ~~~ filter { if [foo] in [foobar] { mutate { add_tag => "field in field" } } if [foo] in "foo" { mutate { add_tag => "field in string" } } if "hello" in [greeting] { mutate { add_tag => "string in field" } } if [foo] in ["hello", "world", "foo"] { mutate { add_tag => "field in list" } } if [missing] in [alsomissing] { mutate { add_tag => "shouldnotexist" } } if !("foo" in ["hello", "world"]) { mutate { add_tag => "shouldexist" } } } ~~~ ### 3.5. not in示例: ~~~ output { if "_grokparsefailure" not in [tags] { elasticsearch { ... } } } ~~~ ### 3.6. @metadata field 在logstash1.5版本開始,有一個特殊的字段,叫做@metadata。@metadata包含的內容不會作為事件的一部分輸出。 ~~~ input { stdin { } } filter { mutate { add_field => { "show" => "This data will be in the output" } } mutate { add_field => { "[@metadata][test]" => "Hello" } } mutate { add_field => { "[@metadata][no_show]" => "This data will not be in the output" } } } output { if [@metadata][test] == "Hello" { stdout { codec => rubydebug } } } ~~~ 輸出結果 ~~~ $ bin/logstash -f ../test.conf Pipeline main started asdf { "@timestamp" => 2016-06-30T02:42:51.496Z, "@version" => "1", "host" => "windcoder.com", "show" => "This data will be in the output", "message" => "asdf" } ~~~ "asdf"變成message字段內容。條件與@metadata內嵌的test字段內容判斷成功,但是輸出并沒有展示@metadata字段和其內容。 不過,如果指定了metadata => true,rubydebug codec允許顯示@metadata字段的內容。 ~~~ stdout { codec => rubydebug { metadata => true } } ~~~ 輸出結果 ~~~ $ bin/logstash -f ../test.conf Pipeline main started asdf { "@timestamp" => 2016-06-30T02:46:48.565Z, "@metadata字段及其子字段內容。" => { "test" => "Hello", "no_show" => "This data will not be in the output" }, "@version" => "1", "host" => "windcoder.com", "show" => "This data will be in the output", "message" => "asdf" } ~~~ 現在就可以見到@metadata字段及其子字段內容。 只有rubydebug codec允許顯示@metadata字段的內容。 只要您需要臨時字段但不希望它在最終輸出中,就可以使用@metadata字段。 最常見的情景是filter的時間字段,需要一臨時的時間戳。如: ~~~ input { stdin { } } filter { grok { match => [ "message", "%{HTTPDATE:[@metadata][timestamp]}" ] } date { match => [ "[@metadata][timestamp]", "dd/MMM/yyyy:HH:mm:ss Z" ] } } output { stdout { codec => rubydebug } } ~~~ 輸出結果 ~~~ $ bin/logstash -f ../test.conf Pipeline main started 02/Mar/2014:15:36:43 +0100 { "@timestamp" => 2014-03-02T14:36:43.000Z, "@version" => "1", "host" => "windcoder.com", "message" => "02/Mar/2014:15:36:43 +0100" } ~~~ 上一篇:[Gro](http://www.hmoore.net/zlt2000/microservices-platform/2139576)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看