sensu-plugins-microsoft-teams 0.0.1 → 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 +4 -4
- data/bin/handler-microsoft-teams.rb +123 -0
- data/lib/sensu-plugins-microsoft-teams/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9647ccc1cbdd3efea9691efb8032e87e3635b0a
|
4
|
+
data.tar.gz: b92a921ae45a3f9c55503e983da3f701cce45fd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cc4167707d7cda39cbe48e2571811fb301520bf30b52dee5b8d03e311d50ed6e3b6d5460452d941b51220bb6f1db6b45e9ecbcd8a00ee510259076915b36dce
|
7
|
+
data.tar.gz: 2a3b156524a994b137a00ba858327a26a2c38acbdc4fb0458f31c051b6c09af69678cff1c9da3d1e0dfc73279bb03b6244f2401d52d898c1e3287918a0046b86
|
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2017 Jose Gaspar and contributors.
|
4
|
+
#
|
5
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
6
|
+
# for details.
|
7
|
+
#
|
8
|
+
# In order to use this plugin, you must first configure an incoming webhook
|
9
|
+
# integration in Microsoft Teams. You can create the required webhook by visiting
|
10
|
+
# https://outlook.office.com/connectors/publish
|
11
|
+
#
|
12
|
+
# After you configure your webhook, you'll need the webhook URL from the connector.
|
13
|
+
|
14
|
+
require 'sensu-handler'
|
15
|
+
require 'json'
|
16
|
+
|
17
|
+
class SLack < Sendsu::Handler
|
18
|
+
option :json_config,
|
19
|
+
description: 'Configuration name',
|
20
|
+
short: '-j JSONCONFIG',
|
21
|
+
long: '--json JSONCONFIG',
|
22
|
+
default: 'microsoft-teams'
|
23
|
+
|
24
|
+
def microsoft_teams_webhook_url
|
25
|
+
get_setting('webhook_url')
|
26
|
+
end
|
27
|
+
|
28
|
+
def proxy_address
|
29
|
+
get_setting('proxy_address')
|
30
|
+
end
|
31
|
+
|
32
|
+
def proxy_port
|
33
|
+
get_setting('proxy_port')
|
34
|
+
end
|
35
|
+
|
36
|
+
def proxy_username
|
37
|
+
get_setting('proxy_username')
|
38
|
+
end
|
39
|
+
|
40
|
+
def proxy_password
|
41
|
+
get_setting('proxy_password')
|
42
|
+
end
|
43
|
+
|
44
|
+
def dashboard_uri
|
45
|
+
get_setting('dashboard')
|
46
|
+
end
|
47
|
+
|
48
|
+
def incident_key
|
49
|
+
if dashboard_uri.nil?
|
50
|
+
@event['client']['name'] + '/' + @event['check']['name']
|
51
|
+
else
|
52
|
+
"<#{dashboard_uri}#{@event['client']['name']}?check=#{@event['check']['name']}|#{@event['client']['name']}/#{@event['check']['name']}>"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_setting(name)
|
57
|
+
settings[config[:json_config]][name]
|
58
|
+
end
|
59
|
+
|
60
|
+
def handle
|
61
|
+
description = @event['check']['notification']
|
62
|
+
post_data("#{incident_key}: #{description}")
|
63
|
+
end
|
64
|
+
|
65
|
+
def post_data(body)
|
66
|
+
uri = URI(microsoft_teams_webhook_url)
|
67
|
+
http = if proxy_address.nil?
|
68
|
+
Net::HTTP.new(uri.host, uri.port)
|
69
|
+
else
|
70
|
+
Net::HTTP::Proxy(proxy.address, proxy_port, proxy_username, proxy_password).new(uri.host, uri.port)
|
71
|
+
end
|
72
|
+
http.use_ssl = true
|
73
|
+
|
74
|
+
req = Net::HTTP::Post.new("#{uri.path}?#{uri.query}", 'Content-Type' => 'application/json')
|
75
|
+
|
76
|
+
payload = {
|
77
|
+
"@type" => "MessageCard",
|
78
|
+
"@context" => "http://schema.org/extensions",
|
79
|
+
"themeColor" => color,
|
80
|
+
"title" => "#{@event['client']['address']} - #{translate_status}",
|
81
|
+
"summary" => "#{@event['client']['address']} - #{translate_status}",
|
82
|
+
"sections" => [ { "text" => "Hello World" } ]
|
83
|
+
}
|
84
|
+
|
85
|
+
req.body = payload.to_json
|
86
|
+
|
87
|
+
response = http.request(req)
|
88
|
+
verify_response(response)
|
89
|
+
end
|
90
|
+
|
91
|
+
def verify_response(response)
|
92
|
+
case response
|
93
|
+
when Net::HTTPSuccess
|
94
|
+
true
|
95
|
+
else
|
96
|
+
raise response.error!
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def color
|
101
|
+
color = {
|
102
|
+
0 => '#36a64f',
|
103
|
+
1 => '#FFCC00',
|
104
|
+
2 => '#FF0000',
|
105
|
+
3 => '#6600CC'
|
106
|
+
}
|
107
|
+
color.fetch(check_status.to_i)
|
108
|
+
end
|
109
|
+
|
110
|
+
def check_status
|
111
|
+
@event['check']['status']
|
112
|
+
end
|
113
|
+
|
114
|
+
def translate_status
|
115
|
+
status = {
|
116
|
+
0 => :OK,
|
117
|
+
1 => :WARNING,
|
118
|
+
2 => :CRITICAL,
|
119
|
+
3 => :UNKNOWN
|
120
|
+
}
|
121
|
+
status[check_status.to_i]
|
122
|
+
end
|
123
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-microsoft-teams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
@@ -138,13 +138,15 @@ dependencies:
|
|
138
138
|
version: '0.8'
|
139
139
|
description: Sensu plugins for interfacing with Microsoft Teams
|
140
140
|
email: "<sensu-users@googlegroups.com>"
|
141
|
-
executables:
|
141
|
+
executables:
|
142
|
+
- handler-microsoft-teams.rb
|
142
143
|
extensions: []
|
143
144
|
extra_rdoc_files: []
|
144
145
|
files:
|
145
146
|
- CHANGELOG.md
|
146
147
|
- LICENSE
|
147
148
|
- README.md
|
149
|
+
- bin/handler-microsoft-teams.rb
|
148
150
|
- lib/sensu-plugins-microsoft-teams.rb
|
149
151
|
- lib/sensu-plugins-microsoft-teams/version.rb
|
150
152
|
homepage: https://github.com/sensu-plugins/sensu-plugins-microsoft-teams
|