<source>
  @type tail
  path /var/log/kolla/openvswitch/ovs-vswitchd.log
  pos_file /var/run/fluentd/openvswitch.pos
  tag infra.openvswitch
  enable_watch_timer {{ fluentd_enable_watch_timer }}
  <parse>
    @type multiline
    format_firstline /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/
    format1 /^(?<Timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})Z\|\d{5,}\|(?<module>\S+)\|(?<log_level>\S+)\|(?<Payload>.*)/
    time_key Timestamp
    time_format %FT%T.%L
  </parse>
</source>

<source>
  @type tail
  path /var/log/kolla/openvswitch/ovsdb-server.log
  pos_file /var/run/fluentd/openvswitchdb.pos
  tag infra.openvswitchdb
  enable_watch_timer {{ fluentd_enable_watch_timer }}
  <parse>
    @type multiline
    format_firstline /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/
    format1 /^(?<Timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})Z\|\d{5,}\|(?<module>\S+)\|(?<log_level>\S+)\|(?<Payload>.*)/
    time_key Timestamp
    time_format %FT%T.%L
  </parse>
</source>

{% if enable_ovn | bool %}
{% if inventory_hostname in groups.get('ovn-controller', []) %}
<source>
  @type tail
  path /var/log/kolla/openvswitch/ovn-controller.log
  pos_file /var/run/fluentd/ovn-controller.pos
  tag infra.ovn_controller
  enable_watch_timer {{ fluentd_enable_watch_timer }}
  <parse>
    @type multiline
    format_firstline /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/
    format1 /^(?<Timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})Z\|\d{5,}\|(?<module>\S+)\|(?<log_level>\S+)\|(?<Payload>.*)/
    time_key Timestamp
    time_format %FT%T.%L
  </parse>
</source>
{% endif %}
{% for ovn_service in ['ovn-nb-db', 'ovn-northd', 'ovn-sb-db'] %}
{% if inventory_hostname in groups.get(ovn_service, []) %}

<source>
  @type tail
  path /var/log/kolla/openvswitch/{{ ovn_service }}.log
  pos_file /var/run/fluentd/{{ ovn_service }}.pos
  tag infra.{{ ovn_service | replace("-", "_") }}
  enable_watch_timer {{ fluentd_enable_watch_timer }}
  <parse>
    @type multiline
    format_firstline /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/
    format1 /^(?<Timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})Z\|\d{5,}\|(?<module>\S+)\|(?<log_level>\S+)\|(?<Payload>.*)/
    time_key Timestamp
    time_format %FT%T.%L
  </parse>
</source>
{% endif %}
{% endfor %}
{% for relay_id in range(1, ovn_sb_db_relay_count | int + 1) %}
{% if inventory_hostname in groups.get('ovn-sb-db-relay', []) %}
<source>
  @type tail
  path /var/log/kolla/openvswitch/ovn-sb-relay-{{ relay_id }}.log
  pos_file /var/run/fluentd/ovn-sb-relay-{{ relay_id }}.pos
  tag infra.ovn-sb-relay-{{ relay_id }}
  enable_watch_timer {{ fluentd_enable_watch_timer }}
  <parse>
    @type multiline
    format_firstline /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/
    format1 /^(?<Timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})Z\|\d{5,}\|(?<module>\S+)\|(?<log_level>\S+)\|(?<Payload>.*)/
    time_key Timestamp
    time_format %FT%T.%L
  </parse>
</source>
{% endif %}
{% endfor %}
{% endif %}
