{"id":9325,"date":"2022-09-15T14:04:03","date_gmt":"2022-09-15T19:04:03","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=9325"},"modified":"2022-09-15T14:25:50","modified_gmt":"2022-09-15T19:25:50","slug":"logstash-setting-config-with-environment-variables","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=9325","title":{"rendered":"Logstash &#8211; Setting Config with Environment Variables"},"content":{"rendered":"\n<p>I took over management of an ElasticSearch environment that has a <em>lot<\/em> of configuration inconsistencies. Unfortunately, the previous owners weren&#8217;t the ones who built the environment either &#8230; so no one knew <em>why<\/em> ServerX did one thing and ServerY did another. Didn&#8217;t mess with it (if it&#8217;s working, don&#8217;t break it!) until we encountered some users who couldn&#8217;t find their data &#8212; because, depending on which logstash server information transits, stuff ends up in different indices. So now we&#8217;re consolidating configurations and I am going to pull the &#8220;right&#8221; config files into a git repo so we can easily maintain consistency. <\/p>\n\n\n\n<p>Except &#8230; any repository becomes in scope for security scanning. And, really, typing your password in clear text <em>isn&#8217;t<\/em> a wonderful plan. So my first step is using environment variables as configuration parameters in logstash. <\/p>\n\n\n\n<p>The first thing to do is <em>set<\/em> the environment variables somewhere logstash can use them. In my case, I&#8217;m using a unit file that sources its environment from \/etc\/default\/logstash<\/p>\n\n\n\n<p>Once the environment variables are there, enclose the variable name in ${} and use it in the config:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/09\/Logstash-EnvInConfig.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"161\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/09\/Logstash-EnvInConfig-1024x161.png\" alt=\"\" class=\"wp-image-9326\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/09\/Logstash-EnvInConfig-1024x161.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/09\/Logstash-EnvInConfig-300x47.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/09\/Logstash-EnvInConfig-768x121.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/09\/Logstash-EnvInConfig-750x118.png 750w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2022\/09\/Logstash-EnvInConfig.png 1226w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Logstash Config<\/figcaption><\/figure>\n\n\n\n<p>Restart ElasticSearch and verify the pipeline(s) have started successfully. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I took over management of an ElasticSearch environment that has a lot of configuration inconsistencies. Unfortunately, the previous owners weren&#8217;t the ones who built the environment either &#8230; so no one knew why ServerX did one thing and ServerY did another. Didn&#8217;t mess with it (if it&#8217;s working, don&#8217;t break it!) until we encountered some &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1588],"tags":[1590,1589,1643],"class_list":["post-9325","post","type-post","status-publish","format-standard","hentry","category-elk","tag-elasticsearch","tag-elk","tag-logstash"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9325"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9325\/revisions"}],"predecessor-version":[{"id":9327,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/9325\/revisions\/9327"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}