moni 0.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.
- data/bin/moni_watcher +18 -0
- data/lib/moni.rb +9 -0
- data/lib/moni/moni_group.rb +43 -0
- data/lib/moni/moni_remote.rb +10 -0
- data/lib/moni/moni_watch.rb +49 -0
- metadata +80 -0
data/bin/moni_watcher
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'moni'
|
3
|
+
|
4
|
+
url = ARGV[0]
|
5
|
+
frequency = ARGV[1].to_i
|
6
|
+
Moni.set_twilio_credentials(ENV['twilio_sid'], ENV['twilio_token'])
|
7
|
+
|
8
|
+
loop do
|
9
|
+
begin
|
10
|
+
mg = Moni::MoniGroup.from_url(url)
|
11
|
+
mg.send_notices!
|
12
|
+
rescue Exception
|
13
|
+
puts $!
|
14
|
+
puts $!.message
|
15
|
+
end
|
16
|
+
|
17
|
+
sleep frequency
|
18
|
+
end
|
data/lib/moni.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
module Moni
|
3
|
+
class MoniGroup
|
4
|
+
def self.from_serialized(serialized)
|
5
|
+
hash = JSON.parse(serialized)
|
6
|
+
new(hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.from_url(url)
|
10
|
+
from_serialized(open(url).read)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(hash)
|
14
|
+
@group_name = hash.delete("group_name")
|
15
|
+
@contacts = hash.delete("contacts")
|
16
|
+
@watches = []
|
17
|
+
|
18
|
+
hash["watches"].to_a.each do |w|
|
19
|
+
@watches << MoniWatch.new(w)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_watch(hash)
|
24
|
+
@watches << MoniWatch.new(hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_and_serialize
|
28
|
+
{
|
29
|
+
:group_name => @group_name,
|
30
|
+
:contacts => @contacts,
|
31
|
+
:watches => @watches.collect(&:check_and_serialize)
|
32
|
+
}.to_json
|
33
|
+
end
|
34
|
+
|
35
|
+
def send_notices!
|
36
|
+
@watches.select(&:failed?).each do |w|
|
37
|
+
@contacts.each do |contact_number|
|
38
|
+
Twilio::Sms.message("5126075807", contact_number, "#{w.name} failed")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'pp'
|
2
|
+
module Moni
|
3
|
+
class MoniWatch
|
4
|
+
def self.from_serialized(serialized)
|
5
|
+
p "serialized"
|
6
|
+
pp serialized
|
7
|
+
hash = JSON.parse(serialized)
|
8
|
+
p "hash"
|
9
|
+
pp hash
|
10
|
+
new(hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :name, :description
|
14
|
+
def initialize(hash)
|
15
|
+
@name = hash.delete("name")
|
16
|
+
@description = hash.delete("description")
|
17
|
+
@proc = hash.delete("proc")
|
18
|
+
if hash.has_key?("passed")
|
19
|
+
@check_run = true
|
20
|
+
@passed = hash.delete("passed")
|
21
|
+
else
|
22
|
+
@check_run = false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def check_and_serialize
|
27
|
+
{
|
28
|
+
:name => @name,
|
29
|
+
:description => @description,
|
30
|
+
:passed => passed?
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def passed?
|
35
|
+
if !@check_run
|
36
|
+
@passed = @proc.call
|
37
|
+
end
|
38
|
+
@passed
|
39
|
+
end
|
40
|
+
|
41
|
+
def failed?
|
42
|
+
!passed?
|
43
|
+
end
|
44
|
+
|
45
|
+
def checkable?
|
46
|
+
!!@proc
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: moni
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bob Potter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-22 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: twilio
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: json
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
description: Moni.
|
38
|
+
email:
|
39
|
+
- bobby.potter@gmail.com
|
40
|
+
executables:
|
41
|
+
- moni_watcher
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- bin/moni_watcher
|
48
|
+
- lib/moni/moni_watch.rb
|
49
|
+
- lib/moni/moni_group.rb
|
50
|
+
- lib/moni/moni_remote.rb
|
51
|
+
- lib/moni.rb
|
52
|
+
homepage:
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Moni allows you to monitor a system and send SMS notifications when something is broken
|
79
|
+
test_files: []
|
80
|
+
|