lita-nagios 0.0.1 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ede4f56d168a547caf8b99d56291d290d0cbe62e
4
- data.tar.gz: 9d0cb06ea65d68ed1717cd9ca49e2314ad5ffec1
3
+ metadata.gz: 47c44656f16b7da317f21677ea42f7b8e60c77d6
4
+ data.tar.gz: 4a39170f725faf85d8cd3400c8f5a2c7dd55ee3d
5
5
  SHA512:
6
- metadata.gz: efd57d34c435a25b6309d10d1330e7b6e4fd3f2f34a84ff044550f18df0d110a1f03c1736bc2543a90a015ea973b6c8012fcf5bff3d478758d178105ab7a81eb
7
- data.tar.gz: bc329db209e663fb2cd243e1b5740aeb8c0f10df94a3abc0505c118d61c73c1d6ced4ca61496334746967dc4481fb9a4b61f81b06231641fc26f4bf9900546b9
6
+ metadata.gz: 9bcb83b3f12db66c0902748793df671583c16f7802e608ab145d4425fde3c2615210f29adb139c57714b42f46b407b85400c902117049d676d13957205b50773
7
+ data.tar.gz: a039c8f62ddd61175db75d81380f0ccbf73434a2ec336214c6ae0438bea52d971fba6484eba07a92d9a2bcc0f69224f45cc8b1d6f872f5bce99d8a1d16c605d4
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # lita-nagios
2
2
 
