newrelic-management 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed2b5325cf0d6218dd3592e8f8322f97cda69f3c
4
+ data.tar.gz: 45f37204436696efabe118860282c604738999ec
5
+ SHA512:
6
+ metadata.gz: a9bb4715645d33f73a579b8fde09bca22c83467857bb1e46ae76bc79dbde1e869492cf844b42e1eb04c4634246d75648b101a52070dcc147fd418ae7fa45acd5
7
+ data.tar.gz: fa5b6ab527e7605b7398e149f7cf8187ffacd91a25aa0fb2f65c5d970460e6f3f25600929e4d1aedee06f31b7a0c4840f8aa644c83fe882a2d519ee25afeca32
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *~
2
+ *#
3
+ .#*
4
+ \#*#
5
+ .*.sw[a-z]
6
+ *.un~
7
+ pkg/
8
+ vendor/
9
+ config.json
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,36 @@
1
+ before_script:
2
+ - ruby -v
3
+ - which ruby
4
+ - gem install bundler --no-ri --no-rdoc
5
+ - bundle install --jobs $(nproc) --path vendor/bundle
6
+
7
+ test:Ruby 2.3:
8
+ image: ruby:2.3
9
+ cache:
10
+ paths:
11
+ - .bundle
12
+ - vendor/bundle
13
+ script:
14
+ - bundle exec rubocop
15
+ tags:
16
+ - ruby
17
+ except:
18
+ - tags
19
+
20
+ release:Ruby 2.3:
21
+ image: ruby:2.3
22
+ cache:
23
+ paths:
24
+ - .bundle
25
+ - vendor/bundle
26
+ script:
27
+ - bundle exec rubocop
28
+ - bundle exec rake build
29
+ artifacts:
30
+ name: "newrelic-management-$CI_BUILD_REF_NAME"
31
+ paths:
32
+ - pkg/*.gem
33
+ tags:
34
+ - ruby
35
+ only:
36
+ - tags
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ Metrics/MethodLength:
2
+ Max: 12
3
+
4
+ Metrics/ModuleLength:
5
+ Max: 150
6
+
7
+ Style/ModuleFunction:
8
+ Enabled: false
9
+
10
+ Style/WordArray:
11
+ Enabled: false
12
+
13
+ Style/FileName:
14
+ Enabled: false
15
+
16
+ AllCops:
17
+ Include:
18
+ - lib/
data/.travis.yml ADDED
@@ -0,0 +1,38 @@
1
+ language: ruby
2
+ cache: bundler
3
+ dist: trusty
4
+ sudo: false
5
+
6
+ rvm:
7
+ - 2.3
8
+
9
+ before_script:
10
+ - ruby -v
11
+ - which ruby
12
+ - gem install bundler --no-ri --no-rdoc
13
+ - bundle install --jobs $(nproc) --path vendor/bundle
14
+
15
+ script:
16
+ - bundle exec rubocop
17
+
18
+ before_deploy:
19
+ - bundle exec rake build
20
+ - export RELEASE_FILE=$(ls pkg/*.gem)
21
+ - echo "deploying $RELEASE_FILE to GitHub releases"
22
+ deploy:
23
+ provider: releases
24
+ api_key:
25
+ secure: S+0jonLbS7kBoIpai+4QG9HJykU/ZIh/xxBDXyKxdrwiMAcDpFXc0QIxS/rqOt8fFwgHF56iys5xMnWv4ERg0FH91j7rQqMTXQdESaG1sUu5wky+iXVtSfmTkXjRSJDeUkcdg3b+nxpEYbqD9H8tS0dTvAURQS4XuGG6H+r5WvOrvMw6ZukHQsn0mQxN2TVzRxR3uKc/fGiUFu9PxY9W4iblYZIWIF36y3gsiyMu78W4Od40LJi4K9DZ04sPkOHQDuOfQ9h6sOsAf4siGHifJPHj7r6LAX6KcVjZFj3Lzy379MpkLR4B57Ee7d70L0kRhP4qVMs+HEDJiz0ZRSkE1ql1qcUr8MYI6mWljHCDthf3/3zFgKdc14DiMK1bF20i4/VUZorr2NB3DNbJ2B16vx27wLKm4+7zDVOfDEjiZAzxutUdWnfNJDMVxb+B/AXF21SCrQAfi5e08i1sp0HH9f3VN8jrnmSrVl9NhjOy+Ufow0fH5Es3pj7hluS8cxHuIuJobPJoYUI36T3hai/WqHs8p4P8b70cwFWO2dtmt4OTBhAgcU2oASYQ3UCD8vqzttBUMRkbjOG0jUYSdxkRzYMXJFLM1iM7/9q3K9Dp/moZL9OGttDiU+lfNx3SboIr0EktN4lBGYSPPvfbT/H43UYquHBL0Ug1eEOX43ZSVU8=
26
+ file_glob: true
27
+ file: "${RELEASE_FILE}"
28
+ skip_cleanup: true
29
+ on:
30
+ repo: bdwyertech/newrelic-management
31
+ tags: true
32
+ notifications:
33
+ webhooks:
34
+ urls:
35
+ - https://webhooks.gitter.im/e/dd82463fde591a8d4195
36
+ on_success: change
37
+ on_failure: always
38
+ on_start: never
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ NewRelic-Management Changelog
2
+ =========================
3
+ This file is used to list changes made in each version of the `newrelic-management` gem.
4
+
5
+ v0.1.1 (2017-01-17)
6
+ -------------------
7
+ - Enable caching of certain NewRelic API calls
8
+ - Clean up notifications
9
+ - Fix configuration pass-through
10
+ - Fix Windows timezone issue
11
+
12
+ v0.1.0 (2017-01-13)
13
+ -------------------
14
+ - Initial Release
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ newrelic-management (0.1.0)
5
+ chronic_duration (~> 0.10)
6
+ deep_merge (~> 1.1.1)
7
+ faraday (~> 0.9)
8
+ faraday_middleware (~> 0.9)
9
+ mixlib-cli (~> 1.7)
10
+ net-http-persistent (~> 2.9.4)
11
+ os
12
+ rufus-scheduler (~> 3.3.2)
13
+ terminal-notifier
14
+
15
+ GEM
16
+ remote: http://rubygems.org/
17
+ specs:
18
+ ast (2.3.0)
19
+ chronic_duration (0.10.6)
20
+ numerizer (~> 0.1.1)
21
+ coderay (1.1.1)
22
+ deep_merge (1.1.1)
23
+ diff-lcs (1.2.5)
24
+ faraday (0.11.0)
25
+ multipart-post (>= 1.2, < 3)
26
+ faraday_middleware (0.11.0)
27
+ faraday (>= 0.7.4, < 1.0)
28
+ method_source (0.8.2)
29
+ mixlib-cli (1.7.0)
30
+ multipart-post (2.0.0)
31
+ net-http-persistent (2.9.4)
32
+ numerizer (0.1.1)
33
+ os (0.9.6)
34
+ parser (2.3.3.1)
35
+ ast (~> 2.2)
36
+ powerpack (0.1.1)
37
+ pry (0.10.4)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.8.1)
40
+ slop (~> 3.4)
41
+ rainbow (2.2.1)
42
+ rake (10.5.0)
43
+ rspec (3.5.0)
44
+ rspec-core (~> 3.5.0)
45
+ rspec-expectations (~> 3.5.0)
46
+ rspec-mocks (~> 3.5.0)
47
+ rspec-core (3.5.4)
48
+ rspec-support (~> 3.5.0)
49
+ rspec-expectations (3.5.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.5.0)
52
+ rspec-mocks (3.5.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.5.0)
55
+ rspec-support (3.5.0)
56
+ rubocop (0.46.0)
57
+ parser (>= 2.3.1.1, < 3.0)
58
+ powerpack (~> 0.1)
59
+ rainbow (>= 1.99.1, < 3.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (~> 1.0, >= 1.0.1)
62
+ ruby-progressbar (1.8.1)
63
+ rufus-scheduler (3.3.2)
64
+ tzinfo
65
+ slop (3.6.0)
66
+ terminal-notifier (1.7.1)
67
+ thread_safe (0.3.5)
68
+ tzinfo (1.2.2)
69
+ thread_safe (~> 0.1)
70
+ unicode-display_width (1.1.2)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler (~> 1.12)
77
+ newrelic-management!
78
+ pry
79
+ rake (~> 10.0)
80
+ rspec (~> 3.0)
81
+ rubocop
82
+
83
+ BUNDLED WITH
84
+ 1.13.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Brian Dwyer - Intelligent Digital Services
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # newrelic-management
2
+ ## NewRelic Management Utility
3
+ * Provides functionality not inherently available through the NewRelic UI
4
+
5
+ [![Gem Version](http://img.shields.io/gem/v/newrelic-management.svg)][gem]
6
+ [![Build Status](http://img.shields.io/travis/bdwyertech/newrelic-management.svg)][travis]
7
+ [![Gitter](https://img.shields.io/badge/Gitter-bdwyertech%2Fnewrelic--management-brightgreen.svg)][gitter]
8
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)][license]
9
+
10
+ [gem]: https://rubygems.org/gems/newrelic-management
11
+ [travis]: http://travis-ci.org/bdwyertech/newrelic-management
12
+ [gitter]: https://gitter.im/bdwyertech/newrelic-management
13
+ [license]: https://raw.githubusercontent.com/bdwyertech/newrelic-management/master/LICENSE.txt
14
+
15
+ ## Background
16
+ The goal here is to allow servers to be added to alert conditions based on tag. For some reason, NewRelic does not allow much dynamicism in this regard.
17
+
18
+ Additionally, non-reporting, stale servers can build up in the NewRelic console. Let's create a programmatic solution to remove servers that haven't reported recently or in X-amount of time.
19
+
20
+ ## Features
21
+ * **Adding & Excluding Servers from Alerts, based on:**
22
+ * Tag
23
+ * Server Name
24
+ * Server ID
25
+
26
+ * **Automatic Removal of Stale, Non-Reporting Servers**
27
+
28
+ * **Running either of the above functions in a daemonized, periodic fashion, e.g. every 10 minutes.**
29
+
30
+ ## Sample Configuration File
31
+ ```json
32
+ {
33
+ "nr_api_key": "abc123def456",
34
+ "cleanup": true,
35
+ "cleanup_interval": "5m",
36
+ "alert_management_interval": "5m",
37
+ "alerts": [
38
+ {
39
+ "name": "Disk Space",
40
+ "match_any": true,
41
+ "labels": [
42
+ "Environment:Production",
43
+ "Environment:Staging"
44
+ ]
45
+ },
46
+ {
47
+ "name": "RAM Utilization",
48
+ "match_any": true,
49
+ "labels": [
50
+ "Environment:Production",
51
+ "Environment:Staging"
52
+ ],
53
+ "exclude": [
54
+ "Role:Consumers",
55
+ "Role:ETL"
56
+ ]
57
+ },
58
+ {
59
+ "name": "Production - DB",
60
+ "labels": [
61
+ "Environment:Production",
62
+ "Role:Database"
63
+ ]
64
+ }
65
+ ]
66
+ }
67
+ ```
68
+
69
+ ## Security
70
+ If daemonizing, you should lock down permissions on all configuration files in this project to only the user which this runs as...
71
+
72
+ ## Installation
73
+
74
+ Add this line to your application's Gemfile:
75
+
76
+ ```ruby
77
+ gem 'newrelic-management'
78
+ ```
79
+
80
+ And then execute:
81
+
82
+ $ bundle
83
+
84
+ Or install it yourself as:
85
+
86
+ $ gem install newrelic-management
87
+
88
+ ## Usage
89
+
90
+ $ newrelic-management -c /path/to/config.json
91
+
92
+ ## Development
93
+
94
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
95
+
96
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
97
+
98
+ ## Contributing
99
+
100
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bdwyertech/newrelic-management. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
101
+
102
+
103
+ ## License
104
+
105
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # rubocop: disable LineLength
3
+
4
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ require 'bundler/setup'
8
+ require 'newrelic-management'
9
+
10
+ # => Use the Pry Console
11
+ require 'pry'
12
+
13
+ # => Custom Pry Commands
14
+ command_set = Pry::CommandSet.new do
15
+ command('reload', 'Reloads the Gem') do
16
+ reload_gem
17
+ output.puts 'Gem Reloaded'
18
+ end
19
+
20
+ helpers do
21
+ def reload_gem
22
+ files = $LOADED_FEATURES.select { |feat| feat =~ %r{\/newrelic-management\/} }
23
+ files.each { |file| load file }
24
+ end
25
+ end
26
+ end
27
+
28
+ Pry::Commands.import command_set
29
+ Pry.config.prompt_name = 'newrelic-management'
30
+
31
+ ARGV.clear
32
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # NewRelic - Management
4
+ # Brian Dwyer - Intelligent Digital Services - 12/28/16
5
+
6
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+
9
+ # => Catch Ctrl+C's to avoid stack traces
10
+ Signal.trap('INT') { abort }
11
+
12
+ require 'newrelic-management'
13
+
14
+ # => Launch the Plugin
15
+ NewRelicManagement::CLI.run(ARGV)
@@ -0,0 +1,10 @@
1
+ # encoding: UTF-8
2
+ # NewRelic - Management
3
+ # Brian Dwyer - Intelligent Digital Services - 12/28/16
4
+
5
+ require 'newrelic-management/cli'
6
+
7
+ # => NewRelic Manager
8
+ module NewRelicManagement
9
+ # => Placeholder
10
+ end
@@ -0,0 +1,91 @@
1
+ # Encoding: UTF-8
2
+ # rubocop: disable LineLength
3
+ #
4
+ # Gem Name:: newrelic-management
5
+ # NewRelicManagement:: CLI
6
+ #
7
+ # Copyright (C) 2017 Brian Dwyer - Intelligent Digital Services
8
+ #
9
+ # All rights reserved - Do Not Redistribute
10
+ #
11
+
12
+ require 'mixlib/cli'
13
+ require 'newrelic-management/config'
14
+ require 'newrelic-management/controller'
15
+ require 'newrelic-management/util'
16
+
17
+ module NewRelicManagement
18
+ #
19
+ # => NewRelic Launcher
20
+ #
21
+ module CLI
22
+ module_function
23
+
24
+ #
25
+ # => Options Parser
26
+ #
27
+ class Options
28
+ # => Mix-In the CLI Option Parser
29
+ include Mixlib::CLI
30
+
31
+ option :config_file,
32
+ short: '-c CONFIG',
33
+ long: '--cfg-file CONFIG',
34
+ description: "Configuration File (Default: #{Config.config_file})"
35
+
36
+ option :cleanup,
37
+ short: '-o',
38
+ long: '--cleanup',
39
+ description: 'Cleanup Non-Reporting Servers',
40
+ boolean: true
41
+
42
+ option :cleanup_age,
43
+ short: '-a AGE',
44
+ long: '--cleanup-age AGE',
45
+ description: 'Cleanup Non-Reporting Servers older than an interval of time'
46
+
47
+ option :daemonize,
48
+ short: '-d',
49
+ long: '--daemonize',
50
+ description: 'Flag for running in Daemonized mode',
51
+ boolean: true
52
+
53
+ option :silent,
54
+ short: '-s',
55
+ long: '--silent',
56
+ description: 'Suppress all notification messages',
57
+ boolean: true
58
+
59
+ option :environment,
60
+ short: '-e ENV',
61
+ long: '--env ENV',
62
+ description: 'Sets the environment for newrelic-management to execute under. Use "development" for more logging.',
63
+ proc: proc { |env| env.to_sym }
64
+ end
65
+
66
+ # => Configure the CLI
67
+ def configure(argv = ARGV)
68
+ # => Parse CLI Configuration
69
+ cli = Options.new
70
+ cli.parse_options(argv)
71
+
72
+ # => Parse JSON Config File (If Specified and Exists)
73
+ json_config = Util.parse_json(cli.config[:config_file] || Config.config_file)
74
+
75
+ # => Merge Configuration (CLI Wins)
76
+ config = [json_config, cli.config].compact.reduce(:merge)
77
+
78
+ # => Apply Configuration
79
+ config.each { |k, v| Config.send("#{k}=", v) }
80
+ end
81
+
82
+ # => Launch the Application
83
+ def run(argv = ARGV)
84
+ # => Parse the Params
85
+ configure(argv)
86
+
87
+ # => Launch the Controller
88
+ Controller.run
89
+ end
90
+ end
91
+ end