|
23 | 23 | src: "{{ role_path }}/templates/clf-instance.yml.j2" |
24 | 24 | dest: "{{ role_path }}/files/clf-instance.yml" |
25 | 25 | delegate_to: localhost |
| 26 | + when: clo_version | float < 6.0 |
| 27 | + |
| 28 | +- name: Generating ClusterLogForwarder file |
| 29 | + template: |
| 30 | + src: "{{ role_path }}/templates/new-clf-instance.yml.j2" |
| 31 | + dest: "{{ role_path }}/files/new-clf-instance.yml" |
| 32 | + delegate_to: localhost |
| 33 | + when: clo_version | float >= 6.0 |
26 | 34 |
|
27 | 35 | # Creating ClusterLogForwarder custom resource |
28 | 36 | - include_tasks: "{{ role_path }}/files/clf-instance.yml" |
| 37 | + when: clo_version | float < 6.0 |
| 38 | + |
| 39 | +- include_tasks: "{{ role_path }}/files/new-clf-instance.yml" |
| 40 | + when: clo_version | float >= 6.0 |
29 | 41 |
|
30 | 42 | # Check if the pods are in good state |
31 | 43 | - name: Check the logging pods are in good state |
|
65 | 77 | - "loki" |
66 | 78 | - "cloudwatch" |
67 | 79 | - "kibana-ldap" |
| 80 | + - "lokistack" |
68 | 81 |
|
69 | 82 | - set_fact: |
70 | 83 | syslog_server_logfile: "/var/log/messages" |
71 | 84 | external_server_logs_path: "/root/clf_logs" |
72 | 85 |
|
| 86 | +- name: Pause for 2 minutes to get new logs |
| 87 | + pause: |
| 88 | + minutes: 2 |
| 89 | + |
73 | 90 | - name: Fetch the logs from external instances |
74 | 91 | block: |
75 | 92 | # Save the logs on external Kafka system and fetch on bastion |
76 | 93 | - block: |
77 | 94 | - name: Save the logs on Kafka server |
78 | 95 | shell: | |
79 | 96 | mkdir -p {{ external_server_logs_path }}/kafka |
80 | | - {{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ log_labels }}-audit --max-messages 10 > {{ external_server_logs_path }}/kafka/audit.txt |
81 | | - {{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ log_labels }}-infrastructure --max-messages 10 > {{ external_server_logs_path }}/kafka/infrastructure.txt |
82 | | - {{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ log_labels }}-application --max-messages 10 > {{ external_server_logs_path }}/kafka/application.txt |
83 | | - async: 30 |
84 | | - poll: 5 |
| 97 | + {{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ app_log_label }} --max-messages 10 > {{ external_server_logs_path }}/kafka/application.txt |
| 98 | + {{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ audit_log_label }} --max-messages 10 > {{ external_server_logs_path }}/kafka/audit.txt |
| 99 | + {{ kafka_path }}/kafka-console-consumer.sh --bootstrap-server {{ kafka_host }}:9092 --topic {{ infra_log_label }} --max-messages 10 > {{ external_server_logs_path }}/kafka/infrastructure.txt |
| 100 | + async: 120 |
| 101 | + poll: 10 |
85 | 102 |
|
86 | 103 | - name: Copy the logs file from Kafka to bastion |
87 | 104 | fetch: |
|
95 | 112 | delegate_to: kafka |
96 | 113 | when: kafka_server_url is defined |
97 | 114 |
|
| 115 | + #Make lokistack.sh file executable |
| 116 | + - name: Give executable permissions for lokistack.sh file |
| 117 | + file: |
| 118 | + path: "{{ role_path }}/files/lokistack.sh" |
| 119 | + mode: '0555' |
| 120 | + state: file |
| 121 | + |
| 122 | + # Check if lokistack exists |
| 123 | + - name: Check the Lokistack |
| 124 | + shell: oc get lokistack -n openshift-logging | grep lokistack | awk 'NR==1{print $1}' |
| 125 | + register: lokistack_present |
| 126 | + |
| 127 | + # Save the logs on external lokistack and fetch on bastion |
| 128 | + - name: Save the logs for lokistack instance |
| 129 | + shell: | |
| 130 | + echo "{{ lokistack_present.stdout }}" |
| 131 | + mkdir -p {{ cl_log_dir }}/lokistack |
| 132 | + {{ role_path }}/files/lokistack.sh {{ lokistack_present.stdout }} |
| 133 | + when: lokistack_present.stdout|length > 0 |
| 134 | + |
98 | 135 | # Save the logs on external Syslog system and fecth on bastion |
99 | 136 | - block: |
100 | 137 | - name: Save the logs on external Syslog instance |
|
123 | 160 | # Fetch logs from Elasticsearch |
124 | 161 | - name: Fetch Logs from Elasticsearch |
125 | 162 | shell: | |
126 | | - curl -XGET "{{ elasticsearch_server_url }}/infra*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ log_labels }}-infrastructure"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/infrastructure.txt |
127 | | - curl -XGET "{{ elasticsearch_server_url }}/audit*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ log_labels }}-audit"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/audit.txt |
128 | | - curl -XGET "{{ elasticsearch_server_url }}/app*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ log_labels }}-application"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/application.txt |
129 | | - when: elasticsearch_server_url is defined |
| 163 | + curl -XGET "{{ elasticsearch_server_url }}/infra*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.label":"{{ infra_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/infrastructure.txt |
| 164 | + curl -XGET "{{ elasticsearch_server_url }}/audit*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.label":"{{ audit_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/audit.txt |
| 165 | + curl -XGET "{{ elasticsearch_server_url }}/app*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.label":"{{ app_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/application.txt |
| 166 | + when: |
| 167 | + - elasticsearch_server_url is defined |
| 168 | + - clo_version | float >= 6.0 |
| 169 | + |
| 170 | + - name: Fetch Logs from Elasticsearch |
| 171 | + shell: | |
| 172 | + curl -XGET "{{ elasticsearch_server_url }}/infra*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ infra_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/infrastructure.txt |
| 173 | + curl -XGET "{{ elasticsearch_server_url }}/audit*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ audit_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/audit.txt |
| 174 | + curl -XGET "{{ elasticsearch_server_url }}/app*/_search" -H 'Content-Type: application/json' -d '{ "query": { "bool": { "must": [ { "match":{"openshift.labels.logs":"{{ app_log_label }}"} } ] } } }' > {{ cl_log_dir }}/elasticsearch/application.txt |
| 175 | + when: |
| 176 | + - elasticsearch_server_url is defined |
| 177 | + - clo_version | float <= 5.9 |
130 | 178 |
|
131 | 179 | # Fetch logs from Loki |
132 | 180 | - name: Fetch logs from Loki |
133 | 181 | shell: | |
134 | 182 | curl -G -s "{{ loki_server_url }}/api/prom/query" --data-urlencode 'query={log_type="infrastructure"}' > {{ cl_log_dir }}/loki/infrastructure.txt |
135 | 183 | curl -G -s "{{ loki_server_url }}/api/prom/query" --data-urlencode 'query={log_type="audit"}' > {{ cl_log_dir }}/loki/audit.txt |
136 | 184 | curl -G -s "{{ loki_server_url }}/api/prom/query" --data-urlencode 'query={log_type="application"}' > {{ cl_log_dir }}/loki/application.txt |
| 185 | + async: 120 |
| 186 | + poll: 10 |
137 | 187 | when: loki_server_url is defined |
138 | 188 |
|
139 | 189 | # Deleting CLF Custom Resource instance because Fluentd and CloudWatch stores the logs on their system |
140 | 190 | - name: Delete ClusterLogForwarder |
141 | 191 | shell: oc delete ClusterLogForwarder instance -n openshift-logging |
| 192 | + when: clo_version | float <= 5.9 |
| 193 | + |
| 194 | + - name: Delete ClusterLogForwarder |
| 195 | + shell: oc delete obsclf collector -n openshift-logging |
| 196 | + when: clo_version | float >= 6.0 |
142 | 197 |
|
143 | 198 | - name: Check the logging pods are restarting |
144 | 199 | shell: oc get pods -n openshift-logging --no-headers | awk '{if ($3 == "Terminating" ) print $1}' | wc -l |
|
216 | 271 |
|
217 | 272 | - name: Elasticsearch clean up |
218 | 273 | shell: | |
219 | | - curl -X POST "{{ elasticsearch_server_url }}/audit*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ log_labels }}-audit" } }}' |
220 | | - curl -X POST "{{ elasticsearch_server_url }}/app*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ log_labels }}-application" } }}' |
221 | | - curl -X POST "{{ elasticsearch_server_url }}/infra*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ log_labels }}-infrastructure" } }}' |
222 | | - when: elasticsearch_server_url is defined |
| 274 | + curl -X POST "{{ elasticsearch_server_url }}/audit*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.label":"{{ audit_log_label }}" } }}' |
| 275 | + curl -X POST "{{ elasticsearch_server_url }}/app*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.label":"{{ app_log_label }}" } }}' |
| 276 | + curl -X POST "{{ elasticsearch_server_url }}/infra*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.label":"{{ infra_log_label }}" } }}' |
| 277 | + when: |
| 278 | + - elasticsearch_server_url is defined |
| 279 | + - clo_version | float >= 6.0 |
| 280 | + |
| 281 | + - name: Elasticsearch clean up |
| 282 | + shell: | |
| 283 | + curl -X POST "{{ elasticsearch_server_url }}/audit*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ audit_log_label }}" } }}' |
| 284 | + curl -X POST "{{ elasticsearch_server_url }}/app*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ app_log_label }}" } }}' |
| 285 | + curl -X POST "{{ elasticsearch_server_url }}/infra*/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "openshift.labels.logs":"{{ infra_log_label }}" } }}' |
| 286 | + when: |
| 287 | + - elasticsearch_server_url is defined |
| 288 | + - clo_version | float <= 5.9 |
223 | 289 | ignore_errors: yes |
0 commit comments