henpecked 0.0.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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *~
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "active_support", '~> 3.0'
4
+
5
+ # Specify your gem's dependencies in henpecked.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 0.9"
9
+ gem "rspec", "~> 2.8.0"
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Heckpacked
2
+ Is a lightweight library for Icinga passive checks. It helps you raise alerts in very easy way in your application :)
3
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new('spec')
7
+
8
+ task :default => :spec
data/henpecked.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "henpecked/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "henpecked"
7
+ s.version = Henpecked::VERSION
8
+ s.authors = ["JakubOboza"]
9
+ s.email = ["jakub.oboza@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Icinga passive checks api library}
12
+ s.description = %q{This gem provides simple api to work with Icinga passive checks}
13
+
14
+ s.rubyforge_project = "henpecked"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,49 @@
1
+ module Henpecked
2
+ module Alert
3
+
4
+
5
+ # definition of alert template
6
+ class AbstractAlert
7
+
8
+ def initialize
9
+ raise "Should be implemented in concrete class! Don't use abstract class"
10
+ end
11
+
12
+ def time
13
+ "[#{Time.now.to_i}]"
14
+ end
15
+
16
+ def command
17
+ "#{ActiveSupport::Inflector.underscore(self.class.to_s.split(/:/).last).upcase};"
18
+ end
19
+
20
+ def arguments
21
+ raise "Should be implemented in concrete class! Don't use abstract class"
22
+ end
23
+
24
+ def icinga_description
25
+ [self.time, self.command, self.arguments].join(" ")
26
+ end
27
+
28
+ end
29
+
30
+ class AcknowledgeHostProblem < AbstractAlert
31
+
32
+ def initialize(host_name = nil, sticky = nil, notify = nil, persistent = nil, author = nil, comment = nil)
33
+ @host_name = host_name
34
+ @sticky = sticky
35
+ @notify = notify
36
+ @persistent = persistent
37
+ @author = author
38
+ @comment = comment
39
+ end
40
+
41
+ def arguments
42
+ [@host_name, @sticky, @notify, @persistent, @author, @comment].join(";")
43
+ end
44
+
45
+ end # end of AcknowledgeHostProblem class
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,19 @@
1
+ module Henpecked
2
+
3
+ @@config = {}
4
+
5
+ def self.config(&block)
6
+ self.instance_eval &block
7
+ end
8
+
9
+ def self.cmd_file(file_path)
10
+ raise Exception.new "Icinga Command file don't exists in this location, check the path" unless File.exists?(file_path)
11
+ @@config[:file_path] = file_path
12
+ end
13
+
14
+ def self.file_path
15
+ return @@config[:file_path] if @@config[:file_path]
16
+ raise Exception.new "Icinga Command file not specified"
17
+ end
18
+
19
+ end
@@ -0,0 +1,10 @@
1
+ module Henpecked
2
+
3
+ def self.push(alert)
4
+ raise Exception.new "Alert object has to have icinga_description method" unless alert.respond_to?(:icinga_description)
5
+ File.open(Henpecked.file_path, "w") do |file|
6
+ file.write(alert.icinga_description + "\n")
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,3 @@
1
+ module Henpecked
2
+ VERSION = "0.0.1"
3
+ end
data/lib/henpecked.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'active_support'
2
+ require "henpecked/version"
3
+ require "henpecked/configuration"
4
+ require "henpecked/base"
5
+ require "henpecked/push"
6
+
7
+ module Henpecked
8
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ class CustomAlert < Henpecked::Alert::AbstractAlert
4
+
5
+ def initialize
6
+ end
7
+
8
+ def arguments
9
+ ""
10
+ end
11
+
12
+ end
13
+
14
+ module Test1
15
+ module Test2
16
+ module Test3
17
+ class TastyCookie < CustomAlert
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+
24
+ describe Henpecked do
25
+
26
+ describe "alerts" do
27
+
28
+ it "should have abstract alert class" do
29
+ lambda do
30
+ Henpecked::Alert::AbstractAlert.new
31
+ end.should raise_error
32
+ end
33
+
34
+ it "should be able to instantiate concrete alert class" do
35
+ lambda do
36
+ CustomAlert.new
37
+ end.should_not raise_error
38
+ end
39
+
40
+ it "should have icinga_description" do
41
+ lambda do
42
+ desc = CustomAlert.new.icinga_description
43
+ desc.should_not be_nil
44
+ desc.should be_kind_of(String)
45
+ desc.should =~ /\[\d+\]\s.+;.+/
46
+ end.should_not raise_error
47
+ end
48
+
49
+ end
50
+
51
+ it "should work ok for nested classes" do
52
+ test = Test1::Test2::Test3::TastyCookie.new
53
+ test.command.should eql("TASTY_COOKIE;")
54
+ end
55
+
56
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Henpecked do
4
+
5
+
6
+ it "should be able to set command file path" do
7
+ lambda do
8
+ Henpecked.config do
9
+ cmd_file "spec/spec_helper.rb"
10
+ end
11
+ end.should_not raise_error
12
+ end
13
+
14
+ it "should blow up if command file is not set" do
15
+ lambda do
16
+ Henpecked.config do
17
+ cmd_file "/does/not/exists"
18
+ end
19
+ end.should raise_error
20
+ end
21
+
22
+ it "should return cmd file path" do
23
+ Henpecked.config do
24
+ cmd_file "spec/spec_helper.rb"
25
+ end
26
+ Henpecked.file_path.should eql("spec/spec_helper.rb")
27
+ end
28
+
29
+ end
data/spec/push_spec.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Henpecked do
4
+
5
+ describe "#push" do
6
+
7
+ it "should be able to push alert" do
8
+ test_path = "/tmp/henpeck.test"
9
+ File.open(test_path, "w")
10
+ lambda do
11
+ Henpecked.config do
12
+ cmd_file test_path
13
+ end
14
+ Henpecked.push(Henpecked::Alert::AcknowledgeHostProblem.new)
15
+
16
+ end.should_not raise_error
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ # our gem
4
+ require 'henpecked'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: henpecked
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - JakubOboza
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-17 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: This gem provides simple api to work with Icinga passive checks
15
+ email:
16
+ - jakub.oboza@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - Gemfile
24
+ - README.md
25
+ - Rakefile
26
+ - henpecked.gemspec
27
+ - lib/henpecked.rb
28
+ - lib/henpecked/base.rb
29
+ - lib/henpecked/configuration.rb
30
+ - lib/henpecked/push.rb
31
+ - lib/henpecked/version.rb
32
+ - spec/alerts_spec.rb
33
+ - spec/configuration_spec.rb
34
+ - spec/push_spec.rb
35
+ - spec/spec_helper.rb
36
+ homepage: ''
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project: henpecked
56
+ rubygems_version: 1.8.15
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Icinga passive checks api library
60
+ test_files:
61
+ - spec/alerts_spec.rb
62
+ - spec/configuration_spec.rb
63
+ - spec/push_spec.rb
64
+ - spec/spec_helper.rb