├── .chef └── config.rb ├── .delivery └── project.toml ├── .foodcritic ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ ├── config.yml │ └── story.md ├── actions │ ├── installation │ │ ├── action.yml │ │ └── install.sh │ ├── linter │ │ └── action.yml │ ├── release │ │ └── action.yml │ └── tests │ │ └── action.yml └── workflows │ ├── main.yml │ └── release.yml ├── .gitignore ├── .kitchen.appveyor.yml ├── .kitchen.dokken.yml ├── .kitchen.yml ├── .ruby-version ├── .travis.yml ├── Berksfile ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── appveyor.yml ├── attributes └── default.rb ├── chefignore ├── libraries ├── infra_helper.rb ├── integration.rb └── matchers.rb ├── metadata.rb ├── recipes ├── agent_linux.rb ├── agent_windows.rb ├── default.rb └── host_integrations.rb ├── spec ├── agent_linux_spec.rb ├── agent_windows_spec.rb ├── default_spec.rb ├── host_integrations_spec.rb ├── integration_spec.rb ├── spec_helper.rb └── support │ └── common_spec.rb ├── templates └── default │ └── systemd.service.erb └── test └── integration └── default └── inspec ├── agent_linux_spec.rb └── host_integrations_spec.rb /.chef/config.rb: -------------------------------------------------------------------------------- 1 | cookbook_path ['./cookbooks'] 2 | node_name 'newrelic' 3 | client_key '../newrelic.pem' 4 | -------------------------------------------------------------------------------- /.delivery/project.toml: -------------------------------------------------------------------------------- 1 | remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml" 2 | -------------------------------------------------------------------------------- /.foodcritic: -------------------------------------------------------------------------------- 1 | ~FC078 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ^^ Provide a general summary of the issue in the title above. ^^ 11 | 12 | ## Description 13 | Describe the problem you're encountering. 14 | TIP: Do NOT share sensitive information, whether personal, proprietary, or otherwise! 15 | 16 | ## Expected Behavior 17 | Tell us what you expected to happen. 18 | 19 | ## [Troubleshooting](https://discuss.newrelic.com/t/troubleshooting-frameworks/108787) or [NR Diag](https://docs.newrelic.com/docs/using-new-relic/cross-product-functions/troubleshooting/new-relic-diagnostics) results 20 | Provide any other relevant log data. 21 | TIP: Scrub logs and diagnostic information for sensitive information 22 | 23 | ## Steps to Reproduce 24 | Please be as specific as possible. 25 | TIP: Link a sample application that demonstrates the issue. 26 | 27 | ## Your Environment 28 | Include as many relevant details about your environment as possible including the running version of New Relic software and any relevant configurations. 29 | 30 | ## Additional context 31 | Add any other context about the problem here. For example, relevant community posts or support tickets. 32 | 33 | ## For Maintainers Only or Hero Triaging this bug 34 | *Suggested Priority (P1,P2,P3,P4,P5):* 35 | *Suggested T-Shirt size (S, M, L, XL, Unknown):* 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Troubleshooting 4 | url: https://github.com/newrelic/infrastructure-agent-chef/blob/master/README.md#support 5 | about: Check out the README for troubleshooting directions 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/story.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Story 3 | about: Issue describing development work to fulfill a feature request 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | priority: '' 8 | --- 9 | ### Description 10 | _What's the goal of this unit of work? What is included? What isn't included?_ 11 | 12 | ### Acceptance Criteria 13 | _What tasks need to be accomplished to achieve the goal?_ 14 | 15 | ### Design Consideration/Limitations 16 | _Why is this the route we should take to achieve our goal?_ 17 | _What can't be achieved within this story?_ 18 | 19 | ### Dependencies 20 | _Do any other teams or parts of the New Relic product need to be considered?_ 21 | _Some common areas: UI, collector, documentation_ 22 | 23 | ### Additional context 24 | _What else should we know about this story that might not fit into the other categories?_ 25 | 26 | ### Estimates 27 | _Please provide initial t-shirt size. S = 1-3 days, M = 3-5 days (1 week), L = 1-2 weeks (1 sprint)_ 28 | -------------------------------------------------------------------------------- /.github/actions/installation/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Install Chef Workstation' 2 | description: 'Install Chef Workstation' 3 | inputs: 4 | version: 5 | description: 'chef version' 6 | required: false 7 | default: '21.7.524' 8 | runs: 9 | using: "composite" 10 | steps: 11 | - name: Install Chef Workstation 12 | id: install 13 | run: ${{ github.action_path }}/install.sh ${{ inputs.version }} 14 | shell: bash 15 | -------------------------------------------------------------------------------- /.github/actions/installation/install.sh: -------------------------------------------------------------------------------- 1 | VERSION=${1:-21.7.524} 2 | 3 | 4 | sudo apt-get install update -y 5 | sudo apt-get install git -y 6 | sudo apt-get install gpg -y 7 | wget https://packages.chef.io/files/stable/chef-workstation/${VERSION}/ubuntu/20.04/chef-workstation_${VERSION}-1_amd64.deb 8 | sudo dpkg -i chef-workstation_${VERSION}-1_amd64.deb 9 | rm -f chef-workstation_${VERSION}-1_amd64.deb 10 | -------------------------------------------------------------------------------- /.github/actions/linter/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Run tests' 2 | description: 'Run kitchen dokken with tests' 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Run linter 7 | id: linter 8 | run: cookstyle . 9 | shell: bash 10 | -------------------------------------------------------------------------------- /.github/actions/release/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Release chef' 2 | description: 'Release cookbook' 3 | inputs: 4 | chef_pem_file: 5 | description: file used for deployment of chef cookbook 6 | required: true 7 | runs: 8 | using: "composite" 9 | steps: 10 | - name: Create pem file 11 | id: pem 12 | run: echo "${{ inputs.chef_pem_file }}" | base64 --decode > newrelic.pem 13 | shell: bash 14 | - name: Release 15 | id: release 16 | run: berks vendor cookbooks && knife supermarket share newrelic-infra 17 | shell: bash 18 | -------------------------------------------------------------------------------- /.github/actions/tests/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Run tests' 2 | description: 'Run kitchen dokken with tests' 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Run tests 7 | id: tests 8 | run: export KITCHEN_LOCAL_YAML=.kitchen.dokken.yml && kitchen test 9 | shell: bash 10 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: 2 | pull_request: 3 | branches: 4 | - master 5 | name: PR workflow 6 | 7 | jobs: 8 | install_chef_workstation: 9 | runs-on: ubuntu-latest 10 | name: Install chef and run tests 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Install Chef Workstation 14 | uses: newrelic/infrastructure-agent-chef/.github/actions/installation@master 15 | - name: Run linter 16 | uses: newrelic/infrastructure-agent-chef/.github/actions/linter@master 17 | - name: Run tests 18 | uses: newrelic/infrastructure-agent-chef/.github/actions/tests@master 19 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | on: 2 | release: 3 | types: [published] 4 | name: Release workflow 5 | 6 | jobs: 7 | pre_release: 8 | runs-on: ubuntu-latest 9 | name: Release chef cookbook 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Install Chef Workstation 13 | uses: newrelic/infrastructure-agent-chef/.github/actions/installation@master 14 | - name: Release 15 | uses: newrelic/infrastructure-agent-chef/.github/actions/release@master 16 | with: 17 | chef_pem_file: ${{ secrets.PEM_BASE64 }} 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | Berksfile.lock 3 | *~ 4 | *# 5 | .#* 6 | \#*# 7 | .*.sw[a-z] 8 | *.un~ 9 | /cookbooks 10 | 11 | # Bundler 12 | Gemfile.lock 13 | bin/* 14 | .bundle/* 15 | vendor/* 16 | 17 | .kitchen/ 18 | .kitchen.local.yml 19 | 20 | **/stderr.txt 21 | **/stdout.txt 22 | 23 | newrelic.pem -------------------------------------------------------------------------------- /.kitchen.appveyor.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: proxy 3 | host: localhost 4 | reset_command: "exit 0" 5 | port: <%= ENV["machine_port"] %> 6 | username: <%= ENV["machine_user"] %> 7 | password: <%= ENV["machine_pass"] %> 8 | 9 | provisioner: 10 | name: chef_zero 11 | product_version: <%= ENV['CHEF_VERSION'] || 15 %> 12 | chef_license: accept 13 | 14 | platforms: 15 | - name: windows-2012r2 16 | 17 | suites: 18 | - name: default 19 | run_list: 20 | - recipe[newrelic-infra::default] 21 | attributes: 22 | newrelic_infra: 23 | config: 24 | license_key: abcd 25 | -------------------------------------------------------------------------------- /.kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | privileged: true # because Docker and SystemD/Upstart 4 | chef_version: <%= ENV['CHEF_VERSION'] || 15 %> 5 | 6 | transport: 7 | name: dokken 8 | 9 | provisioner: 10 | name: dokken 11 | deprecations_as_errors: true 12 | chef_license: accept 13 | 14 | platforms: 15 | - name: centos-7 16 | driver: 17 | image: dokken/centos-7 18 | pid_one_command: /sbin/init 19 | - name: centos-8 20 | driver: 21 | image: dokken/centos-8 22 | pid_one_command: /sbin/init 23 | - name: ubuntu-16.04 24 | driver: 25 | image: dokken/ubuntu-16.04 26 | pid_one_command: /sbin/init 27 | intermediate_instructions: 28 | - RUN /usr/bin/apt-get update 29 | - name: ubuntu-18.04 30 | driver: 31 | image: dokken/ubuntu-18.04 32 | pid_one_command: /bin/systemd 33 | intermediate_instructions: 34 | - RUN /usr/bin/apt-get update 35 | - name: ubuntu-20.04 36 | driver: 37 | image: dokken/ubuntu-20.04 38 | pid_one_command: /bin/systemd 39 | intermediate_instructions: 40 | - RUN /usr/bin/apt-get update 41 | - name: opensuse-leap 42 | driver: 43 | image: dokken/opensuse-leap-15.3 44 | pid_one_command: /usr/lib/systemd/systemd 45 | intermediate_instructions: 46 | - RUN /usr/bin/zypper ref 47 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: vagrant 3 | provider: virtualbox 4 | 5 | provisioner: 6 | name: chef_zero 7 | product_version: <%= ENV['CHEF_VERSION'] || 15 %> 8 | chef_license: accept 9 | 10 | verifier: 11 | name: inspec 12 | 13 | platforms: 14 | - name: centos-7 15 | driver: 16 | box: bento/centos-7 17 | - name: centos-8 18 | driver: 19 | box: bento/centos-8 20 | - name: debian-8 21 | driver: 22 | box: bento/debian-8 23 | - name: debian-9 24 | driver: 25 | box: bento/debian-9 26 | - name: debian-10 27 | driver: 28 | box: bento/debian-10 29 | - name: ubuntu-16.04 30 | driver: 31 | box: bento/ubuntu-16.04 32 | - name: ubuntu-18.04 33 | driver: 34 | box: bento/ubuntu-18.04 35 | - name: ubuntu-20.04 36 | driver: 37 | box: bento/ubuntu-20.04 38 | - name: windows-2012r2 39 | driver: 40 | box: mwrock/Windows2012R2 41 | 42 | suites: 43 | - name: default 44 | run_list: 45 | - recipe[newrelic-infra::default] 46 | attributes: 47 | newrelic_infra: 48 | delete_yaml_quotes: false 49 | features: 50 | host_integrations: ['nri-cassandra', 'nri-mysql', 'nri-redis', 'nri-nginx', 'nri-apache'] 51 | config: 52 | license_key: abcd 53 | host_integrations: 54 | config: 55 | cassandra: 56 | username: test 57 | password: kitchen 58 | hosts: '["/"]' 59 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.3.1 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | addons: 3 | apt: 4 | packages: 5 | - chefdk 6 | sources: 7 | - chef-stable-trusty 8 | before_install: 9 | if [[ -n "$encrypted_e7ed02806170_key" ]]; then 10 | openssl aes-256-cbc 11 | -K "$encrypted_e7ed02806170_key" 12 | -iv "$encrypted_e7ed02806170_iv" 13 | -in newrelic.pem.enc 14 | -out newrelic.pem 15 | -d; 16 | fi 17 | before_script: 18 | - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) 19 | - eval "$(chef shell-init bash)" 20 | - chef --version 21 | - cookstyle --version 22 | - foodcritic --version 23 | branches: 24 | only: 25 | - master 26 | - /^\d+\.\d+\.\d+$/ 27 | dist: trusty 28 | env: 29 | global: 30 | - CHEF_LICENSE=accept 31 | matrix: 32 | - INSTANCE=default-centos-6 33 | - INSTANCE=default-centos-7 34 | - INSTANCE=default-ubuntu-1404 35 | - INSTANCE=default-ubuntu-1604 36 | - INSTANCE=default-ubuntu-1804 37 | - INSTANCE=default-opensuse-leap 38 | - INSTANCE=verify 39 | install: skip # Don't `bundle install` which takes about 1.5 mins 40 | jobs: 41 | include: 42 | - stage: deploy 43 | if: tag =~ ^\d+\.\d+\.\d+$ 44 | deploy: 45 | on: 46 | tags: true 47 | provider: script 48 | # We can't use --cookbook-path until https://github.com/chef/chef/issues/6379 49 | # is fixed. chefignore wouldn't be honored. Symlink into cookbooks and upload that copy. 50 | script: rm -rf cookbooks/* && berks vendor cookbooks && knife supermarket share newrelic-infra 51 | skip_cleanup: true # The cleanup step will remove the newrelic.pem file written out in the before_install step 52 | script: skip 53 | services: [] 54 | sudo: false 55 | script: if [[ "$INSTANCE" == verify ]]; then chef exec delivery local all; else KITCHEN_LOCAL_YAML=.kitchen.dokken.yml kitchen verify ${INSTANCE}; fi 56 | services: docker 57 | sudo: required 58 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # newrelic-infra Cookbook CHANGELOG 2 | 3 | This file is used to list changes made in each version of the `newrelic-infra` cookbook. 4 | 5 | ## 0.12.1 (2021-09-08) 6 | 7 | FEATURES: 8 | 9 | * The minimum supported Centos version is now 7.0 instead of 5.0. 10 | ## 0.12.0 (2021-08-02) 11 | 12 | BREAKING CHANGES: 13 | 14 | * The minimum supported Chef version is now 15+ instead of 12.5+. 15 | * Removed `poise_service` and `poise_archive` dependencies, `agent_linux.rb` rewritten to use Chef resources instead. 16 | * Change of creation of config file and it's location - removed `agent.yaml` and changed it to `newrelic.yml` in `/etc`. 17 | 18 | ## 0.11.0 (2019-07-04) 19 | 20 | FEATURES: 21 | 22 | * Add support for Amazon Linux 2. 23 | 24 | IMPROVEMENTS: 25 | 26 | * Add support for disabling the removal of quotes in the generated 27 | integration definition and config files. 28 | 29 | ## 0.10.0 (2019-05-27) 30 | 31 | FEATURES: 32 | 33 | * Add support for installing the agent in different linux architecture from the 34 | tarballs. 35 | 36 | ## 0.9.0 (2019-03-29) 37 | 38 | IMPROVEMENTS: 39 | 40 | * *Breaking change*: Add support for installing individual integrations. The role 41 | switches from the deprecated `newrelic-infra-integrations` package (which 42 | only included 5 integrations), to the `nri-*` individual integration 43 | packages. The `host_integrations` changes from a bool to a list specifying 44 | the names of `nri-*` integration packages to install. 45 | 46 | 47 | ## 0.8.1 (2018-11-16) 48 | 49 | IMPROVEMENTS: 50 | 51 | * Fix upstart config reload when running inside a Centos6 docker container 52 | 53 | ## 0.8.0 (2018-11-16) 54 | 55 | IMPROVEMENTS: 56 | 57 | * Add support for Centos/RHEL 5 58 | 59 | ## 0.7.2 (2018-08-24) 60 | 61 | BUG FIXES: 62 | 63 | * Add support for Ubuntu 18.04 (bionic) 64 | * Fix case where `false` values were not added to configuration 65 | * Change `require_chef_omnibus` to `product_version` in Test Kitchen config to avoid deprecation message 66 | 67 | ## 0.7.1 (2018-05-31) 68 | 69 | BUG FIXES: 70 | 71 | * Remove duplicate constant warning 72 | 73 | IMPROVEMENTS: 74 | 75 | * Update Fauxhai OS versions for tests 76 | 77 | ## 0.7.0 (2018-05-21) 78 | 79 | IMPROVEMENTS: 80 | 81 | * Make Yum repositories default to `:create` action instead of `[:add, :makecache]` 82 | 83 | ## 0.6.0 (2018-03-13) 84 | 85 | FEATURES: 86 | 87 | * SLES support 88 | 89 | ## 0.5.1 (2018-02-25) 90 | 91 | IMPROVEMENTS: 92 | 93 | * Pattern match on later versions of Amazon Linux 94 | 95 | ## 0.5.0 (2018-01-17) 96 | 97 | FEATURES: 98 | 99 | * Add `retries` attribute for packages 100 | 101 | ## 0.4.0 (2017-11-12) 102 | 103 | FEATURES: 104 | 105 | * Windows support 106 | 107 | ## 0.3.3 (2017-11-06) 108 | 109 | BUG FIXES: 110 | 111 | * Travis deploy was not honoring the chefignore file 112 | 113 | ## 0.3.2 (2017-11-06) 114 | 115 | IMPROVEMENTS: 116 | 117 | * Cookbook is automatically deployed to [Chef Supermarket](https://supermarket.chef.io/cookbooks/newrelic-infra) 118 | 119 | ## 0.3.1 (2017-10-23) 120 | 121 | IMPROVEMENTS: 122 | 123 | * Add .kitchen.dokken.yml to allow Test Kitchen tests in Docker 124 | * Add .travis.yml to run tests in Travis CI 125 | * Typo fixes 126 | * Change "LWRP" to "custom resource" in documentation 127 | * Automatically deploy with Travis CI to supermarket 128 | 129 | ## 0.3.0 (2017-10-18) 130 | 131 | BREAKING CHANGES: 132 | 133 | * The minimum supported Chef version is now 12.15+ instead of 12.14+. 134 | * The prefix name for custom on-host integrations has been changed to use the name of the Chef resource instead of the integration name since the New Relic Infrastructure API does not accept prefix names with `.`'s. 135 | 136 | FEATURES: 137 | 138 | * Add `sensitive` to all configuration file resources as well as associated unit testing for the `sensitive` property. 139 | 140 | BUG FIXES: 141 | 142 | * Remove the use of `Hash#compact`, which only works with Ruby >= 2.4. No versions of Chef 12.x ship with a version of Ruby this new. Replace with monkey patched method `Hash.delete_blank` ([#18](https://github.com/newrelic/infrastructure-agent-chef/issues/18)). 143 | * Modify the generated YAML configuration files to generate a format that is compatible with the Infrastructure agent's Go YAML parser ([#19](https://github.com/newrelic/infrastructure-agent-chef/issues/19)). 144 | 145 | ## 0.2.0 (2017-10-16) 146 | 147 | FEATURES: 148 | 149 | * Add `sensitive` to agent configuration file resource 150 | 151 | ## 0.1.0 (2017-10-12) 152 | 153 | NOTE: Versions prior to 0.1.0 were not tagged or released on the [Chef supermarket](https://supermarket.chef.io). 154 | 155 | BREAKING CHANGES: 156 | 157 | * *Attribute namespace changed:* The top-level attribute key was changed from `newrelic-infra` to `newrelic_infra` in order to be used as both strings and symbols. 158 | * Only `chef-client` versions `>= 12.14` are supported. 159 | * Lots of attribute changes to help simplify configuration generation. See [README.md](README.md) for more details. 160 | 161 | FEATURES: 162 | 163 | * **Testing added:** Unit and integration tests added. See the [CONTRIBUTING][3] guide for more details. 164 | * **newrelic\_infra\_integration LWRP added:** An LWRP for installing and configuring custom New Relic Infrastructure on-host integrations. Custom integrations can also be installed using by including the default recipe and the appropriate attributes. 165 | * **New Relic On-Host integrations:** Added the capability to install and configure the New Relic provided on-host integrations. See the [README.md](README.md) for more details on what attributes to set. 166 | 167 | IMPROVEMENTS: 168 | 169 | * Updated the apt and YUM repository resources to use metaprogramming. This allows all properties available for each of the respective resources to be available as attributes. 170 | * Resolved all Rubocop and Foodcritic violations. 171 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ### Hello! We're glad you've joined us. 2 | 3 | We believe participation in our community should be a harassment free experience for everyone. 4 | 5 | Learn more about our guidelines and principles by reading our [Code of Conduct](https://opensource.newrelic.com/code-of-conduct/) on our Open Source Website. 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are always welcome. Before contributing please read the 4 | [code of conduct](./CODE_OF_CONDUCT.md) and [search the issue tracker](issues); your issue may have already been discussed or fixed in `main`. To contribute, 5 | [fork](https://help.github.com/articles/fork-a-repo/) this repository, commit your changes, and [send a Pull Request](https://help.github.com/articles/using-pull-requests/). 6 | 7 | Note that our [code of conduct](./CODE_OF_CONDUCT.md) applies to all platforms and venues related to this project; please follow it in all your interactions with the project and its participants. 8 | 9 | ## Feature Requests 10 | 11 | Feature requests should be submitted in the [Issue tracker](../../issues), with a description of the expected behavior & use case, where they’ll remain closed until sufficient interest, [e.g. :+1: reactions](https://help.github.com/articles/about-discussions-in-issues-and-pull-requests/), has been [shown by the community](../../issues?q=label%3A%22votes+needed%22+sort%3Areactions-%2B1-desc). 12 | Before submitting an Issue, please search for similar ones in the 13 | [closed issues](../../issues?q=is%3Aissue+is%3Aclosed+label%3Aenhancement). 14 | 15 | ## Pull Requests 16 | 17 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. 18 | 2. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 19 | 3. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. 20 | 21 | ## Contributor License Agreement 22 | 23 | Keep in mind that when you submit your Pull Request, you'll need to sign the CLA via the click-through using CLA-Assistant. If you'd like to execute our corporate CLA, or if you have any questions, please drop us an email at opensource@newrelic.com. 24 | 25 | For more information about CLAs, please check out Alex Russell’s excellent post, 26 | [“Why Do I Need to Sign This?”](https://infrequently.org/2008/06/why-do-i-need-to-sign-this/). 27 | 28 | ## Slack 29 | 30 | We host a public Slack with a dedicated channel for contributors and maintainers of open source projects hosted by New Relic. If you are contributing to this project, you're welcome to request access to the #oss-contributors channel in the newrelicusers.slack.com workspace. To request access, see https://join.slack.com/t/newrelicusers/shared_invite/zt-1ayj69rzm-~go~Eo1whIQGYnu3qi15ng. 31 | -------------------------------------------------------------------------------- /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 2020 New Relic 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Community Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Project.png)](https://opensource.newrelic.com/oss-category/#community-project) 2 | 3 | |:warning:| New Relic offers a new [Chef solution](https://github.com/newrelic/chef-install) that simplifies scaling your New Relic Observability efforts. Please consider using this solution going forward. | 4 | |---------------|:------------------------| 5 | 6 | # Chef cookbook for the New Relic infrastructure agent 7 | This cookbook installs and configures the New Relic infrastructure agent, as well New Relic and and [on-host integrations](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/). 8 | 9 | ## Install and use the Chef cookbook 10 | 11 | ### Requirements 12 | 13 | #### Platforms 14 | 15 | * Amazon Linux all versions 16 | * CentOS version 5 or higher 17 | * Debian version 7 ("Wheezy") or higher 18 | * Red Hat Enterprise Linux (RHEL) version 5 or higher 19 | * Ubuntu versions 16.04.*, 18.04.*, 20.04* (LTS versions) 20 | * Windows Server 2008, 2012, 2016, and 2019, and their service packs. 21 | * SUSE Linux Enterprise 11, 12 22 | 23 | #### Chef 24 | 25 | - Chef 15+ 26 | 27 | ### Recipes 28 | 29 | #### `newrelic-infra::default` 30 | 31 | Determines the platform and includes the appropriate platform specific recipe. This is the only recipe that should be included in a node's run list. 32 | 33 | #### `newrelic-infra::agent_linux` 34 | 35 | Installs and configures the Infrastructure agent on a Linux host. This recipe should _NOT_ be directly included in a node's run list. The default recipe will automatically determine which platform specific recipe to apply. 36 | 37 | Here are the steps that the recipe performs: 38 | 39 | 1. Adds the `newrelic-infra` package repository source. 40 | 2. Can install, upgrade, or remove the `newrelic-infra` package. By default, the package is only installed. 41 | 3. Enables and starts the `newrelic_infra` agent service. 42 | 4. Generates the agent configuration file. 43 | 5. Includes the `newrelic-infra::host_integrations` recipe to install and configure any on-host integrations. 44 | 45 | #### `newrelic-infra::agent_windows` 46 | 47 | Installs and configures the Infrastructure agent on a Windows host. This recipe should _NOT_ be directly included in a node's run list. The default recipe will automatically determine which platform specific recipe to apply. 48 | 49 | #### `newrelic-infra::host_integrations` 50 | 51 | Installs New Relic provided and on-host integrations if the integration has been addded to the list of `host_integrations` (for example, `default['newrelic_infra']['features]['host_integrations'] = []`). It also generates configuration for any of the available on-host integrations from New Relic, and installs any custom integrations defined with attributes. 52 | 53 | For more infromation on the available custom resource for installing and configuring custom on-host integrations see the [Custom resources][9] documentation. 54 | 55 | Example configuration for a custom on-host integration installed and configured via attributes: 56 | 57 | ```ruby 58 | default['newrelic_infra']['custom_integrations']['test_integration'] = { 59 | integration_name: 'com.test.integration', 60 | remote_url: 'https://url-to-a-tarball-for-install.com/test.tar.gz', 61 | instances: [ 62 | { 63 | name: 'test_integration_metrics', 64 | command: 'metrics', 65 | arguments: { 66 | test: true 67 | }, 68 | labels: { 69 | environment: 'test' 70 | } 71 | } 72 | ], 73 | commands: { 74 | metrics: %w[--metrics] 75 | } 76 | } 77 | ``` 78 | 79 | For more information on the available New Relic on-host integrations and configuration you can check the [official documentation][6]. 80 | 81 | ### Attributes 82 | 83 | See [attributes/defaults.rb][3] for more details and default values. 84 | 85 | | Name | Default value | Description | 86 | |:-----|:--------------|:------------| 87 | | `default['newrelic_infra']['features']['host_integrations']` | `[]` | List of New Relic on-host integrations | 88 | | `default['newrelic_infra']['user']['name']` | `newrelic_infra` | Service account user name | 89 | | `default['newrelic_infra']['group']['name']` | `newrelic_infra` | Service account group name | 90 | | `default['newrelic_infra']['config']['license_key']` | `nil` | Account license key to send metrics to | 91 | | `default['newrelic_infra']['config']['display_name']` | `nil` | Override the auto-generated hostname for reporting | 92 | | `default['newrelic_infra']['config']['proxy']` | `nil` | Use a proxy to communicate with New Relic | 93 | | `default['newrelic_infra']['config']['verbose']` | `nil` | When set to 1, enables verbose logging for the agent | 94 | | `default['newrelic_infra']['config']['debug']` | `nil` | Enable Golang debugging | 95 | | `default['newrelic_infra']['config']['log_file']` | `nil` | To log to another location; when not set, the agent logs to the system log files | 96 | | `default['newrelic_infra']['config']['custom_attributes']` | `{}` | A hash of custom attributes to annotate the data from this agent instance | 97 | | `default['newrelic_infra']['agent']['config']['file']` | `agent.yaml` | File name for the agent configuration | 98 | | `default['newrelic_infra']['agent']['config']['mode']` | `0640` | File permissions for the agent configuration | 99 | | `default['newrelic_infra']['agent']['directory']['path']` | `/etc/newrelic-infra` | Directory path for the agent configuration | 100 | | `default['newrelic_infra']['agent']['directory']['mode']` | `0750` | Directory permissions for the agent configuration | 101 | | `default['newrelic_infra']['packages']['agent']['action']` | `[:install]` | Action(s) to perform on the agent package | 102 | | `default['newrelic_infra']['packages']['agent']['retries']` | `0` | The number of times to catch exceptions and retry the resource | 103 | | `default['newrelic_infra']['packages']['agent']['version']` | `nil` | Version of the agent package to install | 104 | | `default['newrelic_infra']['packages'][integration_package_name]['action']` | `[:install]` | Action(s) to perform on the agent on-host integration package | 105 | | `default['newrelic_infra']['packages'][integration_package_name]['retries']` | `0` | The number of times to catch exceptions and retry the resource | 106 | | `default['newrelic_infra']['packages'][integration_package_name]['version']` | `nil` | Version of the on-host integration package to install | 107 | | `default['newrelic_infra']['host_integrations']['config_dir']` | `/etc/newrelic-infra/integrations.d` | Directory for the New Relic provided on-host integration configurations | 108 | | `default['newrelic_infra']['host_integrations']['config']` | `{}` | New Relic provided on-host integration configuration | 109 | | `default['newrelic_infra']['custom_integrations']` | `{}` | New Relic Infrastructure on-host custom integration configuration | 110 | | `default['newrelic_infra']['provider']` | `package_manager` | When `package_manager` installs the packages from yum/apt/zypp, if `tarball` installs the agent from a tarball | 111 | | `default['newrelic_infra']['tarball']['version']` | `nil` | the version number of the tarball to install | 112 | | `default['newrelic_infra']['delete_yaml_quotes']` | `true` | if true it deletes the quotes (`"`) from the generated integration configs and definitions files | 113 | 114 | #### APT repository attributes 115 | 116 | The `apt_repository` Chef resource is built using metaprogramming, so that the configuration can be extended via attributes. Any property available to the resource can be passed in via attributes. 117 | 118 | Attributes that cannot be passed to the resource are logged out as warnings in order to prevent potential failes from typos, older Chef versions, etc. 119 | For more information, refer to the Chef documentation on the [apt_repository][4] resource. 120 | 121 | | Name | Default value | Description | 122 | |:-----|:--------------|:------------| 123 | | `default['newrelic_infra']['apt']['uri']` | `https://download.newrelic.com/infrastructure_agent/linux/apt` | Repository base URL | 124 | | `default['newrelic_infra']['apt']['key']` | `https://download.newrelic.com/infrastructure_agent/keys/newrelic_apt_key_current.gpg` | Repository GPG key URL | 125 | | `default['newrelic_infra']['apt']['distribution']` | `node['lsb']['codename']` | Distribution code name | 126 | | `default['newrelic_infra']['apt']['components']` | `['main']` | Repository components | 127 | | `default['newrelic_infra']['apt']['arch']` | `'amd64'` | Package architecture to install | 128 | | `default['newrelic_infra']['apt']['action']` | `[:add]` | `apt_repository` resource actions to perform | 129 | 130 | #### Windows attributes 131 | 132 | When using Windows, you can set a source URL and checksum for the agent download. 133 | 134 | | Name | Default value | Description | 135 | |:-----|:--------------|:------------| 136 | | `default['newrelic-infra']['windows_source']` | `https://download.newrelic.com/infrastructure_agent/windows/newrelic-infra.msi` | Remote URL for Infrastructure agent windows download | 137 | | `default['newrelic-infra']['windows_checksum']` | `nil` | SHA-256 Checksum for source file | 138 | 139 | #### Yum repository attributes 140 | 141 | The `yum_repository` Chef resource is built using metaprogramming, so that the configuration can be extended via attributes. Any property available to the resource can be passed in via attributes. 142 | 143 | Attributes that cannot be passed to the resource are logged out as warnings in order to prevent potential failes from typos, older Chef versions, etc. 144 | For more information, refer to the Chef documentation on the [yum_repository][5] resource. 145 | 146 | | Name | Default value | Description | 147 | |:-----|:--------------|:------------| 148 | | `default['newrelic_infra']['yum']['description']` | 'New Relic Infrastructure' | Repository description | 149 | | `default['newrelic_infra']['yum']['baseurl']` | Default is determined by distribution see [attributes/default.rb][3] for more information. | Repository base URL | 150 | | `default['newrelic_infra']['yum']['gpgkey']` | `'https://download.newrelic.com/infrastructure_agent/keys/newrelic_rpm_key_current.gpg'` | Repository GPG key URL | 151 | | `default['newrelic_infra']['yum']['gpgcheck']` | `true` | Perform a GPG check on installed packages | 152 | | `default['newrelic_infra']['yum']['repo_gpgcheck']` | `true` | Perform a GPG check on the package repository | 153 | | `default['newrelic_infra']['yum']['action']` | `[:add, :makecache]` | `yum_repository` resource actions to perform | 154 | 155 | ### Custom Resources 156 | 157 | #### `newrelic_infra_integration` 158 | 159 | Installs and configures a custom New Relic Infrastructure on-host integration. 160 | 161 | Example: 162 | 163 | ```ruby 164 | newrelic_infra_integration 'test' do 165 | integration_name 'test_integration' 166 | remote_url 'https://url-to-a-tarball-for-install.com/test.tar.gz' 167 | commands { metrics: %w[--metrics] } 168 | instances( 169 | [ 170 | { 171 | name: 'test_integration_metrics', 172 | command: 'metrics', 173 | arguments: { 174 | test: true 175 | }, 176 | labels: { 177 | environment: 'test' 178 | } 179 | } 180 | ] 181 | ) 182 | end 183 | ``` 184 | 185 | Supported properties: 186 | 187 | | Property name | Required | Type | Default | 188 | |:--------------|:---------|:-----|:--------| 189 | | `integration_name` | `true` | String | nil | 190 | | `remote_url` | `true` | String | nil | 191 | | `instances` | `true` | Array | nil | 192 | | `commands` | `true` | Hash | nil | 193 | | `description` | `false` | [String, nil] | nil | 194 | | `cli_options` | `false` | [Hash, nil] | nil | 195 | | `interval` | `false` | Integer | 10 | 196 | | `prefix` | `false` | String | `integration/#{integration_name}` | 197 | | `install_method` | `true` | `'tarball'` or `'binary'` | 'tarball' | 198 | | `os` | `false` | `'linux'` | 'linux' | 199 | | `protocol_version` | `false` | Integer | 1 | 200 | | `user` | `false` | String | `'newrelic_infra'` | 201 | | `group` | `false` | String | `'newrelic_infra'` | 202 | | `base_dir` | `false` | String | `'/var/db/newrelic-infra/custom-integrations'` | 203 | | `bin_dir` | `false` | String | `/opt/newrelic-infra` | 204 | | `bin` | `false` | String | The folder is `#{bin_dir}/#{name}` and the file name is the tarball or binary without any extension | 205 | | `definition_file` | `false` | String | `#{base_dir}/#{resource_name).yaml` | 206 | | `config_dir` | `false` | String | '/etc/newrelic-infra/integrations.d/' | 207 | | `config_file` | `false` | String | `#{config_dir}/#{resource_name).yaml` | 208 | 209 | ### Usage 210 | 211 | #### Cookbook usage 212 | 213 | - Set any attributes necessary for your desired configuration 214 | - Add the `newrelic-infra::default` recipe your run list 215 | - For wrapper cookbooks, add the `newrelic-infra` cookbook as a dependency to your `metadata.rb` or `Berksfile`, then include `newrelic-infra::default` recipe. 216 | 217 | #### Custom resource usage 218 | 219 | - Add the `newrelic-infra` cookbook as a dependency to your `metadata.rb` or `Berksfile` 220 | - Configure the custom resource(s) using the supported properties 221 | 222 | ### Testing 223 | 224 | Refer to 225 | https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD 226 | 227 | ### Releasing new versions 228 | 229 | For releasing a new version to the [Chef Supermarket][12] follow this steps: 230 | 231 | - Update the version number in [metadata.rb][13]. 232 | - Create the github release for the new version. This will trigger a 233 | GitHub Actions job that will deploy the new version. 234 | - Watch the build with the version number in Github Actions: 235 | https://github.com/newrelic/infrastructure-agent-chef/actions 236 | - If that passes, the new version should be on 237 | https://supermarket.chef.io/cookbooks/newrelic-infra and available to 238 | use everywhere 239 | 240 | ## Support 241 | 242 | Should you need assistance with New Relic products, you are in good hands with several support diagnostic tools and support channels. 243 | 244 | >New Relic offers NRDiag, [a client-side diagnostic utility](https://docs.newrelic.com/docs/using-new-relic/cross-product-functions/troubleshooting/new-relic-diagnostics) that automatically detects common problems with New Relic agents. If NRDiag detects a problem, it suggests troubleshooting steps. NRDiag can also automatically attach troubleshooting data to a New Relic Support ticket. Remove this section if it doesn't apply. 245 | 246 | If the issue has been confirmed as a bug or is a feature request, file a GitHub issue. 247 | 248 | **Support Channels** 249 | 250 | * [New Relic Documentation](https://docs.newrelic.com): Comprehensive guidance for using our platform 251 | * [New Relic Community](https://discuss.newrelic.com/c/support-products-agents/new-relic-infrastructure): The best place to engage in troubleshooting questions 252 | * [New Relic Developer](https://developer.newrelic.com/): Resources for building a custom observability applications 253 | * [New Relic University](https://learn.newrelic.com/): A range of online training for New Relic users of every level 254 | * [New Relic Technical Support](https://support.newrelic.com/) 24/7/365 ticketed support. Read more about our [Technical Support Offerings](https://docs.newrelic.com/docs/licenses/license-information/general-usage-licenses/support-plan). 255 | 256 | ## Privacy 257 | 258 | At New Relic we take your privacy and the security of your information seriously, and are committed to protecting your information. We must emphasize the importance of not sharing personal data in public forums, and ask all users to scrub logs and diagnostic information for sensitive information, whether personal, proprietary, or otherwise. 259 | 260 | We define “Personal Data” as any information relating to an identified or identifiable individual, including, for example, your name, phone number, post code or zip code, Device ID, IP address, and email address. 261 | 262 | For more information, review [New Relic’s General Data Privacy Notice](https://newrelic.com/termsandconditions/privacy). 263 | 264 | ## Contribute 265 | 266 | We encourage your contributions to improve this project! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. 267 | 268 | If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at opensource@newrelic.com. 269 | 270 | **A note about vulnerabilities** 271 | 272 | As noted in our [security policy](../../security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals. 273 | 274 | If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic). 275 | 276 | If you would like to contribute to this project, review [these guidelines](./CONTRIBUTING.md). 277 | 278 | To all contributors, we thank you! Without your contribution, this project would not be what it is today. 279 | 280 | ## License 281 | 282 | infrastructure-agent-chef is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License. 283 | 284 | [1]: attributes/default.rb 285 | [2]: https://docs.chef.io/resource_apt_repository.html 286 | [3]: https://docs.chef.io/resource_yum_repository.html 287 | [4]: https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list 288 | [5]: #custom-resources 289 | [6]: CONTRIBUTING.md 290 | [7]: CHANGELOG.md 291 | [8]: https://supermarket.chef.io/cookbooks/newrelic-infra 292 | [9]: metadata.rb#L10 -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{branch}-{build}" 2 | branches: 3 | only: 4 | - master 5 | build_script: 6 | - kitchen create default-windows-2012r2 7 | clone_folder: c:\projects\kitchen-machine 8 | clone_depth: 1 9 | environment: 10 | machine_user: test_user 11 | machine_pass: Pass@word1 12 | machine_port: 5985 13 | KITCHEN_YAML: .kitchen.appveyor.yml 14 | install: 15 | - ps: net user /add $env:machine_user $env:machine_pass 16 | - ps: net localgroup administrators $env:machine_user /add 17 | - ps: $env:PATH="C:\opscode\chefdk\bin;$env:PATH" 18 | - ps: . { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install -project chefdk 19 | os: Windows Server 2012 R2 20 | platform: 21 | - x64 22 | test_script: 23 | - kitchen converge default-windows-2012r2 24 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (c) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | default['newrelic_infra']['provider'] = 'package_manager' 8 | default['newrelic_infra']['tarball']['version'] = nil 9 | default['newrelic_infra']['delete_yaml_quotes'] = true 10 | 11 | default['newrelic_infra']['tarball']['architecture'] = case node['kernel']['machine'] 12 | when 'x86_64' 13 | 'amd64' 14 | when 'i386' 15 | '386' 16 | else 17 | node['kernel']['machine'] 18 | end 19 | 20 | # Feature flags 21 | # Whether or not to install the New Relic on-host integrations 22 | default['newrelic_infra']['features']['host_integrations'] = [] 23 | 24 | # Service account attributes 25 | # Name of the service account user 26 | default['newrelic_infra']['user']['name'] = 'newrelic_infra' 27 | # Name of the service account group 28 | default['newrelic_infra']['group']['name'] = 'newrelic_infra' 29 | 30 | # New Relic infrastructure agent configuration options 31 | default['newrelic_infra']['config'].tap do |conf| 32 | # Account license key 33 | conf['license_key'] = nil 34 | # Override the auto-generated hostname for reporting 35 | conf['display_name'] = nil 36 | # Use a proxy to communicate with New Relic 37 | conf['proxy'] = nil 38 | # When set to 1, enables verbose logging for the agent 39 | conf['verbose'] = 0 40 | # Enable Golang debugging 41 | conf['debug'] = nil 42 | # To log to another location; when not set, the agent logs to the system log files 43 | conf['log_file'] = nil 44 | # A hash of custom attributes to annotate the data from this agent instance 45 | conf['custom_attributes'] = {} 46 | end 47 | 48 | # New Relic infrastructure agent configuration file and directory properties 49 | default['newrelic_infra']['agent'].tap do |conf| 50 | conf['config']['file'] = 'newrelic-infra.yml' 51 | conf['config']['mode'] = '0640' 52 | conf['directory']['path'] = '/etc/' 53 | end 54 | 55 | # New Relic Infrastructure agent package configuration 56 | default['newrelic_infra']['packages']['agent']['action'] = %i(install) 57 | default['newrelic_infra']['packages']['agent']['retries'] = 0 58 | default['newrelic_infra']['packages']['agent']['version'] = nil 59 | 60 | # New Relic Infrastructure on-host integration package configuration 61 | # NOTE: The package actions will only be performed if the integration has been 62 | # added to the host_integrations features list 63 | default['newrelic_infra']['packages']['nri-cassandra']['action'] = %i(install) 64 | default['newrelic_infra']['packages']['nri-cassandra']['retries'] = 0 65 | default['newrelic_infra']['packages']['nri-cassandra']['version'] = nil 66 | default['newrelic_infra']['packages']['nri-mysql']['action'] = %i(install) 67 | default['newrelic_infra']['packages']['nri-mysql']['retries'] = 0 68 | default['newrelic_infra']['packages']['nri-mysql']['version'] = nil 69 | default['newrelic_infra']['packages']['nri-redis']['action'] = %i(install) 70 | default['newrelic_infra']['packages']['nri-redis']['retries'] = 0 71 | default['newrelic_infra']['packages']['nri-redis']['version'] = nil 72 | default['newrelic_infra']['packages']['nri-nginx']['action'] = %i(install) 73 | default['newrelic_infra']['packages']['nri-nginx']['retries'] = 0 74 | default['newrelic_infra']['packages']['nri-nginx']['version'] = nil 75 | default['newrelic_infra']['packages']['nri-apache']['action'] = %i(install) 76 | default['newrelic_infra']['packages']['nri-apache']['retries'] = 0 77 | default['newrelic_infra']['packages']['nri-apache']['version'] = nil 78 | 79 | # New Relic Infrastructure on-host integration configuration 80 | default['newrelic_infra']['host_integrations']['config_dir'] = '/etc/newrelic-infra/integrations.d' 81 | default['newrelic_infra']['host_integrations']['config'] = {} 82 | 83 | # New Relic Infrastructure on-host custom integration configuration 84 | default['newrelic_infra']['custom_integrations'] = {} 85 | 86 | # apt repository configuration for Debian based hosts 87 | # See https://docs.chef.io/resource_apt_repository.html for more information 88 | default['newrelic_infra']['apt'].tap do |conf| 89 | conf['uri'] = 'https://download.newrelic.com/infrastructure_agent/linux/apt' 90 | conf['key'] = 'https://download.newrelic.com/infrastructure_agent/keys/newrelic_apt_key_current.gpg' 91 | conf['distribution'] = (node['lsb'] || {})['codename'] # node['lsb'] is nil on windows, so set a default 92 | conf['components'] = %w(main) 93 | conf['arch'] = 'amd64' 94 | conf['action'] = %i(add) 95 | end 96 | 97 | # Package version to install for Windows based hosts 98 | default['newrelic-infra']['windows_source'] = 'https://download.newrelic.com/infrastructure_agent/windows/newrelic-infra.msi' 99 | 100 | # YUM repository configuration for RHEL based hosts 101 | # See https://docs.chef.io/resource_yum_repository.html for more information 102 | default['newrelic_infra']['yum'].tap do |conf| 103 | conf['description'] = 'New Relic Infrastructure' 104 | conf['baseurl'] = value_for_platform( 105 | amazon: { 106 | '= 2013' => 'https://download.newrelic.com/infrastructure_agent/linux/yum/el/6/x86_64', 107 | '> 2013.0' => 'https://download.newrelic.com/infrastructure_agent/linux/yum/el/6/x86_64', 108 | '= 2' => 'https://download.newrelic.com/infrastructure_agent/linux/yum/el/7/$basearch', 109 | }, 110 | %w(redhat oracle centos) => { 111 | default: "https://download.newrelic.com/infrastructure_agent/linux/yum/el/#{node['platform_version'].to_i}/x86_64", 112 | } 113 | ) 114 | conf['gpgkey'] = 'https://download.newrelic.com/infrastructure_agent/keys/newrelic_rpm_key_current.gpg' 115 | conf['gpgcheck'] = true 116 | conf['repo_gpgcheck'] = node['platform_version'].to_i != 5 117 | conf['action'] = %i(create) 118 | end 119 | 120 | # Zypp repository configuration for SLES based hosts 121 | # See https://docs.chef.io/resource_zypper_repository.html for more information 122 | default['newrelic_infra']['zypper'].tap do |conf| 123 | platform_version = 124 | if node['platform_version'] =~ /^42/ 125 | '12.4' 126 | else 127 | node['platform_version'] 128 | end 129 | 130 | conf['description'] = 'New Relic Infrastructure' 131 | # TODO: Create a dokken image for SLES 12.4 132 | conf['baseurl'] = "https://download.newrelic.com/infrastructure_agent/linux/zypp/sles/#{platform_version}/x86_64" 133 | conf['gpgkey'] = 'https://download.newrelic.com/infrastructure_agent/keys/newrelic_rpm_key_current.gpg' 134 | conf['gpgcheck'] = true 135 | conf['repo_gpgcheck'] = true 136 | conf['action'] = %i(add) 137 | end 138 | -------------------------------------------------------------------------------- /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 | # SASS # 14 | ######## 15 | .sass-cache 16 | 17 | # EDITORS # 18 | ########### 19 | \#* 20 | .#* 21 | *~ 22 | *.sw[a-z] 23 | *.bak 24 | REVISION 25 | TAGS* 26 | tmtags 27 | *_flymake.* 28 | *_flymake 29 | *.tmproj 30 | .project 31 | .settings 32 | mkmf.log 33 | 34 | ## COMPILED ## 35 | ############## 36 | a.out 37 | *.o 38 | *.pyc 39 | *.so 40 | *.com 41 | *.class 42 | *.dll 43 | *.exe 44 | */rdoc/ 45 | 46 | # Testing # 47 | ########### 48 | .watchr 49 | .rspec 50 | spec/* 51 | spec/fixtures/* 52 | test/* 53 | features/* 54 | Guardfile 55 | Procfile 56 | 57 | # SCM # 58 | ####### 59 | .git 60 | */.git 61 | .gitignore 62 | .gitmodules 63 | .gitconfig 64 | .gitattributes 65 | .svn 66 | */.bzr/* 67 | */.hg/* 68 | */.svn/* 69 | 70 | # Berkshelf # 71 | ############# 72 | cookbooks/* 73 | tmp 74 | 75 | # Cookbooks # 76 | ############# 77 | CONTRIBUTING 78 | CHANGELOG* 79 | 80 | # Strainer # 81 | ############ 82 | Colanderfile 83 | Strainerfile 84 | .colander 85 | .strainer 86 | 87 | # Vagrant # 88 | ########### 89 | .vagrant 90 | Vagrantfile 91 | 92 | # Travis # 93 | ########## 94 | .travis.yml 95 | 96 | # Bundler # 97 | ########### 98 | vendor/bundle/** 99 | 100 | .chef 101 | .kitchen* 102 | 103 | # Encrypted key for Travis deployment 104 | newrelic* -------------------------------------------------------------------------------- /libraries/infra_helper.rb: -------------------------------------------------------------------------------- 1 | class Chef 2 | class Recipe 3 | # Helper methods for the `newrelic-infra` cookbook recipes 4 | # 5 | # @since 0.1.0 6 | module NewRelicInfra 7 | class << self 8 | # Method to generate a String of configuration flags from a given hash 9 | # 10 | # @param flags [Hash] hash of configuration flags and associated values 11 | # @return [String] string of configuration flags and associated values 12 | def generate_flags(flags) 13 | flag_arr = flags.each_with_object([]) do |(flag_key, flag_value), obj| 14 | obj << "-#{flag_key}=#{flag_value}" unless flag_value.nil? 15 | end 16 | flag_arr.join(' ') 17 | end 18 | 19 | # Method to modify YAML files to generate files that are compatiable with the New Relic 20 | # Infrastructure agent. Currently, the agent's Go library for parsing YAML files 21 | # does not conform to YAML spec. Thus, nested lists would have 2 spaces before 22 | # each element in the list. 23 | # 24 | # @since 0.3.0 25 | # @author Trevor G. Wood 26 | # @param current_contents [String] generated YAML file string 27 | # @return [String] YAML file with nested lists modifed 28 | def yaml_file_workaround(current_contents, delete_quotes) 29 | nested_map = current_contents[/^\-\s\w+:/] ? true : false 30 | regex = nested_map ? /^(\-?\s+)/ : /^(\s+\-\s)/ 31 | if delete_quotes 32 | current_contents.delete!('"') 33 | end 34 | current_contents.gsub!(regex, ' \\1') 35 | current_contents 36 | end 37 | end 38 | end 39 | end 40 | end 41 | 42 | # Adds a method to Hash class types to recursively string-ify all keys 43 | class Hash 44 | def deep_stringify 45 | each_with_object({}) do |(key, value), options| 46 | deep_val = 47 | if value.is_a? Hash 48 | value.deep_stringify 49 | elsif value.is_a? Array 50 | value.map do |arr| 51 | arr.is_a?(Hash) ? arr.deep_stringify : arr 52 | end 53 | else 54 | value 55 | end 56 | 57 | options[key.to_s] = deep_val 58 | end 59 | end 60 | 61 | def delete_blank 62 | delete_if do |_, value| 63 | (value.respond_to?(:empty?) ? value.empty? : (!value if value != false)) || value.instance_of?(Hash) && value.delete_blank.empty? 64 | end 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /libraries/integration.rb: -------------------------------------------------------------------------------- 1 | module NewRelicInfraCookbook 2 | # Chef custom resource to install the New Relic infrastructure agent on a node. 3 | class Integration < ::Chef::Resource 4 | BASENAME_IGNORE = /(\.(t?(ar|gz|bz2?|xz)|zip))+$/.freeze unless defined? BASENAME_IGNORE 5 | 6 | resource_name :newrelic_infra_integration 7 | 8 | # register with the resource resolution system 9 | provides :newrelic_infra_integration 10 | 11 | allowed_actions :create, :remove 12 | default_action :create 13 | 14 | # Required properties 15 | property :instance, String, name_property: true, desired_state: false 16 | property :integration_name, String, required: true 17 | property :remote_url, String, required: true 18 | property :instances, Array, required: true 19 | property :commands, Hash, required: true 20 | 21 | # Optional properties 22 | property :description, [String, nil] 23 | property :cli_options, [Hash, nil] 24 | 25 | # Properties with defaults 26 | property :interval, Integer, default: 10, desired_state: false 27 | property :prefix, String, default: lazy { |r| ::File.join('integration', r.instance) }, desired_state: false 28 | property :install_method, %w(tarball binary), default: 'tarball', desired_state: false 29 | property :os, %w(linux), default: 'linux', desired_state: false 30 | property :protocol_version, Integer, default: 1, desired_state: false 31 | property :user, String, default: 'newrelic_infra', desired_state: false 32 | property :group, String, default: 'newrelic_infra', desired_state: false 33 | property :base_dir, String, default: '/var/db/newrelic-infra/custom-integrations', desired_state: false 34 | property :bin_dir, String, default: '/opt/newrelic-infra', desired_state: false 35 | property :bin, String, default: lazy { |r| ::File.join(r.bin_dir, r.name, ::File.basename(r.remote_url).gsub(BASENAME_IGNORE, '')) }, desired_state: false 36 | property :definition_file, String, default: lazy { |r| ::File.join(r.base_dir, ::File.basename(r.name) << '.yaml') } 37 | property :config_dir, String, default: '/etc/newrelic-infra/integrations.d/', desired_state: false 38 | property :config_file, String, default: lazy { |r| ::File.join(r.config_dir, ::File.basename(r.name) << '.yaml') } 39 | 40 | # Helper methods 41 | def definition_file_content 42 | @definition_file_content ||= { 43 | name: integration_name, 44 | protocol_version: protocol_version, 45 | os: os, 46 | description: description, 47 | commands: build_definition_commands, 48 | } 49 | end 50 | 51 | def build_definition_commands 52 | @build_definition_commands ||= commands.each_with_object({}) do |(command, args), object| 53 | object.store( 54 | command, 55 | command: args.to_a.unshift(bin), 56 | interval: interval, 57 | prefix: prefix 58 | ) 59 | end 60 | end 61 | 62 | def config_file_content 63 | @config_file_content ||= { 64 | integration_name: integration_name, 65 | instances: instances.to_a, 66 | } 67 | end 68 | 69 | # Actions 70 | action :create do 71 | # Creates and manages the directory for the custom integration executable 72 | %W( 73 | #{new_resource.bin_dir} 74 | #{::File.join(new_resource.bin_dir, new_resource.name)} 75 | ).each do |dir| 76 | directory dir do 77 | owner new_resource.user 78 | group new_resource.group 79 | mode '0750' 80 | recursive true 81 | end 82 | end 83 | 84 | # Fetch the remote executable binary if the install method is set to `binary` 85 | remote_file new_resource.bin do 86 | user new_resource.user 87 | group new_resource.group 88 | source new_resource.remote_url 89 | only_if { new_resource.install_method == 'binary' } 90 | end 91 | 92 | # Fetch the remote executable tarball if the install method is set to `tarball` 93 | archive_file new_resource.remote_url do 94 | destination ::File.join(new_resource.bin_dir, new_resource.name) 95 | keep_existing true 96 | only_if { new_resource.install_method == 'tarball' } 97 | end 98 | 99 | file new_resource.bin do 100 | owner new_resource.user 101 | group new_resource.group 102 | mode '0750' 103 | end 104 | 105 | # Generate both the definiton and configuration files for the custom 106 | # New Relic Infrastructure on-host integration 107 | %w( 108 | definition_file 109 | config_file 110 | ).each do |file_to_create| 111 | file_path = new_resource.send(:"#{file_to_create}") 112 | 113 | file file_to_create do 114 | owner new_resource.user 115 | group new_resource.group 116 | path file_path 117 | content(lazy do 118 | ::Chef::Recipe::NewRelicInfra.yaml_file_workaround( 119 | YAML.dump(new_resource.send(:"#{file_to_create}_content").delete_blank.deep_stringify), 120 | node['newrelic_infra']['delete_yaml_quotes'] 121 | ) 122 | end) 123 | sensitive true 124 | mode '0640' 125 | end 126 | end 127 | end 128 | 129 | action :remove do 130 | # Remove all of the resources for the New Relic Infrastructure 131 | # custom on-host integration 132 | %W( 133 | #{new_resource.bin} 134 | #{new_resource.definition_file} 135 | #{new_resource.config_file} 136 | ).each do |file_to_remove| 137 | file file_to_remove do 138 | action :delete 139 | end 140 | end 141 | end 142 | end 143 | end 144 | -------------------------------------------------------------------------------- /libraries/matchers.rb: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'newrelic-infra' 2 | maintainer 'New Relic, Inc' 3 | maintainer_email 'caos-dev@newrelic.com' 4 | license 'All rights reserved' 5 | description 'Installs/Configures the New Relic Infrastructure agent ' \ 6 | 'and on-host integrations' 7 | source_url 'https://github.com/newrelic/infrastructure-agent-chef' 8 | issues_url 'https://github.com/newrelic/infrastructure-agent-chef/issues' 9 | version '0.12.3' 10 | chef_version '>= 15' 11 | 12 | # Platform support 13 | supports 'amazon', '>= 2013.0' 14 | supports 'debian', '>= 7.0' 15 | supports 'ubuntu', '>= 16.04' 16 | supports 'redhat', '>= 5.0' 17 | supports 'oracle', '>= 6.0' 18 | supports 'centos', '>= 7.0' 19 | supports 'suse' 20 | supports 'windows' 21 | -------------------------------------------------------------------------------- /recipes/agent_linux.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (c) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | # 8 | # Recipe:: to install and configure the New Relic Infrastructure agent on Linux 9 | # TODO: Convert to custom resource 10 | # 11 | node.default['newrelic_infra']['agent']['flags']['config'] = ::File.join( 12 | node['newrelic_infra']['agent']['directory']['path'], 13 | node['newrelic_infra']['agent']['config']['file'] 14 | ) 15 | 16 | group node['newrelic_infra']['group']['name'] do 17 | group_name node['newrelic_infra']['group']['name'] 18 | end 19 | 20 | # Setup a service account 21 | user node['newrelic_infra']['user']['name'] do 22 | gid node['newrelic_infra']['group']['name'] 23 | shell '/bin/false' 24 | end 25 | 26 | # Based on the Ohai attribute `platform_family` either an APT or YUM repository 27 | # will be created. The respective Chef resources are built using metaprogramming, 28 | # so that the configuration can be extended via attributes without having to 29 | # release a new version of the cookbook. Attributes that cannot be passed to the resource 30 | # are logged out as warnings in order to prevent potential failes from typos, 31 | # older Chef versions, etc. 32 | case node['newrelic_infra']['provider'] 33 | when 'package_manager' 34 | case node['platform_family'] 35 | when 'debian' 36 | # Create APT repo file 37 | apt_repository cookbook_name do 38 | arch node['newrelic_infra']['apt']['arch'] 39 | uri node['newrelic_infra']['apt']['uri'] 40 | key node['newrelic_infra']['apt']['key'] 41 | distribution node['newrelic_infra']['apt']['distribution'] 42 | components node['newrelic_infra']['apt']['components'] 43 | action node['newrelic_infra']['apt']['action'] 44 | end 45 | when 'rhel', 'amazon' 46 | yum_repository cookbook_name do 47 | description node['newrelic_infra']['yum']['description'] 48 | baseurl node['newrelic_infra']['yum']['baseurl'] 49 | gpgkey node['newrelic_infra']['yum']['gpgkey'] 50 | gpgcheck node['newrelic_infra']['yum']['gpgcheck'] 51 | repo_gpgcheck node['newrelic_infra']['yum']['repo_gpgcheck'] 52 | action node['newrelic_infra']['yum']['action'] 53 | end 54 | when 'suse' 55 | zypper_repository cookbook_name do 56 | description node['newrelic_infra']['zypper']['description'] 57 | baseurl node['newrelic_infra']['zypper']['baseurl'] 58 | gpgkey node['newrelic_infra']['zypper']['gpgkey'] 59 | gpgcheck node['newrelic_infra']['zypper']['gpgcheck'] 60 | action node['newrelic_infra']['zypper']['action'] 61 | end 62 | end 63 | 64 | # Install the newrelic-infra agent 65 | package 'newrelic-infra' do 66 | action node['newrelic_infra']['packages']['agent']['action'] 67 | retries node['newrelic_infra']['packages']['agent']['retries'] 68 | version node['newrelic_infra']['packages']['agent']['version'] 69 | end 70 | 71 | include_recipe 'newrelic-infra::host_integrations' 72 | 73 | # Fix for docker centos6 run 74 | execute 'reload_initctl_conf' do 75 | command 'initctl reload-configuration' 76 | only_if { node['platform_version'] =~ /^6/ } 77 | only_if { ::File.exist?('/.dockerenv') } 78 | end 79 | 80 | # Create and manage the agent directory 81 | directory node['newrelic_infra']['agent']['directory']['path'] do 82 | owner node['newrelic_infra']['user']['name'] 83 | group node['newrelic_infra']['group']['name'] 84 | mode node['newrelic_infra']['agent']['directory']['mode'] 85 | end 86 | 87 | # Build the New Relic infrastructure agent configuration 88 | file node['newrelic_infra']['agent']['flags']['config'] do 89 | content(lazy do 90 | YAML.dump( 91 | node['newrelic_infra']['config'].to_h.deep_stringify.delete_blank 92 | ) 93 | end) 94 | owner node['newrelic_infra']['user']['name'] 95 | group node['newrelic_infra']['group']['name'] 96 | mode node['newrelic_infra']['agent']['config']['mode'] 97 | sensitive true 98 | notifies :restart, 'service[newrelic-infra]' 99 | end 100 | 101 | # Enable and start the agent as a service on the node with any available 102 | # CLI options 103 | service 'newrelic-infra' do 104 | # TODO: Figure out how to run as a service account. 105 | # user node['newrelic_infra']['user']['name'] 106 | start_command '/usr/bin/newrelic-infra' 107 | options [:systemd, 108 | template: 'newrelic-infra:default/systemd.service.erb', 109 | after: %w(syslog.target network.target)] 110 | end 111 | when 'tarball' 112 | node['newrelic_infra']['tarball'].tap do |conf| 113 | remote_file "/opt/linux_#{conf['version']}_#{conf['architecture']}.tar.gz" do 114 | source "https://download.newrelic.com/infrastructure_agent/binaries/linux/#{conf['architecture']}/newrelic-infra_linux_#{conf['version']}_#{conf['architecture']}.tar.gz" 115 | action :create 116 | end 117 | directory '/opt/newrelic_infra/' do 118 | action :create 119 | end 120 | directory "/opt/newrelic_infra/linux_#{conf['version']}_#{conf['architecture']}" do 121 | action :create 122 | end 123 | 124 | execute 'extract_newrelic_infra_tarball' do 125 | command "tar -xzf /opt/linux_#{conf['version']}_#{conf['architecture']}.tar.gz -C /opt/newrelic_infra/linux_#{conf['version']}_#{conf['architecture']}/" 126 | not_if { ::File.exist?("/opt/newrelic_infra/linux_#{conf['version']}_#{conf['architecture']}/newrelic-infra") } 127 | notifies :run, 'execute[run_installation_script]', :immediately 128 | end 129 | 130 | execute 'run_installation_script' do 131 | command "/opt/newrelic_infra/linux_#{conf['version']}_#{conf['architecture']}/newrelic-infra/installer.sh" 132 | cwd "/opt/newrelic_infra/linux_#{conf['version']}_#{conf['architecture']}/newrelic-infra/" 133 | environment 'NRIA_LICENSE_KEY' => node['newrelic_infra']['config']['license_key'] 134 | action :nothing 135 | end 136 | end 137 | 138 | # Build the New Relic infrastructure agent configuration 139 | file '/etc/newrelic-infra.yml' do 140 | content(lazy do 141 | YAML.dump( 142 | node['newrelic_infra']['config'].to_h.deep_stringify.delete_blank 143 | ) 144 | end) 145 | owner node['newrelic_infra']['user']['name'] 146 | group node['newrelic_infra']['group']['name'] 147 | mode node['newrelic_infra']['agent']['config']['mode'] 148 | sensitive true 149 | notifies :restart, 'service[newrelic-infra]' 150 | end 151 | 152 | service 'newrelic-infra' do 153 | action :start 154 | end 155 | end 156 | -------------------------------------------------------------------------------- /recipes/agent_windows.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (C) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | # 8 | # Recipe:: to install and configure the New Relic Infrastructure agent on Windows 9 | # 10 | # Chef uses sha256 checksums, to generate this, I downloaded the file 11 | # and on OS X did 'shasum -a 256 newrelic-infra.msi' YMMV on other 12 | # platforms. It'd be *really* cool if NewRelic could provide an API 13 | # that you could ask for checksum values, or have checksums published 14 | # and available in some other way. 15 | # 16 | # TODO: make install location configurable 17 | 18 | windows_package 'newrelic-infra' do 19 | action :install 20 | checksum node['newrelic-infra']['windows_checksum'] 21 | installer_type :msi 22 | retries node['newrelic_infra']['packages']['agent']['retries'] 23 | source node['newrelic-infra']['windows_source'] 24 | end 25 | 26 | # Build the New Relic infrastructure agent configuration 27 | file 'C:\Program Files\New Relic\newrelic-infra\newrelic-infra.yml' do 28 | content(lazy do 29 | YAML.dump( 30 | node['newrelic_infra']['config'].to_h.deep_stringify.delete_blank 31 | ) 32 | end) 33 | sensitive true 34 | notifies :restart, 'service[newrelic-infra]' 35 | end 36 | 37 | # Setup newrelic-infra service 38 | service 'newrelic-infra' do 39 | action [:enable, :start] 40 | end 41 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (C) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | # Install and configure the New Relic Infrastructure agent 8 | if platform?('windows') 9 | include_recipe 'newrelic-infra::agent_windows' 10 | else 11 | include_recipe 'newrelic-infra::agent_linux' 12 | end 13 | -------------------------------------------------------------------------------- /recipes/host_integrations.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (c) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | # 8 | # Installs New Relic provided and custom on-host integrations 9 | # 10 | 11 | # Install host integrations defined with attributes 12 | if node['newrelic_infra']['features']['host_integrations'].any? 13 | node['newrelic_infra']['features']['host_integrations'].each do |integration_name| 14 | package integration_name do 15 | action node['newrelic_infra']['packages'][integration_name]['action'] 16 | retries node['newrelic_infra']['packages'][integration_name]['retries'] 17 | version node['newrelic_infra']['packages'][integration_name]['version'] 18 | end 19 | end 20 | 21 | directory node['newrelic_infra']['host_integrations']['config_dir'] do 22 | owner node['newrelic_infra']['user']['name'] 23 | group node['newrelic_infra']['group']['name'] 24 | mode '0750' 25 | end 26 | 27 | # Generate configuration for the New Relic provided host integrations 28 | node['newrelic_infra']['host_integrations']['config'].each do |integration_name, config| 29 | file_path = ::File.join( 30 | node['newrelic_infra']['host_integrations']['config_dir'], 31 | "#{integration_name}.yaml" 32 | ) 33 | 34 | file file_path do 35 | content(lazy do 36 | NewRelicInfra.yaml_file_workaround( 37 | YAML.dump(config.to_h.delete_blank.deep_stringify), 38 | node['newrelic_infra']['delete_yaml_quotes'] 39 | ) 40 | end) 41 | owner node['newrelic_infra']['user']['name'] 42 | group node['newrelic_infra']['group']['name'] 43 | mode '0640' 44 | sensitive true 45 | notifies :restart, 'service[newrelic-infra]' 46 | end 47 | end 48 | end 49 | 50 | # Install any custom integrations defined with attributes 51 | node['newrelic_infra']['custom_integrations'].each do |integration_name, config| 52 | newrelic_infra_integration integration_name do |infra_resource| 53 | config.each do |property, value| 54 | unless infra_resource.class.properties.include?(property.to_sym) && !value.nil? || property == 'action' 55 | Chef::Log.warn("[#{cookbook_name}::#{recipe_name}] #{property} with #{value}" \ 56 | 'is not valid for the Chef resource `yum_repository`!') 57 | next 58 | end 59 | 60 | infra_resource.send(property, value) 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/agent_linux_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (c) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | require 'spec_helper' 8 | 9 | describe 'newrelic-infra::agent_linux' do 10 | shared_examples_for :default do 11 | let(:service_user) { 'newrelic_infra' } 12 | 13 | it 'should create the service account `newrelic_infra`' do 14 | expect(chef_cached).to create_poise_service_user(service_user).with( 15 | group: service_user 16 | ) 17 | end 18 | 19 | it 'should create the agent configuration directory' do 20 | expect(chef_cached).to create_directory('/etc/newrelic-infra').with( 21 | owner: service_user, 22 | group: service_user, 23 | mode: '0750' 24 | ) 25 | end 26 | 27 | it 'should create the agent configuration file' do 28 | expect(chef_cached).to create_file('/etc/newrelic-infra/agent.yaml').with( 29 | owner: service_user, 30 | group: service_user, 31 | mode: '0640', 32 | sensitive: true 33 | ) 34 | end 35 | 36 | it 'configuration file generation notifies agent to restart' do 37 | file_resource = chef_cached.file('/etc/newrelic-infra/agent.yaml') 38 | expect(file_resource).to notify('poise_service[newrelic-infra]').to(:restart).delayed 39 | end 40 | 41 | it 'should create add the package repo' do 42 | next unless chef_cached.node['platform_family'] == 'debian' 43 | expect(chef_cached).to ChefSpec::Matchers::ResourceMatcher.new(:apt_repository, :add, 'newrelic-infra') 44 | end 45 | 46 | it 'should create the repo cache for YUM repos' do 47 | next unless %w(rhel amazon).include? chef_cached.node['platform_family'] 48 | expect(chef_cached).to create_yum_repository('newrelic-infra') 49 | end 50 | 51 | it 'should install the agent package' do 52 | expect(chef_cached).to install_package('newrelic-infra').with(action: [:install], 53 | retries: 3, 54 | version: '') 55 | end 56 | 57 | it 'should enable the agent service' do 58 | expect(chef_cached).to enable_poise_service('newrelic-infra').with( 59 | command: '/usr/bin/newrelic-infra -config=/etc/newrelic-infra/agent.yaml' 60 | ) 61 | end 62 | 63 | it 'should include the host integrations recipe' do 64 | expect(chef_cached).to include_recipe('newrelic-infra::host_integrations') 65 | end 66 | end 67 | 68 | supported_platforms.each do |platform, versions| 69 | versions.each do |version| 70 | context "On #{platform}: #{version} with default attributes" do 71 | let(:chef_run) do 72 | ChefSpec::SoloRunner.new(platform: platform.to_s, 73 | version: version) do |node| 74 | node.normal['newrelic_infra']['packages']['agent']['retries'] = 3 75 | end.converge(described_recipe) 76 | end 77 | cached(:chef_cached) { chef_run } 78 | 79 | it_behaves_like :default 80 | end 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /spec/agent_windows_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (c) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | require 'spec_helper' 8 | 9 | describe 'newrelic-infra::agent_windows' do 10 | let(:chef_run) do 11 | ChefSpec::SoloRunner.new(platform: 'windows', version: '2016') do |node| 12 | node.normal['newrelic_infra']['packages']['agent']['retries'] = 3 13 | end.converge(described_recipe) 14 | end 15 | 16 | it 'converges' do 17 | expect { chef_run }.to_not raise_error 18 | end 19 | 20 | it 'installs the agent package' do 21 | expect(chef_run).to install_windows_package('newrelic-infra').with(action: [:install], 22 | retries: 3, 23 | version: nil) 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/default_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (c) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | require 'spec_helper' 8 | 9 | describe 'newrelic-infra::default' do 10 | shared_examples_for :default do 11 | it 'should include the Linux install recipe' do 12 | expect(chef_cached).to include_recipe('newrelic-infra::agent_linux') 13 | end 14 | end 15 | 16 | supported_platforms.each do |platform, versions| 17 | versions.each do |version| 18 | context "On #{platform}: #{version} with default attributes" do 19 | let(:chef_run) do 20 | ChefSpec::SoloRunner.new(platform: platform.to_s, 21 | version: version).converge(described_recipe) 22 | end 23 | cached(:chef_cached) { chef_run } 24 | 25 | it_behaves_like :default 26 | end 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /spec/host_integrations_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (C) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | require 'spec_helper' 8 | 9 | describe 'newrelic-infra::host_integrations' do 10 | shared_examples_for :default do 11 | let(:file_path) { '/etc/newrelic-infra/integrations.d/cassandra.yaml' } 12 | 13 | it 'should install the host packages' do 14 | expect(chef_cached).to install_package('nri-cassandra').with(action: [:install], 15 | retries: 3, 16 | version: '') 17 | expect(chef_cached).to install_package('nri-mysql').with(action: [:install], 18 | retries: 3, 19 | version: '') 20 | expect(chef_cached).to install_package('nri-redis').with(action: [:install], 21 | retries: 3, 22 | version: '') 23 | expect(chef_cached).to install_package('nri-nginx').with(action: [:install], 24 | retries: 3, 25 | version: '') 26 | expect(chef_cached).to install_package('nri-apache').with(action: [:install], 27 | retries: 3, 28 | version: '') 29 | end 30 | 31 | it 'should create the on-host integration configuration directory' do 32 | expect(chef_cached).to create_directory('/etc/newrelic-infra/integrations.d').with( 33 | owner: 'newrelic_infra', 34 | group: 'newrelic_infra', 35 | mode: '0750' 36 | ) 37 | end 38 | 39 | it 'should create the on-host integration configuration files' do 40 | expect(chef_cached).to create_file(file_path).with( 41 | owner: 'newrelic_infra', 42 | group: 'newrelic_infra', 43 | mode: '0640', 44 | sensitive: true 45 | ) 46 | end 47 | 48 | it 'should render the on-host integration configuration with any specified configuration' do 49 | expect(chef_cached).to(render_file(file_path).with_content do |content| 50 | expect(content).to match(/username: chef/) 51 | expect(content).to match(/password: spec/) 52 | end) 53 | end 54 | end 55 | 56 | supported_platforms.each do |platform, versions| 57 | versions.each do |version| 58 | context "On #{platform}: #{version} with host integrations enabled" do 59 | let(:solo) do 60 | ChefSpec::SoloRunner.new(platform: platform.to_s, version: version) do |node| 61 | node.normal['newrelic_infra']['features']['host_integrations'] = %w(nri-cassandra nri-mysql nri-redis nri-nginx nri-apache) 62 | node.normal['newrelic_infra']['host_integrations']['config']['cassandra']['username'] = 'chef' 63 | node.normal['newrelic_infra']['host_integrations']['config']['cassandra']['password'] = 'spec' 64 | node.normal['newrelic_infra']['packages']['nri-cassandra']['retries'] = 3 65 | node.normal['newrelic_infra']['packages']['nri-mysql']['retries'] = 3 66 | node.normal['newrelic_infra']['packages']['nri-redis']['retries'] = 3 67 | node.normal['newrelic_infra']['packages']['nri-nginx']['retries'] = 3 68 | node.normal['newrelic_infra']['packages']['nri-apache']['retries'] = 3 69 | end 70 | end 71 | let(:chef_run) do 72 | solo.converge(described_recipe) do 73 | solo.resource_collection.insert( 74 | PoiseService::Resources::PoiseService::Resource.new('newrelic-infra', solo.run_context) 75 | ) 76 | end 77 | end 78 | cached(:chef_cached) { chef_run } 79 | 80 | it_behaves_like :default 81 | end 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /spec/integration_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (c) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | require 'spec_helper' 8 | 9 | describe 'newrelic-infra::host_integrations' do 10 | shared_examples_for :default_create do 11 | let(:service_account) { 'newrelic_infra' } 12 | 13 | it 'installs the New Relic Infrastructure custom integration' do 14 | expect(chef_cached).to create_newrelic_infra_integration('test_integration').with( 15 | integration_name: 'com.test.integration', 16 | remote_url: 'https://url-to-a-tarball-for-install.com/test.tar.gz' 17 | ) 18 | end 19 | 20 | %w( 21 | /opt/newrelic-infra 22 | /opt/newrelic-infra/test_integration 23 | ).each do |dir| 24 | it 'creates the integration binary directory' do 25 | expect(chef_cached).to create_directory(dir).with( 26 | owner: service_account, 27 | group: service_account, 28 | mode: '0750' 29 | ) 30 | end 31 | end 32 | 33 | it 'does not download the remote file' do 34 | resource = chef_cached.remote_file('/opt/newrelic-infra/test_integration/test') 35 | expect(resource).to do_nothing 36 | end 37 | 38 | it 'unpacks the remote tarball' do 39 | expect(chef_cached).to unpack_poise_archive('https://url-to-a-tarball-for-install.com/test.tar.gz').with( 40 | destination: '/opt/newrelic-infra/test_integration', 41 | keep_existing: true 42 | ) 43 | end 44 | 45 | %w( 46 | definition_file 47 | config_file 48 | ).each do |file_to_create| 49 | it "creates the integration #{file_to_create}" do 50 | expect(chef_cached).to create_file(file_to_create).with( 51 | owner: service_account, 52 | group: service_account, 53 | mode: '0640', 54 | sensitive: true 55 | ) 56 | end 57 | end 58 | 59 | it 'updates the binary file with the correct permissions' do 60 | expect(chef_cached).to create_file('/opt/newrelic-infra/test_integration/test').with( 61 | owner: service_account, 62 | group: service_account, 63 | mode: '0750' 64 | ) 65 | end 66 | 67 | it 'renders the integration definition file with the correct configuration' do 68 | expect(chef_cached).to(render_file('definition_file').with_content do |content| 69 | expect(content).to match(/name: com.test.integration/) 70 | expect(content).to match(/description: A test custom integration/) 71 | expect(content).to match(/protocol_version: 1/) 72 | expect(content).to match(/os: linux/) 73 | expect(content).to match(/interval: 10/) 74 | expect(content).to match(/commands:/) 75 | expect(content).to match(/\s{2}metrics:/) 76 | expect(content).to match(/\s{4}command:/) 77 | expect(content).to match(%r{\s{6}- /opt/newrelic-infra/test_integration/test}) 78 | expect(content).to match(/\s{6}- --metrics/) 79 | end) 80 | end 81 | 82 | it 'renders the configuration file with the correct configuration' do 83 | expect(chef_cached).to(render_file('config_file').with_content do |content| 84 | expect(content).to match(/integration_name: com.test.integration/) 85 | expect(content).to match(/instances:/) 86 | expect(content).to match(/\s{2}- name: test_integration_metrics/) 87 | expect(content).to match(/\s{4}command: metrics/) 88 | expect(content).to match(/\s{4}arguments:/) 89 | expect(content).to match(/\s{6}test: true/) 90 | expect(content).to match(/\s{4}labels:/) 91 | expect(content).to match(/\s{6}environment: test/) 92 | end) 93 | end 94 | end 95 | 96 | shared_examples_for :default_remove do 97 | %w( 98 | /opt/newrelic-infra/test_integration/test 99 | /var/db/newrelic-infra/custom-integrations/test_integration.yaml 100 | /etc/newrelic-infra/integrations.d/test_integration.yaml 101 | ).each do |file_to_delete| 102 | it "deletes the file #{file_to_delete}" do 103 | expect(chef_cached).to delete_file(file_to_delete) 104 | end 105 | end 106 | end 107 | 108 | supported_platforms.each do |platform, versions| 109 | versions.each do |version| 110 | context "On #{platform}: #{version} with custom integration attributes" do 111 | let(:chef_run) do 112 | ChefSpec::SoloRunner.new(platform: platform.to_s, version: version, step_into: ['newrelic_infra_integration']) do |node| 113 | node.normal['newrelic_infra']['custom_integrations']['test_integration'] = { 114 | action: %i(create remove), 115 | integration_name: 'com.test.integration', 116 | description: 'A test custom integration', 117 | remote_url: 'https://url-to-a-tarball-for-install.com/test.tar.gz', 118 | instances: [ 119 | { 120 | name: 'test_integration_metrics', 121 | command: 'metrics', 122 | arguments: { 123 | test: true, 124 | }, 125 | labels: { 126 | environment: 'test', 127 | }, 128 | }, 129 | ], 130 | commands: { 131 | metrics: %w(--metrics), 132 | }, 133 | } 134 | end.converge(described_recipe) 135 | end 136 | cached(:chef_cached) { chef_run } 137 | 138 | it_behaves_like :default_create 139 | it_behaves_like :default_remove 140 | end 141 | end 142 | end 143 | end 144 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (C) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | require 'chefspec' 8 | require 'chefspec/berkshelf' 9 | 10 | Dir[File.join(__dir__, 'support/**/*.rb')].sort.each { |f| require f } 11 | 12 | RSpec.configure do |config| 13 | config.log_level = :error 14 | config.file_cache_path = '/var/chef/cache' 15 | 16 | # Disable STDOUT and STDERR 17 | original_stderr = $stderr 18 | original_stdout = $stdout 19 | config.before(:all) do 20 | # Redirect stderr and stdout 21 | $stderr = File.new(File.join(File.dirname(__FILE__), 'stderr.txt'), 'w') 22 | $stdout = File.new(File.join(File.dirname(__FILE__), 'stdout.txt'), 'w') 23 | end 24 | # Re-enable STDOUT and STDERR 25 | config.after(:all) do 26 | $stderr = original_stderr 27 | $stdout = original_stdout 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /spec/support/common_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (C) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | # Pulled from https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md 8 | def supported_platforms 9 | { 10 | redhat: %w(7.5 6.9), 11 | oracle: %w(7.4 6.9), 12 | centos: %w(7.4.1708 6.9), 13 | amazon: %w(2018.03 2015.09), 14 | debian: %w(9.4 8.10 7.11), 15 | ubuntu: %w(18.04 16.04 14.04), 16 | suse: %w(11.4 12.2), 17 | } 18 | end 19 | 20 | def unsupported_platforms 21 | { 22 | windows: %w(2012R2 2008R2), 23 | } 24 | end 25 | -------------------------------------------------------------------------------- /templates/default/systemd.service.erb: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=<%= @name %> 3 | After=<%= @options['after'].is_a?(Array) ? @options['after'].join(' ') : @options['after'] %> 4 | 5 | [Service] 6 | Type=simple 7 | Environment=<%= @environment.map {|key, val| %Q{"#{key}=#{val}"} }.join(' ') %> 8 | ExecStart=<%= @command %> 9 | User=<%= @user %> 10 | KillSignal=TERM 11 | MemoryLimit=1G 12 | Restart=always 13 | RestartSec=20 14 | StartLimitInterval=0 15 | StartLimitBurst=5 16 | 17 | [Install] 18 | WantedBy=multi-user.target 19 | -------------------------------------------------------------------------------- /test/integration/default/inspec/agent_linux_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (C) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | 7 | describe user('newrelic_infra') do 8 | it { should exist } 9 | its('group') { should eq 'newrelic_infra' } 10 | its('home') { should eq '/home/newrelic_infra' } 11 | its('shell') { should eq '/bin/false' } 12 | end 13 | 14 | describe group('newrelic_infra') do 15 | it { should exist } 16 | end 17 | 18 | if os[:family] == 'debian' 19 | apt('https://download.newrelic.com/infrastructure_agent/linux/apt') do 20 | it { should exist } 21 | it { should be_enabled } 22 | end 23 | elsif os[:family] == 'redhat' 24 | describe yum.repo('newrelic-infra') do 25 | it { should exist } 26 | it { should be_enabled } 27 | its('baseurl') { should include("https://download.newrelic.com/infrastructure_agent/linux/yum/el/#{os[:release][0]}") } 28 | end 29 | end 30 | 31 | describe package('newrelic-infra') do 32 | it { should be_installed } 33 | end 34 | 35 | describe file('/etc/newrelic-infra') do 36 | it { should be_directory } 37 | it { should be_owned_by 'root' } 38 | it { should be_grouped_into 'root' } 39 | its('mode') { should cmp '0755' } 40 | end 41 | 42 | describe file('/etc/newrelic-infra.yml') do 43 | it { should be_file } 44 | it { should be_owned_by 'newrelic_infra' } 45 | it { should be_grouped_into 'newrelic_infra' } 46 | its('mode') { should cmp '0640' } 47 | its('content') { should match(/license_key: abcd/) } 48 | its('content') { should match(/verbose: 0/) } 49 | end 50 | 51 | # `poise_service` uses upstart for RHEL systems less than 7; 52 | # however, Inspec uses `sysvinit`, so we need to.override 53 | # the default autodetected service type for these systems. 54 | newrelic_service = os[:family] == 'redhat' && os[:release].to_i < 7 ? upstart_service('newrelic-infra') : service('newrelic-infra') 55 | 56 | describe newrelic_service do 57 | it { should be_enabled } 58 | it { should be_installed } 59 | it { should be_running } 60 | end 61 | -------------------------------------------------------------------------------- /test/integration/default/inspec/host_integrations_spec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright:: (C) 2016-2017 New Relic, Inc. 3 | # 4 | # All rights reserved. 5 | # 6 | describe package('nri-cassandra') do 7 | it { should be_installed } 8 | end 9 | 10 | describe package('nri-mysql') do 11 | it { should be_installed } 12 | end 13 | describe package('nri-redis') do 14 | it { should be_installed } 15 | end 16 | 17 | describe package('nri-nginx') do 18 | it { should be_installed } 19 | end 20 | 21 | describe package('nri-apache') do 22 | it { should be_installed } 23 | end 24 | 25 | describe file('/etc/newrelic-infra/integrations.d/cassandra.yaml') do 26 | it { should be_file } 27 | it { should be_owned_by 'newrelic_infra' } 28 | it { should be_grouped_into 'newrelic_infra' } 29 | its('mode') { should cmp '0640' } 30 | its('content') { should match(/username: test/) } 31 | its('content') { should match(/password: kitchen/) } 32 | its('content') { should match(%r{hosts: '\["/"\]'}) } 33 | end 34 | --------------------------------------------------------------------------------