Skip to content

Commit

Permalink
Update templates with valid fields (#1500)
Browse files Browse the repository at this point in the history
Add field validation to generation script
Add Nested document support
  • Loading branch information
ruflin authored and tsg committed Apr 27, 2016
1 parent 498a22f commit 42dbe6d
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 80 deletions.
19 changes: 17 additions & 2 deletions libbeat/scripts/generate_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ def fill_field_properties(field, defaults, path):
}

elif field["type"] in ["geo_point", "date", "long", "integer",
"double", "float", "keyword"]:
"double", "float", "keyword", "boolean"]:
properties[field["name"]] = {
"type": field.get("type")
}
if field["type"] == "keyword":
properties[field["name"]]["ignore_above"] = \
defaults.get("ignore_above", 1024)

elif field["type"] == "dict":
elif field["type"] in ["dict", "list"]:
if field.get("dict-type") == "keyword":
# add a dynamic template to set all members of
# the dict as keywords
Expand Down Expand Up @@ -198,6 +198,21 @@ def fill_field_properties(field, defaults, path):
properties[field.get("name")]["properties"] = prop

dynamic_templates.extend(dynamic)
elif field.get("type") == "nested":
if len(path) > 0:
path = path + "." + field["name"]
else:
path = field["name"]
prop, dynamic = fill_section_properties(field, defaults, path)

# Only add properties if they have a content
if len(prop) is not 0:
properties[field.get("name")] = {"type": "nested", "properties": {}}
properties[field.get("name")]["properties"] = prop

dynamic_templates.extend(dynamic)
else:
raise ValueError("Unkown type found: " + field.get("type"))

return properties, dynamic_templates

Expand Down
4 changes: 2 additions & 2 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Apache HTTPD server metrics collected from the mod_status module.

==== apache-status.hostname

type: string
type: keyword

Apache hostname

Expand Down Expand Up @@ -426,7 +426,7 @@ Redis cluster information

==== redis-info.cluster.cluster_enabled

type: bool
type: boolean

Indicate Redis cluster is enabled

Expand Down
4 changes: 2 additions & 2 deletions metricbeat/etc/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ apache:
page.
fields:
- name: hostname
type: string
type: keyword
description: >
Apache hostname
- name: totalAccesses
Expand Down Expand Up @@ -326,7 +326,7 @@ redis:
Redis cluster information
fields:
- name: cluster_enabled
type: bool
type: boolean
description: >
Indicate Redis cluster is enabled
Expand Down
11 changes: 11 additions & 0 deletions metricbeat/metricbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
}
}
},
"hostname": {
"ignore_above": 1024,
"type": "keyword"
},
"idleWorkers": {
"type": "integer"
},
Expand Down Expand Up @@ -210,6 +214,13 @@
}
}
},
"cluster": {
"properties": {
"cluster_enabled": {
"type": "boolean"
}
}
},
"cpu": {
"properties": {
"used_cpu_sys": {
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/apache/status/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
page.
fields:
- name: hostname
type: string
type: keyword
description: >
Apache hostname
- name: totalAccesses
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/redis/info/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Redis cluster information
fields:
- name: cluster_enabled
type: bool
type: boolean
description: >
Indicate Redis cluster is enabled
Expand Down
Loading

0 comments on commit 42dbe6d

Please sign in to comment.