sensu-handlers-elasticsearch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE +23 -0
- data/README.md +23 -0
- data/bin/handler-elasticsearch.rb +65 -0
- data/lib/sensu-handlers-elasticsearch.rb +1 -0
- data/lib/sensu-handlers-elasticsearch/version.rb +9 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e8c53ed56f1fecf8a05e55f036f3425eae261cc5
|
4
|
+
data.tar.gz: 7eb1d47a3b87409106c1503fe664f5427496db62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3cbffd39de1acd9fc647d9544190a67d35fbadf9d67b6b823e47d4cb0c984c7dfa9437b1348e54dbefa22c8f8f1c5e9950e49f0e0bfb676f21a717d5d755d1fd
|
7
|
+
data.tar.gz: 954497f91c1b33ba16be9f42c59e4fd2fdc93f15b79effa0cfdfc0a71d8a6448343db7c4f5cf5485a9ad379ce4f70756d13e3728b803b8ad3c67006fa32daf70
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2016 Matteo Cerutti
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Sensu handler for Elasticsearch
|
2
|
+
|
3
|
+
A sensu handler to send events to Elasticsearch.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
The handler accepts the following command line options:
|
8
|
+
|
9
|
+
```
|
10
|
+
Usage: handler-elasticsearch.rb (options)
|
11
|
+
-i, --index <INDEX> Elasticsearch index (default: sensu)
|
12
|
+
-t, --type <TYPE> Elasticsearch index type (default: handler)
|
13
|
+
-u, --url <URL> Elasticsearch URL
|
14
|
+
```
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
```
|
19
|
+
/opt/sensu/embedded/bin/gem install sensu-handlers-elasticsearch
|
20
|
+
```
|
21
|
+
|
22
|
+
## Author
|
23
|
+
Matteo Cerutti - <matteo.cerutti@hotmail.co.uk>
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# handler-elasticsearch.rb
|
3
|
+
#
|
4
|
+
# Author: Matteo Cerutti <matteo.cerutti@hotmail.co.uk>
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'sensu-handler'
|
8
|
+
require 'net/http'
|
9
|
+
require 'time'
|
10
|
+
|
11
|
+
class HandlerElasticsearch < Sensu::Handler
|
12
|
+
option :url,
|
13
|
+
:description => "Elasticsearch URL",
|
14
|
+
:short => "-u <URL>",
|
15
|
+
:long => "--url <URL>",
|
16
|
+
:default => "http://localhost:9200"
|
17
|
+
|
18
|
+
option :index,
|
19
|
+
:description => "Elasticsearch index (default: sensu)",
|
20
|
+
:short => "-i <INDEX>",
|
21
|
+
:long => "--index <INDEX>",
|
22
|
+
:default => "sensu"
|
23
|
+
|
24
|
+
option :type,
|
25
|
+
:description => "Elasticsearch index type (default: handler)",
|
26
|
+
:short => "-t <TYPE>",
|
27
|
+
:long => "--type <TYPE>",
|
28
|
+
:default => "handler"
|
29
|
+
|
30
|
+
def handle
|
31
|
+
event = {
|
32
|
+
:@timestamp => Time.at(@event['timestamp']).utc.iso8601,
|
33
|
+
:action => @event['action'],
|
34
|
+
:occurrences => @event['occurrences'],
|
35
|
+
:client => {
|
36
|
+
:name => @event['client']['name'],
|
37
|
+
:address => @event['client']['address']
|
38
|
+
},
|
39
|
+
:check => {
|
40
|
+
:name => @event['check']['name'],
|
41
|
+
:interval => @event['check']['interval'],
|
42
|
+
:command => @event['check']['command'],
|
43
|
+
:duration => @event['check']['duration'],
|
44
|
+
:output => @event['check']['output'].chomp,
|
45
|
+
:status => @event['check']['status']
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
uri = URI("#{config[:url]}/#{config[:index]}/#{config[:type]}/#{@event['id']}")
|
50
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
51
|
+
request = Net::HTTP::Post.new(uri.path, "Content-Type" => "application/json")
|
52
|
+
request.body = JSON.dump(event)
|
53
|
+
|
54
|
+
begin
|
55
|
+
resp = http.request(request)
|
56
|
+
if resp.code == '200' or resp.code == '201'
|
57
|
+
puts "Event posted (Code: #{resp.code}, Reply: #{resp.body})"
|
58
|
+
else
|
59
|
+
puts "Failed to post event (Code: #{resp.code}, Reply: #{resp.body})"
|
60
|
+
end
|
61
|
+
rescue
|
62
|
+
puts "Failed to post event - Caught exception (#{$!})"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-handlers-elasticsearch/version'
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-handlers-elasticsearch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matteo Cerutti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sensu-plugin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
description: This handler provides facilities for sending events to Elasticsearch
|
28
|
+
email: "<matteo.cerutti@hotmail.co.uk>"
|
29
|
+
executables:
|
30
|
+
- handler-elasticsearch.rb
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- bin/handler-elasticsearch.rb
|
38
|
+
- lib/sensu-handlers-elasticsearch.rb
|
39
|
+
- lib/sensu-handlers-elasticsearch/version.rb
|
40
|
+
homepage: https://github.com/m4ce/sensu-handlers-elasticsearch
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
maintainer: "@m4ce"
|
45
|
+
development_status: active
|
46
|
+
production_status: stable
|
47
|
+
release_draft: 'false'
|
48
|
+
release_prerelease: 'false'
|
49
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
50
|
+
in /etc/default/sensu
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.9.3
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.4.5.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Sensu handler for sending event to Elasticsearch
|
70
|
+
test_files: []
|