nodata-monitor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Temporary Files
2
+ *~
3
+
4
+ # Build files
5
+ *.gem
6
+
7
+ # IDE Files
8
+ .idea
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use 1.9.3@nodata-monitor
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nodata-monitor (0.0.1)
5
+ dogapi (~> 1.6.0)
6
+ gli (~> 2.5.4)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ dogapi (1.6.0)
12
+ json (>= 1.5.1)
13
+ gli (2.5.4)
14
+ json (1.7.7)
15
+ rake (10.0.3)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ nodata-monitor!
22
+ rake (~> 10.0.3)
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2013 Mavenlink, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nodata-monitor'
3
+ require 'gli'
4
+ require 'yaml'
5
+ require 'pp'
6
+
7
+ include GLI::App
8
+
9
+ program_desc 'A simple monitor for datadog which checks for alerts in the no-data state and outputs an event in that case.'
10
+
11
+ # Global Arguments
12
+
13
+ desc 'Specify the credentials configuration file'
14
+ arg_name 'credentials'
15
+ default_value File.join(ENV['HOME'],'.nodata-monitor.yml')
16
+ flag [:c, :credentials]
17
+
18
+ desc 'Be verbose'
19
+ switch :verbose
20
+
21
+ desc 'Check for no data state alerts, write event if present'
22
+ command :monitor do |monitor|
23
+ monitor.flag :notify, :arg_name => '[@user1 ...]', :desc => 'User list to notify on datadog', :type => String
24
+ monitor.action do |global_options, options, args|
25
+ alerts = NodataMonitor::Alerts.retrieve_all($credential)
26
+ alerts_requiring_action =
27
+ NodataMonitor::Filters::StateFilter.select(
28
+ NodataMonitor::Filters::IgnoreFilter.select(
29
+ alerts
30
+ ),
31
+ 'No Data'
32
+ )
33
+ notifier = NodataMonitor::Notifier.new($credential, options[:notify], alerts_requiring_action)
34
+ notifier.notify!
35
+ end
36
+ end
37
+
38
+ # load credentials YAML file
39
+ pre do |global_options, command, options, args|
40
+ raw_credentials = YAML.load(File.read(global_options[:credentials]))
41
+ $credential = NodataMonitor::Credential.new(raw_credentials['api_key'], raw_credentials['app_key'])
42
+ true
43
+ end
44
+
45
+ exit run(ARGV)
@@ -0,0 +1,67 @@
1
+ require 'dogapi'
2
+
3
+ module NodataMonitor
4
+ class Credential
5
+ def initialize api_key, app_key
6
+ @api_key = api_key
7
+ @app_key = app_key
8
+ end
9
+
10
+ def client
11
+ @client ||= Dogapi::Client.new(@api_key, @app_key)
12
+ end
13
+ end
14
+
15
+ class Alert
16
+ attr_accessor :name
17
+ attr_accessor :message
18
+ attr_accessor :state
19
+ attr_accessor :query
20
+
21
+ def initialize options
22
+ @name = options['name']
23
+ @message = options['message']
24
+ @state = options['state']
25
+ @query = options['query']
26
+ end
27
+ end
28
+
29
+ class Alerts
30
+ def self.retrieve_all credential
31
+ credential.client.get_all_alerts[1]['alerts'].map do |alert|
32
+ Alert.new(alert)
33
+ end
34
+ end
35
+ end
36
+
37
+ class Notifier
38
+ def initialize credential, endpoints_to_notify, alerts
39
+ @credential = credential
40
+ @endpoints_to_notify = endpoints_to_notify
41
+ @alerts = alerts
42
+ end
43
+
44
+ def notify!
45
+ @alerts.each do |alert|
46
+ @credential.client.emit_event(Dogapi::Event.new('A no-data state was detected for the alert: ' + alert.name + ' ' + @endpoints_to_notify))
47
+ end
48
+ end
49
+ end
50
+
51
+ module Filters
52
+ class StateFilter
53
+ def self.select set, state
54
+ set.select do |set_member|
55
+ set_member.state == state
56
+ end
57
+ end
58
+ end
59
+ class IgnoreFilter
60
+ def self.select set
61
+ set.select do |set_member|
62
+ !set_member.message.include?('%nodata-monitor_ignore%')
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'nodata-monitor'
3
+ gem.version = '0.0.1'
4
+
5
+ gem.authors = ["Justin 'J' Lynn", "Sponsored by Mavenlink, Inc."]
6
+ gem.email = ["j@jaesharp.com"]
7
+
8
+ gem.summary = "A Datadog monitor which checks for alerts in the 'no data' state, writing an event if they are found."
9
+ gem.description = gem.summary
10
+
11
+ gem.homepage = "http://github.com/mavenlink/nodata-monitor"
12
+
13
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename f }
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split "\n"
15
+ gem.files = `git ls-files`.split "\n"
16
+
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.required_ruby_version = '>= 1.9.3'
20
+ gem.required_rubygems_version = Gem::Requirement.new '>= 1.8.24'
21
+
22
+ gem.add_dependency "dogapi", "~> 1.6.0"
23
+ gem.add_dependency "gli", "~> 2.5.4"
24
+
25
+ # Testing
26
+ gem.add_development_dependency 'rake', '~> 10.0.3'
27
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nodata-monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin 'J' Lynn
9
+ - Sponsored by Mavenlink, Inc.
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-03-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dogapi
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.6.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: gli
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 2.5.4
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.5.4
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 10.0.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 10.0.3
63
+ description: A Datadog monitor which checks for alerts in the 'no data' state, writing
64
+ an event if they are found.
65
+ email:
66
+ - j@jaesharp.com
67
+ executables:
68
+ - nodata-monitor
69
+ extensions: []
70
+ extra_rdoc_files: []
71
+ files:
72
+ - .gitignore
73
+ - .rvmrc
74
+ - Gemfile
75
+ - Gemfile.lock
76
+ - LICENSE
77
+ - bin/nodata-monitor
78
+ - lib/nodata-monitor.rb
79
+ - nodata-monitor.gemspec
80
+ homepage: http://github.com/mavenlink/nodata-monitor
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.9.3
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: 1.8.24
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.25
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: A Datadog monitor which checks for alerts in the 'no data' state, writing
104
+ an event if they are found.
105
+ test_files: []