3
- TODO: Add a description of the plugin.
3
+ [![Build Status](https://travis-ci.org/josqu4red/lita-nagios.png?branch=master)](https://travis-ci.org/josqu4red/lita-nagios)
4
+ [![Coverage Status](https://coveralls.io/repos/josqu4red/lita-nagios/badge.png)](https://coveralls.io/r/josqu4red/lita-nagios)
5
+
6
+ **lita-nagios** is a handler for [Lita](https://github.com/jimmycuadra/lita) that allows interaction with Nagios monitoring solution.
7
+ It listens for notifications on a HTTP endpoint and uses [nagiosharder](https://github.com/railsmachine/nagiosharder) to send commands to the Nagios instance.
8
+
9
+ Note: Colors in notifications are not enabled yet, because it relies completely on the adapter and no abstraction layer is implemented nor designed as of now.
4
10
 
5
11
  ## Installation
6
12
 
@@ -12,11 +18,60 @@ gem "lita-nagios"
12
18
 
13
19
  ## Configuration
14
20
 
15
- TODO: Describe any configuration attributes the plugin exposes.
21
+ ### HTTP interface
22
+ * `default_room` (String) - Default chat room for notifications
23
+
24
+ ### Nagios commands (`nagiosharder` config)
25
+ * `cgi` - Nagios CGI URL
26
+ * `user` - Nagios user with system commands authorization
27
+ * `pass` - User password
28
+ * `version` - Nagios version, default: 3
29
+ * `time_format` - default: "iso8601"
30
+ * `verify_ssl` - default: `true`
31
+
32
+ ### Example
33
+
34
+ ``` ruby
35
+ Lita.configure do |config|
36
+ config.handlers.nagios.default_room = "#admin_room"
37
+ config.handlers.nagios.cgi = "http://nagios.example.com/cgi-bin/nagios3"
38
+ config.handlers.nagios.user = "lita"
39
+ config.handlers.nagios.pass = "xxxx"
40
+ config.handlers.nagios.version = 3
41
+ config.handlers.nagios.time_format = "iso8601"
42
+ config.handlers.nagios.verify_ssl = true
43
+ end
44
+ ```
16
45
 
17
46
  ## Usage
18
47
 
19
- TODO: Describe the plugin's features and how to use them.
48
+ ### Display notifications in channel
49
+
50
+ lita-nagios provides a HTTP endpoint to receive Nagios notifications:
51
+
52
+ ```
53
+ POST /nagios/notifications
54
+ ```
55
+ Request parameters must include those fields:
56
+ * `type` - `host` or `service`
57
+ * `room` - notifications destination (see `default_room` in configuration section)
58
+ * `host` - Nagios' $HOSTNAME$ or $HOSTALIAS$
59
+ * `output` - Nagios' $HOSTOUTPUT$ or $SERVICEOUTPUT$
60
+ * `state` - Nagios' $HOSTSTATE$ or $SERVICESTATE$
61
+ * `notificationtype` - Nagios' $NOTIFICATIONTYPE$
62
+ * `description` - Nagios' $SERVICEDESC$ (only for `service` type)
63
+
64
+ An example Nagios configuration (contact, commands) to send alerts to channels is provided in [contrib](contrib/nagios_config.txt) folder
65
+
66
+ ### Send commands to Nagios
67
+
68
+ ```
69
+ lita: nagios enable notif(ication(s)) <-h | --host HOST> [-s | --service SERVICE] - Enable notifications for given host/service
70
+ lita: nagios disable notif(ication(s)) <-h | --host HOST> [-s | --service SERVICE] - Disable notifications for given host/service
71
+ lita: nagios recheck <-h | --host HOST> [-s | --service SERVICE] - Reschedule check for given host/service
72
+ lita: nagios ack(nowledge) <-h | --host HOST> [-s | --service SERVICE] [-m | --message MESSAGE] - Acknowledge host/service problem with optional message
73
+ lita: nagios (fixed|flexible) downtime <-d | --duration DURATION > <-h | --host HOST> [-s | --service SERVICE] - Schedule downtime for a host/service with duration units in (m, h, d, default to seconds)
74
+ ```
20
75
 
21
76
  ## License
22
77
 
@@ -30,5 +30,5 @@ define contact{
30
30
  host_notification_options d,r
31
31
  service_notification_commands notify-service-by-bot
32
32
  host_notification_commands notify-host-by-bot
33
- address1 http://lita.example.com:8080/nagios
33
+ address1 http://lita.example.com/nagios/notifications
34
34
  }
data/lib/lita-nagios.rb CHANGED
@@ -1 +1,4 @@
1
+ require "lita"
2
+ require "nagiosharder"
3
+ require "lita-keyword-arguments"
1
4
  require "lita/handlers/nagios"
@@ -1,14 +1,160 @@
1
- require "lita"
2
-
3
1
  module Lita
4
2
  module Handlers
5
3
  class Nagios < Handler
6
4
 
7
5
  def self.default_config(config)
8
6
  config.default_room = nil
7
+ config.cgi = nil
8
+ config.user = nil
9
+ config.pass = nil
10
+ config.version = 3
11
+ config.time_format = "iso8601"
12
+ config.verify_ssl = true
13
+ end
14
+
15
+ def initialize(robot)
16
+ @site = NagiosHarder::Site.new(
17
+ config.cgi,
18
+ config.user,
19
+ config.pass,
20
+ config.version,
21
+ config.time_format,
22
+ config.verify_ssl
23
+ )
24
+ super(robot)
25
+ end
26
+
27
+ ##
28
+ # Chat routes
29
+ ##
30
+
31
+ route /^nagios\s+(?<action>enable|disable)\s+notif(ication(s)?)?/, :toggle_notifications,
32
+ command: true,
33
+ restrict_to: ["admins"],
34
+ kwargs: {
35
+ host: { short: "h" },
36
+ service: { short: "s" }
37
+ },
38
+ help: {
39
+ "nagios enable notif(ication(s)) <-h | --host HOST> [-s | --service SERVICE]" => "Enable notifications for given host/service",
40
+ "nagios disable notif(ication(s)) <-h | --host HOST> [-s | --service SERVICE]" => "Disable notifications for given host/service",
41
+ }
42
+
43
+ def toggle_notifications(response)
44
+ args = response.extensions[:kwargs]
45
+ return response.reply("Missing 'host' argument") unless args[:host]
46
+
47
+ action = response.match_data[:action]
48
+
49
+ reply = @site.send("#{action}_service_notifications", args[:host], args[:service])
50
+ response.reply(reply)
9
51
  end
10
52
 
11
- http.post "/nagios", :receive
53
+ route /^nagios\s+recheck/, :recheck,
54
+ command: true,
55
+ restrict_to: ["admins"],
56
+ kwargs: {
57
+ host: { short: "h" },
58
+ service: { short: "s" }
59
+ },
60
+ help: {
61
+ "nagios recheck <-h | --host HOST> [-s | --service SERVICE]" => "Reschedule check for given host/service"
62
+ }
63
+
64
+ def recheck(response)
65
+ args = response.extensions[:kwargs]
66
+ return response.reply("Missing 'host' argument") unless args[:host]
67
+
68
+ if args[:service]
69
+ method_w_params = [ :schedule_service_check, args[:host], args[:service] ]
70
+ reply = "#{args[:service]} on #{args[:host]}"
71
+ else
72
+ method_w_params = [ :schedule_host_check, args[:host] ]
73
+ reply = args[:host]
74
+ end
75
+
76
+ reply = @site.send(*method_w_params) ? "Check scheduled for #{reply}" : "Failed to schedule check for #{reply}"
77
+ response.reply(reply)
78
+ end
79
+
80
+ route /^nagios\s+ack(nowledge)?/, :acknowledge,
81
+ command: true,
82
+ restrict_to: ["admins"],
83
+ kwargs: {
84
+ host: { short: "h" },
85
+ service: { short: "s" },
86
+ message: { short: "m" }
87
+ },
88
+ help: {
89
+ "nagios ack(nowledge) <-h | --host HOST> [-s | --service SERVICE] [-m | --message MESSAGE]" => "Acknowledge host/service problem with optional message",
90
+ }
91
+
92
+ def acknowledge(response)
93
+ args = response.extensions[:kwargs]
94
+ return response.reply("Missing 'host' argument") unless args[:host]
95
+
96
+ user = response.message.source.user.name
97
+ message = args[:message] ? "#{args[:message]} (#{user})" : "acked by #{user}"
98
+
99
+ if args[:service]
100
+ method_w_params = [ :acknowledge_service, args[:host], args[:service], message ]
101
+ reply = "#{args[:service]} on #{args[:host]}"
102
+ else
103
+ method_w_params = [ :acknowledge_host, args[:host], message ]
104
+ reply = args[:host]
105
+ end
106
+
107
+ reply = @site.send(*method_w_params) ? "Acknowledgment set for #{reply}" : "Failed to acknowledge #{reply}"
108
+ response.reply(reply)
109
+ end
110
+
111
+ route /^nagios(\s+(?<type>fixed|flexible))?\s+downtime/, :schedule_downtime,
112
+ command: true,
113
+ restrict_to: ["admins"],
114
+ kwargs: {
115
+ host: { short: "h" },
116
+ service: { short: "s" },
117
+ duration: { short: "d" }
118
+ },
119
+ help: {
120
+ "nagios (fixed|flexible) downtime <-d | --duration DURATION > <-h | --host HOST> [-s | --service SERVICE]" => "Schedule downtime for a host/service with duration units in (m, h, d, default to seconds)"
121
+ }
122
+
123
+ def schedule_downtime(response)
124
+ args = response.extensions[:kwargs]
125
+ return response.reply("Missing 'host' argument") unless args[:host]
126
+
127
+ units = { "m" => :minutes, "h" => :hours, "d" => :days }
128
+ match = /^(?<value>\d+)(?<unit>[#{units.keys.join}])?$/.match(args[:duration])
129
+ return response.reply("Invalid downtime duration") unless (match and match[:value])
130
+
131
+ duration = match[:unit] ? match[:value].to_i.send(units[match[:unit]]) : match[:value].to_i
132
+
133
+ options = case response.match_data[:type]
134
+ when "fixed"
135
+ { type: :fixed, start_time: Time.now, end_time: Time.now + duration }
136
+ when "flexible"
137
+ { type: :flexible, hours: (duration / 3600), minutes: (duration % 3600 / 60) }
138
+ end.merge({ author: "#{response.message.source.user.name} via Lita" })
139
+
140
+ if args[:service]
141
+ method_w_params = [ :schedule_service_downtime, args[:host], args[:service], options ]
142
+ reply = "#{args[:service]} on #{args[:host]}"
143
+ else
144
+ method_w_params = [ :schedule_host_downtime, args[:host], options ]
145
+ reply = args[:host]
146
+ end
147
+
148
+ reply = @site.send(*method_w_params) ? "#{options[:type].capitalize} downtime set for #{reply}" : "Failed to schedule downtime for #{reply}"
149
+ response.reply(reply)
150
+ end
151
+
152
+
153
+ ##
154
+ # HTTP endpoints
155
+ ##
156
+
157
+ http.post "/nagios/notifications", :receive
12
158
 
13
159
  def receive(request, response)
14
160
  if request.params.has_key?("type")
@@ -22,18 +168,16 @@ module Lita
22
168
 
23
169
  if request.params.has_key?("room")
24
170
  room = request.params["room"]
25
- elsif Lita.config.handlers.nagios.default_room
26
- room = Lita.config.handlers.nagios.default_room
171
+ elsif config.default_room
172
+ room = config.default_room
27
173
  else
28
174
  raise "Room must be defined. Either fix your command or specify a default room ('config.handlers.nagios.default_room')"
29
175
  end
30
176
 
31
177
  message = send(notif_type, request.params)
32
178
 
33
- ack = request.params["notificationtype"] == "ACKNOWLEDGEMENT" ? "[ACK] " : ""
34
-
35
179
  target = Source.new(room: room)
36
- robot.send_message(target, "nagios: #{ack}#{message}")
180
+ robot.send_message(target, "nagios: #{message}")
37
181
  rescue Exception => e
38
182
  Lita.logger.error(e)
39
183
  end
data/lita-nagios.gemspec CHANGED
@@ -1,21 +1,26 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-nagios"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.1.0"
4
4
  spec.authors = ["Jonathan Amiez"]
5
5
  spec.email = ["jonathan.amiez@gmail.com"]
6
6
  spec.description = "Nagios interaction with Lita"
7
7
  spec.summary = "Receive notification and send ACK/recheck, etc. to Nagios"
8
8
  spec.homepage = "https://github.com/josqu4red/lita-nagios"
9
9
  spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
10
11
 
11
12
  spec.files = `git ls-files`.split($/)
12
13
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
15
  spec.require_paths = ["lib"]
15
16
 
16
- spec.add_runtime_dependency "lita", "~> 3.0"
17
+ spec.add_runtime_dependency "lita", ">= 3.2"
18
+ spec.add_runtime_dependency "lita-keyword-arguments"
19
+ spec.add_runtime_dependency "nagiosharder", ">= 0.5.0"
17
20
 
18
21
  spec.add_development_dependency "bundler", "~> 1.3"
19
22
  spec.add_development_dependency "rake", "~> 0"
20
23
  spec.add_development_dependency "rspec", "~> 2.14"
24
+ spec.add_development_dependency "simplecov"
25
+ spec.add_development_dependency "coveralls"
21
26
  end
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-nagios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Amiez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-02 00:00:00.000000000 Z
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: lita-keyword-arguments
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: nagiosharder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
25
53
  - !ruby/object:Gem::Version
26
- version: '3.0'
54
+ version: 0.5.0
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +94,34 @@ dependencies:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: '2.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  description: Nagios interaction with Lita
70
126
  email:
71
127
  - jonathan.amiez@gmail.com
@@ -87,7 +143,8 @@ files:
87
143
  homepage: https://github.com/josqu4red/lita-nagios
88
144
  licenses:
89
145
  - MIT
90
- metadata: {}
146
+ metadata:
147
+ lita_plugin_type: handler
91
148
  post_install_message:
92
149
  rdoc_options: []
93
150
  require_paths: