-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.xml
1073 lines (1036 loc) · 87.4 KB
/
feed.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://nicklas.wiegandt.eu/feed.xml" rel="self" type="application/atom+xml" /><link href="https://nicklas.wiegandt.eu/" rel="alternate" type="text/html" /><updated>2024-12-03T06:19:45-06:00</updated><id>https://nicklas.wiegandt.eu/feed.xml</id><title type="html">Nicklas Wiegandt</title><subtitle>About Nicklas Wiegandt (Nicklas2751) and his Blog.</subtitle><author><name>Nicklas Wiegandt</name></author><entry><title type="html">Skip the first two lines of a file in Apache Camel</title><link href="https://nicklas.wiegandt.eu/2023/02/09/apache-camel-skip-lines.html" rel="alternate" type="text/html" title="Skip the first two lines of a file in Apache Camel" /><published>2023-02-09T14:00:00-06:00</published><updated>2023-02-09T14:00:00-06:00</updated><id>https://nicklas.wiegandt.eu/2023/02/09/apache-camel-skip-lines</id><content type="html" xml:base="https://nicklas.wiegandt.eu/2023/02/09/apache-camel-skip-lines.html"><div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p><a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a> is a popular open-source framework for integrating various systems and services. It provides a variety of components and tools to make it easier to integrate different systems, such as file systems, databases, and web services.</p>
</div>
<div class="paragraph">
<p>However, in some cases, it might be necessary to skip some lines in a file while processing it with <a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a>. For instance, you might have a file that has some metadata in the first two lines, and you only want to process the actual data from the file.</p>
</div>
<div class="paragraph">
<p>In this article, I&#8217;ll show you how to skip the first two lines of a file in <a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a>. The solution can be applied to any type of message that&#8217;s split by the <code>split</code> component, not just files.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-problem">The Problem</h2>
<div class="sectionbody">
<div class="paragraph">
<p>When you&#8217;re processing a file in <a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a>, it&#8217;s possible to use the <code>split</code> component to split the file into separate messages, one message per line. However, if you want to skip some lines, such as the first two lines, you need a way to filter out those messages before they&#8217;re processed.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-solution">The Solution</h2>
<div class="sectionbody">
<div class="paragraph">
<p><a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a> provides a <code>filter</code> component that allows you to filter out messages based on a condition. The condition can be specified using the <code>simple</code> language, which provides a simple expression language for filtering messages.</p>
</div>
<div class="paragraph">
<p>To skip the first two lines of a file, we can use the <code>filter</code> component and check the value of the <code>CamelSplitIndex</code> property. This property is set by the <code>split</code> component and indicates the current index of the message in the split list.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of how to skip the first two lines of a file in <a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="n">from</span><span class="o">(</span><span class="s">"file:input?noop=true"</span><span class="o">)</span>
<span class="o">.</span><span class="na">split</span><span class="o">().</span><span class="na">tokenize</span><span class="o">(</span><span class="s">"\n"</span><span class="o">)</span>
<span class="o">.</span><span class="na">filter</span><span class="o">(</span><span class="n">simple</span><span class="o">(</span><span class="s">"${exchangeProperty.CamelSplitIndex} &gt; 1"</span><span class="o">))</span>
<span class="o">.</span><span class="na">to</span><span class="o">(</span><span class="s">"file:output"</span><span class="o">);</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>In this example, we start by reading a file from the <code>input</code> directory using the <code>file</code> component. The <code>noop</code> option is set to <code>true</code>, which means that <a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a> will not delete the original file after processing it.</p>
</div>
<div class="paragraph">
<p>Next, we use the <code>split</code> component to split the file into separate messages, one message per line. The <code>tokenize</code> option is set to <code>"\n"</code>, which means that the file will be split on newline characters.</p>
</div>
<div class="paragraph">
<p>After that, we use the <code>filter</code> component to filter out messages that have an index lower than or equal to 1. This will effectively skip the first two lines of the file.</p>
</div>
<div class="paragraph">
<p>Finally, we use the <code>to</code> component to write the filtered messages to the <code>output</code> directory.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="conclusion">Conclusion</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In this article, I showed you how to skip the first two lines of a file in <a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a>. By using the <code>filter</code> component and checking the value of the <code>CamelSplitIndex</code> property, you can easily filter out the unwanted lines in a file. With <a href="https://camel.apache.org" target="_blank" rel="noopener">Apache Camel</a>, it&#8217;s possible to solve a variety of integration problems, and this is just one of the many examples.</p>
</div>
<hr>
<div class="paragraph">
<p>This article was created with the help of OpenAI, an AI model by OpenAI.</p>
</div>
</div>
</div></content><author><name>Nicklas Wiegandt</name></author><category term="apache-camel" /><summary type="html">Apache Camel is a popular open-source framework for integrating various systems and services. It provides a variety of components and tools to make it easier to integrate different systems, such as file systems, databases, and web services.</summary></entry><entry><title type="html">Using Docker in jenkins with jenkins Docker agent</title><link href="https://nicklas.wiegandt.eu/2021/06/06/jenkins-docker-agent-with-docker.html" rel="alternate" type="text/html" title="Using Docker in jenkins with jenkins Docker agent" /><published>2021-06-06T03:00:00-05:00</published><updated>2021-06-06T03:00:00-05:00</updated><id>https://nicklas.wiegandt.eu/2021/06/06/jenkins-docker-agent-with-docker</id><content type="html" xml:base="https://nicklas.wiegandt.eu/2021/06/06/jenkins-docker-agent-with-docker.html"><div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Getting <a href="https://jenkins.io" target="_blank" rel="noopener">Jenkins CI</a> to build Docker container with a jenkins Docker agent</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-problem">The problem</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Running <a href="https://jenkins.io" target="_blank" rel="noopener">Jenkins CI</a> agents as containers is a nice thing. However it can be a
hassle if you want to build a container inside the containerized docker agent. Using the standard Jenkins agent container
will result in an error telling you that the Docker binary is not found.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-solution">The solution</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The default <a href="https://hub.docker.com/r/jenkins/agent" target="_blank" rel="noopener">Jenkins agent container</a> doesn&#8217;t contain the Docker binaries. 😔</p>
</div>
<div class="paragraph">
<p>But the <a href="https://hub.docker.com/r/jenkins/jnlp-agent-docker" target="_blank" rel="noopener">Jenkins JNLP agent Docker container</a> does! 😀</p>
</div>
<div class="paragraph">
<p>Unfortunately the image is missing any description and finding any documentation is hard. You can neither view the Dockerfile nor is the source linked. But in the <a href="https://github.com/jenkinsci/jnlp-agents" target="_blank" rel="noopener">GitHub repository</a> for the <a href="https://github.com/jenkinsci/jnlp-agents" target="_blank" rel="noopener">JNLP Agents</a> is a subdirectory called <code>docker</code> in which you can find this <a href="https://github.com/jenkinsci/jnlp-agents/blob/master/docker/Dockerfile">Dockerfile</a>. This seems to be the source for the linked image. One can see that the Docker binary is getting installed on build time.</p>
</div>
<div class="paragraph">
<p>In order to use the agent go to your Jenkins server settings and click on <code>Manage Nodes and Clouds</code> &#8594; <code>Configure Clouds</code>.</p>
</div>
<div class="paragraph">
<p>If you haven&#8217;t already set your Docker settings:<br>
<strong>Name:</strong> <code>docker</code><br>
<strong>Docker Host URI:</strong> <code>unix:///var/run/docker.sock</code><br></p>
</div>
<div class="imageblock">
<div class="content">
<img src="assets/images/jenkins-configure-clouds.png" alt="The Jenkins Docker settings">
</div>
</div>
<div class="paragraph">
<div class="title">The Jenkins Docker setting</div>
<p>Then open the Docker Agent templates section.<br>
Change the <strong>Docker Image</strong> to: <code>jenkins/jnlp-agent-docker</code></p>
</div>
<div class="imageblock">
<div class="content">
<img src="assets/images/jenkins-agent-template.png" alt="The Jenkins agent template settings">
</div>
</div>
<div class="paragraph">
<div class="title">The Jenkins agent template settings</div>
<p>After that open the container settings and set the following:<br>
<strong>User:</strong> <code>root</code><br>
<strong>Volumes:</strong> <code>/var/run/docker.sock:/var/run/docker.sock</code></p>
</div>
<div class="imageblock">
<div class="content">
<img src="assets/images/jenkins-agent-template-container-settings.png" alt="The Jenkins agent template container settings">
</div>
</div>
<div class="paragraph">
<div class="title">The Jenkins agent template container settings</div>
<p>Thats it. Happy dockerizing 🙂</p>
</div>
</div>
</div></content><author><name>Nicklas Wiegandt</name></author><category term="jenkins" /><category term="cicd" /><category term="docker" /><category term="docker-in-docker" /><category term="containerd" /><summary type="html">Getting Jenkins CI to build Docker container with a jenkins Docker agent</summary></entry><entry><title type="html">Docker Compose log aggregation using Grafana Loki and Fluent Bit</title><link href="https://nicklas.wiegandt.eu/2020/12/20/docker-compose-log-aggregation-with-grafana-loki.html" rel="alternate" type="text/html" title="Docker Compose log aggregation using Grafana Loki and Fluent Bit" /><published>2020-12-20T15:00:00-06:00</published><updated>2020-12-20T15:00:00-06:00</updated><id>https://nicklas.wiegandt.eu/2020/12/20/docker-compose-log-aggregation-with-grafana-loki</id><content type="html" xml:base="https://nicklas.wiegandt.eu/2020/12/20/docker-compose-log-aggregation-with-grafana-loki.html"><div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>How to use <a href="https://grafana.com/oss/loki/">Grafana Loki</a> for <a href="https://docs.docker.com/compose/">docker compose</a> log aggregation using <a href="https://fluentbit.io/">Fluent Bit</a>.</p>
</div>
<div class="paragraph">
<p>Recently <a href="https://elaon.de">Alex</a>, my co-maintainer of <a href="https://mediathekview.de">MediathekView</a>, asked me to build a Docker Compose file to view the <a href="https://github.com/mediathekview/MServer/">MServer</a> logs with <a href="https://grafana.com/oss/loki/">Grafana Loki</a>. I chose <a href="https://fluentbit.io/">Fluent Bit</a> as log proccessor and forwarder becuase Docker Compose can use the fluentd logging driver <a href="https://docs.docker.com/config/containers/logging/fluentd/">out of the box</a>.</p>
</div>
<div class="paragraph">
<p>This does not seem particularly complex at first. However, there are some pitfalls hidden due to missing or outdated information.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-solution">The solution</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="loki-grafana-and-fluent-bit">Loki, Grafana and Fluent Bit</h3>
<div class="paragraph">
<p>The Docker Compose part for Loki and Grafana is straightforward:</p>
</div>
<div class="listingblock">
<div class="title">docker-compose-loki.yml</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"> <span class="na">version</span><span class="pi">:</span> <span class="s2">"</span><span class="s">3.3"</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="na">loki</span><span class="pi">:</span>
<span class="na">driver</span><span class="pi">:</span> <span class="s">bridge</span>
<span class="na">services</span><span class="pi">:</span>
<span class="na">loki</span><span class="pi">:</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">grafana/loki:2.0.0</span>
<span class="na">container_name</span><span class="pi">:</span> <span class="s">loki</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">3100:3100"</span>
<span class="na">command</span><span class="pi">:</span> <span class="s">-config.file=/etc/loki/local-config.yaml</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">loki</span>
<span class="na">grafana</span><span class="pi">:</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">grafana/grafana:latest</span>
<span class="na">container_name</span><span class="pi">:</span> <span class="s">grafana</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">3000:3000"</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">loki</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The fluent bit part is also straightforward, but unlike the <a href="https://docs.fluentbit.io/manual/v/master/local-testing/logging-pipeline#docker-compose">sample Fluent Bit Docker Compose file</a>, port 24224 is exposed. The port is required by the <a href="https://docs.docker.com/config/containers/logging/fluentd/">fluentd docker logging driver</a>.</p>
</div>
<div class="listingblock">
<div class="title">docker-compose-loki.yml</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"> <span class="na">fluent-bit</span><span class="pi">:</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">fluent/fluent-bit</span>
<span class="na">container_name</span><span class="pi">:</span> <span class="s">fluentbit</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">24224:24224"</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">24224:24224/udp"</span>
<span class="na">volumes</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">.docker/logging/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">loki</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The two compose configuration can then be combined into one single compose file:</p>
</div>
<div class="listingblock">
<div class="title">docker-compose-loki.yml</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><span class="na">version</span><span class="pi">:</span> <span class="s2">"</span><span class="s">3.3"</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="na">loki</span><span class="pi">:</span>
<span class="na">driver</span><span class="pi">:</span> <span class="s">bridge</span>
<span class="na">services</span><span class="pi">:</span>
<span class="na">loki</span><span class="pi">:</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">grafana/loki:2.0.0</span>
<span class="na">container_name</span><span class="pi">:</span> <span class="s">loki</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">3100:3100"</span>
<span class="na">command</span><span class="pi">:</span> <span class="s">-config.file=/etc/loki/local-config.yaml</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">loki</span>
<span class="na">grafana</span><span class="pi">:</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">grafana/grafana:latest</span>
<span class="na">container_name</span><span class="pi">:</span> <span class="s">grafana</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">3000:3000"</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">loki</span>
<span class="na">fluent-bit</span><span class="pi">:</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">fluent/fluent-bit</span>
<span class="na">container_name</span><span class="pi">:</span> <span class="s">fluentbit</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">24224:24224"</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">24224:24224/udp"</span>
<span class="na">volumes</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">.docker/logging/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf</span>
<span class="na">networks</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">loki</span></code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="fluent-bit-configuration">Fluent Bit configuration</h3>
<div class="paragraph">
<p>The configuration of Fluent Bit is almost identically to the <a href="https://docs.fluentbit.io/manual/pipeline/outputs/loki">example in the Fluent Bit documentation</a>, but one important change must be made.</p>
</div>
<div class="paragraph">
<p>The label <code>$sub['stream']</code> of the example isn&#8217;t applicable for Docker Compose logs.
An example for a log line looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="json"><span class="p">{</span><span class="nl">"container_id"</span><span class="p">:</span><span class="s2">"05070542e00a616589a3671404d34fe7374f3b6f08ef6f71431acc42fbfa8675"</span><span class="p">,</span><span class="nl">"container_name"</span><span class="p">:</span><span class="s2">"/mserver_mserver_1"</span><span class="p">,</span><span class="nl">"source"</span><span class="p">:</span><span class="s2">"stdout"</span><span class="p">,</span><span class="nl">"log"</span><span class="p">:</span><span class="s2">"[INFO ] [EtmMonitor] Shutting down JETM."</span><span class="p">}</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Instead of <code>$sub['stream']</code> I defined <code>$container_id</code>, <code>$container_name</code> and <code>$source</code> as labels.</p>
</div>
<div class="listingblock">
<div class="title">fluent-bit.conf</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="conf">[<span class="n">SERVICE</span>]
<span class="n">Flush</span> <span class="m">1</span>
<span class="n">Daemon</span> <span class="n">Off</span>
<span class="n">Log_Level</span> <span class="n">info</span>
[<span class="n">INPUT</span>]
<span class="n">Name</span> <span class="n">forward</span>
<span class="n">Listen</span> <span class="m">0</span>.<span class="m">0</span>.<span class="m">0</span>.<span class="m">0</span>
<span class="n">Port</span> <span class="m">24224</span>
[<span class="n">Output</span>]
<span class="n">Name</span> <span class="n">loki</span>
<span class="n">Match</span> *
<span class="n">host</span> <span class="n">loki</span>
<span class="n">port</span> <span class="m">3100</span>
<span class="n">labels</span> <span class="n">job</span>=<span class="n">mserver</span>,$<span class="n">container_id</span>,$<span class="n">container_name</span>,$<span class="n">source</span>
<span class="n">line_format</span> <span class="n">json</span></code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="using-the-fluentd-docker-logging-driver">Using the fluentd docker logging driver</h3>
<div class="paragraph">
<p>To use the fluentd docker logging driver in conjunction with other Docker Compose this snippet can be used:</p>
</div>
<div class="listingblock">
<div class="title">docker-compose.yml</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"> <span class="na">logging</span><span class="pi">:</span>
<span class="na">driver</span><span class="pi">:</span> <span class="s2">"</span><span class="s">fluentd"</span>
<span class="na">options</span><span class="pi">:</span>
<span class="na">fluentd-address</span><span class="pi">:</span> <span class="s">localhost:24224</span>
<span class="na">tag</span><span class="pi">:</span> <span class="s">httpd.access</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Sending the logs of nginx to Loki may look like this:
.docker-compose.yml</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><span class="na">version</span><span class="pi">:</span> <span class="s2">"</span><span class="s">3.3"</span>
<span class="na">services</span><span class="pi">:</span>
<span class="na">nginx</span><span class="pi">:</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">nginx</span>
<span class="na">volumes</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">./templates:/etc/nginx/templates</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">8080:80"</span>
<span class="na">environment</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">NGINX_HOST=foobar.com</span>
<span class="pi">-</span> <span class="s">NGINX_PORT=80</span>
<span class="na">logging</span><span class="pi">:</span>
<span class="na">driver</span><span class="pi">:</span> <span class="s2">"</span><span class="s">fluentd"</span>
<span class="na">options</span><span class="pi">:</span>
<span class="na">fluentd-address</span><span class="pi">:</span> <span class="s">localhost:24224</span>
<span class="na">tag</span><span class="pi">:</span> <span class="s">httpd.access</span></code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="grafana-loki-show-only-log-message">Grafana Loki show only Log message</h3>
<div class="paragraph">
<p>When viewing the logs in the Grafana exploring view or with the Dashboard Log Panel, the individual lines are quite ugly. The entire json message is displayed, which quickly becomes very confusing. In order to get the log messages into a more readable format, one can use a <a href="https://grafana.com/docs/loki/latest/logql/#Line-Format-Expression">new feature of Loki version 2.0</a>: <code>line_format</code></p>
</div>
<div class="paragraph">
<p>An example query for the container <code>mserver_mserver_1</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="bash"><span class="o">{</span><span class="nv">container_name</span><span class="o">=</span><span class="s2">"/mserver_mserver_1"</span><span class="o">}</span> | json | line_format <span class="s2">"{{.log}}"</span></code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="links">Links</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Some useful Links:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://docs.fluentbit.io/manual/pipeline/outputs/loki">Documentation - Fluent Bit</a></p>
</li>
<li>
<p><a href="https://grafana.com/docs/loki/latest/clients/fluentbit/">Documentation - Grafana Loki</a></p>
</li>
<li>
<p><a href="https://grafana.com/blog/2020/10/28/loki-2.0-released-transform-logs-as-youre-querying-them-and-set-up-alerts-within-loki/">Blog post Grafana Loki 2.0</a></p>
</li>
</ul>
</div>
<hr>
<div class="paragraph">
<p><span class="small">Thanks to <a href="https://friedmann.dev/">Daniel</a> for his review of this post</span></p>
</div>
</div>
</div></content><author><name>Nicklas Wiegandt</name></author><category term="docker-compose" /><category term="docker" /><category term="grafana" /><category term="log" /><category term="loki" /><category term="fluent-bit" /><summary type="html">How to use Grafana Loki for docker compose log aggregation using Fluent Bit.</summary></entry><entry><title type="html">Use K3OS system Traefik with Let’s Encrypt</title><link href="https://nicklas.wiegandt.eu/2020/08/02/use-k3os-traefik-letsencrypt.html" rel="alternate" type="text/html" title="Use K3OS system Traefik with Let’s Encrypt" /><published>2020-08-02T07:00:00-05:00</published><updated>2020-08-02T07:00:00-05:00</updated><id>https://nicklas.wiegandt.eu/2020/08/02/use-k3os-traefik-letsencrypt</id><content type="html" xml:base="https://nicklas.wiegandt.eu/2020/08/02/use-k3os-traefik-letsencrypt.html"><div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>How to use <a href="https://k3os.io/" target="_blank" rel="noopener">K3OS</a> system <a href="https://containo.us/traefik/" target="_blank" rel="noopener">Traefik</a> with <a href="https://letsencrypt.org" target="_blank" rel="noopener">Let&#8217;s Encrypt</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-problem">The problem</h2>
<div class="sectionbody">
<div class="paragraph">
<p>K3OS comes with a system Traefik. Nice so we can use it to route our services and give them with Let&#8217;s Encrypt HTTPS. Yes!</p>
</div>
<div class="paragraph">
<p>But how to configure it to do what we want? There is a configuration file: <code>/var/lib/rancher/k3s/server/manifests/traefik.yaml</code></p>
</div>
<div class="paragraph">
<p>Seems to work pretty well so where is the problem? If you reboot your server or, like in my case your provider restarts your server, all Traefik configuration is lost.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-solution">The solution</h2>
<div class="sectionbody">
<div class="paragraph">
<p>K3OS has some persistent directories and <code>/var/lib/rancher/k3s/server/manifests</code> isn&#8217;t one. Ok but <a href="https://github.com/rancher/k3os#kubernetes" target="_blank" rel="noopener">the documentation says</a> that you can write manifests with the configuration key <code>write_files</code>. But there&#8217;s another stumbling block! Per default K3OS overwrites the Traefik configuration on each boot.</p>
</div>
<div class="paragraph">
<p>So here is the solution, you need to add this to your K3OS configuration:</p>
</div>
<div class="listingblock">
<div class="title">/var/lib/rancher/k3os/config.yaml</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"> <span class="na">k3s_args</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">server</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">--no-deploy=traefik"</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Now don&#8217;t forget to write the Traefik configuration with <code>write_files</code>:</p>
</div>
<div class="listingblock">
<div class="title">/var/lib/rancher/k3os/config.yaml</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><span class="na">write_files</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">content</span><span class="pi">:</span> <span class="pi">|-</span>
<span class="s">apiVersion: helm.cattle.io/v1</span>
<span class="s">kind: HelmChart</span>
<span class="s">metadata:</span>
<span class="s">name: traefik</span>
<span class="s">namespace: kube-system</span>
<span class="s">spec:</span>
<span class="s">chart: https://%{KUBERNETES_API}%/static/charts/traefik-1.81.0.tgz</span>
<span class="s">set:</span>
<span class="s">rbac.enabled: "true"</span>
<span class="s">ssl.enabled: "true"</span>
<span class="s">ssl.enforced: "true"</span>
<span class="s">acme.enabled: "true"</span>
<span class="s">acme.challengeType: "tls-alpn-01"</span>
<span class="s">acme.email: "[email protected]"</span>
<span class="s">acme.staging: "false"</span>
<span class="s">metrics.prometheus.enabled: "true"</span>
<span class="s">kubernetes.ingressEndpoint.useDefaultPublishedService: "true"</span>
<span class="s">image: "rancher/library-traefik"</span>
<span class="na">owner</span><span class="pi">:</span> <span class="s">root</span>
<span class="na">path</span><span class="pi">:</span> <span class="s">/var/lib/rancher/k3s/server/manifests/traefik.yaml</span>
<span class="na">permissions</span><span class="pi">:</span> <span class="s1">'</span><span class="s">0755'</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>A complete configuration could look like this:</p>
</div>
<div class="listingblock">
<div class="title">/var/lib/rancher/k3os/config.yaml</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><table class="linenotable"><tbody><tr><td class="linenos gl"><pre class="lineno"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre><span class="na">k3os</span><span class="pi">:</span>
<span class="na">k3s_args</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">server</span>
<span class="pi">-</span> <span class="s2">"</span><span class="s">--no-deploy=traefik"</span>
<span class="na">sshAuthorizedKeys</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">github:yourGithubUserName</span>
<span class="na">write_files</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">content</span><span class="pi">:</span> <span class="pi">|-</span>
<span class="s">apiVersion: helm.cattle.io/v1</span>
<span class="s">kind: HelmChart</span>
<span class="s">metadata:</span>
<span class="s">name: traefik</span>
<span class="s">namespace: kube-system</span>
<span class="s">spec:</span>
<span class="s">chart: https://%{KUBERNETES_API}%/static/charts/traefik-1.81.0.tgz</span>
<span class="s">set:</span>
<span class="s">rbac.enabled: "true"</span>
<span class="s">ssl.enabled: "true"</span>
<span class="s">ssl.enforced: "true"</span>
<span class="s">acme.enabled: "true"</span>
<span class="s">acme.challengeType: "tls-alpn-01"</span>
<span class="s">acme.email: "[email protected]"</span>
<span class="s">acme.staging: "false"</span>
<span class="s">metrics.prometheus.enabled: "true"</span>
<span class="s">kubernetes.ingressEndpoint.useDefaultPublishedService: "true"</span>
<span class="s">image: "rancher/library-traefik"</span>
<span class="na">owner</span><span class="pi">:</span> <span class="s">root</span>
<span class="na">path</span><span class="pi">:</span> <span class="s">/var/lib/rancher/k3s/server/manifests/traefik.yaml</span>
<span class="na">permissions</span><span class="pi">:</span> <span class="s1">'</span><span class="s">0755'</span>
</pre></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="how-to-use-it-for-a-container">How to use it for a container</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In case you are reading this and do not know how to use Traefik with your container now, here is how it works:</p>
</div>
<div class="paragraph">
<p>It&#8217;s super simple! :)
Of course your domain has to be configured to point to your server for all domains you wan&#8217;t to use. Your Traefik configuration has to be correct to. How to do this is documented in the <a href="https://docs.traefik.io/https/acme/" target="_blank" rel="noopener">Traefik documentation</a> and there is a example in the solution above. If these basic conditions are fulfilled it is super easy.</p>
</div>
<div class="paragraph">
<p>To instruct Traefik to route a subdomain with HTTPS to a service you just need to create a <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" target="_blank" rel="noopener">Ingress</a> for your service:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><span class="nn">---</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Ingress</span>
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">extensions/v1beta1</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">myservice-ingress</span>
<span class="na">namespace</span><span class="pi">:</span> <span class="s">myservice</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">rules</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">host</span><span class="pi">:</span> <span class="s">service.mydoma.in</span>
<span class="na">http</span><span class="pi">:</span>
<span class="na">paths</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">path</span><span class="pi">:</span> <span class="s">/</span>
<span class="na">backend</span><span class="pi">:</span>
<span class="na">serviceName</span><span class="pi">:</span> <span class="s">my-service</span>
<span class="na">servicePort</span><span class="pi">:</span> <span class="s">8080</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>A complete service description inclunding Ingress could look like this:</p>
</div>
<div class="listingblock">
<div class="title">README.md <a href="https://github.com/mediathekview/zapp-backend/blob/29d08f164dceb9f924b7248893ce6d2b202ccd40/README.md#kubernetes" target="_blank" rel="noopener">view</a> <a href="https://raw.githubusercontent.com/mediathekview/zapp-backend/29d08f164dceb9f924b7248893ce6d2b202ccd40/README.md" target="_blank" rel="noopener">raw</a></div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><table class="linenotable"><tbody><tr><td class="linenos gl"><pre class="lineno"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre><span class="na">apiVersion</span><span class="pi">:</span> <span class="s">v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Namespace</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">mediathekview</span>
<span class="nn">---</span>
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Service</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">zapp-backend</span>
<span class="na">namespace</span><span class="pi">:</span> <span class="s">mediathekview</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">http</span>
<span class="na">protocol</span><span class="pi">:</span> <span class="s">TCP</span>
<span class="na">port</span><span class="pi">:</span> <span class="m">3000</span>
<span class="na">selector</span><span class="pi">:</span>
<span class="na">app</span><span class="pi">:</span> <span class="s">zapp-backend</span>
<span class="nn">---</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Deployment</span>
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">apps/v1</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">namespace</span><span class="pi">:</span> <span class="s">mediathekview</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">zapp-backend</span>
<span class="na">labels</span><span class="pi">:</span>
<span class="na">app</span><span class="pi">:</span> <span class="s">zapp-backend</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">replicas</span><span class="pi">:</span> <span class="m">1</span>
<span class="na">selector</span><span class="pi">:</span>
<span class="na">matchLabels</span><span class="pi">:</span>
<span class="na">app</span><span class="pi">:</span> <span class="s">zapp-backend</span>
<span class="na">template</span><span class="pi">:</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">labels</span><span class="pi">:</span>
<span class="na">app</span><span class="pi">:</span> <span class="s">zapp-backend</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">containers</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">zapp-backend</span>
<span class="na">image</span><span class="pi">:</span> <span class="s">mediathekview/zapp-backend</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">web</span>
<span class="na">containerPort</span><span class="pi">:</span> <span class="m">3000</span>
<span class="nn">---</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Ingress</span>
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">extensions/v1beta1</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">zapp-backend-ingress</span>
<span class="na">namespace</span><span class="pi">:</span> <span class="s">mediathekview</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">rules</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">host</span><span class="pi">:</span> <span class="s">api.zapp.mediathekview.de</span>
<span class="na">http</span><span class="pi">:</span>
<span class="na">paths</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">path</span><span class="pi">:</span> <span class="s">/</span>
<span class="na">backend</span><span class="pi">:</span>
<span class="na">serviceName</span><span class="pi">:</span> <span class="s">zapp-backend</span>
<span class="na">servicePort</span><span class="pi">:</span> <span class="s">3000</span>
</pre></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div></content><author><name>Nicklas Wiegandt</name></author><category term="kubernetes" /><category term="traefik" /><category term="letsencrypt" /><category term="k3os" /><category term="rancher" /><summary type="html">How to use K3OS system Traefik with Let&#8217;s Encrypt.</summary></entry><entry><title type="html">Elastic Stack with Fluent Bit Helm for Kubernetes container logs</title><link href="https://nicklas.wiegandt.eu/2020/08/01/elastic-stack-with-fluentbit-helm-for-kubernetes-container-logs.html" rel="alternate" type="text/html" title="Elastic Stack with Fluent Bit Helm for Kubernetes container logs" /><published>2020-08-01T13:15:00-05:00</published><updated>2020-08-01T13:15:00-05:00</updated><id>https://nicklas.wiegandt.eu/2020/08/01/elastic-stack-with-fluentbit-helm-for-kubernetes-container-logs</id><content type="html" xml:base="https://nicklas.wiegandt.eu/2020/08/01/elastic-stack-with-fluentbit-helm-for-kubernetes-container-logs.html"><div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>How to install Elastic Stack with Helm and get all Kubernetes container logs in to it with Fluent Bit.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-problem">The problem</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The helm chart for Elastic Stack (<a href="https://hub.helm.sh/charts/stable/elastic-stack" target="_blank" rel="noopener">stable/elastic-stack</a>) seems to be pretty easy right? Yeah it is but if you install it with Fluent Bit activated it tries to find Fluentd and even if you install Fluentd too it can&#8217;t find it. And to get it even worse Fluentd can&#8217;t find Elasticsearch. But why?</p>
</div>
<div class="paragraph">
<p>Fluent Bit uses the wrong hostname of Fluentd and Fluentd uses the wrong hostname of Elasticsearch.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="the-solution">The solution</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Fortunally Fluent Bit don&#8217;t need Fluentd to send its logs to Elasticsearch. So we just need to configure Fluent Bit to communicate with Elasticsearch and use the right hostname.
The default helm values already include the right Elasticsearch hostname. Why it isn&#8217;t already set for Fluentd and Fluent Bit? I don&#8217;t know.</p>
</div>
<div class="paragraph">
<p>Here is my values file to get it working:</p>
</div>
<div class="listingblock">
<div class="title">elastic-stack-fluentbit-values.yaml</div>
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><table class="linenotable"><tbody><tr><td class="linenos gl"><pre class="lineno"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre><span class="na">elasticsearch</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">true</span>
<span class="na">kibana</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">true</span>
<span class="na">env</span><span class="pi">:</span>
<span class="na">ELASTICSEARCH_HOSTS</span><span class="pi">:</span> <span class="s">http://{{ .Release.Name }}-elasticsearch-client:9200</span>
<span class="na">logstash</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">false</span>
<span class="c1"># elasticsearch:</span>
<span class="c1"># host: elastic-stack-elasticsearch-client</span>
<span class="na">filebeat</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">false</span>
<span class="c1"># config:</span>
<span class="c1"># output.file.enabled: false</span>
<span class="c1"># output.logstash:</span>
<span class="c1"># hosts: ["{{ .Release.Name }}-logstash:5044"]</span>
<span class="c1"># indexTemplateLoad:</span>
<span class="c1"># - {{ .Release.Name }}-elasticsearch-client:9200</span>
<span class="na">fluentd</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">false</span>
<span class="na">fluent-bit</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">true</span>
<span class="na">backend</span><span class="pi">:</span>
<span class="na">type</span><span class="pi">:</span> <span class="s">es</span>
<span class="na">es</span><span class="pi">:</span>
<span class="na">host</span><span class="pi">:</span> <span class="pi">{{</span> <span class="nv">.Release.Name</span> <span class="pi">}}</span><span class="s">-elasticsearch-client</span>
<span class="na">fluentd-elasticsearch</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">false</span>
<span class="na">nginx-ldapauth-proxy</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">false</span>
<span class="na">elasticsearch-curator</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">false</span>
<span class="na">elasticsearch-exporter</span><span class="pi">:</span>
<span class="na">enabled</span><span class="pi">:</span> <span class="no">false</span>
</pre></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div></content><author><name>Nicklas Wiegandt</name></author><category term="kubernetes" /><category term="elastic-stack" /><category term="fluentbit" /><category term="helm" /><summary type="html">How to install Elastic Stack with Helm and get all Kubernetes container logs in to it with Fluent Bit.</summary></entry><entry><title type="html">About this blog</title><link href="https://nicklas.wiegandt.eu/2020/07/31/first-post.html" rel="alternate" type="text/html" title="About this blog" /><published>2020-07-31T13:15:00-05:00</published><updated>2020-07-31T13:15:00-05:00</updated><id>https://nicklas.wiegandt.eu/2020/07/31/first-post</id><content type="html" xml:base="https://nicklas.wiegandt.eu/2020/07/31/first-post.html"><div class="paragraph">
<p>My first post on my new blog. This posts is about the blog itself and how it&#8217;s made.</p>
</div>
<div class="paragraph">
<p>I created this blog to write about DevOp&#8217;s things that keep me occupied. These will mainly be solutions to problems for which I had to search and try around for a long time. With this I want to achieve that others do not have to search so long for the right solution. Maybe, if I find time and motivation, I will also write articles about my work on MediathekView. And maybe I will also write articles about frameworks &amp; technologies I am currently busy oneself with. And maybe I write articles about frameworks and technologies I&#8217;m currently working with.</p>
</div>
<div class="paragraph">
<p>The blog itself is made with <a href="https://jekyllrb.com/">Jekyll</a> and <a href="https://github.com/asciidoctor/jekyll-asciidoc">AsciiDoc</a>. It&#8217;s hosted on GitHub where you can also find the source: <a href="https://github.com/nicklas2751/nicklas2751.github.io" class="bare">https://github.com/nicklas2751/nicklas2751.github.io</a> Because this don&#8217;t allows to send E-Mails on server side, I created a AWS Lambda for the contact form.</p>
</div>
<div class="paragraph">
<p>This is the source of my contact form lambda:</p>
</div>
<div class="listingblock">
<div class="title">lambda_function.py <a href="https://github.com/Nicklas2751/contact-form-lambda/blob/30b833e/lambda_function.py" target="_blank" rel="noopener">view</a> <a href="https://raw.githubusercontent.com/Nicklas2751/contact-form-lambda/30b833e/lambda_function.py" target="_blank" rel="noopener">raw</a></div>
<div class="content">
<pre class="rouge highlight"><code data-lang="python"><table class="linenotable"><tbody><tr><td class="linenos gl"><pre class="lineno"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
</pre></td><td class="code"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
<span class="kn">from</span> <span class="nn">botocore.exceptions</span> <span class="kn">import</span> <span class="n">ClientError</span>
<span class="kn">from</span> <span class="nn">urllib.request</span> <span class="kn">import</span> <span class="n">urlopen</span>
<span class="kn">import</span> <span class="nn">boto3</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">requests</span>
<span class="k">def</span> <span class="nf">lambda_handler</span><span class="p">(</span><span class="n">event</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
<span class="k">if</span> <span class="s">"g-recaptcha-response"</span> <span class="ow">in</span> <span class="n">event</span> <span class="ow">and</span> <span class="s">"mail"</span> <span class="ow">in</span> <span class="n">event</span> <span class="ow">and</span> <span class="s">"text"</span> <span class="ow">in</span> <span class="n">event</span><span class="p">:</span>
<span class="n">success</span> <span class="o">=</span> <span class="n">checkRecaptcha</span><span class="p">(</span><span class="n">event</span><span class="p">[</span><span class="s">"g-recaptcha-response"</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">if</span> <span class="n">success</span><span class="p">:</span>
<span class="n">send_email</span><span class="p">(</span><span class="n">event</span><span class="p">[</span><span class="s">"mail"</span><span class="p">],</span><span class="n">event</span><span class="p">[</span><span class="s">"text"</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="s">"RECaptcha failed!"</span><span class="p">)</span>
<span class="k">return</span> <span class="p">{</span>
<span class="s">"location"</span><span class="p">:</span> <span class="n">event</span><span class="p">[</span><span class="s">"referer"</span><span class="p">]</span>
<span class="p">}</span>
<span class="k">def</span> <span class="nf">checkRecaptcha</span><span class="p">(</span><span class="n">captchaCode</span><span class="p">):</span>
<span class="n">requestData</span> <span class="o">=</span> <span class="p">{</span> <span class="s">"secret"</span><span class="p">:</span> <span class="s">"mySecret"</span><span class="p">,</span> <span class="s">"response"</span><span class="p">:</span> <span class="n">captchaCode</span> <span class="p">}</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">requests</span><span class="p">.</span><span class="n">post</span><span class="p">(</span><span class="s">"https://www.google.com/recaptcha/api/siteverify"</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">requestData</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">data</span><span class="p">.</span><span class="n">json</span><span class="p">()</span>
<span class="k">return</span> <span class="n">result</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">'success'</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">send_email</span><span class="p">(</span><span class="n">userMail</span><span class="p">,</span> <span class="n">content</span><span class="p">):</span>
<span class="c1"># Replace [email protected] with your "From" address.
</span> <span class="c1"># This address must be verified with Amazon SES.
</span> <span class="n">SENDER</span> <span class="o">=</span> <span class="s">"My Sender &lt;[email protected]&gt;"</span>
<span class="c1"># Replace [email protected] with a "To" address. If your account
</span> <span class="c1"># is still in the sandbox, this address must be verified.
</span> <span class="n">RECIPIENT</span> <span class="o">=</span> <span class="s">"[email protected]"</span>
<span class="c1"># If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
</span> <span class="n">AWS_REGION</span> <span class="o">=</span> <span class="s">"eu-west-1"</span>
<span class="c1"># The subject line for the email.
</span> <span class="n">SUBJECT</span> <span class="o">=</span> <span class="s">"A user has sent you a message"</span>
<span class="c1"># The character encoding for the email.
</span> <span class="n">CHARSET</span> <span class="o">=</span> <span class="s">"UTF-8"</span>
<span class="c1"># Create a new SES resource and specify a region.
</span> <span class="n">client</span> <span class="o">=</span> <span class="n">boto3</span><span class="p">.</span><span class="n">client</span><span class="p">(</span><span class="s">'ses'</span><span class="p">,</span><span class="n">region_name</span><span class="o">=</span><span class="n">AWS_REGION</span><span class="p">)</span>
<span class="c1"># Try to send the email.
</span> <span class="k">try</span><span class="p">:</span>
<span class="c1">#Provide the contents of the email.
</span> <span class="n">response</span> <span class="o">=</span> <span class="n">client</span><span class="p">.</span><span class="n">send_email</span><span class="p">(</span>
<span class="n">Destination</span><span class="o">=</span><span class="p">{</span>
<span class="s">'ToAddresses'</span><span class="p">:</span> <span class="p">[</span>
<span class="n">RECIPIENT</span>
<span class="p">]</span>
<span class="p">},</span>
<span class="n">ReplyToAddresses</span><span class="o">=</span><span class="p">[</span>
<span class="n">userMail</span><span class="p">,</span>
<span class="p">],</span>
<span class="n">Message</span><span class="o">=</span><span class="p">{</span>
<span class="s">'Body'</span><span class="p">:</span> <span class="p">{</span>
<span class="s">'Text'</span><span class="p">:</span> <span class="p">{</span>
<span class="s">'Charset'</span><span class="p">:</span> <span class="n">CHARSET</span><span class="p">,</span>
<span class="s">'Data'</span><span class="p">:</span> <span class="n">content</span><span class="p">,</span>
<span class="p">},</span>
<span class="p">},</span>
<span class="s">'Subject'</span><span class="p">:</span> <span class="p">{</span>
<span class="s">'Charset'</span><span class="p">:</span> <span class="n">CHARSET</span><span class="p">,</span>
<span class="s">'Data'</span><span class="p">:</span> <span class="n">SUBJECT</span><span class="p">,</span>
<span class="p">},</span>
<span class="p">},</span>
<span class="n">Source</span><span class="o">=</span><span class="n">SENDER</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># Display an error if something goes wrong.
</span> <span class="k">except</span> <span class="n">ClientError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="n">response</span><span class="p">[</span><span class="s">'Error'</span><span class="p">][</span><span class="s">'Message'</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="s">"Email sent! Message ID:"</span><span class="p">),</span>
<span class="k">print</span><span class="p">(</span><span class="n">response</span><span class="p">[</span><span class="s">'MessageId'</span><span class="p">])</span>
</pre></td></tr></tbody></table></code></pre>
</div>
</div>
<div class="paragraph">
<p>Because the HTML form sends it&#8217;s data as www-form-urlencoded the following API gateway integration request mapping template is needed:</p>
</div>
<div class="listingblock">
<div class="title">api_gateway_mapping_template.vtl <a href="https://github.com/Nicklas2751/contact-form-lambda/blob/30b833e/api_gateway_mapping_template.vtl" target="_blank" rel="noopener">view</a> <a href="https://raw.githubusercontent.com/Nicklas2751/contact-form-lambda/30b833e/api_gateway_mapping_template.vtl" target="_blank" rel="noopener">raw</a></div>
<div class="content">
<pre class="rouge highlight"><code data-lang="vtl"><table class="linenotable"><tbody><tr><td class="linenos gl"><pre class="lineno"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34