redis_alerting 1.3.2 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9002db58d2b36ba06bb23317c3bf5da1fe8a7699
4
- data.tar.gz: 43fecfbb4fa2a032d0aa384b085504fa0c5c19a9
3
+ metadata.gz: 1a362dc26fffaa5486de92d039dc8faedd7053c6
4
+ data.tar.gz: 1a81505cad316a2c186836bcecc1858d4d8c18ea
5
5
  SHA512:
6
- metadata.gz: 0693caadb5119b3cb42855c85d82a95155645455d3568f0641d80ee33c16bbe50e13f17522adf6cf9d5a03acfc839417d68724c4b9138d17c1b8369aeffe59f0
7
- data.tar.gz: 95509af5f6264bb945082dc2dae47495b487d2159cf07bf6aa1c65473e0c6ad300b170319d17b5c48498987e7aefb725a34551f2ae91e8e01efbae91d26b1d28
6
+ metadata.gz: 165adae5b617fc8d6521590bd3d73067755eeb61eac0b314cd6e192937bb608ba25704ef0ee981f5e64b5f68c4dbd5c34cac5d3e44eece4969caa7e24049618b
7
+ data.tar.gz: 3de8b783b0ed529bd749ba3e111e26d2a13d11620738f426010deefe19a89246e71b101a6005adfbb96b509aca940187d4a799fdb232d790f7ec282d271251d1
data/README.md CHANGED
@@ -57,6 +57,7 @@ Given the config file below we will describe how the gem would check some limits
57
57
  :namespace: alerts # the namespace to use for tracking active alerts/conditions
58
58
  :separator: . # redis namespace separator
59
59
  :channel: alerts # publish alert messages to this channel
60
+ :faye_url: http://localhost/faye # the URL of the Faye endpoint to publish to
60
61
  :extrema: # details for where to find extrema information
61
62
  :min: min # what you call your minimum
62
63
  :max: max # what you call your maximum
@@ -133,6 +134,21 @@ When an alert is no longer active, this message will be published:
133
134
  }
134
135
  ```
135
136
 
137
+ #### Publishing to Faye
138
+
139
+ There is also support for publishing to a [Faye](http://faye.jcoglan.com/) URL. Simply put the Faye URL in your config file like so:
140
+
141
+ ```yaml
142
+ :faye_url: http://localhost/faye
143
+ :channel: alerts
144
+ ```
145
+
146
+ Or set it at command line:
147
+
148
+ $ redis-alerting run -- -c config.yml --faye-url http://localhost/faye
149
+
150
+ This will disable publishing to redis. The channel will automatically be set to `/alerts` if you leave out the leading slash.
151
+
136
152
  ### Simple example
137
153
 
138
154
  With the engine started try this (still sticking with the keys in the config file above):
data/bin/redis-alerting CHANGED
@@ -30,6 +30,7 @@ Daemons.run_proc("redis_alerting", daemon_opts ) do
30
30
  on :c, :config=, 'Configuration File'
31
31
  on :p, :pwd=, "Working directory"
32
32
  on :l, :log=, "Log at the specified level to stdout"
33
+ on :"faye-url=", "The Faye URL to publish to"
33
34
  end
34
35
 
35
36
  begin
data/etc/config.yml CHANGED
@@ -3,6 +3,7 @@
3
3
  :namespace: alerts
4
4
  :separator: .
5
5
  :channel: alerts
6
+ :faye_url: http://localhost/faye
6
7
  :extrema:
7
8
  :min: min
8
9
  :max: max
@@ -19,6 +19,8 @@ module RedisAlerting
19
19
  @config[:config] = File.expand_path(@config[:config], @config[:pwd])
20
20
  end
21
21
 
22
+ @config[:faye_url] = @config[:"faye-url"] || @config[:faye_url]
23
+
22
24
  raise ArgumentError, "Invalid config file: #{@config[:config]}" unless File.exists? @config[:config]
23
25
 
24
26
  yaml = YAML.load_file(@config[:config])
@@ -1,7 +1,8 @@
1
1
  module RedisAlerting
2
2
  class Engine
3
- def initialize(config, redis, log)
3
+ def initialize(config, redis, log, publisher)
4
4
  @config = config
5
+ @publisher = publisher
5
6
  @active_set = "#{@config[:namespace]}#{@config[:separator]}active"
6
7
  @redis = redis
7
8
  @log = log
@@ -95,7 +96,7 @@ module RedisAlerting
95
96
  end
96
97
 
97
98
  def publish(message)
98
- @redis.publish @config[:channel], message.to_json
99
+ @publisher.publish @config[:channel], message
99
100
  @log.info "Pushed message: #{message.inspect}"
100
101
  end
101
102
 
@@ -0,0 +1,19 @@
1
+ require 'faye'
2
+ require 'faye/redis'
3
+ require 'eventmachine'
4
+
5
+ module RedisAlerting
6
+ class FayePublisher
7
+
8
+ def initialize(url)
9
+ Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
10
+ @client = Faye::Client.new(url)
11
+ end
12
+
13
+ def publish(channel, message)
14
+ channel = "/#{channel}" unless channel.start_with?("/")
15
+ @client.publish(channel, message)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module RedisAlerting
3
+ class RedisPublisher
4
+
5
+ def initialize(redis)
6
+ @client = redis
7
+ end
8
+
9
+ def publish(channel, message)
10
+ @client.publish(channel, message.to_json)
11
+ end
12
+
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module RedisAlerting
2
- VERSION = "1.3.2"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "redis_alerting/version"
2
2
  require "redis_alerting/engine"
3
3
  require "redis_alerting/config"
4
+ require "redis_alerting/faye_publisher"
4
5
  require 'redis'
5
6
  require 'logger'
6
7
  require 'yaml'
@@ -9,14 +10,23 @@ require 'json'
9
10
  module RedisAlerting
10
11
  class << self
11
12
  def run(opts)
12
- config = RedisAlerting::Config.new(opts).to_hash
13
+ @config = RedisAlerting::Config.new(opts).to_hash
13
14
  log = Logger.new STDOUT
14
- log.level = config[:log_level]
15
- engine = RedisAlerting::Engine.new(config, ::Redis.new, log)
15
+ log.level = @config[:log_level]
16
+ @redis = ::Redis.new
17
+ engine = RedisAlerting::Engine.new(@config, @redis, log, publisher)
16
18
 
17
19
  loop do
18
20
  engine.run
19
- sleep config[:interval]
21
+ sleep @config[:interval]
22
+ end
23
+ end
24
+
25
+ def publisher
26
+ if @config[:faye_url]
27
+ return RedisAlerting::FayePublisher.new(@config[:faye_url])
28
+ else
29
+ return RedisAlerting::RedisPublisher.new(@redis)
20
30
  end
21
31
  end
22
32
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "redis"
22
- spec.add_dependency "slop"
22
+ spec.add_dependency "slop", '~> 3.6.0'
23
23
  spec.add_dependency "daemons"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.7"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_alerting
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert McLeod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-09 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: slop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 3.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 3.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: daemons
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +127,8 @@ files:
127
127
  - lib/redis_alerting.rb
128
128
  - lib/redis_alerting/config.rb
129
129
  - lib/redis_alerting/engine.rb
130
+ - lib/redis_alerting/faye_publisher.rb
131
+ - lib/redis_alerting/redis_publisher.rb
130
132
  - lib/redis_alerting/version.rb
131
133
  - redis_alerting.gemspec
132
134
  - spec/lib/redis_alerting/engine_spec.rb