alertdesigner 0.0.2 → 0.0.3
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 +8 -8
- data/Gemfile.lock +1 -1
- data/README.md +24 -0
- data/lib/alertdesigner.rb +20 -1
- data/lib/alertdesigner/command.rb +16 -0
- data/lib/alertdesigner/formatters/nagios.rb +23 -0
- data/test/integration/test_formatters_nagios.rb +40 -1
- data/test/unit/test_command.rb +20 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTBmZDQ1NTg2NGQ3MDgzY2JjMWNkMjFiNTA2YjBhZWVlMmJjY2IyYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTFiZmZmMGU1MTlmYTkyZTM3NWI4YjM4NjgxYzdmOTZjYzQ0YzFiOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Mzg4NjQ1NGUwNGEwZTA5Y2Q3ZmE4MTE4Y2YzNTA0NGFkMjA5YzUzM2RmM2I3
|
10
|
+
YzJhMGM1NGRmNzlkZDY0NTBkYjYwNDdjMGFmOTc2YWQ5MWI4NWY4N2UzNzI3
|
11
|
+
YTFlZmMwMTZkNmE3YjM4YmIxOWEyMTg0MGZmNTc4MTQ3Zjg1ZDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjJkOWQ4NmIzMGM3MTU0YTZkMDY5NGYxMTY3ZGY3YjE4NDMyMTE0OGUyMTA1
|
14
|
+
NjM4YzRkOTlkMzUwM2EzMWU1OGFhZDkwZGQ5N2ViYjRlZWZlYTAzNDM5MTYw
|
15
|
+
OGQ5ZDI3ZTlkZWMyZTEwNzZmOWNkZTJhMjM1Y2ExZGI2N2JjMjg=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/mrtazz/AlertDesigner)
|
4
4
|
[](https://coveralls.io/github/mrtazz/AlertDesigner?branch=master)
|
5
5
|
[](https://codeclimate.com/github/mrtazz/AlertDesigner)
|
6
|
+
[](https://rubygems.org/gems/alertdesigner)
|
6
7
|
[](http://opensource.org/licenses/MIT)
|
7
8
|
|
8
9
|
## Overview
|
@@ -20,6 +21,16 @@ AlertDesigner.define do
|
|
20
21
|
check_template "generic-service"
|
21
22
|
end
|
22
23
|
|
24
|
+
{
|
25
|
+
"check_nrpe" => "$USER1$/check_nrpe2 -H $HOSTADDRESS$ -c $ARG1$ -t 30",
|
26
|
+
"check_local_disk" => "$USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$",
|
27
|
+
}.each do |name, check_cmd|
|
28
|
+
|
29
|
+
command name do
|
30
|
+
command check_cmd
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
23
34
|
# a simple disk space check
|
24
35
|
check "/ Partition Disk Space" do
|
25
36
|
hostgroups ["freebsd-base"]
|
@@ -52,6 +63,19 @@ end
|
|
52
63
|
puts AlertDesigner.format
|
53
64
|
```
|
54
65
|
|
66
|
+
## Installation
|
67
|
+
Install from rubygems:
|
68
|
+
|
69
|
+
```bash
|
70
|
+
gem install alertdesigner
|
71
|
+
```
|
72
|
+
|
73
|
+
Or in your Gemfile:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
gem 'alertdesigner'
|
77
|
+
```
|
78
|
+
|
55
79
|
## FAQ
|
56
80
|
### Couldn't most of this be done with a clever config hierarchy?
|
57
81
|
Probably.
|
data/lib/alertdesigner.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require "alertdesigner/formatters"
|
2
2
|
require "alertdesigner/check"
|
3
|
+
require "alertdesigner/command"
|
3
4
|
|
4
5
|
# Top level AlertDesigner module with static methods for the DSL
|
5
6
|
module AlertDesigner
|
6
7
|
@checks = []
|
7
8
|
@formatters = []
|
9
|
+
@commands = []
|
8
10
|
|
9
11
|
def self.checks
|
10
12
|
@checks
|
@@ -14,19 +16,35 @@ module AlertDesigner
|
|
14
16
|
@formatters
|
15
17
|
end
|
16
18
|
|
19
|
+
def self.commands
|
20
|
+
@commands
|
21
|
+
end
|
22
|
+
|
17
23
|
def self.define(&block)
|
18
24
|
instance_eval(&block)
|
19
25
|
end
|
20
26
|
|
27
|
+
def self.reset
|
28
|
+
@checks = []
|
29
|
+
@formatters = []
|
30
|
+
@commands = []
|
31
|
+
end
|
32
|
+
|
21
33
|
def self.check(description, &block)
|
22
34
|
check = Check.new(description)
|
23
35
|
check.instance_eval(&block)
|
24
36
|
@checks << check
|
25
37
|
end
|
26
38
|
|
39
|
+
def self.command(name, &block)
|
40
|
+
command = Command.new(name)
|
41
|
+
command.instance_eval(&block)
|
42
|
+
@commands << command
|
43
|
+
end
|
44
|
+
|
27
45
|
def self.formatter(formatter_class, &block)
|
28
46
|
formatter = formatter_class.new
|
29
|
-
formatter.instance_eval(&block)
|
47
|
+
formatter.instance_eval(&block) if block_given?
|
30
48
|
@formatters << formatter
|
31
49
|
end
|
32
50
|
|
@@ -34,6 +52,7 @@ module AlertDesigner
|
|
34
52
|
ret = ""
|
35
53
|
@formatters.each do |formatter|
|
36
54
|
ret << formatter.format(:checks, @checks)
|
55
|
+
ret << formatter.format(:commands, @commands)
|
37
56
|
end
|
38
57
|
ret
|
39
58
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module AlertDesigner
|
2
|
+
# Class to represent a command
|
3
|
+
class Command < BasicObject
|
4
|
+
attr_reader :command, :name
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
@command = ""
|
9
|
+
end
|
10
|
+
|
11
|
+
def command(command = nil)
|
12
|
+
return @command if command.nil?
|
13
|
+
@command = command
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -31,6 +31,15 @@ define <%= type %>{
|
|
31
31
|
fmt_check.properties["check_command"] = check.command
|
32
32
|
fmt_check
|
33
33
|
end
|
34
|
+
|
35
|
+
def self.get_command(name, cmd)
|
36
|
+
fmt_command = NagiosDefinition.new
|
37
|
+
fmt_command.type = "command"
|
38
|
+
fmt_command.properties = {}
|
39
|
+
fmt_command.properties["command_name"] = name
|
40
|
+
fmt_command.properties["command_line"] = cmd
|
41
|
+
fmt_command
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
45
|
def check_template(template)
|
@@ -39,10 +48,24 @@ define <%= type %>{
|
|
39
48
|
|
40
49
|
def format(type, value)
|
41
50
|
return format_checks(value) if type == :checks
|
51
|
+
return format_commands(value) if type == :commands
|
42
52
|
end
|
43
53
|
|
44
54
|
private
|
45
55
|
|
56
|
+
def format_commands(commands)
|
57
|
+
ret = ""
|
58
|
+
|
59
|
+
commands ||= []
|
60
|
+
|
61
|
+
commands.each do |cmd|
|
62
|
+
command = NagiosDefinition.get_command(cmd.name, cmd.command)
|
63
|
+
ret << command.render
|
64
|
+
end
|
65
|
+
|
66
|
+
ret
|
67
|
+
end
|
68
|
+
|
46
69
|
def format_checks(checks)
|
47
70
|
ret = ""
|
48
71
|
checks.each do |check|
|
@@ -10,9 +10,10 @@ class FormatterNagiosTest < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def teardown
|
13
|
+
AlertDesigner.reset
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
+
def test_nagios_formatter_services
|
16
17
|
|
17
18
|
AlertDesigner.define do
|
18
19
|
|
@@ -95,6 +96,44 @@ define service{
|
|
95
96
|
contact_groups api-team
|
96
97
|
}
|
97
98
|
|
99
|
+
EOS
|
100
|
+
|
101
|
+
assert_equal(expected, ret)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_nagios_formatter_commands
|
105
|
+
|
106
|
+
AlertDesigner.define do
|
107
|
+
|
108
|
+
# let's use the Nagios formatter
|
109
|
+
formatter AlertDesigner::Formatters::Nagios
|
110
|
+
|
111
|
+
# define some basic commands
|
112
|
+
{
|
113
|
+
"check_nrpe" => "$USER1$/check_nrpe2 -H $HOSTADDRESS$ -c $ARG1$ -t 30",
|
114
|
+
"check_local_disk" => "$USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$",
|
115
|
+
}.each do |name, check_cmd|
|
116
|
+
|
117
|
+
command name do
|
118
|
+
command check_cmd
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
ret = AlertDesigner.format
|
125
|
+
|
126
|
+
expected = <<-EOS
|
127
|
+
define command{
|
128
|
+
command_name check_nrpe
|
129
|
+
command_line $USER1$/check_nrpe2 -H $HOSTADDRESS$ -c $ARG1$ -t 30
|
130
|
+
}
|
131
|
+
|
132
|
+
define command{
|
133
|
+
command_name check_local_disk
|
134
|
+
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
|
135
|
+
}
|
136
|
+
|
98
137
|
EOS
|
99
138
|
|
100
139
|
assert_equal(expected, ret)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'alertdesigner/command'
|
5
|
+
|
6
|
+
class CommandTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@c = AlertDesigner::Command.new "check-host-alive"
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_basic_instantiation
|
16
|
+
@c.command "$USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5"
|
17
|
+
assert_equal("check-host-alive", @c.name)
|
18
|
+
assert_equal("$USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5", @c.command)
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alertdesigner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schauenberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -85,11 +85,13 @@ files:
|
|
85
85
|
- alertdesigner.gemspec
|
86
86
|
- lib/alertdesigner.rb
|
87
87
|
- lib/alertdesigner/check.rb
|
88
|
+
- lib/alertdesigner/command.rb
|
88
89
|
- lib/alertdesigner/formatters.rb
|
89
90
|
- lib/alertdesigner/formatters/nagios.rb
|
90
91
|
- test/integration/test_formatters_nagios.rb
|
91
92
|
- test/test_helper.rb
|
92
93
|
- test/unit/test_check.rb
|
94
|
+
- test/unit/test_command.rb
|
93
95
|
- test/unit/test_formatter_nagios.rb
|
94
96
|
- test/unit/test_formatters.rb
|
95
97
|
homepage: https://github.com/mrtazz/AlertDesigner
|
@@ -119,5 +121,6 @@ test_files:
|
|
119
121
|
- test/integration/test_formatters_nagios.rb
|
120
122
|
- test/test_helper.rb
|
121
123
|
- test/unit/test_check.rb
|
124
|
+
- test/unit/test_command.rb
|
122
125
|
- test/unit/test_formatter_nagios.rb
|
123
126
|
- test/unit/test_formatters.rb
|