【问题标题】:Getting timestamp from WAF/Kinesis to Elasticsearch从 WAF/Kinesis 获取时间戳到 Elasticsearch
【发布时间】:2019-03-11 03:40:55
【问题描述】:

我们正在尝试寻找如何将来自 AWS WAF/Kinesis Firehose 的时间戳转换为 Elasticsearch,使其类型为日期字段。创建索引映射时,它具有时间戳字段,但它是long 类型,尽管似乎有epoch_millis 类型的选项(这就是数据)。

Kibana 界面说使用映射 api 来更改字段类型,但我似乎无法弄清楚这一点。示例 here 展示了如何通过创建新索引来执行此操作,但 kinesis 正在创建/旋转索引,因此我们似乎需要一种方法来修改默认值。

字段如下所示

  "timestamp": {
    "type": "long"
  },

完整的索引定义看起来像这样,但这些又是定期创建的,所以我们试图弄清楚如何更改默认值

  "waf-prod-2018-10-05": {
    "mappings": {
      "waf-prod": {
        "properties": {
          "action": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "formatVersion": {
            "type": "long"
          },
          "httpRequest": {
            "properties": {
              "args": { 
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "clientIp": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "country": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "headers": {
                "properties": {
                  "name": {
                    "type": "text",
                    "fields": {
                      "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                      }
                    }
                  },
                  "value": {
                    "type": "text",
                    "fields": {
                      "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                      }
                    }
                  }
                }
              },
              "httpMethod": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "httpVersion": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "uri": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "httpSourceId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "httpSourceName": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "nonTerminatingMatchingRules": {
            "properties": {
              "action": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "ruleId": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "rateBasedRuleList": {
            "properties": {
              "limitKey": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "maxRateAllowed": {
                "type": "long"
              },
              "rateBasedRuleId": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "terminatingRuleId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "terminatingRuleType": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "timestamp": {
            "type": "long"
          },
          "webaclId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  },

【问题讨论】:

    标签: amazon-web-services elasticsearch amazon-kinesis-firehose amazon-waf


    【解决方案1】:

    只需将timestamp 格式添加到映射中:

    "timestamp": {
        "type": "date",
        "format": "epoch_millis"
    }
    

    【讨论】:

      【解决方案2】:

      模板的代码取决于您的 ES 版本。 如果您使用的是 7.x 版本。 您需要删除字段(映射类型字段,在您的情况下称为“waf-prod”)属性之前和映射之后。您可以尝试这样做(例如,这是我对 ES 7.x 的配置):

      PUT _template/template_waf-logs
      {
        "order": 0,
        "index_patterns": [
          "aws-waf-logs-detected-requests-*"
        ],
        "settings": {
          "index": {
            "number_of_shards": "1",
            "number_of_replicas": "0",
            "refresh_interval": "5s"
          }
        },
        "mappings": {
          "properties": {
            "httpRequest": {
              "properties": {
                "clientIp": {
                  "type": "keyword",
                  "fields": {
                    "keyword": {
                      "type": "ip"
                    }
                  }
                }
              }
            },
            "timestamp": {
              "type": "date",
              "format": "epoch_millis"
            }
          }
        }
      }
      
      1. 在此处查看 AWS 的文档:https://aws.amazon.com/blogs/security/how-to-analyze-aws-waf-logs-using-amazon-elasticsearch-service/
      2. 在此处使用 ES 社区的答案更新您的知识:https://discuss.elastic.co/t/root-mapping-definition-has-unsupported-parameters-when-creating-custom-index/240690

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-21
        • 1970-01-01
        • 2021-06-21
        • 2011-09-21
        • 2011-12-08
        • 2011-08-08
        相关资源
        最近更新 更多