monit2slack 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 32c3b90972a6c0e80579b4a3d10eddabf575bf62405cd2b7a55ac3f0c9b7cfbe
4
+ data.tar.gz: dfba270f04da58f98642bee0a75f574f2b1651a11ecda86606c68fea142ed898
5
+ SHA512:
6
+ metadata.gz: 3a47b30972a0f96d991abbd915e609a7e3915b3be16137ba6ebcfb0678714c158a4b7af7a613525d024bceac0ad24b60db50efba9883a24c0bc2abc7ebbc0b4a
7
+ data.tar.gz: 7e6800b383fc75f5df35eab5b0243ec9d0f761fe2c58cf3f8d43372082a43bee7d5ed02eab1f036b688467398bea530e20ce2bd19076b98d1004000a770cbbd2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in monit2slack.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Nedim Hadzimahmutovic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # Monit2slack
2
+
3
+ Send messages to Slack via Monit.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'monit2slack'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install monit2slack
20
+
21
+ ## Usage
22
+
23
+ This gem provides a binary `monit2slack`.
24
+
25
+ ````
26
+ monit2slack --webhook 'https://hooks.slack.com/services/xxx/xxx/xxx' --host MyServer --service NginX --status error --text 'Process NginX is down'
27
+ ````
28
+
29
+ If you prefer you can call if manually from a rb file.
30
+
31
+ ````
32
+ #!/usr/bin/env ruby
33
+
34
+ require "monit2slack"
35
+
36
+ Monit2Slack::Post
37
+ ````
38
+
39
+ ## Monit configuration file
40
+
41
+ ````
42
+ check process NginX
43
+ with pidfile /run/nginx.pid
44
+ start program = "/etc/init.d/nginx start" with timeout 30 seconds
45
+ stop program = "/etc/init.d/nginx stop" with timeout 30 seconds
46
+ if does not exist for 1 cycle
47
+ then exec "monit2slack --webhook 'https://hooks.slack.com/services/xxx/xxx/xxx' --host MyServer --service NginX --status error --text 'Process NginX is down'"
48
+ else if succeeded for 1 cycle then exec "monit2slack --webhook 'https://hooks.slack.com/services/xxx/xxx/xxx' --host MyServer --service NginX --status ok --text 'Process NginX is up'"
49
+ if does not exist then restart
50
+ ````
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "monit2slack"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "monit2slack"
5
+
6
+ Monit2Slack::Post
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "lib/monit2slack"
4
+
5
+ Monit2Slack::Post
@@ -0,0 +1,107 @@
1
+ require "monit2slack/version"
2
+ require 'optparse'
3
+ require 'slack-notifier'
4
+
5
+ module Monit2Slack
6
+ class Post
7
+ options = {}
8
+
9
+ opt_parser = OptionParser.new do |opt|
10
+
11
+ opt.banner = "Usage: COMMAND [OPTIONS]"
12
+
13
+ opt.on '--webhook WEBHOOK', 'Slack webhook.' do |arg|
14
+ options[:webhook] = arg
15
+ end
16
+
17
+ opt.on '--channel CHANNEL', "name of the channel to post to" do |arg|
18
+ options[:channel] = arg
19
+ end
20
+
21
+ opt.on '--emoji EMOJI', 'emoji icon' do |arg|
22
+ options[:emoji] = arg
23
+ end
24
+
25
+ opt.on '--username USERNAME', 'username' do |arg|
26
+ options[:username] = arg
27
+ end
28
+
29
+ opt.on '--status [error,ok]', "message satus" do |arg|
30
+ options[:status] = arg
31
+ end
32
+
33
+ opt.on '--service SERVICE', "Monit service" do |arg|
34
+ options[:service] = arg
35
+ end
36
+
37
+ opt.on '--text TEXT', "text of the message" do |arg|
38
+ options[:text] = arg
39
+ end
40
+
41
+ opt.on '--color [good,bad,danger]', "text of the message" do |arg|
42
+ options[:color] = arg
43
+ end
44
+
45
+ opt.on '--ping PING', "ping message" do |arg|
46
+ options[:ping] = arg
47
+ end
48
+
49
+ opt.on '--service SERVICE', "The monitored service" do |arg|
50
+ options[:service] = arg
51
+ end
52
+
53
+ opt.on '--host HOST', "Server hostname" do |arg|
54
+ options[:host] = arg
55
+ end
56
+ end
57
+
58
+ opt_parser.parse!
59
+
60
+ options[:color] ||= case options[:status]
61
+ when "error"
62
+ "danger"
63
+ when 'ok'
64
+ 'good'
65
+ else
66
+ 'info'
67
+ end
68
+
69
+ options[:emoji] ||= case options[:status]
70
+ when "error"
71
+ ':bangbang:'
72
+ when 'ok'
73
+ ':ok:'
74
+ else
75
+ ':ghost:'
76
+ end
77
+
78
+ options[:text] ||= case options[:status]
79
+ when "error"
80
+ "Error, process is down."
81
+ when 'ok'
82
+ 'Status is OK, process seems to be running.'
83
+ else
84
+ 'Not sure.'
85
+ end
86
+
87
+ username = "#{options[:service]}@#{options[:host]}-#{options[:status]}"
88
+
89
+ options[:username] ||= username
90
+
91
+ attachment = {
92
+ fallback: "Everything looks peachy",
93
+ text: options[:text],
94
+ color: options[:color]
95
+ }
96
+
97
+ if options[:webhook]
98
+ notifier = Slack::Notifier.new options[:webhook] do
99
+ defaults channel: options[:channel],
100
+ username: options[:username]
101
+ end
102
+ notifier.post text: "Message from Monit", icon_emoji: options[:emoji] if options[:text] && options[:emoji]
103
+ notifier.post attachments: [attachment] if attachment
104
+ notifier.ping options[:ping] if options[:ping]
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,3 @@
1
+ module Monit2Slack
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "monit2slack/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "monit2slack"
8
+ spec.version = Monit2Slack::VERSION
9
+ spec.authors = ["Nedim Hadzimahmutovic"]
10
+ spec.email = ["h.nedim@gmail.com"]
11
+
12
+ spec.summary = %q{Post monit status messages to Slack.}
13
+ spec.description = %q{Post monit status messages to Slack.}
14
+ spec.homepage = "https://github.com/inservio/monit2slack"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "bin"
23
+ spec.executables = %w(monit2slack)
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+
30
+ spec.add_dependency "slack-notifier"
31
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monit2slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Nedim Hadzimahmutovic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slack-notifier
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Post monit status messages to Slack.
70
+ email:
71
+ - h.nedim@gmail.com
72
+ executables:
73
+ - monit2slack
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/monit2slack
83
+ - bin/setup
84
+ - example.rb
85
+ - lib/monit2slack.rb
86
+ - lib/monit2slack/version.rb
87
+ - monit2slack.gemspec
88
+ homepage: https://github.com/inservio/monit2slack
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.7.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Post monit status messages to Slack.
112
+ test_files: []