alertdesigner 0.0.2

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzMzYTRjZWUxMmFlMWFkMzc0NDBjY2NlYWI2NDU2M2EzNDIxYWRjYQ==
5
+ data.tar.gz: !binary |-
6
+ Yzk1ODUwYmI3YjFlOTYxYTFmMTIxODE4MTllMzI0MTk2M2U0ZWQ2Yg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NGJiYjYwNDYxZmVkZDNlYzYzNWJhMTRmMjQ4YzFhYjczODJiMmY0YzcwMGUx
10
+ NjBjODg0OTUwM2VhNTNhOTJmNjY2Mzg2NzcxM2QzMmRiODM3NTg0M2Y5NjBj
11
+ OGM1M2QxMzdlNGM5Zjg2N2ZiMjEyZTAyMDkxMzY0ZDAzMmQ0NjQ=
12
+ data.tar.gz: !binary |-
13
+ ZDg5ZmUyMDViMmE5MjE0MDA2YmM0NTAyOGJhY2RiYTA0MTVlMDRkNmJhOTVi
14
+ YTIwNjQ5ZGU2Zjg1ZWYyOTMxNDc3M2JjNzIzYzk3ZmY2N2RkNjI3MGNmMzI4
15
+ N2ZiMzQ4ZWNhNTg3ZDVhY2NkYWJhYzQ4ZjFmYjMwNDg2NjZkOTE=
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ vendor
2
+ .bundle
3
+ coverage
data/.rubocop.yml ADDED
@@ -0,0 +1,131 @@
1
+ # Ruby linting configuration.
2
+ # We only worry about two kinds of issues: 'error' and anything less than that.
3
+ # Error is not about severity, but about taste. Simple style choices that
4
+ # never have a great excuse to be broken, such as 1.9 JSON-like hash syntax,
5
+ # are errors. Choices that tend to have good exceptions in practice, such as
6
+ # line length, are warnings.
7
+
8
+ # If you'd like to make changes, a full list of available issues is at
9
+ # https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
10
+ # A list of configurable issues is at:
11
+ # https://github.com/bbatsov/rubocop/blob/master/config/default.yml
12
+ #
13
+ # If you disable a check, document why.
14
+
15
+
16
+ StringLiterals:
17
+ EnforcedStyle: double_quotes
18
+ Severity: error
19
+
20
+ HashSyntax:
21
+ EnforcedStyle: ruby19
22
+ Severity: error
23
+ Exclude:
24
+ - !ruby/regexp /db\/schema.rb/
25
+
26
+ AlignHash:
27
+ SupportedLastArgumentHashStyles: always_ignore
28
+
29
+ AlignParameters:
30
+ Enabled: false # This is usually true, but we often want to roll back to
31
+ # the start of a line.
32
+
33
+ Attr:
34
+ Enabled: false # We have no styleguide guidance here, and it seems to be
35
+ # in frequent use.
36
+
37
+ ClassAndModuleChildren:
38
+ Enabled: false # module X<\n>module Y is just as good as module X::Y.
39
+
40
+ Documentation:
41
+ Exclude:
42
+ - !ruby/regexp /spec\/*\/*/
43
+
44
+ ClassLength:
45
+ Max: 125
46
+ Exclude:
47
+ - !ruby/regexp /spec\/*\/*/
48
+
49
+ PercentLiteralDelimiters:
50
+ PreferredDelimiters:
51
+ '%w': '{}'
52
+
53
+ LineLength:
54
+ Max: 80
55
+ Severity: warning
56
+
57
+ MultilineTernaryOperator:
58
+ Severity: error
59
+
60
+ UnreachableCode:
61
+ Severity: error
62
+
63
+ AndOr:
64
+ Severity: error
65
+
66
+ EndAlignment:
67
+ Severity: error
68
+
69
+ IndentationWidth:
70
+ Severity: error
71
+
72
+ MethodLength:
73
+ CountComments: false # count full line comments?
74
+ Max: 30
75
+ Severity: error
76
+
77
+ Alias:
78
+ Enabled: false # We have no guidance on alias vs alias_method
79
+
80
+ RedundantSelf:
81
+ Enabled: false # Sometimes a self.field is a bit more clear
82
+
83
+ IfUnlessModifier:
84
+ Enabled: false
85
+
86
+ Metrics/AbcSize:
87
+ Max: 16
88
+
89
+ Style/TrivialAccessors:
90
+ # When set to false the cop will suggest the use of accessor methods
91
+ # in situations like:
92
+ #
93
+ # def name
94
+ # @other_name
95
+ # end
96
+ #
97
+ # This way you can uncover "hidden" attributes in your code.
98
+ ExactNameMatch: true
99
+ AllowPredicates: true
100
+ # Allows trivial writers that don't end in an equal sign. e.g.
101
+ #
102
+ # def on_exception(action)
103
+ # @on_exception=action
104
+ # end
105
+ # on_exception :restart
106
+ #
107
+ # Commonly used in DSLs
108
+ AllowDSLWriters: true
109
+
110
+ AllCops:
111
+ # Include gemspec and Rakefile
112
+ Include:
113
+ - '**/*.gemspec'
114
+ - '**/*.rake'
115
+ - '**/Gemfile'
116
+ - '**/Rakefile'
117
+ - '**/Capfile'
118
+ - '**/Guardfile'
119
+ - '**/Podfile'
120
+ - '**/Vagrantfile'
121
+ Exclude:
122
+ - 'db/**/*'
123
+ - 'bin/*'
124
+ - 'script/**/*'
125
+ - 'config/**/*'
126
+ - 'vendor/**/*'
127
+ - 'test/**/*'
128
+ # By default, the rails cops are not run. Override in project or home
129
+ # directory .rubocop.yml files, or by giving the -R/--rails option.
130
+ Rails:
131
+ Enabled: true
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ env:
3
+ global:
4
+ - COVERAGE=true
5
+ rvm:
6
+ - 2.3.0
7
+ script: rake ci
8
+ bundler_args: --with development
9
+ deploy:
10
+ provider: rubygems
11
+ api_key:
12
+ secure: ld+MEQvKynXgjIG3mTufIDHKLmPUUNvVk1sQAL4saHD+h4d6uindQXs9d3842Ng9EKAfbhgdyBJuKTFTbQ+M3C5Zqlv/L+IHH8lkk6LbjPD7DAbXK/o/Ny2tOsVr579eE0t/n8zfGEl+EzVF2u8wAQkOOMtDULbOsqUtobxMscif4gVOJFDO4GQhI6hbCizZDfze4GlVSYIGMorFNe7tNdHwyFf1otKr632iFgLkTmrighKifjwTCVUf72Kge6J/iO8/wrX9RTvrBR1LU37SYVjKvp+NF4FE3YCHJKtd/43LPtQVoDkMk92iihd6cUkseMxdO8VoZZvL545yYnekLcXlVSlrqcdv4aDGclQUaZGVRkgjj4tT48rQnY44Q3Fjy/hhbdSCU6Y6Y6Dh+Vw+gJS10EzOCqVUrwX6b7Z/mPUyBqvFdA9phjVIN32ZdO88sotl+1fu3l4RhB3xb9+WsomjBTXUY31HQZf1siE1TX9w5WlYRYMlebd44ogbkwOCKVKWtobh0ci/k4LtXLz1sPjWzcOyXQcViatp7mJsJAh5ZeIgsfEcqTDPOQ+PmMQ3bF7uOnjgOKx23x3avLr1Np+cSkt9subLkUDJqaTdnMQi/Xm7H+szkvmNn7IGGnpcpjEoNg6JIsQbaYfU8XfIQv7y1uXC/ZjP82mSwlqDL6k=
13
+ gem: alertdesigner
14
+ on:
15
+ tags: true
16
+ repo: mrtazz/AlertDesigner
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Changelog
2
+
3
+ ## v0.1.0 (??-??-????)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,11 @@
1
+ # Contribute
2
+ - Fork the project.
3
+ - Make your feature addition or bug fix.
4
+ - Add tests for it. This is important so I don't break it in a future version
5
+ unintentionally.
6
+ - Commit, do not mess with version
7
+ - If you add functionality, document it in the README
8
+ - Send me a pull request. Bonus points for topic branches.
9
+
10
+ ## How to run tests
11
+ - bundle install && bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ alertdesigner (0.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.2.0)
10
+ coveralls (0.8.13)
11
+ json (~> 1.8)
12
+ simplecov (~> 0.11.0)
13
+ term-ansicolor (~> 1.3)
14
+ thor (~> 0.19.1)
15
+ tins (~> 1.6.0)
16
+ docile (1.1.5)
17
+ json (1.8.3)
18
+ parser (2.3.0.6)
19
+ ast (~> 2.2)
20
+ power_assert (0.2.7)
21
+ powerpack (0.1.1)
22
+ rainbow (2.1.0)
23
+ rake (11.1.1)
24
+ rubocop (0.38.0)
25
+ parser (>= 2.3.0.6, < 3.0)
26
+ powerpack (~> 0.1)
27
+ rainbow (>= 1.99.1, < 3.0)
28
+ ruby-progressbar (~> 1.7)
29
+ unicode-display_width (~> 1.0, >= 1.0.1)
30
+ ruby-progressbar (1.7.5)
31
+ simplecov (0.11.2)
32
+ docile (~> 1.1.0)
33
+ json (~> 1.8)
34
+ simplecov-html (~> 0.10.0)
35
+ simplecov-html (0.10.0)
36
+ term-ansicolor (1.3.2)
37
+ tins (~> 1.0)
38
+ test-unit (3.1.7)
39
+ power_assert
40
+ thor (0.19.1)
41
+ tins (1.6.0)
42
+ unicode-display_width (1.0.2)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ alertdesigner!
49
+ coveralls
50
+ rake (= 11.1.1)
51
+ rubocop (~> 0.38)
52
+ test-unit
53
+
54
+ BUNDLED WITH
55
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2016 Daniel Schauenberg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # AlertDesigner
2
+
3
+ [![Build Status](https://travis-ci.org/mrtazz/AlertDesigner.svg?branch=master)](https://travis-ci.org/mrtazz/AlertDesigner)
4
+ [![Coverage Status](https://coveralls.io/repos/mrtazz/AlertDesigner/badge.svg?branch=master&service=github)](https://coveralls.io/github/mrtazz/AlertDesigner?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/mrtazz/AlertDesigner/badges/gpa.svg)](https://codeclimate.com/github/mrtazz/AlertDesigner)
6
+ [![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)
7
+
8
+ ## Overview
9
+ AlertDesigner is a Ruby DSL to create Nagios checks. It attempts to take some
10
+ of the repetitive work of creating Nagios alerts away. It's supposed to
11
+ complement your existing setup and not necessarily replace it.
12
+
13
+ ## Example
14
+
15
+ ```ruby
16
+ AlertDesigner.define do
17
+
18
+ # let's use the Nagios formatter
19
+ formatter NagiosFormatter do
20
+ check_template "generic-service"
21
+ end
22
+
23
+ # a simple disk space check
24
+ check "/ Partition Disk Space" do
25
+ hostgroups ["freebsd-base"]
26
+ command "check_nrpe!check_root"
27
+ end
28
+
29
+ # define some base checks with repeating properties
30
+ {
31
+ "vulnerable packages" => "check_nrpe!check_portaudit",
32
+ "FreeBSD security updates" => "check_nrpe!check_freebsd_update",
33
+ "FreeBSD kernel version" => "check_nrpe!check_freebsd_kernel",
34
+ "zpool status" => "check_nrpe!check_zpool"
35
+ }.each do |description, check_cmd|
36
+
37
+ check description do
38
+ hostgroups ["freebsd-base"]
39
+ command check_cmd
40
+ end
41
+
42
+ end
43
+
44
+ # set contact groups for specific clusters
45
+ check "Apache Running" do
46
+ hostgroups ["WebServers" => "web-team", "ApiServers" => "api-team"]
47
+ command "check_nrpe!check_httpd"
48
+ end
49
+
50
+ end
51
+
52
+ puts AlertDesigner.format
53
+ ```
54
+
55
+ ## FAQ
56
+ ### Couldn't most of this be done with a clever config hierarchy?
57
+ Probably.
58
+
59
+
60
+ ## Inspiration
61
+ - [Gmail Britta](https://github.com/antifuchs/gmail-britta)
62
+ - [Chef](https://www.chef.io/)
63
+
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+ require "rubocop/rake_task"
5
+ require "coveralls/rake/task"
6
+
7
+ task default: ["test:unit", "test:integration"]
8
+
9
+ namespace :test do
10
+ Rake::TestTask.new(:unit) do |t|
11
+ t.libs << "test"
12
+ t.test_files = FileList["test/unit/test*.rb"]
13
+ t.verbose = true
14
+ end
15
+
16
+ Rake::TestTask.new(:integration) do |t|
17
+ t.libs << "test"
18
+ t.test_files = FileList["test/integration/test*.rb"]
19
+ t.verbose = true
20
+ end
21
+ end
22
+
23
+ RuboCop::RakeTask.new
24
+ Coveralls::RakeTask.new
25
+ task ci: [:rubocop, "test:unit", "test:integration", "coveralls:push"]
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
+ require "alertdesigner"
3
+ require "English"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "alertdesigner"
7
+ gem.version = `git describe --tags --abbrev=0`
8
+ gem.authors = ["Daniel Schauenberg"]
9
+ gem.email = "d@unwiredcouch.com"
10
+ gem.homepage = "https://github.com/mrtazz/AlertDesigner"
11
+ gem.summary = "A Ruby DSL for generating Nagios check definitions"
12
+ gem.description = "A Ruby DSL for generating Nagios check definitions"
13
+
14
+ gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency "rake", "11.1.1"
20
+ gem.add_development_dependency "coveralls"
21
+ gem.add_development_dependency "rubocop", "~> 0.38"
22
+ gem.add_development_dependency "test-unit"
23
+ end
@@ -0,0 +1,40 @@
1
+ require "alertdesigner/formatters"
2
+ require "alertdesigner/check"
3
+
4
+ # Top level AlertDesigner module with static methods for the DSL
5
+ module AlertDesigner
6
+ @checks = []
7
+ @formatters = []
8
+
9
+ def self.checks
10
+ @checks
11
+ end
12
+
13
+ def self.formatters
14
+ @formatters
15
+ end
16
+
17
+ def self.define(&block)
18
+ instance_eval(&block)
19
+ end
20
+
21
+ def self.check(description, &block)
22
+ check = Check.new(description)
23
+ check.instance_eval(&block)
24
+ @checks << check
25
+ end
26
+
27
+ def self.formatter(formatter_class, &block)
28
+ formatter = formatter_class.new
29
+ formatter.instance_eval(&block)
30
+ @formatters << formatter
31
+ end
32
+
33
+ def self.format
34
+ ret = ""
35
+ @formatters.each do |formatter|
36
+ ret << formatter.format(:checks, @checks)
37
+ end
38
+ ret
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ module AlertDesigner
2
+ # Class to represent a check
3
+ class Check < BasicObject
4
+ def initialize(description)
5
+ @attributes = {}
6
+ @description = description
7
+ @command = ""
8
+ @hostgroups = []
9
+ end
10
+
11
+ def command(command = nil)
12
+ return @command if command.nil?
13
+ @command = command
14
+ end
15
+
16
+ def hostgroups(groups = nil)
17
+ return @hostgroups if groups.nil?
18
+ @hostgroups = groups
19
+ end
20
+
21
+ attr_reader :attributes, :description
22
+
23
+ def method_missing(name, *args)
24
+ attributes[name] = args[0]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ module AlertDesigner
2
+ module Formatters
3
+ # basic (abstract) class to inherit from for formatters
4
+ class Formatter
5
+ def format(_type, _value)
6
+ raise "'format' method not implemented."
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,83 @@
1
+ require "alertdesigner/formatters"
2
+
3
+ require "erb"
4
+ require "ostruct"
5
+
6
+ module AlertDesigner
7
+ module Formatters
8
+ # Class for the generic nagios formatter
9
+ class Nagios < Formatter
10
+ # Generic Nagios definition class
11
+ class NagiosDefinition < OpenStruct
12
+ TEMPLATE = <<-EOS.freeze
13
+ define <%= type %>{
14
+ <% properties.each do |key, value| %>
15
+ <%= key %> <%= value %>
16
+ <% end %>
17
+ }
18
+
19
+ EOS
20
+
21
+ def render
22
+ ERB.new(TEMPLATE, 0, "<>").result(binding)
23
+ end
24
+
25
+ def self.get_service(check, check_template)
26
+ fmt_check = NagiosDefinition.new
27
+ fmt_check.type = "service"
28
+ fmt_check.properties = check.attributes
29
+ fmt_check.properties["use"] = check_template
30
+ fmt_check.properties["service_description"] = check.description
31
+ fmt_check.properties["check_command"] = check.command
32
+ fmt_check
33
+ end
34
+ end
35
+
36
+ def check_template(template)
37
+ @check_template = template
38
+ end
39
+
40
+ def format(type, value)
41
+ return format_checks(value) if type == :checks
42
+ end
43
+
44
+ private
45
+
46
+ def format_checks(checks)
47
+ ret = ""
48
+ checks.each do |check|
49
+ # split up host groups with default and explicitly specified contact
50
+ # definitions
51
+ hgroups, hgroups_with_contacts = check.hostgroups.partition do |grp|
52
+ grp.is_a?(String)
53
+ end
54
+
55
+ # create service definition for default contacts
56
+ fmt_check = NagiosDefinition.get_service(check, @check_template)
57
+ fmt_check.properties["hostgroup_name"] = hgroups.join(",")
58
+ ret << fmt_check.render
59
+
60
+ ret << checks_for_hostgroups_with_contacts(check,
61
+ hgroups_with_contacts)
62
+ end
63
+
64
+ ret
65
+ end
66
+
67
+ def checks_for_hostgroups_with_contacts(check, hgroups)
68
+ ret = ""
69
+ # create service definition for specified contacts
70
+ hgroups.each do |entry|
71
+ entry.each do |group, contact|
72
+ fmt_check = NagiosDefinition.get_service(check, @check_template)
73
+ fmt_check.properties["hostgroup_name"] = group
74
+ fmt_check.properties["contact_groups"] = contact
75
+ ret << fmt_check.render
76
+ end
77
+ end
78
+
79
+ ret
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,103 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ require 'test/unit'
4
+ require 'alertdesigner'
5
+ require 'alertdesigner/formatters/nagios'
6
+
7
+ class FormatterNagiosTest < Test::Unit::TestCase
8
+
9
+ def setup
10
+ end
11
+
12
+ def teardown
13
+ end
14
+
15
+ def test_nagios_formatter_integration
16
+
17
+ AlertDesigner.define do
18
+
19
+ # let's use the Nagios formatter
20
+ formatter AlertDesigner::Formatters::Nagios do
21
+ check_template "generic-service"
22
+ end
23
+
24
+ # a simple disk space check
25
+ check "/ Partition Disk Space" do
26
+ hostgroups ["freebsd-base"]
27
+ command "check_nrpe!check_root"
28
+ end
29
+
30
+ # define some base checks with repeating properties
31
+ {
32
+ "vulnerable packages" => "check_nrpe!check_portaudit",
33
+ "FreeBSD security updates" => "check_nrpe!check_freebsd_update",
34
+ }.each do |description, check_cmd|
35
+
36
+ check description do
37
+ hostgroups ["freebsd-base"]
38
+ command check_cmd
39
+ end
40
+
41
+ end
42
+
43
+ # set contact groups for specific clusters
44
+ check "Apache Running" do
45
+ hostgroups ["LinuxServers", "WebServers" => "web-team", "ApiServers" => "api-team"]
46
+ command "check_nrpe!check_httpd"
47
+ end
48
+
49
+ end
50
+
51
+ ret = AlertDesigner.format
52
+
53
+ expected = <<-EOS
54
+ define service{
55
+ use generic-service
56
+ service_description / Partition Disk Space
57
+ check_command check_nrpe!check_root
58
+ hostgroup_name freebsd-base
59
+ }
60
+
61
+ define service{
62
+ use generic-service
63
+ service_description vulnerable packages
64
+ check_command check_nrpe!check_portaudit
65
+ hostgroup_name freebsd-base
66
+ }
67
+
68
+ define service{
69
+ use generic-service
70
+ service_description FreeBSD security updates
71
+ check_command check_nrpe!check_freebsd_update
72
+ hostgroup_name freebsd-base
73
+ }
74
+
75
+ define service{
76
+ use generic-service
77
+ service_description Apache Running
78
+ check_command check_nrpe!check_httpd
79
+ hostgroup_name LinuxServers
80
+ }
81
+
82
+ define service{
83
+ use generic-service
84
+ service_description Apache Running
85
+ check_command check_nrpe!check_httpd
86
+ hostgroup_name WebServers
87
+ contact_groups web-team
88
+ }
89
+
90
+ define service{
91
+ use generic-service
92
+ service_description Apache Running
93
+ check_command check_nrpe!check_httpd
94
+ hostgroup_name ApiServers
95
+ contact_groups api-team
96
+ }
97
+
98
+ EOS
99
+
100
+ assert_equal(expected, ret)
101
+ end
102
+
103
+ end
@@ -0,0 +1,13 @@
1
+ if ENV["COVERAGE"]
2
+ require "coveralls"
3
+ require "simplecov"
4
+ SimpleCov.start do
5
+ add_filter "/test/"
6
+ command_name "Unit Tests"
7
+ end
8
+ end
9
+
10
+ require "test/unit"
11
+
12
+ module TestHelper
13
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ require 'test/unit'
4
+ require 'alertdesigner/check'
5
+
6
+ class CheckTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @c = AlertDesigner::Check.new "simple check"
10
+ end
11
+
12
+ def teardown
13
+ end
14
+
15
+ def test_basic_instantiation
16
+ @c.command "check_nrpe!check_root"
17
+ @c.hostgroups ["Webservers"]
18
+ assert_equal("simple check", @c.description)
19
+ assert_equal("check_nrpe!check_root", @c.command)
20
+ assert_equal(["Webservers"], @c.hostgroups)
21
+ end
22
+
23
+ def test_method_missing
24
+ @c.foo "foo"
25
+ assert_equal("foo", @c.attributes[:foo])
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ require 'test/unit'
4
+ require 'alertdesigner/formatters/nagios'
5
+ require 'alertdesigner/check'
6
+
7
+ class FormatterNagiosTest < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @formatter = AlertDesigner::Formatters::Nagios.new
11
+ @formatter.check_template "generic-service"
12
+ end
13
+
14
+ def teardown
15
+ end
16
+
17
+ def test_split_hostgroups_by_contact
18
+ c = AlertDesigner::Check.new "simple check"
19
+ c.command "check_nrpe!check_root"
20
+ c.hostgroups ["Webservers"]
21
+
22
+ ret = @formatter.format(:checks, [c])
23
+
24
+ expected = <<-EOS
25
+ define service{
26
+ use generic-service
27
+ service_description simple check
28
+ check_command check_nrpe!check_root
29
+ hostgroup_name Webservers
30
+ }
31
+
32
+ EOS
33
+
34
+ assert_equal(expected, ret)
35
+
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ require 'test/unit'
4
+ require 'alertdesigner/formatters'
5
+
6
+ class FormatterTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ end
10
+
11
+ def teardown
12
+ end
13
+
14
+ def test_formatter_is_abstract
15
+ format = AlertDesigner::Formatters::Formatter.new
16
+ assert_raise RuntimeError do
17
+ format.format("foo", "bar")
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alertdesigner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Schauenberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 11.1.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 11.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.38'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.38'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A Ruby DSL for generating Nagios check definitions
70
+ email: d@unwiredcouch.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .gitignore
76
+ - .rubocop.yml
77
+ - .travis.yml
78
+ - CHANGELOG.md
79
+ - CONTRIBUTING.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - alertdesigner.gemspec
86
+ - lib/alertdesigner.rb
87
+ - lib/alertdesigner/check.rb
88
+ - lib/alertdesigner/formatters.rb
89
+ - lib/alertdesigner/formatters/nagios.rb
90
+ - test/integration/test_formatters_nagios.rb
91
+ - test/test_helper.rb
92
+ - test/unit/test_check.rb
93
+ - test/unit/test_formatter_nagios.rb
94
+ - test/unit/test_formatters.rb
95
+ homepage: https://github.com/mrtazz/AlertDesigner
96
+ licenses: []
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A Ruby DSL for generating Nagios check definitions
118
+ test_files:
119
+ - test/integration/test_formatters_nagios.rb
120
+ - test/test_helper.rb
121
+ - test/unit/test_check.rb
122
+ - test/unit/test_formatter_nagios.rb
123
+ - test/unit/test_formatters.rb