├── .delivery └── project.toml ├── .foodcritic ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .travis.yml ├── Berksfile ├── Building-Filebeat-On-Solaris11.md ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Rakefile ├── Thorfile ├── Vagrantfile ├── _config.yml ├── chefignore ├── files └── mac_os_x │ └── co.elastic.filebeat.plist ├── kitchen.dokken.yml ├── kitchen.yml ├── kitchen.zone.yml ├── libraries ├── helper.rb └── matchers.rb ├── metadata.rb ├── recipes └── lwrp_test.rb ├── resources ├── config.rb ├── install.rb ├── install_preview.rb ├── prospector.rb ├── runit_service.rb └── service.rb ├── spec ├── spec_helper.rb └── unit │ └── recipes │ └── default_spec.rb ├── templates └── default │ ├── filebeat │ ├── filebeat.xml.erb │ └── start-stop-filebeat.sh.erb │ └── sv-filebeat-run.erb └── test ├── cookbooks └── filebeat_test │ ├── README.md │ ├── attributes │ └── default.rb │ ├── metadata.rb │ └── recipes │ ├── current-ver.rb │ ├── preview.rb │ ├── previous-ver.rb │ └── runit.rb └── smoke ├── current-ver └── default.rb ├── previous-ver └── default.rb └── runit └── default.rb /.delivery/project.toml: -------------------------------------------------------------------------------- 1 | remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml" 2 | -------------------------------------------------------------------------------- /.foodcritic: -------------------------------------------------------------------------------- 1 | ~FC057 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .rbx 3 | *.class 4 | .kitchen/ 5 | .kitchen.local.yml 6 | tmp/ 7 | *# 8 | .#* 9 | \#*# 10 | .*.sw[a-z] 11 | *.un~ 12 | pkg/ 13 | 14 | # Berkshelf 15 | .vagrant 16 | /cookbooks 17 | Berksfile.lock 18 | 19 | # Bundler 20 | .vendor 21 | Gemfile.lock 22 | bin/* 23 | .bundle/* 24 | .DS_Store 25 | coverage/ 26 | 27 | .kitchen/ 28 | .kitchen.local.yml 29 | 30 | .ignore/ 31 | 32 | # IDE 33 | .idea/ 34 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | # TargetRubyVersion: 2.3 3 | Exclude: 4 | - Rakefile 5 | - Berksfile 6 | - Vagrantfile 7 | - Thorfile 8 | - Gemfile 9 | - '.kitchen/*' 10 | - 'vendor/*' 11 | AlignParameters: 12 | Enabled: true 13 | Encoding: 14 | Enabled: false 15 | HashSyntax: 16 | Enabled: false 17 | Metrics/LineLength: 18 | Enabled: false 19 | Metrics/MethodLength: 20 | Max: 75 21 | BracesAroundHashParameters: 22 | Enabled: true 23 | CyclomaticComplexity: 24 | Enabled: false 25 | GuardClause: 26 | Enabled: false 27 | Metrics/PerceivedComplexity: 28 | Max: 50 29 | Metrics/ModuleLength: 30 | Enabled: false 31 | ClassLength: 32 | Enabled: false 33 | Metrics/MethodLength: 34 | Enabled: false 35 | Metrics/BlockLength: 36 | Max: 125 37 | Exclude: 38 | - "**/*_spec.rb" 39 | AbcSize: 40 | Enabled: false 41 | Style/BlockComments: 42 | Enabled: false 43 | ChefModernize/WindowsZipfileUsage: 44 | Enabled: false 45 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | addons: 2 | apt: 3 | sources: 4 | - chef-stable-xenial 5 | packages: 6 | - chef-workstation 7 | 8 | install: echo "skip bundle install" 9 | 10 | branches: 11 | only: 12 | - master 13 | - /^(?i:travis).*$/ 14 | 15 | services: docker 16 | 17 | env: 18 | matrix: 19 | - INSTANCE=current-ver-amazonlinux 20 | - INSTANCE=current-ver-amazonlinux-2 21 | - INSTANCE=current-ver-debian-9 22 | - INSTANCE=current-ver-debian-10 23 | - INSTANCE=current-ver-centos-7 24 | - INSTANCE=current-ver-centos-8 25 | - INSTANCE=current-ver-oraclelinux-7 26 | - INSTANCE=current-ver-oraclelinux-8 27 | - INSTANCE=current-ver-fedora-latest 28 | - INSTANCE=current-ver-ubuntu-1804 29 | - INSTANCE=current-ver-ubuntu-2004 30 | - INSTANCE=previous-ver-amazonlinux 31 | - INSTANCE=previous-ver-amazonlinux-2 32 | - INSTANCE=previous-ver-debian-9 33 | - INSTANCE=previous-ver-debian-10 34 | - INSTANCE=previous-ver-centos-7 35 | - INSTANCE=previous-ver-centos-8 36 | - INSTANCE=previous-ver-oraclelinux-7 37 | - INSTANCE=previous-ver-oraclelinux-8 38 | - INSTANCE=previous-ver-fedora-latest 39 | - INSTANCE=previous-ver-ubuntu-1804 40 | - INSTANCE=previous-ver-ubuntu-2004 41 | 42 | before_script: 43 | - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) 44 | - eval "$(chef shell-init bash)" 45 | - chef --version 46 | 47 | script: CHEF_LICENSE=accept KITCHEN_LOCAL_YAML=kitchen.dokken.yml kitchen verify ${INSTANCE} 48 | 49 | matrix: 50 | allow_failures: 51 | - env: INSTANCE=previous-ver-oraclelinux-7 52 | - env: INSTANCE=previous-ver-oraclelinux-8 53 | - env: INSTANCE=current-ver-oraclelinux-7 54 | - env: INSTANCE=current-ver-oraclelinux-8 55 | - env: INSTANCE=previous-ver-fedora-latest 56 | - env: INSTANCE=current-ver-fedora-latest 57 | include: 58 | - script: 59 | - delivery local all 60 | env: 61 | - UNIT_AND_LINT=1 62 | - CHEF_LICENSE=accept 63 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | cookbook 'filebeat_test', path: './test/cookbooks/filebeat_test' 6 | -------------------------------------------------------------------------------- /Building-Filebeat-On-Solaris11.md: -------------------------------------------------------------------------------- 1 | You need Vagrant and VirtualBox to follow these 2 | 3 | - checkout https://github.com/elastic/beats (currently at commit 5bc18eae9044f44806813926346401550e925513) 4 | - vagrant up solaris 5 | - vagrant ssh solaris (or the name of the vm you created) 6 | - export GO15VENDOREXPERIMENT=1 7 | - export GOROOT=/go 8 | - export GOPATH=/export/home/vagrant/go 9 | - export PATH=/export/home/vagrant/go/bin:/go/bin:/usr/bin:/usr/sbin 10 | - cd /export/home/vagrant/go/src/github.com/elastic/beats/filebeat 11 | - gmake 12 | - tar -cvf filebeat--solaris.tar.gz filebeat filebeat.yml filebeat.template.json (or use gtar) 13 | 14 | use filebeat--solaris.tar.gz to install filebeat 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | filebeat CHANGELOG 2 | ================== 3 | 4 | 2.4.0 5 | ----- 6 | 7 | - Piotr Kantyka - Added property for prefix in prospector yaml filename 8 | 9 | - Oskar Bedychaj - Added filebeat_install no resource handle 10 | 11 | - Neil Duff-Howie - Fixed runit service when a service name is supplied 12 | 13 | - Doug Luxem - Fixes Windows issue where filebeats service is reinstalled on each run 14 | 15 | - Chris Minton - Update the config and prospector resources to handle version dependency 16 | 17 | - Chris Minton - Update the integration tests for configs 18 | 19 | - Chris Minton - Update the README to give the correct configuration for different versions 20 | 21 | - Virender Khatri - Updated Kitchen Tests 22 | 23 | - Virender Khatri - Update filebeat version to the latest 24 | 25 | - Virender Khatri - Fix issue #159 - Filebeat 7.x replaces filebeat.registry_file with filebeat.registry.path 26 | 27 | - Virender Khatri - Update dependency cookbook versions 28 | 29 | 30 | 2.2.0 31 | ----- 32 | 33 | - Luke Waite - Correct default file path for `filebeat_config` lwrp 34 | 35 | - Piotr Kantyka - Updated logging.files path config only when empty 36 | 37 | - Virender Khatri - Updated filebeat version to v6.4.2 38 | 39 | - Virender Khatri - Updated Kitchen Test for recent Chef Version 40 | 41 | - Virender Khatri - Removed v5 / Chef12 configuration references 42 | 43 | - Virender Khatri - Rename helper method purge_prospectors_dir to purge_prospectors_config in favor of filebeat_service resource 44 | 45 | - Virender Khatri - Wrapped helper methods into a module Filebeat::Helpers 46 | 47 | 48 | 2.1.0 49 | ----- 50 | 51 | - Virender Khatri - Added filebeat_install attr :elastic_repo_options for :elastic_repo resource configuration 52 | 53 | - Virender Khatri - Added filebeat Log Directory Resource 54 | 55 | - Virender Khatri - Updated filebeat_service service resource 56 | 57 | - Virender Khatri - Updated filebeat_resource lookup to use attr filebeat_install_resource_name 58 | 59 | - Virender Khatri - Fixed filebeat_install for windows 60 | 61 | - Virender Khatri - Updated elastic_repo cookbook version 62 | 63 | 64 | 2.0.0 65 | ----- 66 | 67 | - Virender Khatri - Converted Recipes to LWRP Resources, check README for available resources and test cookbook for usage reference 68 | 69 | - Virender Khatri - LWRP Resources uses elastic_repo cookbook to setup elastic yum/apt repository 70 | 71 | - Michael Burns - Clean up redundant filebeat_prospector resource attribute in test cookbook 72 | 73 | 1.5.0 74 | ----- 75 | - Virender Khatri - Updated filebeat version to v6.2.4 76 | 77 | - Jean Rouge - Making it possible to pass additional command line arguments to the filebeat service 78 | 79 | - Virender Khatri - Updated tests and clean up 80 | 81 | - Michael Burns - Updated default_spec.rb 82 | 83 | - Michael Burns - Use unzip_windows_zipfile for unit test 84 | 85 | - Oleksiy Kovyrin - Enable sensitive flag for filebeat file resource 86 | 87 | 1.4.0 88 | ----- 89 | 90 | - Virender Khatri - Updated filebeat version v6.0.1 91 | 92 | 1.3.0 93 | ----- 94 | 95 | - Virender Khatri - Use cookbook elastic_beats_repo 96 | 97 | - Virender Khatri - Updated filebeat version v5.6.4 98 | 99 | 1.2.0 100 | ----- 101 | 102 | - Antek S. Baranski - Adding filebeat on Mac OS X install support 103 | 104 | - Virender Khatri - Update filebeat version v5.6.3 105 | 106 | - Virender Khatri - Added RC preview version support 107 | 108 | 1.1.0 109 | ----- 110 | 111 | - Diogo Costa - PR Fix incorrect access to multiline_pattern attribute #116 112 | 113 | - Virender Khatri - Update file beat version v5.6.0 #117 114 | 115 | - Virender Khatri - Add test recipe missing prospector resource attributes #118 116 | 117 | - Virender Khatri - Match prospector resource attributes type with documentation #119 118 | 119 | - Virender Khatri - Add test recipe for v6 #120 120 | 121 | - Virender Khatri - Updated .kitchen.yml, dokken sync 122 | 123 | 1.0.0 124 | ----- 125 | 126 | - Virender Khatri - LWRP `filebeat_prospector` now creates configuration file with a prefix `lwrp-prospector-#{resource name}`, #73 127 | 128 | - Virender Khatri - Prospectors via node attribute `node['filebeat']['prospectors']` now uses LWRP `filebeat_prospector` instead of creating JSON file with a prefix `node-prospector-#{prospector name}`, #114 129 | 130 | - Virender Khatri - Added prospectors configuration files purge capability, #73, #103 131 | 132 | * Added new attribute `default['filebeat']['delete_prospectors_dir']` (default: `false`). If set to true, cookbook always delete and re-create prospectors configuration directory 133 | * Added new attribute `default['filebeat']['purge_prospectors_dir']` (default: `false`): If set to true, purge files under prospectors configuration directory, except `lwrp-prospector-` (created by LWRP) 134 | 135 | >>> Note: Set attribute `default['filebeat']['delete_prospectors_dir']` or `default['filebeat']['purge_prospectors_dir']` as per your requirement. 136 | 137 | - Virender Khatri - Dropped support for Chef <12.x, #110 138 | 139 | - Virender Khatri - No longer activelt test/support Filebeat v1.x, #113 140 | 141 | - Virender Khatri - Updated Kitchen Tests 142 | * Created Chef 12.x and 13.x tests, #108 143 | * Use Pinned Travis chef-dk version 144 | * Use stable chef-dk version 145 | * Added Amazon, Debian and, Fedora tests 146 | * Added Filebeat preview release support 147 | * Added Filebeat test cookbook 148 | 149 | - Virender Khatri - Added recent Filebeat prospector option to LWRP filebeat_prospector, #100 150 | 151 | - Virender Khatri - Updated Filebeat version to v5.5.2 152 | 153 | - Virender Khatri - Added Filebeat Preview (alpha/beta) version support, #112 154 | 155 | - Virender Khatri - Created separate cookbooks for prospectors and service 156 | 157 | - Virender Khatri - Updated attributes to use new . convention, issue # 158 | 159 | - Virender Khatri - Added apt install option --force-yes, #104 160 | 161 | 162 | 0.5.0 163 | ----- 164 | 165 | - Virender Khatri - Updated Beats Version to v5.4.2 166 | 167 | - Virender Khatri - Updated config file permissions to 0600 168 | 169 | - Virender Khatri - Optional apt/yum repository setup #98 170 | 171 | - Dmitry Krasnoukhov - Allow to customize filebeat service name 172 | 173 | 0.4.9 174 | ----- 175 | 176 | - Virender Khatri - Updated Beats Version to v5.2.2 177 | 178 | 0.4.8 179 | ----- 180 | 181 | - Kyle Gochenour - PR #89, correct spool_size to use the correct parameter 182 | 183 | - Virender Khatri - Issue #91, allow to ignore package verson in favor of pre installed filebeat packages 184 | 185 | - Virender Khatri - PR #94, Travis CI Fix 186 | 187 | - Len Smith - PR #93, Added check to avoid restart if service is disabled or notify restart is set to false 188 | 189 | 0.4.7 190 | ----- 191 | 192 | - Tom Michaud - PR #86, Supports prospector 'tags' attribute 193 | 194 | - Virender Khatri - Fixed Issue #88, Filebeat 5.2.0 Released, Unable to Install on Ubuntu 195 | 196 | - Virender Khatri - Updated default version to v5.2.0 197 | 198 | 0.4.6 199 | ----- 200 | 201 | - William Soula - PR #83, upgrade to filebeat 5.1.2, fix for #84 202 | 203 | 0.4.5 204 | ----- 205 | 206 | - Virender Khatri - issue #78, fixed windows filebeat directory issue for v5.x 207 | 208 | - Virender Khatri - use chefdk 209 | 210 | - Virender Khatri - added kitchen dokken 211 | 212 | 0.4.4 213 | ----- 214 | 215 | - Virender Khatri - fixed runit service 216 | 217 | 0.4.3 218 | ----- 219 | 220 | - Michael Mosher - added json attributes to filebeat_prospector 221 | 222 | - Virender Khatri - added v5.x support 223 | 224 | - Virender Khatri - updated default filebeat version to v5.1.1 225 | 226 | 0.4.2 227 | ----- 228 | 229 | - Andrei Scopenco - include yum-plugin-versionlock recipe for platform_family instead 230 | 231 | 0.4.1 232 | ----- 233 | 234 | - Jesse Cotton - Add support for using runit instead of the default init system 235 | 236 | 0.4.0 237 | ----- 238 | 239 | - Virender Khatri - fix for #60, HWRP does not restart filebeat service 240 | 241 | 0.3.9 242 | ----- 243 | 244 | - Virender Khatri - fix for #65, added yum apt version lock 245 | 246 | - Virender Khatri - updated beats version to v1.3.1 247 | 248 | 0.3.8 249 | ----- 250 | 251 | - Virender Khatri - #68, config_dir attribute not getting set 252 | 253 | 0.3.7 254 | ----- 255 | 256 | - Virender Khatri - Move derived attributes to recipe attributes 257 | 258 | - Virender Khatri - Update filebeat version to v1.3.0 259 | 260 | 0.3.6 261 | ----- 262 | 263 | - Arif Khan - Added Solaris Support 264 | 265 | - Tom Noonan - Handle when new_resource.action is an array 266 | 267 | - Virender Khatri - Updated filebeat config deprecated url reference 268 | 269 | - Virender Khatri - Added service resource configurable attributes with default values 270 | 271 | - Scott Nelson Windels - Add enable attribute back (used to be enabled, not it has been brought back as enable) 272 | 273 | - Eric Herot - Only call powershell resource on windows machines 274 | 275 | - Virender Khatri - Fix Travis 276 | 277 | - Virender Khatri - Use powershell_script instead 278 | 279 | - Scott Nelson Windels - Remove enabled attribute for now, as it isn't a feature in filebeat beyond the rc versions 280 | 281 | 0.3.4 282 | ----- 283 | 284 | - Samuel Sampaio - added new filebeat prospector attributes 285 | 286 | 0.3.3 287 | ----- 288 | 289 | - Virender Khatri - updated beats version to v1.2.3 290 | 291 | 0.3.2 292 | ----- 293 | 294 | - Prerak Shah - Fixed Travis Errors 295 | 296 | - Prerak Shah - Fixed Unit Tests 297 | 298 | - Al Lefebvre - Added missing attribute for exclude_files 299 | 300 | - Luke Lowery - Fixing issue with patterns and older versions of Ruby 301 | Updated YAML engine to adhere to ruby style guide 302 | 303 | - Prerak Shah - Fixed default Install paths for windows 304 | 305 | - Martin Smith - Respect service flags on package installation 306 | 307 | - Azat Khadiev - Support spaces in file path for Windows 308 | 309 | 310 | 311 | 0.3.1 312 | ----- 313 | 314 | - Virender Khatri - fix for #41 315 | 316 | - Virender Khatri - added apt-get options, fix for #39 317 | 318 | - Virender Khatri - bump filebeat version to v1.2.1 319 | 320 | 0.2.8 321 | ----- 322 | 323 | - Spencer Owen - Adds a tag to berksfile 324 | 325 | - Chris Barber - cleaning up mixmatch of tabs and spaces. fixed spelling error on prospector 326 | 327 | - Eric Herot - Fix the formatting on the LWRP example in the README 328 | 329 | - Roberto Rivera - Add include_lines and exclude lines. 330 | 331 | - Sean Nolen - #33 added multiline support for LWRP 332 | 333 | - Sean Nolen - #30 fixed rubocop error 334 | 335 | - Seva Orlov - #34, restart filebeat on upgrade 336 | 337 | - Virender Khatri - update to beat v1.1.2 338 | 339 | 0.2.7 340 | ----- 341 | 342 | - Virender Khatri - #21, add yum_repository resource attribute metadata_expire 343 | 344 | - Virender Khatri - #20, update to beat v1.0.1 345 | 346 | 0.2.6 347 | ----- 348 | 349 | - Virender Khatri - #18, added LWRP resource for prospectors 350 | 351 | - Virender Khatri - #15, fix kitchen test 352 | 353 | 0.2.5 354 | ----- 355 | 356 | - Virender Khatri - disabled default output configuration and enable_localhost_output attributes 357 | 358 | - Virender Khatri - #10, handle missing attribute node['filebeat']['windows']['version_string'] 359 | 360 | - Virender Khatri - #6, added specs 361 | 362 | - Virender Khatri - #13, major changes to support repository package install 363 | 364 | 0.2.1 365 | ----- 366 | 367 | - Virender Khatri - Added platforms metadata info 368 | 369 | - Virender Khatri - #8, add missing dependency on powershell for windows platform 370 | 371 | - Virender Khatri - #9, use resource powershell instead of powershell_script 372 | 373 | 0.2.0 374 | ----- 375 | - Brandon Wilson - Include dpkg options to keep old config files when upgrading filebeat to a new release. Without specifying the dpkg options, dpkg will attempt to interactively ask if it should keep the old conf file, or replace it with the vendor supplied conf file which comes with the new version of the package. Since chef is running dpkg non-interactively, it causes dpkg to exit with code 1, and the chef run fails. 376 | 377 | - Virender Khatri - Fix for #4, handle derived attribute for package_url 378 | 379 | - Patrick Christopher - Added support for Windows OS 380 | 381 | 0.1.0 382 | ----- 383 | 384 | - Virender Khatri - Initial release of filebeat 385 | 386 | - - - 387 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 388 | 389 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 390 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | filebeat Cookbook 2 | ================ 3 | 4 | [![Cookbook](https://img.shields.io/github/tag/vkhatri/chef-filebeat.svg)](https://github.com/vkhatri/chef-filebeat) [![Build Status](https://travis-ci.org/vkhatri/chef-filebeat.svg?branch=master)](https://travis-ci.org/vkhatri/chef-filebeat) 5 | 6 | This is a [Chef] cookbook to manage [Filebeat]. 7 | 8 | >> For Production environment, always prefer the [most recent release](https://supermarket.chef.io/cookbooks/filebeat). 9 | 10 | ## Most Recent Release 11 | 12 | ```ruby 13 | cookbook 'filebeat', '~> 2.4.0' 14 | ``` 15 | 16 | ## From Git 17 | 18 | ```ruby 19 | cookbook 'filebeat', github: 'vkhatri/chef-filebeat', tag: 'v2.4.0' 20 | ``` 21 | 22 | ## Repository 23 | 24 | ```bash 25 | https://github.com/vkhatri/chef-filebeat 26 | ``` 27 | 28 | ## Supported OS 29 | 30 | - Windows 31 | - Amazon Linux 32 | - CentOS 33 | - Fedora 34 | - Ubuntu 35 | - Debian 36 | - Mac OSX 37 | 38 | Also works on Solaris zones given a physical Solaris 11.2 server. For that, use the .kitchen.zone.yml file. Check usage at (https://github.com/criticalmass/kitchen-zone). You will need an url to a filebeat package that works on Solaris 11.2. Checkout Building-Filebeat-On-Solaris11.md for instructions to build a filebeat package. 39 | 40 | ## Supported Chef 41 | 42 | This cookbook is tested against current Chef version. But, the cookbook is known to work with Chef Client version >=12.14. 43 | 44 | ## Supported Filebeat 45 | 46 | - 6.x 47 | - 7.x 48 | 49 | ## Cookbook Dependency 50 | 51 | - `homebrew` 52 | - `elastic_repo` 53 | - `yum-plugin-versionlock` 54 | - `runit` 55 | - `windows` 56 | 57 | ## Recipes 58 | 59 | - lwrp_test - LWRP examples recipe 60 | 61 | ## LWRP Resources 62 | 63 | - `filebeat_config` - filebeat configuration resource 64 | 65 | - `filebeat_install` - filebeat install resource 66 | 67 | - `filebeat_install_preview` - filebeat preview package install resource 68 | 69 | - `filebeat_service` - filebeat service resource 70 | 71 | - `filebeat_runit_service` - filebeat service resource using runit 72 | 73 | - `filebeat_prospector` - filebeat prospector resource (renamed filebeat inputs in version 6.3+) 74 | 75 | ## Limitations 76 | 77 | The Mac OSX setup only allows for package installs and depends on brew, this means that version selection and preview build installs are not supported. 78 | 79 | ## LWRP filebeat_install 80 | 81 | LWRP `filebeat_install` installs filebeat, creates log/prospectors directories, and also enable filebeat service. 82 | 83 | Below attributes are derived using helper methods and also used by other LWRP. 84 | 85 | - `conf_dir` 86 | - `prospectors_dir` 87 | - `log_dir` 88 | 89 | **LWRP example** 90 | 91 | ```ruby 92 | filebeat_install 'default' do 93 | [options ..] 94 | end 95 | ``` 96 | 97 | 98 | **LWRP Options** 99 | 100 | - *action* (optional) - default `:create`, options: :create, :delete 101 | - *version* (optional, String) - default `6.3.0`, filebeat version 102 | - *release* (optional, String) - default `1`, filebeat release version, used by `rhel` family package resource 103 | - *setup_repo* (optional, Boolean) - default `true`, set to `false`, to skip elastic repository setup using cookbook `elastic_repo` 104 | - *ignore_package_version* (optional, Boolean) - default `false`, set to true, to install latest available yum/apt filebeat package 105 | - *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources 106 | - *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service 107 | - *notify_restart* (optional, Boolean) - default `true`, set to `false`, to ignore filebeat service restart notify 108 | - *delete_prospectors_dir* (optional, Boolean) - default `false`, set to `true`, to purge prospectors directory by deleting and recrating prospectors directory 109 | - *conf_dir* (optional, String, NilClass) - default `nil`, filebeat configuration directory, this attribute is derived by helper method 110 | - *prospectors_dir* (optional, String, NilClass) - default `nil`, filebeat prospectors directory, this attribute is derived by helper method 111 | - *log_dir* (optional, String, NilClass) - default `nil`, filebeat log directory, this attribute is derived by helper method 112 | - *windows_package_url* (optional, String) - default `auto`, windows filebeat package url 113 | - *windows_base_dir* (optional, String) - default `C:/opt/filebeat`, filebeat windows base directory 114 | - *apt_options* (optional, Array) - default `%w[stable main]`, filebeat package resource attribute for `debian` platform family 115 | - *elastic_repo_options* (optional, Hash) - default `{}`, resource elastic_repo options, `filebeat_install` attribute `version` overrides `elasti_repo_options` key `version` value. Check out [elastic_repo cookbook](https://github.com/vkhatri/chef-elastic-repo) for more details. 116 | 117 | 118 | ## LWRP filebeat_service 119 | 120 | LWRP `filebeat_service` configures `filebeat` service. 121 | 122 | 123 | **LWRP example** 124 | 125 | ```ruby 126 | filebeat_service 'default' do 127 | [options ..] 128 | end 129 | ``` 130 | 131 | **LWRP Options** 132 | 133 | - *action* (optional) - default `:create`, options: :create, :delete 134 | - *filebeat_install_resource_name* (optional, String) - default `default`, filebeat_install/filebeat_install_preview resource name, set this attribute if LWRP resource name is other than `default` 135 | - *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources 136 | - *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service 137 | - *purge_prospectors_dir* (optional, Boolean) - default `false`, set to `true`, to purge prospectors 138 | - *service_ignore_failure* (optional, Boolean) - default `false`, set to `true`, to ignore filebeat service failures 139 | - *service_retries* (optional, Integer) - default `2`, filebeat service resource attribute 140 | - *service_retry_delay* (optional, Integer) - default `0`, filebeat service resource attribute 141 | 142 | ## LWRP filebeat_config 143 | 144 | LWRP `filebeat_config` creates filebeat configuration yaml file `/etc/filebeat/filebeat.yml`. 145 | 146 | Below filebeat configuration parameters gets overwritten by the LWRP. 147 | 148 | - `filebeat.registry_file` 149 | - `filebeat.config_dir` 150 | - `logging.files` 151 | 152 | ### Filebeat version < 6.0 153 | 154 | ```ruby 155 | conf = { 156 | 'filebeat.modules' => [], 157 | 'prospectors' => [], 158 | 'logging.level' => 'info', 159 | 'logging.to_files' => true, 160 | 'logging.files' => { 'name' => 'filebeat' }, 161 | 'output.elasticsearch' => { 'hosts' => ['127.0.0.1:9200'] } 162 | } 163 | 164 | filebeat_config 'default' do 165 | config conf 166 | action :create 167 | end 168 | ``` 169 | 170 | Above LWRP Resource will create a file `/etc/filebeat/filebeat.yml` with content: 171 | 172 | ```yaml 173 | filebeat.modules: [] 174 | prospectors: [] 175 | logging.level: info 176 | logging.to_files: true 177 | logging.files: 178 | path: "/var/log/filebeat" 179 | output.elasticsearch: 180 | hosts: 181 | - 127.0.0.1:9200 182 | filebeat.registry_file: "/var/lib/filebeat/registry" 183 | filebeat.config_dir: "/etc/filebeat/conf.d" 184 | ``` 185 | 186 | ### Filebeat version 6.0+ 187 | 188 | ```ruby 189 | conf = { 190 | 'filebeat.modules' => [], 191 | 'filebeat.inputs' => [], 192 | 'logging.level' => 'info', 193 | 'logging.to_files' => true, 194 | 'logging.files' => { 'name' => 'filebeat' }, 195 | 'output.elasticsearch' => { 'hosts' => ['127.0.0.1:9200'] } 196 | } 197 | 198 | filebeat_config 'default' do 199 | config conf 200 | action :create 201 | end 202 | ``` 203 | 204 | Above LWRP Resource will create a file `/etc/filebeat/filebeat.yml` with content: 205 | 206 | ```yaml 207 | filebeat.modules: [] 208 | prospectors: [] 209 | logging.level: info 210 | logging.to_files: true 211 | logging.files: 212 | path: "/var/log/filebeat" 213 | output.elasticsearch: 214 | hosts: 215 | - 127.0.0.1:9200 216 | filebeat.registry_file: "/var/lib/filebeat/registry" 217 | filebeat.config.inputs: 218 | enabled: true 219 | path: "/etc/filebeat/conf.d/*.yml" 220 | ``` 221 | 222 | **LWRP Options** 223 | 224 | - *action* (optional) - default `:create`, options: :create, :delete 225 | - *filebeat_install_resource_name* (optional, String) - default `default`, filebeat_install/filebeat_install_preview resource name, set this attribute if LWRP resource name is other than `default` 226 | - *config* (Hash) - default `{}` filebeat configuration options 227 | - *config_sensitive* (optional, Boolean) - default `false`, filebeat configuration file chef resource attribute 228 | - *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources 229 | - *conf_file* (optional, String, NilClass) - default `nil`, filebeat configuration file, this attribute is derived by helper method 230 | - *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service 231 | - *notify_restart* (optional, Boolean) - default `true`, set to `false`, to ignore filebeat service restart notify 232 | - *prefix* (optional, String) - default `lwrp-prospector-`, filebeat prospecteor filename prefix, set to '' if no prefix is desired 233 | 234 | 235 | ## LWRP filebeat_prospector (inputs) 236 | 237 | ### Filebeat version up to 6.3 238 | LWRP `filebeat_prospector` creates a filebeat prospector configuration yaml file under prospectors directory with file name `lwrp-prospector-#{resource_name}.yml`. 239 | `lwrp-prospector-` prefix can be changed with `prefix` property (see above). 240 | 241 | **LWRP example** 242 | 243 | ```ruby 244 | conf = { 245 | 'enabled' => true, 246 | 'paths' => ['/var/log/messages'], 247 | 'type' => 'log', 248 | 'fields' => {'type' => 'messages_log'} 249 | } 250 | 251 | filebeat_prospector 'messages_log' do 252 | config conf 253 | action :create 254 | prefix 'my-custom-prefix-' 255 | end 256 | ``` 257 | 258 | Above LWRP Resource will create a file `/etc/filebeat/conf.d/my-custom-prefix-messages_log.yml` with content: 259 | 260 | ```yaml 261 | filebeat: 262 | prospectors: 263 | - enabled: true 264 | paths: 265 | - "/var/log/messages" 266 | type: log 267 | fields: 268 | type: messages_log 269 | ``` 270 | 271 | ### Filebeat version 6.3+ 272 | 273 | With `filebeat.config.inputs` set, Filebeat 6.3+ will read in the files as previous versions and the same config will work as expected 274 | 275 | ```ruby 276 | conf = { 277 | 'type' => 'log', 278 | 'enabled' => true, 279 | 'paths' => ['/var/log/messages'], 280 | 'type' => 'log', 281 | 'fields' => {'type' => 'messages_log'} 282 | } 283 | 284 | filebeat_prospector 'messages_log' do 285 | config conf 286 | action :create 287 | end 288 | ``` 289 | 290 | the file is created with content: 291 | 292 | ```yaml 293 | - enabled: true 294 | paths: 295 | - "/var/log/messages" 296 | type: log 297 | fields: 298 | type: messages_log 299 | ``` 300 | 301 | **LWRP Options** 302 | 303 | - *action* (optional) - default `:create`, options: :create, :delete 304 | - *filebeat_install_resource_name* (optional, String) - default `default`, filebeat_install/filebeat_install_preview resource name, set this attribute if LWRP resource name is other than `default` 305 | - *config* (Hash) - default `{}` filebeat configuration options 306 | - *config_sensitive* (optional, Boolean) - default `false`, filebeat configuration file chef resource attribute 307 | - *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources 308 | - *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service 309 | - *notify_restart* (optional, Boolean) - default `true`, set to `false`, to ignore filebeat service restart notify 310 | 311 | ## LWRP filebeat_runit_service 312 | 313 | LWRP `filebeat_runit_service` configures `filebeat` service using `runit`. 314 | 315 | 316 | **LWRP example** 317 | 318 | ```ruby 319 | filebeat_runit_service 'default' do 320 | [options ..] 321 | end 322 | ``` 323 | 324 | **LWRP Options** 325 | 326 | - *action* (optional) - default `:create`, options: :create, :delete 327 | - *filebeat_install_resource_name* (optional, String) - default `default`, filebeat_install/filebeat_install_preview resource name, set this attribute if LWRP resource name is other than `default` 328 | - *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources 329 | - *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service 330 | - *purge_prospectors_dir* (optional, Boolean) - default `false`, set to `true`, to purge prospectors 331 | - *runit_filebeat_cmd_options* (optional, Boolean) - default `''`, set to `true`, runit filebeat service command line options 332 | - *service_ignore_failure* (optional, Boolean) - default `false`, set to `true`, to ignore filebeat service failures 333 | 334 | 335 | ## How to Create Filebeat LWRP Resources via Node Attribute 336 | 337 | Check out filebeat test cookbook [filebeat_test](test/cookbooks/filebeat_test). 338 | 339 | ## TODO 340 | 341 | - Add other platforms support to install_preview resource 342 | 343 | ## Contributing 344 | 345 | 1. Fork the repository on Github 346 | 2. Create a named feature branch (like `add_component_x`) 347 | 3. Write your change 348 | 4. Write tests for your change (if applicable) 349 | 5. Run the tests (`rake & rake knife`), ensuring they all pass 350 | 6. Write new resource/attribute description to `README.md` 351 | 7. Write description about changes to PR 352 | 8. Submit a Pull Request using Github 353 | 354 | ## Copyright & License 355 | 356 | Authors:: Virender Khatri and [Contributors] 357 | 358 |
359 | Licensed under the Apache License, Version 2.0 (the "License");
360 | you may not use this file except in compliance with the License.
361 | You may obtain a copy of the License at
362 | 
363 |     http://www.apache.org/licenses/LICENSE-2.0
364 | 
365 | Unless required by applicable law or agreed to in writing, software
366 | distributed under the License is distributed on an "AS IS" BASIS,
367 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
368 | See the License for the specific language governing permissions and
369 | limitations under the License.
370 | 
371 | 372 | [Chef]: https://www.chef.io/ 373 | [Filebeat]: https://www.elastic.co/products/beats/filebeat 374 | [Contributors]: https://github.com/vkhatri/chef-filebeat/graphs/contributors 375 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | 3 | require 'foodcritic' 4 | require 'rubocop/rake_task' 5 | require 'rspec/core/rake_task' 6 | 7 | desc 'Run all lints' 8 | task :lint => %w(foodcritic rubocop spec) 9 | task :default => :lint 10 | 11 | desc 'Run Rubocop Lint Task' 12 | task :rubocop do 13 | RuboCop::RakeTask.new 14 | end 15 | 16 | desc 'Run Food Critic Lint Task' 17 | task :foodcritic do 18 | FoodCritic::Rake::LintTask.new do |fc| 19 | fc.options = {:fail_tags => ['any']} 20 | end 21 | end 22 | 23 | desc 'Run Knife Cookbook Test Task' 24 | task :knife do 25 | current_dir = File.expand_path(File.dirname(__FILE__)) 26 | cookbook_dir = File.dirname(current_dir) 27 | cookbook_name = File.basename(current_dir) 28 | sh "bundle exec knife cookbook test -o #{cookbook_dir} #{cookbook_name}" 29 | end 30 | 31 | desc 'Run Chef Spec Test' 32 | task :spec do 33 | RSpec::Core::RakeTask.new(:spec) 34 | end 35 | -------------------------------------------------------------------------------- /Thorfile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'bundler' 4 | require 'bundler/setup' 5 | require 'berkshelf/thor' 6 | 7 | begin 8 | require "kitchen/thor_tasks" 9 | Kitchen::ThorTasks.new 10 | rescue LoadError 11 | puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV["CI"] 12 | end 13 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = '2' 6 | 7 | Vagrant.require_version '>= 1.5.0' 8 | 9 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 10 | # All Vagrant configuration is done here. The most common configuration 11 | # options are documented and commented below. For a complete reference, 12 | # please see the online documentation at vagrantup.com. 13 | 14 | config.vm.hostname = 'filebeat-berkshelf' 15 | 16 | # Set the version of chef to install using the vagrant-omnibus plugin 17 | # NOTE: You will need to install the vagrant-omnibus plugin: 18 | # 19 | # $ vagrant plugin install vagrant-omnibus 20 | # 21 | if Vagrant.has_plugin?("vagrant-omnibus") 22 | config.omnibus.chef_version = 'latest' 23 | end 24 | 25 | # Every Vagrant virtual environment requires a box to build off of. 26 | # If this value is a shorthand to a box in Vagrant Cloud then 27 | # config.vm.box_url doesn't need to be specified. 28 | config.vm.box = 'chef/ubuntu-14.04' 29 | 30 | 31 | # Assign this VM to a host-only network IP, allowing you to access it 32 | # via the IP. Host-only networks can talk to the host machine as well as 33 | # any other machines on the same network, but cannot be accessed (through this 34 | # network interface) by any external networks. 35 | config.vm.network :private_network, type: 'dhcp' 36 | 37 | # Create a forwarded port mapping which allows access to a specific port 38 | # within the machine from a port on the host machine. In the example below, 39 | # accessing "localhost:8080" will access port 80 on the guest machine. 40 | 41 | # Share an additional folder to the guest VM. The first argument is 42 | # the path on the host to the actual folder. The second argument is 43 | # the path on the guest to mount the folder. And the optional third 44 | # argument is a set of non-required options. 45 | # config.vm.synced_folder "../data", "/vagrant_data" 46 | 47 | # Provider-specific configuration so you can fine-tune various 48 | # backing providers for Vagrant. These expose provider-specific options. 49 | # Example for VirtualBox: 50 | # 51 | # config.vm.provider :virtualbox do |vb| 52 | # # Don't boot with headless mode 53 | # vb.gui = true 54 | # 55 | # # Use VBoxManage to customize the VM. For example to change memory: 56 | # vb.customize ["modifyvm", :id, "--memory", "1024"] 57 | # end 58 | # 59 | # View the documentation for the provider you're using for more 60 | # information on available options. 61 | 62 | # The path to the Berksfile to use with Vagrant Berkshelf 63 | # config.berkshelf.berksfile_path = "./Berksfile" 64 | 65 | # Enabling the Berkshelf plugin. To enable this globally, add this configuration 66 | # option to your ~/.vagrant.d/Vagrantfile file 67 | config.berkshelf.enabled = true 68 | 69 | # An array of symbols representing groups of cookbook described in the Vagrantfile 70 | # to exclusively install and copy to Vagrant's shelf. 71 | # config.berkshelf.only = [] 72 | 73 | # An array of symbols representing groups of cookbook described in the Vagrantfile 74 | # to skip installing and copying to Vagrant's shelf. 75 | # config.berkshelf.except = [] 76 | 77 | config.vm.provision :chef_solo do |chef| 78 | chef.json = { 79 | mysql: { 80 | server_root_password: 'rootpass', 81 | server_debian_password: 'debpass', 82 | server_repl_password: 'replpass' 83 | } 84 | } 85 | 86 | chef.run_list = [ 87 | 'recipe[filebeat::default]' 88 | ] 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-leap-day -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # or sharing to the community site. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | Icon? 9 | nohup.out 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | .kitchen/ 14 | .kitchen.local.yml 15 | 16 | # SASS # 17 | ######## 18 | .sass-cache 19 | 20 | # EDITORS # 21 | ########### 22 | \#* 23 | .#* 24 | *~ 25 | *.sw[a-z] 26 | *.bak 27 | REVISION 28 | TAGS* 29 | tmtags 30 | *_flymake.* 31 | *_flymake 32 | *.tmproj 33 | .project 34 | .settings 35 | mkmf.log 36 | 37 | ## COMPILED ## 38 | ############## 39 | a.out 40 | *.o 41 | *.pyc 42 | *.so 43 | *.com 44 | *.class 45 | *.dll 46 | *.exe 47 | */rdoc/ 48 | 49 | # Testing # 50 | ########### 51 | .watchr 52 | .rspec 53 | spec/* 54 | spec/fixtures/* 55 | test/* 56 | features/* 57 | Guardfile 58 | Procfile 59 | 60 | # SCM # 61 | ####### 62 | .git 63 | */.git 64 | .gitignore 65 | .gitmodules 66 | .gitconfig 67 | .gitattributes 68 | .svn 69 | */.bzr/* 70 | */.hg/* 71 | */.svn/* 72 | 73 | # Berkshelf # 74 | ############# 75 | cookbooks/* 76 | tmp 77 | 78 | # Cookbooks # 79 | ############# 80 | CONTRIBUTING 81 | CHANGELOG* 82 | 83 | # Strainer # 84 | ############ 85 | Colanderfile 86 | Strainerfile 87 | .colander 88 | .strainer 89 | 90 | # Vagrant # 91 | ########### 92 | .vagrant 93 | Vagrantfile 94 | 95 | # Travis # 96 | ########## 97 | .travis.yml 98 | 99 | # Coverage # 100 | ########## 101 | coverage/ 102 | 103 | # Berkshelf 104 | Berksfile.lock 105 | 106 | # Bundler 107 | Gemfile.lock 108 | 109 | # Data Bag Sample Files 110 | databag/ 111 | 112 | .ignore/ 113 | -------------------------------------------------------------------------------- /files/mac_os_x/co.elastic.filebeat.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | co.elastic.filebeat 7 | ProgramArguments 8 | 9 | /usr/local/bin/filebeat 10 | -c 11 | /etc/filebeat/filebeat.yml 12 | 13 | KeepAlive 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: dokken 4 | privileged: true 5 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> 6 | chef_license: accept-no-persist 7 | 8 | transport: 9 | name: dokken 10 | 11 | provisioner: 12 | name: dokken 13 | attributes: 14 | apt: 15 | confd: 16 | install_recommends: false 17 | 18 | verifier: 19 | name: inspec 20 | 21 | platforms: 22 | - name: amazonlinux 23 | driver: 24 | image: dokken/amazonlinux 25 | pid_one_command: /sbin/init 26 | 27 | - name: amazonlinux-2 28 | driver: 29 | image: dokken/amazonlinux-2 30 | pid_one_command: /usr/lib/systemd/systemd 31 | 32 | - name: debian-9 33 | driver: 34 | image: dokken/debian-9 35 | pid_one_command: /bin/systemd 36 | intermediate_instructions: 37 | - RUN /usr/bin/apt-get update 38 | 39 | - name: debian-10 40 | driver: 41 | image: dokken/debian-10 42 | pid_one_command: /bin/systemd 43 | intermediate_instructions: 44 | - RUN /usr/bin/apt-get update 45 | 46 | - name: centos-7 47 | driver: 48 | image: dokken/centos-7 49 | pid_one_command: /usr/lib/systemd/systemd 50 | 51 | - name: centos-8 52 | driver: 53 | image: dokken/centos-8 54 | pid_one_command: /usr/lib/systemd/systemd 55 | 56 | - name: oraclelinux-7 57 | driver: 58 | image: dokken/oraclelinux-7 59 | pid_one_command: /usr/lib/systemd/systemd 60 | 61 | - name: oraclelinux-8 62 | driver: 63 | image: dokken/oraclelinux-8 64 | pid_one_command: /usr/lib/systemd/systemd 65 | 66 | - name: fedora-latest 67 | driver: 68 | image: dokken/fedora-latest 69 | pid_one_command: /usr/lib/systemd/systemd 70 | 71 | - name: ubuntu-18.04 72 | driver: 73 | image: dokken/ubuntu-18.04 74 | pid_one_command: /bin/systemd 75 | intermediate_instructions: 76 | - RUN /usr/bin/apt-get update 77 | 78 | - name: ubuntu-20.04 79 | driver: 80 | image: dokken/ubuntu-20.04 81 | pid_one_command: /bin/systemd 82 | intermediate_instructions: 83 | - RUN /usr/bin/apt-get update 84 | 85 | suites: 86 | - name: current-ver 87 | verifier: 88 | inspec_tests: 89 | - test/smoke/current-ver 90 | run_list: 91 | - recipe[filebeat_test::current-ver] 92 | 93 | - name: previous-ver 94 | verifier: 95 | inspec_tests: 96 | - test/smoke/previous-ver 97 | run_list: 98 | - recipe[filebeat_test::previous-ver] 99 | 100 | - name: runit 101 | verifier: 102 | inspec_tests: 103 | - test/smoke/runit 104 | run_list: 105 | - recipe[filebeat_test::runit] 106 | -------------------------------------------------------------------------------- /kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | verifier: 6 | name: inspec 7 | 8 | provisioner: 9 | # client_rb: 10 | # treat_deprecation_warnings_as_errors: true 11 | # resource_cloning: false 12 | name: chef_zero 13 | log_file: "/kitchen-chef-client.log" 14 | # log_level: debug 15 | attributes: 16 | apt: 17 | confd: 18 | install_recommends: false 19 | 20 | platforms: 21 | - name: ubuntu-18.04 22 | run_list: 23 | - recipe[apt] 24 | - name: centos-7.6 25 | run_list: 26 | - recipe[yum] 27 | - name: centos-8.0 28 | run_list: 29 | - recipe[yum] 30 | - name: windows-2012R2 31 | driver: 32 | box: mwrock/Windows2012R2 33 | guest: windows 34 | communicator: winrm 35 | gui: false 36 | platform: windows 37 | 38 | suites: 39 | - name: chef13 40 | driver: 41 | require_chef_omnibus: 13.11.3 42 | verifier: 43 | inspec_tests: 44 | - test/smoke/v6 45 | excludes: 46 | - windows-2012R2 47 | run_list: 48 | - recipe[filebeat_test::defaultv6] 49 | 50 | - name: chef14 51 | driver: 52 | require_chef_omnibus: 14.5.33 53 | verifier: 54 | inspec_tests: 55 | - test/smoke/v6 56 | excludes: 57 | - windows-2012R2 58 | run_list: 59 | - recipe[filebeat_test::defaultv6] 60 | 61 | - name: chef14win 62 | driver: 63 | require_chef_omnibus: 14.5.33 64 | verifier: 65 | inspec_tests: 66 | - test/smoke/v6windows 67 | run_list: 68 | - recipe[filebeat_test::defaultv6] 69 | includes: 70 | - windows-2012R2 71 | 72 | - name: chef14runit 73 | driver: 74 | require_chef_omnibus: 14.5.33 75 | excludes: 76 | - windows-2012R2 77 | run_list: 78 | - recipe[filebeat::default] 79 | 80 | - name: chef14preview 81 | driver: 82 | require_chef_omnibus: 14.5.33 83 | verifier: 84 | inspec_tests: 85 | - test/smoke/v6 86 | excludes: 87 | - windows-2012R2 88 | run_list: 89 | - recipe[filebeat_test::defaultv6preview] 90 | attributes: 91 | filebeat: 92 | version: 6.0.0-beta2 93 | -------------------------------------------------------------------------------- /kitchen.zone.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: zone 3 | 4 | provisioner: 5 | name: chef_zero 6 | 7 | platforms: 8 | - name: solaris-11-i86pc 9 | provisioner: 10 | sudo_command: 'sudo -E' 11 | verifier: 12 | sudo_command: 'sudo -E' 13 | driver: 14 | global_zone_hostname: '' 15 | global_zone_user: '' 16 | global_zone_password: '' 17 | test_zone_ip: '' 18 | suites: 19 | - name: filebeat 20 | run_list: 21 | - recipe[cm-monitor-collection::filebeat] 22 | attributes: 23 | filebeat: 24 | version: '' 25 | package_url: '' 26 | package_force_overwrite: true 27 | config: 28 | logging: 29 | to_syslog: false 30 | to_files: true 31 | files: 32 | path: /var/log/filebeat 33 | name: filebeat.log 34 | keepfiles: 7 35 | rotateeverybytes: 10485760 36 | level: info 37 | output: 38 | logstash: 39 | hosts: [""] 40 | tls: 41 | insecure: true 42 | - name: test 43 | run_list: 44 | - recipe[cm-monitor-collection::filebeat] -------------------------------------------------------------------------------- /libraries/helper.rb: -------------------------------------------------------------------------------- 1 | require 'fileutils' 2 | 3 | module Filebeat 4 | # Filebeat Helper Module 5 | module Helpers 6 | def purge_prospectors_config(prospectors_dir) 7 | valid_prospectors = [] 8 | 9 | # collect lwrp filebeat_prospector prospectors 10 | run_context.resource_collection.select { |resource| valid_prospectors.push("#{resource.prefix}#{resource.name}.yml") if resource.resource_name == :filebeat_prospector } 11 | 12 | # prospectors yml files to clean up 13 | extra_prospectors = Dir.entries(prospectors_dir).reject { |a| valid_prospectors.include?(a) || a.match(/^custom-prospector-.*yml$/) }.sort 14 | extra_prospectors -= ['.', '..'] 15 | 16 | extra_prospectors.each do |prospector| 17 | prospector_file = ::File.join(prospectors_dir, prospector) 18 | FileUtils.rm prospector_file 19 | Chef::Log.warn("deleted filebeat prospector configuration file #{prospector_file}") 20 | end 21 | 22 | Chef::Log.info("\n could not find any filebeat prospector configuration file to purge") if extra_prospectors.empty? 23 | end 24 | 25 | def machine_arch 26 | node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'x86' 27 | end 28 | 29 | def win_package_url(version, package_url) 30 | package_url = if version < '5.0' 31 | package_url == 'auto' ? "https://download.elastic.co/beats/filebeat/filebeat-#{version}-windows.zip" : package_url 32 | else 33 | package_url == 'auto' ? "https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-#{version}-windows-#{machine_arch}.zip" : package_url 34 | end 35 | package_url 36 | end 37 | 38 | def default_config_dir(version, windows_base_dir) 39 | conf_dir = if node['platform'] == 'windows' 40 | if version < '5.0' 41 | "#{windows_base_dir}/filebeat-#{version}-windows" 42 | else 43 | "#{windows_base_dir}/filebeat-#{version}-windows-#{machine_arch}" 44 | end 45 | else 46 | '/etc/filebeat' 47 | end 48 | conf_dir 49 | end 50 | 51 | def default_conf_file(conf_dir) 52 | node['platform'] == 'windows' ? "#{conf_dir}/filebeat.yml" : ::File.join(conf_dir, 'filebeat.yml') 53 | end 54 | 55 | def default_prospectors_dir(conf_dir) 56 | node['platform'] == 'windows' ? "#{conf_dir}/conf.d" : ::File.join(conf_dir, 'conf.d') 57 | end 58 | 59 | def check_beat_resource(run_context, resource_type, resource_name = 'default') 60 | run_context.resource_collection.find(resource_type => resource_name) 61 | rescue StandardError 62 | nil 63 | end 64 | 65 | def find_beat_resource(run_context, resource_type, resource_name = 'default') 66 | run_context.resource_collection.find(resource_type => resource_name) 67 | end 68 | 69 | def default_log_dir(conf_dir) 70 | node['platform'] == 'windows' ? "#{conf_dir}/logs" : '/var/log/filebeat' 71 | end 72 | end 73 | end 74 | 75 | # ::Chef::Recipe.send(:include, Filebeat::Helpers) 76 | # ::Chef::Resource.send(:include, Filebeat::Helpers) 77 | # ::Chef::Provider.send(:include, Filebeat::Helpers) 78 | -------------------------------------------------------------------------------- /libraries/matchers.rb: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'filebeat' 2 | maintainer 'Virender Khatri' 3 | maintainer_email 'vir.khatri@gmail.com' 4 | license 'Apache-2.0' 5 | description 'Installs/Configures Elastic Filebeat' 6 | version '2.4.0' 7 | source_url 'https://github.com/vkhatri/chef-filebeat' 8 | issues_url 'https://github.com/vkhatri/chef-filebeat/issues' 9 | chef_version '>= 12.14' 10 | 11 | depends 'homebrew', '~> 4.2' 12 | depends 'elastic_repo', '>= 1.2.0' 13 | depends 'yum-plugin-versionlock', '>= 0.2.1' 14 | depends 'runit' 15 | depends 'windows' 16 | 17 | %w(windows debian ubuntu centos amazon redhat fedora).each do |os| 18 | supports os 19 | end 20 | -------------------------------------------------------------------------------- /recipes/lwrp_test.rb: -------------------------------------------------------------------------------- 1 | filebeat_install 'default' 2 | 3 | filebeat_config 'default' 4 | 5 | filebeat_service 'default' 6 | -------------------------------------------------------------------------------- /resources/config.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: filebeat 3 | # Resource:: filebeat_config 4 | # 5 | 6 | default_config = { 'filebeat.inputs' => [], 'filebeat.prospectors' => [], 'filebeat.modules' => [], 'prospectors' => [] } 7 | 8 | resource_name :filebeat_config 9 | 10 | property :service_name, String, default: 'filebeat' 11 | property :filebeat_install_resource_name, String, default: 'default' 12 | property :config, Hash, default: default_config 13 | property :conf_file, [String, NilClass] 14 | property :disable_service, [true, false], default: false 15 | property :notify_restart, [true, false], default: true 16 | property :config_sensitive, [true, false], default: false 17 | 18 | default_action :create 19 | 20 | action :create do 21 | install_preview_resource = check_beat_resource(Chef.run_context, :filebeat_install_preview, new_resource.filebeat_install_resource_name) 22 | install_resource = check_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name) 23 | filebeat_install_resource = install_preview_resource || install_resource 24 | raise "could not find resource filebeat_install[#{new_resource.filebeat_install_resource_name}] or filebeat_install_preview[#{new_resource.filebeat_install_resource_name}]" if filebeat_install_resource.nil? 25 | 26 | new_resource.conf_file = new_resource.conf_file || default_conf_file(filebeat_install_resource.conf_dir) 27 | 28 | config = new_resource.config.dup 29 | logging_files_path = platform?('windows') ? "#{filebeat_install_resource.conf_dir}/logs" : filebeat_install_resource.log_dir 30 | 31 | config['logging.files']['path'] ||= logging_files_path 32 | 33 | if filebeat_install_resource.version.to_f >= 7.0 34 | config['filebeat.registry.path'] = platform?('windows') ? "#{filebeat_install_resource.conf_dir}/registry" : '/var/lib/filebeat/registry' 35 | else 36 | config['filebeat.registry_file'] = platform?('windows') ? "#{filebeat_install_resource.conf_dir}/registry" : '/var/lib/filebeat/registry' 37 | end 38 | 39 | if filebeat_install_resource.version.to_f >= 6.0 40 | config['filebeat.config.inputs'] ||= { 41 | 'enabled' => true, 42 | 'path' => "#{filebeat_install_resource.prospectors_dir}/*.yml", 43 | } 44 | else 45 | config['filebeat.config_dir'] = filebeat_install_resource.prospectors_dir 46 | end 47 | 48 | # Filebeat and psych v1.x don't get along. 49 | if Psych::VERSION.start_with?('1') 50 | defaultengine = YAML::ENGINE.yamler 51 | YAML::ENGINE.yamler = 'syck' 52 | end 53 | 54 | file new_resource.conf_file do 55 | content JSON.parse(config.to_json).to_yaml.lines.to_a[1..-1].join 56 | notifies :restart, "service[#{new_resource.service_name}]" if new_resource.notify_restart && !new_resource.disable_service 57 | mode '600' 58 | sensitive new_resource.config_sensitive 59 | end 60 | 61 | # ...and put this back the way we found them. 62 | YAML::ENGINE.yamler = defaultengine if Psych::VERSION.start_with?('1') 63 | end 64 | 65 | action :delete do 66 | filebeat_install_resource = find_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name) 67 | new_resource.conf_file = new_resource.conf_file || default_conf_file(filebeat_install_resource.conf_dir) 68 | 69 | file new_resource.conf_file do 70 | action :delete 71 | end 72 | end 73 | 74 | action_class do 75 | include ::Filebeat::Helpers 76 | end 77 | -------------------------------------------------------------------------------- /resources/install.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: filebeat 3 | # Resource:: filebeat_install 4 | # 5 | 6 | resource_name :filebeat_install 7 | 8 | property :version, String, default: '7.6.2' 9 | property :release, String, default: '1' 10 | property :setup_repo, [true, false], default: true 11 | property :ignore_package_version, [true, false], default: false 12 | property :service_name, String, default: 'filebeat' 13 | property :notify_restart, [true, false], default: true 14 | property :disable_service, [true, false], default: false 15 | property :delete_prospectors_dir, [true, false], default: false 16 | property :conf_dir, [String, NilClass] 17 | property :prospectors_dir, [String, NilClass] 18 | property :log_dir, [String, NilClass] 19 | property :windows_package_url, String, default: 'auto' 20 | property :windows_base_dir, String, default: 'C:/opt/filebeat' 21 | property :apt_options, String, default: "-o Dpkg::Options::='--force-confnew' --force-yes" 22 | property :elastic_repo_options, Hash, default: {} 23 | 24 | default_action :create 25 | 26 | action :create do 27 | new_resource.conf_dir = new_resource.conf_dir || default_config_dir(new_resource.version, new_resource.windows_base_dir) 28 | new_resource.prospectors_dir = new_resource.prospectors_dir || default_prospectors_dir(new_resource.conf_dir) 29 | new_resource.log_dir = new_resource.log_dir || default_log_dir(new_resource.conf_dir) 30 | version_string = platform_family?('fedora', 'rhel', 'amazon') ? "#{new_resource.version}-#{new_resource.release}" : new_resource.version 31 | 32 | with_run_context(:root) do 33 | edit_resource(:service, new_resource.service_name) do 34 | action :nothing 35 | end 36 | end 37 | 38 | ## install filebeat MacOS 39 | if platform?('mac_os_x') 40 | include_recipe 'homebrew' 41 | 42 | # The brew package does not create the 'filebeat' directory in '/etc'. 43 | directory '/etc/filebeat' do 44 | action :create 45 | mode '755' 46 | owner 'root' 47 | group 'wheel' 48 | end 49 | 50 | # Need to drop the .plist file before the package install as brew will try to start the service immediately. 51 | cookbook_file '/Library/LaunchDaemons/co.elastic.filebeat.plist' do 52 | action :create 53 | content 'co.elastic.filebeat.plist' 54 | end 55 | 56 | # This install depends on brew for the installation of filebeat. 57 | package 'filebeat' do 58 | action :install 59 | end 60 | end 61 | 62 | ## install filebeat windows 63 | if platform?('windows') 64 | package_url = win_package_url(new_resource.version, new_resource.windows_package_url) 65 | package_file = ::File.join(Chef::Config[:file_cache_path], ::File.basename(package_url)) 66 | 67 | remote_file 'filebeat_package_file' do 68 | path package_file 69 | source package_url 70 | not_if { ::File.exist?(package_file) } 71 | end 72 | 73 | directory new_resource.windows_base_dir do 74 | recursive true 75 | action :create 76 | end 77 | 78 | windows_zipfile new_resource.windows_base_dir do 79 | source package_file 80 | action :unzip 81 | not_if { ::File.exist?(new_resource.conf_dir + '/install-service-filebeat.ps1') } 82 | notifies :run, 'powershell_script[install filebeat as service]', :immediately 83 | end 84 | 85 | powershell_script 'install filebeat as service' do 86 | code "& '#{new_resource.conf_dir}/install-service-filebeat.ps1'" 87 | action :nothing 88 | end 89 | end 90 | 91 | ## install filebeat yum/apt 92 | if platform_family?('fedora', 'rhel', 'amazon', 'debian') 93 | # setup yum/apt repository 94 | elastic_repo_opts = new_resource.elastic_repo_options.dup 95 | elastic_repo_opts['version'] = new_resource.version 96 | elastic_repo 'default' do 97 | elastic_repo_opts.each do |key, value| 98 | send(key, value) unless value.nil? 99 | end 100 | only_if { new_resource.setup_repo } 101 | end 102 | 103 | # pin yum/apt version 104 | case node['platform_family'] 105 | when 'debian' 106 | unless new_resource.ignore_package_version # ~FC023 107 | apt_preference 'filebeat' do 108 | pin "version #{new_resource.version}" 109 | pin_priority '700' 110 | end 111 | end 112 | when 'fedora', 'rhel', 'amazon' 113 | include_recipe 'yum-plugin-versionlock::default' 114 | 115 | unless new_resource.ignore_package_version # ~FC023 116 | yum_version_lock 'filebeat' do 117 | version new_resource.version 118 | release new_resource.release 119 | action :update 120 | end 121 | end 122 | end 123 | 124 | package 'filebeat' do # ~FC009 125 | version version_string unless new_resource.ignore_package_version 126 | options new_resource.apt_options if new_resource.apt_options && platform_family?('debian') 127 | notifies :restart, "service[#{new_resource.service_name}]" if new_resource.notify_restart && !new_resource.disable_service 128 | if platform_family?('rhel', 'amazon') 129 | flush_cache(:before => true) 130 | allow_downgrade true 131 | end 132 | end 133 | end 134 | 135 | directory new_resource.log_dir do 136 | mode '755' 137 | end 138 | 139 | prospectors_dir_action = new_resource.delete_prospectors_dir ? %i(delete create) : %i(create) 140 | 141 | directory new_resource.prospectors_dir do 142 | recursive true 143 | action prospectors_dir_action 144 | end 145 | end 146 | 147 | action :delete do 148 | with_run_context(:root) do 149 | edit_resource(:service, new_resource.service_name) do 150 | action :stop, :disable 151 | end 152 | end 153 | 154 | package 'filebeat' do 155 | action :remove 156 | end 157 | 158 | directory '/etc/filebeat' do 159 | action :delete 160 | recursive true 161 | end 162 | 163 | directory '/var/log/filebeat' do 164 | action :delete 165 | recursive true 166 | end 167 | end 168 | 169 | action_class do 170 | include ::Filebeat::Helpers 171 | end 172 | -------------------------------------------------------------------------------- /resources/install_preview.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: filebeat 3 | # Resource:: filebeat_install_preview 4 | # 5 | 6 | resource_name :filebeat_install_preview 7 | 8 | property :version, String, default: '6.0.0-rc2' 9 | property :service_name, String, default: 'filebeat' 10 | property :notify_restart, [true, false], default: true 11 | property :disable_service, [true, false], default: false 12 | property :delete_prospectors_dir, [true, false], default: false 13 | property :package_url, String, default: 'auto' 14 | 15 | property :conf_dir, [String, NilClass] 16 | property :prospectors_dir, [String, NilClass] 17 | property :log_dir, [String, NilClass] 18 | 19 | property :windows_base_dir, String, default: 'C:/opt/filebeat' 20 | 21 | property :apt_install_options, [String, NilClass] 22 | 23 | default_action :create 24 | 25 | action :create do 26 | new_resource.conf_dir = new_resource.conf_dir || default_config_dir(new_resource.version, new_resource.windows_base_dir) 27 | new_resource.prospectors_dir = new_resource.prospectors_dir || default_prospectors_dir(new_resource.conf_dir) 28 | new_resource.log_dir = new_resource.log_dir || default_log_dir(new_resource.conf_dir) 29 | 30 | with_run_context(:root) do 31 | edit_resource(:service, new_resource.service_name) do 32 | action :nothing 33 | end 34 | end 35 | 36 | if platform_family?('fedora', 'rhel', 'amazon') 37 | package_arch = node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'i686' 38 | package_family = 'rpm' 39 | elsif platform_family?('debian') 40 | package_arch = node['kernel']['machine'] =~ /x86_64/ ? 'amd64' : 'i386' 41 | package_family = 'deb' 42 | else 43 | raise "platform_family #{node['platform_family']} not supported" 44 | end 45 | 46 | package_url = new_resource.package_url == 'auto' ? "https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-#{new_resource.version}-#{package_arch}.#{package_family}" : new_resource.package_url 47 | package_file = ::File.join(Chef::Config[:file_cache_path], ::File.basename(package_url)) 48 | 49 | remote_file 'filebeat_package_file' do 50 | path package_file 51 | source package_url 52 | not_if { ::File.exist?(package_file) } 53 | end 54 | 55 | package 'filebeat' do # ~FC109 56 | source package_file 57 | provider Chef::Provider::Package::Dpkg if platform_family?('debian') 58 | end 59 | 60 | directory new_resource.log_dir do 61 | mode '755' 62 | end 63 | 64 | prospectors_dir_action = new_resource.delete_prospectors_dir ? %i(delete create) : %i(create) 65 | 66 | directory new_resource.prospectors_dir do 67 | recursive true 68 | action prospectors_dir_action 69 | end 70 | end 71 | 72 | action :delete do 73 | with_run_context(:root) do 74 | edit_resource(:service, new_resource.service_name) do 75 | action :stop, :disable 76 | end 77 | end 78 | 79 | package 'filebeat' do 80 | action :remove 81 | end 82 | 83 | directory '/etc/filebeat' do 84 | action :delete 85 | recursive true 86 | end 87 | end 88 | 89 | action_class do 90 | include ::Filebeat::Helpers 91 | end 92 | -------------------------------------------------------------------------------- /resources/prospector.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: filebeat 3 | # Resource:: filebeat_prospector 4 | # 5 | 6 | resource_name :filebeat_prospector 7 | 8 | property :service_name, String, default: 'filebeat' 9 | property :filebeat_install_resource_name, String, default: 'default' 10 | property :prefix, String, default: 'lwrp-prospector-' 11 | property :config, [Array, Hash], default: {} 12 | property :cookbook_file_name, [String, NilClass] 13 | property :cookbook_file_name_cookbook, [String, NilClass] 14 | property :disable_service, [true, false], default: false 15 | property :notify_restart, [true, false], default: true 16 | property :config_sensitive, [true, false], default: false 17 | 18 | default_action :create 19 | 20 | action :create do 21 | install_preview_resource = check_beat_resource(Chef.run_context, :filebeat_install_preview, new_resource.filebeat_install_resource_name) 22 | install_resource = check_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name) 23 | filebeat_install_resource = install_preview_resource || install_resource 24 | raise "could not find resource filebeat_install[#{new_resource.filebeat_install_resource_name}] or filebeat_install_preview[#{new_resource.filebeat_install_resource_name}]" if filebeat_install_resource.nil? 25 | 26 | config = new_resource.config.dup 27 | config = [config] unless new_resource.config.is_a?(Array) 28 | 29 | # Filebeat and psych v1.x don't get along. 30 | if Psych::VERSION.start_with?('1') 31 | defaultengine = YAML::ENGINE.yamler 32 | YAML::ENGINE.yamler = 'syck' 33 | end 34 | 35 | # file_content = { 'filebeat' => { 'prospectors' => config } }.to_yaml 36 | file_content = 37 | if filebeat_install_resource.version.to_f >= 6.3 38 | JSON.parse(config.to_json).to_yaml.lines.to_a[1..-1].join 39 | else 40 | JSON.parse({ 'filebeat' => { 'prospectors' => config } }.to_json).to_yaml.lines.to_a[1..-1].join 41 | end 42 | 43 | # ...and put this back the way we found them. 44 | YAML::ENGINE.yamler = defaultengine if Psych::VERSION.start_with?('1') 45 | 46 | prospector_file_name = "#{new_resource.prefix}#{new_resource.name}.yml" 47 | 48 | if new_resource.cookbook_file_name && new_resource.cookbook_file_name_cookbook 49 | cookbook_file "prospector_#{new_resource.name}" do 50 | path ::File.join(filebeat_install_resource.prospectors_dir, prospector_file_name) 51 | source new_resource.cookbook_file_name 52 | cookbook new_resource.cookbook_file_name_cookbook 53 | notifies :restart, "service[#{new_resource.service_name}]" if new_resource.notify_restart && !new_resource.disable_service 54 | mode '600' 55 | sensitive new_resource.config_sensitive 56 | end 57 | else 58 | file "prospector_#{new_resource.name}" do 59 | path ::File.join(filebeat_install_resource.prospectors_dir, prospector_file_name) 60 | content file_content 61 | notifies :restart, "service[#{new_resource.service_name}]" if new_resource.notify_restart && !new_resource.disable_service 62 | mode '600' 63 | sensitive new_resource.config_sensitive 64 | end 65 | end 66 | end 67 | 68 | action :delete do 69 | prospector_file_name = "#{new_resource.prefix}#{new_resource.name}.yml" 70 | filebeat_install_resource = find_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name) 71 | file "prospector_#{new_resource.name}" do 72 | path ::File.join(filebeat_install_resource.prospectors_dir, prospector_file_name) 73 | action :delete 74 | end 75 | end 76 | 77 | action_class do 78 | include ::Filebeat::Helpers 79 | end 80 | -------------------------------------------------------------------------------- /resources/runit_service.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: filebeat 3 | # Resource:: filebeat_runit_service 4 | # 5 | 6 | resource_name :filebeat_runit_service 7 | 8 | property :service_name, String, default: 'filebeat' 9 | property :filebeat_install_resource_name, String, default: 'default' 10 | property :disable_service, [true, false], default: false 11 | property :purge_prospectors_dir, [true, false], default: false 12 | property :runit_filebeat_cmd_options, String, default: '' 13 | property :service_ignore_failure, [true, false], default: false 14 | 15 | default_action :create 16 | 17 | action :create do 18 | install_preview_resource = check_beat_resource(Chef.run_context, :filebeat_install_preview, new_resource.filebeat_install_resource_name) 19 | install_resource = check_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name) 20 | filebeat_install_resource = install_preview_resource || install_resource 21 | raise "could not find resource filebeat_install[#{new_resource.filebeat_install_resource_name}] or filebeat_install_preview[#{new_resource.filebeat_install_resource_name}]" if filebeat_install_resource.nil? 22 | 23 | conf_file = default_conf_file(filebeat_install_resource.conf_dir) 24 | 25 | ruby_block 'delay run purge prospectors dir' do 26 | block do 27 | end 28 | notifies :run, 'ruby_block[purge_prospectors_dir]' 29 | end 30 | 31 | ruby_block 'purge_prospectors_dir' do 32 | block do 33 | purge_prospectors_dir(filebeat_install_resource.prospectors_dir) 34 | end 35 | only_if { new_resource.purge_prospectors_dir } 36 | action :nothing 37 | end 38 | 39 | ruby_block 'delay filebeat service start' do 40 | block do 41 | end 42 | notifies :start, "service[#{new_resource.service_name}]" 43 | not_if { new_resource.disable_service } 44 | end 45 | 46 | include_recipe 'runit::default' 47 | 48 | service_action = new_resource.disable_service ? %i(disable stop) : %i(enable nothing) 49 | 50 | runit_cmd = "/usr/share/filebeat/bin/filebeat -c #{conf_file} -path.home /usr/share/filebeat -path.config #{filebeat_install_resource.conf_dir} -path.data /var/lib/filebeat -path.logs #{filebeat_install_resource.log_dir} #{new_resource.runit_filebeat_cmd_options}" 51 | runit_service new_resource.service_name do 52 | options( 53 | 'user' => 'root', 54 | 'cmd' => runit_cmd 55 | ) 56 | default_logger true 57 | action service_action 58 | ignore_failure new_resource.service_ignore_failure 59 | run_template_name 'filebeat' # use sv-filebeat-run.erb as the run file 60 | cookbook 'filebeat' 61 | end 62 | end 63 | 64 | action :delete do 65 | end 66 | 67 | action_class do 68 | include ::Filebeat::Helpers 69 | end 70 | -------------------------------------------------------------------------------- /resources/service.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: filebeat 3 | # Resource:: filebeat_service 4 | # 5 | 6 | resource_name :filebeat_service 7 | 8 | property :service_name, String, default: 'filebeat' 9 | property :filebeat_install_resource_name, String, default: 'default' 10 | property :disable_service, [true, false], default: false 11 | property :purge_prospectors_dir, [true, false], default: false 12 | 13 | property :service_ignore_failure, [true, false], default: false 14 | property :service_retries, Integer, default: 2 15 | property :service_retry_delay, Integer, default: 0 16 | 17 | default_action :create 18 | 19 | action :create do 20 | install_preview_resource = check_beat_resource(Chef.run_context, :filebeat_install_preview, new_resource.filebeat_install_resource_name) 21 | install_resource = check_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name) 22 | filebeat_install_resource = install_preview_resource || install_resource 23 | raise "could not find resource filebeat_install[#{new_resource.filebeat_install_resource_name}] or filebeat_install_preview[#{new_resource.filebeat_install_resource_name}]" if filebeat_install_resource.nil? 24 | 25 | ruby_block 'delay run purge prospectors dir' do 26 | block do 27 | end 28 | notifies :run, 'ruby_block[purge_prospectors_dir]' 29 | end 30 | 31 | with_run_context(:root) do 32 | ruby_block 'purge_prospectors_dir' do 33 | block do 34 | purge_prospectors_config(filebeat_install_resource.prospectors_dir) 35 | end 36 | only_if { new_resource.purge_prospectors_dir } 37 | action :nothing 38 | end 39 | end 40 | 41 | ruby_block 'delay filebeat service start' do 42 | block do 43 | end 44 | notifies :start, "service[#{new_resource.service_name}]" 45 | not_if { new_resource.disable_service } 46 | end 47 | 48 | service_action = new_resource.disable_service ? %i(disable stop) : %i(enable) 49 | 50 | service new_resource.service_name do 51 | provider Chef::Provider::Service::Solaris if platform_family?('solaris2') 52 | retries new_resource.service_retries 53 | retry_delay new_resource.service_retry_delay 54 | supports :status => true, :restart => true 55 | action service_action 56 | ignore_failure new_resource.service_ignore_failure 57 | end 58 | end 59 | 60 | action :delete do 61 | end 62 | 63 | action_class do 64 | include ::Filebeat::Helpers 65 | end 66 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rspec --init` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # Require this file using `require "spec_helper"` to ensure that it is only 4 | # loaded once. 5 | # 6 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 7 | 8 | require 'chefspec' 9 | require 'chefspec/berkshelf' 10 | 11 | RSpec.configure do |config| 12 | config.expect_with :rspec do |c| 13 | c.syntax = :expect 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/unit/recipes/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'filebeat::lwrp_test' do 4 | ############ 5 | # filebeat_install 6 | ############ 7 | shared_examples_for 'filebeat_install' do 8 | context 'linux_platforms' do 9 | it 'create filebeat install resource' do 10 | expect(chef_run).to create_filebeat_install('default') 11 | end 12 | 13 | it 'install filebeat package' do 14 | expect(chef_run).to install_package('filebeat') 15 | end 16 | 17 | it 'create prospector directory /etc/filebeat/conf.d' do 18 | expect(chef_run).to create_directory('/etc/filebeat/conf.d') 19 | end 20 | 21 | it 'create filebeat log directory /var/log/filebeat' do 22 | expect(chef_run).to create_directory('/var/log/filebeat') 23 | end 24 | end 25 | end 26 | 27 | context 'rhel-install' do 28 | let(:chef_run) do 29 | ChefSpec::SoloRunner.new(step_into: ['filebeat_install'], platform: 'centos', version: '7.6') do |node| 30 | node.automatic['platform_family'] = 'rhel' 31 | end.converge(described_recipe) 32 | end 33 | 34 | let(:node) { chef_run.node } 35 | 36 | include_examples 'filebeat_install' 37 | 38 | it 'adds elastic yum repository' do 39 | expect(chef_run).to create_elastic_repo('default') 40 | end 41 | 42 | it 'include yum-plugin-versionlock::default recipe' do 43 | expect(chef_run).to include_recipe('yum-plugin-versionlock::default') 44 | end 45 | 46 | it 'update yum_version_lock filebeat' do 47 | expect(chef_run).to update_yum_version_lock('filebeat') 48 | end 49 | end 50 | 51 | context 'ubuntu-install' do 52 | let(:chef_run) do 53 | ChefSpec::SoloRunner.new(step_into: ['filebeat_install'], platform: 'ubuntu', version: '18.04') do |node| 54 | node.automatic['platform_family'] = 'debian' 55 | end.converge(described_recipe) 56 | end 57 | 58 | let(:node) { chef_run.node } 59 | 60 | include_examples 'filebeat_install' 61 | 62 | it 'adds elastic apt repository' do 63 | expect(chef_run).to create_elastic_repo('default') 64 | end 65 | 66 | it 'add apt_preference filebeat' do 67 | expect(chef_run).to add_apt_preference('filebeat') 68 | end 69 | end 70 | 71 | context 'windows-install' do 72 | let(:chef_run) do 73 | ChefSpec::SoloRunner.new(step_into: ['filebeat_install'], platform: 'windows', version: '2012R2') do |node| 74 | node.automatic['platform_family'] = 'windows' 75 | node.automatic['kernel']['machine'] = 'x86_64' 76 | end.converge(described_recipe) 77 | end 78 | 79 | let(:node) { chef_run.node } 80 | 81 | it 'create prospector directory C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/conf.d' do 82 | expect(chef_run).to create_directory('C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/conf.d') 83 | end 84 | 85 | it 'create prospector directory C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/logs' do 86 | expect(chef_run).to create_directory('C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/logs') 87 | end 88 | 89 | it 'download filebeat package file' do 90 | expect(chef_run).to create_remote_file('filebeat_package_file') 91 | end 92 | 93 | it 'create filebeat base dir C:/opt/filebeat' do 94 | expect(chef_run).to create_directory('C:/opt/filebeat') 95 | end 96 | 97 | it 'unzip filebeat package file to C:/opt/filebeat' do 98 | expect(chef_run).to unzip_windows_zipfile('C:/opt/filebeat') 99 | end 100 | 101 | it 'run powershell_script to install filebeat as service' do 102 | expect(chef_run.windows_zipfile('C:/opt/filebeat')).to notify('powershell_script[install filebeat as service]').to(:run).immediately 103 | expect(chef_run).to_not run_powershell_script('install filebeat as service') 104 | end 105 | end 106 | 107 | ############ 108 | # filebeat_service 109 | ############ 110 | shared_examples_for 'filebeat_service' do 111 | context 'linux_platforms' do 112 | it 'create filebeat service resource' do 113 | expect(chef_run).to create_filebeat_service('default') 114 | end 115 | 116 | it 'run ruby_block delay run purge prospectors dir' do 117 | expect(chef_run).to run_ruby_block('delay run purge prospectors dir') 118 | end 119 | 120 | it 'run ruby_block delay filebeat service start' do 121 | expect(chef_run).to run_ruby_block('delay filebeat service start') 122 | end 123 | 124 | it 'enable filebeat service' do 125 | expect(chef_run).to enable_service('filebeat') 126 | end 127 | end 128 | end 129 | 130 | context 'rhel-service' do 131 | let(:chef_run) do 132 | ChefSpec::SoloRunner.new(step_into: ['filebeat_service'], platform: 'centos', version: '7.6') do |node| 133 | node.automatic['platform_family'] = 'rhel' 134 | end.converge(described_recipe) 135 | end 136 | 137 | let(:node) { chef_run.node } 138 | 139 | include_examples 'filebeat_service' 140 | end 141 | 142 | context 'ubuntu-service' do 143 | let(:chef_run) do 144 | ChefSpec::SoloRunner.new(step_into: ['filebeat_service'], platform: 'ubuntu', version: '18.04') do |node| 145 | node.automatic['platform_family'] = 'debian' 146 | end.converge(described_recipe) 147 | end 148 | 149 | let(:node) { chef_run.node } 150 | 151 | include_examples 'filebeat_service' 152 | end 153 | 154 | context 'windows-service' do 155 | let(:chef_run) do 156 | ChefSpec::SoloRunner.new(step_into: ['filebeat_service'], platform: 'windows', version: '2012R2') do |node| 157 | node.automatic['platform_family'] = 'windows' 158 | node.automatic['kernel']['machine'] = 'x86_64' 159 | end.converge(described_recipe) 160 | end 161 | 162 | let(:node) { chef_run.node } 163 | 164 | include_examples 'filebeat_service' 165 | end 166 | 167 | ############ 168 | # filebeat_config 169 | ############ 170 | # context 'rhel-config' do 171 | # let(:chef_run) do 172 | # ChefSpec::SoloRunner.new(step_into: ['filebeat_config'], platform: 'centos', version: '7.6') do |node| 173 | # node.automatic['platform_family'] = 'rhel' 174 | # end.converge(described_recipe) 175 | # end 176 | # 177 | # let(:node) { chef_run.node } 178 | # 179 | # it 'configure /etc/filebeat/filebeat.yml' do 180 | # expect(chef_run).to create_file('/etc/filebeat/filebeat.yml') 181 | # end 182 | # end 183 | # 184 | # context 'ubuntu-config' do 185 | # let(:chef_run) do 186 | # ChefSpec::SoloRunner.new(step_into: ['filebeat_config'], platform: 'ubuntu', version: '18.04') do |node| 187 | # node.automatic['platform_family'] = 'debian' 188 | # end.converge(described_recipe) 189 | # end 190 | # 191 | # let(:node) { chef_run.node } 192 | # 193 | # it 'configure /etc/filebeat/filebeat.yml' do 194 | # expect(chef_run).to create_file('/etc/filebeat/filebeat.yml') 195 | # end 196 | # end 197 | # 198 | # context 'windows-config' do 199 | # let(:chef_run) do 200 | # ChefSpec::SoloRunner.new(step_into: ['filebeat_config'], platform: 'windows', version: '2012R2') do |node| 201 | # node.automatic['platform_family'] = 'windows' 202 | # node.automatic['kernel']['machine'] = 'x86_64' 203 | # end.converge(described_recipe) 204 | # end 205 | # 206 | # let(:node) { chef_run.node } 207 | # 208 | # it 'configure C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/filebeat.yml' do 209 | # expect(chef_run).to create_file('C:/opt/filebeat/filebeat-7.6.2-windows-x86_64/filebeat.yml') 210 | # end 211 | # end 212 | end 213 | -------------------------------------------------------------------------------- /templates/default/filebeat/filebeat.xml.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 41 | 42 | 43 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /templates/default/filebeat/start-stop-filebeat.sh.erb: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | # This file was generated by Chef for <%= node['fqdn'] %>. 3 | # Do not modify this file by hand! 4 | # 5 | 6 | NAME=<%= @name %> 7 | 8 | PIDFILE="/var/run/${NAME}.pid" 9 | DAEMON=<%= @daemon_path %> 10 | ARGS="-c <%= @conf_path %> <%= node['filebeat']['service']['additional_command_line_options'] %>" 11 | 12 | start() { 13 | echo -n $"Starting $NAME: " 14 | nohup $DAEMON $ARGS -v > /dev/null 2>&1 & 15 | PID=$! 16 | if [ -z $PID ]; then 17 | printf "%s\n" "Failed to start $NAME" 18 | exit 2 19 | else 20 | echo $PID > $PIDFILE 21 | printf "%s\n" "Success" 22 | fi 23 | } 24 | 25 | stop() { 26 | if status ; then 27 | echo -n $"Stopping $NAME: " 28 | pid=$(cat $PIDFILE) 29 | kill $pid 30 | retval=$? 31 | echo 32 | [ $retval -eq 0 ] && rm -f $PIDFILE 33 | return $retval 34 | else 35 | echo "$NAME not running" 36 | fi 37 | } 38 | 39 | status() { 40 | if [ -f "$PIDFILE" ] ; then 41 | pid=`cat "$PIDFILE"` 42 | if kill -0 $pid > /dev/null 2> /dev/null ; then 43 | # process by this pid is running. 44 | # It may not be our pid, but that's what you get with just pidfiles. 45 | return 0 46 | else 47 | return 2 # program is dead but pid file exists 48 | fi 49 | else 50 | return 3 # program is not running 51 | fi 52 | } 53 | 54 | case "$1" in 55 | start) 56 | $1 57 | ;; 58 | stop) 59 | $1 60 | ;; 61 | esac 62 | -------------------------------------------------------------------------------- /templates/default/sv-filebeat-run.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec 2>&1 3 | exec chpst -u <%= @options['user'] %> <%= @options['cmd'] %> 4 | -------------------------------------------------------------------------------- /test/cookbooks/filebeat_test/README.md: -------------------------------------------------------------------------------- 1 | filebeat_test 2 | ===== 3 | -------------------------------------------------------------------------------- /test/cookbooks/filebeat_test/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default['filebeat_test']['prospectors']['test'].tap do |t| 2 | t['enabled'] = true 3 | t['sensitive'] = false 4 | t['type'] = 'log' 5 | t['fields'] = { 'type' => 'test1_logs', 'engine' => 'kitchen' } 6 | t['type'] = 'log' 7 | t['input_type'] = 'log' 8 | t['paths'] = %w(/var/log/test1.log) 9 | t['recursive_glob_enabled'] = false 10 | t['encoding'] = 'utf-8' 11 | t['exclude_lines'] = ['^DBG'] 12 | t['include_lines'] = ['^WARN', '^ERR'] 13 | t['exclude_files'] = ['\.gz$'] 14 | t['tags'] = ['kitchen'] 15 | t['fields_under_root'] = true 16 | t['ignore_older'] = '1h' 17 | t['close_inactive'] = '1m' 18 | t['close_renamed'] = true 19 | t['close_removed'] = true 20 | t['close_eof'] = false 21 | t['close_timeout'] = '0' 22 | t['clean_inactive'] = '2h' 23 | t['clean_removed'] = true 24 | t['scan_frequency'] = '30s' 25 | t['scan_sort'] = 'modtime' 26 | t['scan_order'] = 'asc' 27 | t['document_type'] = 'log' 28 | t['harvester_buffer_size'] = 16_384 29 | t['max_bytes'] = 10_485_760 30 | t['json_keys_under_root'] = true 31 | t['json_overwrite_keys'] = false 32 | t['json_add_error_key'] = true 33 | t['json_message_key'] = 'log' 34 | t['multiline_pattern'] = '^\[' 35 | t['multiline_negate'] = true 36 | t['multiline_match'] = 'after' 37 | t['multiline_flush_pattern'] = '^\[?[0-9]{10}\]' 38 | t['multiline_max_lines'] = 500 39 | t['multiline_timeout'] = '5s' 40 | t['tail_files'] = false 41 | t['pipeline'] = 'bigespipeline' 42 | t['symlinks'] = false 43 | t['backoff'] = '1s' 44 | t['max_backoff'] = '10s' 45 | t['backoff_factor'] = 2 46 | t['harvester_limit'] = 0 47 | t['enabled'] = true 48 | end 49 | 50 | default['filebeat_test']['prospectors']['secure_logs'].tap do |s| 51 | s['enabled'] = true 52 | s['paths'] = ['/var/log/secure'] 53 | s['type'] = 'log' 54 | s['fields'] = { 'type' => 'secure_logs' } 55 | end 56 | 57 | default['filebeat_test']['prospectors']['syslog_logs'].tap do |s| 58 | s['enabled'] = true 59 | s['paths'] = ['/var/log/syslog'] 60 | s['type'] = 'log' 61 | s['fields'] = { 'type' => 'syslog_logs' } 62 | end 63 | 64 | default['filebeat_test']['prospectors']['messages_log'].tap do |s| 65 | s['enabled'] = true 66 | s['paths'] = ['/var/log/messages'] 67 | s['type'] = 'log' 68 | s['fields'] = { 'type' => 'messages_log' } 69 | end 70 | 71 | default['filebeat_test']['prospectors']['extra_log'].tap do |s| 72 | s['enabled'] = true 73 | s['paths'] = ['/var/log/*.log'] 74 | s['type'] = 'log' 75 | s['fields'] = { 'type' => 'extra_log' } 76 | s['exclude_files'] = ['/var/log/messages', '/var/log/syslog', '/var/log/secure'] 77 | end 78 | 79 | default['filebeat_test']['prospectors']['extra_log_list'] = [ 80 | { 81 | 'enabled' => true, 82 | 'paths' => ['/var/log/*.logy'], 83 | 'type' => 'log', 84 | 'fields' => { 'type' => 'extra_log_y' }, 85 | 'exclude_files' => ['/var/log/messages', '/var/log/syslog', '/var/log/secure'], 86 | }, 87 | { 88 | 'enabled' => true, 89 | 'paths' => ['/var/log/*.logx'], 90 | 'type' => 'log', 91 | 'fields' => { 'type' => 'extra_log_x' }, 92 | 'exclude_files' => ['/var/log/messages', '/var/log/syslog', '/var/log/secure'], 93 | }, 94 | ] 95 | 96 | default['filebeat_test']['filebeat_config'].tap do |c| 97 | # c['filebeat.prospectors'] = [] 98 | c['filebeat.modules'] = [] 99 | c['prospectors'] = [] 100 | c['logging.level'] = 'info' 101 | c['logging.to_files'] = true 102 | c['logging.files'] = { 'name' => 'filebeat' } 103 | c['output.elasticsearch'] = { 'hosts' => ['127.0.0.1:9200'] } 104 | end 105 | -------------------------------------------------------------------------------- /test/cookbooks/filebeat_test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'filebeat_test' 2 | maintainer 'Virender Khatri' 3 | maintainer_email 'vir.khatri@gmail.com' 4 | license 'Apache-2.0' 5 | description 'Installs/Configures Filebeat Test Cookbook Resources' 6 | version '0.0.1' 7 | source_url 'https://github.com/vkhatri/chef-filebeat' 8 | issues_url 'https://github.com/vkhatri/chef-filebeat/issues' 9 | chef_version '>= 12.14' 10 | 11 | depends 'filebeat' 12 | -------------------------------------------------------------------------------- /test/cookbooks/filebeat_test/recipes/current-ver.rb: -------------------------------------------------------------------------------- 1 | filebeat_install 'default' 2 | 3 | filebeat_config 'default' do 4 | config node['filebeat_test']['filebeat_config'] 5 | end 6 | 7 | node['filebeat_test']['prospectors'].each do |p_name, p_config| 8 | filebeat_prospector p_name do 9 | config p_config 10 | end 11 | end 12 | 13 | filebeat_service 'default' do 14 | purge_prospectors_dir true 15 | end 16 | -------------------------------------------------------------------------------- /test/cookbooks/filebeat_test/recipes/preview.rb: -------------------------------------------------------------------------------- 1 | filebeat_install_preview 'default' 2 | 3 | filebeat_config 'default' do 4 | config node['filebeat_test']['filebeat_config'] 5 | end 6 | 7 | node['filebeat_test']['prospectors'].each do |p_name, p_config| 8 | filebeat_prospector p_name do 9 | config p_config 10 | end 11 | end 12 | 13 | filebeat_service 'default' 14 | -------------------------------------------------------------------------------- /test/cookbooks/filebeat_test/recipes/previous-ver.rb: -------------------------------------------------------------------------------- 1 | filebeat_install 'default' do 2 | version '6.8.8' 3 | end 4 | 5 | filebeat_config 'default' do 6 | config node['filebeat_test']['filebeat_config'] 7 | end 8 | 9 | node['filebeat_test']['prospectors'].each do |p_name, p_config| 10 | filebeat_prospector p_name do 11 | config p_config 12 | end 13 | end 14 | 15 | filebeat_service 'default' do 16 | purge_prospectors_dir true 17 | end 18 | -------------------------------------------------------------------------------- /test/cookbooks/filebeat_test/recipes/runit.rb: -------------------------------------------------------------------------------- 1 | filebeat_install 'default' do 2 | disable_service true 3 | notify_restart false 4 | end 5 | 6 | filebeat_config 'default' do 7 | config node['filebeat_test']['filebeat_config'] 8 | notify_restart false 9 | end 10 | 11 | node['filebeat_test']['prospectors'].each do |p_name, p_config| 12 | filebeat_prospector p_name do 13 | config p_config 14 | notify_restart false 15 | end 16 | end 17 | 18 | filebeat_runit_service 'default' 19 | -------------------------------------------------------------------------------- /test/smoke/current-ver/default.rb: -------------------------------------------------------------------------------- 1 | # # encoding: utf-8 2 | 3 | # Inspec test for recipe filebeat::v6 4 | 5 | # The Inspec reference, with examples and extensive documentation, can be 6 | # found at http://inspec.io/docs/reference/resources/ 7 | 8 | if %w(redhat fedora amazon).include?(os[:family]) 9 | describe file('/etc/yum.repos.d/elastic7.repo') do 10 | its('content') { should match %r{https://artifacts.elastic.co/packages/7.x/yum} } 11 | end 12 | else 13 | describe file('/etc/apt/sources.list.d/elastic7.list') do 14 | its('content') { should match %r{https://artifacts.elastic.co/packages/7.x/apt} } 15 | end 16 | end 17 | 18 | describe file('/etc/filebeat/filebeat.yml') do 19 | it { should exist } 20 | # its('content') { should match 'filebeat.config.inputs' } 21 | end 22 | 23 | describe command('filebeat test config') do 24 | its('exit_status') { should eq 0 } 25 | its('stdout') { should match 'Config OK' } 26 | end 27 | 28 | describe package('filebeat') do 29 | it { should be_installed } 30 | its('version') { should match '7.6.2' } 31 | end 32 | 33 | if %w(18.04 20.04 2 7 8).include?(os[:release]) 34 | describe systemd_service('filebeat') do 35 | it { should be_installed } 36 | it { should be_enabled } 37 | it { should be_running } 38 | end 39 | else 40 | describe service('filebeat') do 41 | it { should be_installed } 42 | it { should be_enabled } 43 | it { should be_running } 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /test/smoke/previous-ver/default.rb: -------------------------------------------------------------------------------- 1 | # # encoding: utf-8 2 | 3 | # Inspec test for recipe filebeat::v6 4 | 5 | # The Inspec reference, with examples and extensive documentation, can be 6 | # found at http://inspec.io/docs/reference/resources/ 7 | 8 | if %w(redhat fedora amazon).include?(os[:family]) 9 | describe file('/etc/yum.repos.d/elastic6.repo') do 10 | its('content') { should match %r{https://artifacts.elastic.co/packages/6.x/yum} } 11 | end 12 | else 13 | describe file('/etc/apt/sources.list.d/elastic6.list') do 14 | its('content') { should match %r{https://artifacts.elastic.co/packages/6.x/apt} } 15 | end 16 | end 17 | 18 | describe file('/etc/filebeat/filebeat.yml') do 19 | it { should exist } 20 | # its('content') { should match 'filebeat.config.inputs' } 21 | end 22 | 23 | describe command('filebeat test config') do 24 | its('exit_status') { should eq 0 } 25 | its('stdout') { should match 'Config OK' } 26 | end 27 | 28 | describe package('filebeat') do 29 | it { should be_installed } 30 | its('version') { should match '6.8.8' } 31 | end 32 | 33 | if %w(16.04 2 7).include?(os[:release]) 34 | describe systemd_service('filebeat') do 35 | it { should be_installed } 36 | it { should be_enabled } 37 | it { should be_running } 38 | end 39 | else 40 | describe service('filebeat') do 41 | it { should be_installed } 42 | it { should be_enabled } 43 | it { should be_running } 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /test/smoke/runit/default.rb: -------------------------------------------------------------------------------- 1 | describe command('filebeat test config') do 2 | its('exit_status') { should eq 0 } 3 | its('stdout') { should match 'Config OK' } 4 | end 5 | --------------------------------------------------------------------------------