mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-05-09 21:02:36 +02:00
Make Telegraf Postgres templates idempotent
Use CREATE TABLE IF NOT EXISTS and a WHERE-guarded create_parent() so a Telegraf restart can re-run the templates safely after manual DB surgery. Add an explicit tag_table_create_templates mirroring the plugin default with IF NOT EXISTS for the same reason.
This commit is contained in:
@@ -114,10 +114,15 @@
|
||||
# ALTER it before create_parent(). And create_parent() splits
|
||||
# p_parent_table on '.' to look up raw identifiers, so the literal must
|
||||
# be 'schema.name' (not '"schema"."name"' as .table|quoteLiteral emits).
|
||||
# IF NOT EXISTS keeps the three templates idempotent so a Telegraf
|
||||
# restart after any DB-side surgery re-runs them safely.
|
||||
create_templates = [
|
||||
'''CREATE TABLE {{ .table }} ({{ .columns }}) PARTITION BY RANGE ("time")''',
|
||||
'''CREATE TABLE IF NOT EXISTS {{ .table }} ({{ .columns }}) PARTITION BY RANGE ("time")''',
|
||||
'''ALTER TABLE {{ .table }} ALTER COLUMN "time" SET NOT NULL''',
|
||||
'''SELECT partman.create_parent(p_parent_table := {{ printf "%s.%s" .table.Schema .table.Name | quoteLiteral }}, p_control := 'time', p_type := 'range', p_interval := '1 day', p_premake := 3)'''
|
||||
'''SELECT partman.create_parent(p_parent_table := {{ printf "%s.%s" .table.Schema .table.Name | quoteLiteral }}, p_control := 'time', p_type := 'range', p_interval := '1 day', p_premake := 3) WHERE NOT EXISTS (SELECT 1 FROM partman.part_config WHERE parent_table = {{ printf "%s.%s" .table.Schema .table.Name | quoteLiteral }})'''
|
||||
]
|
||||
tag_table_create_templates = [
|
||||
'''CREATE TABLE IF NOT EXISTS {{ .table }} ({{ .columns }}, PRIMARY KEY (tag_id))'''
|
||||
]
|
||||
{% endraw %}
|
||||
{%- endif %}
|
||||
|
||||
Reference in New Issue
Block a user