cgp_teams_connector 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 +7 -0
- data/.rspec +3 -0
- data/.rspec_status +4 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +20 -0
- data/Rakefile +8 -0
- data/cgp_teams_connector.gemspec +31 -0
- data/lib/cgp_teams_connector/configuration.rb +21 -0
- data/lib/cgp_teams_connector/initializer.rb +11 -0
- data/lib/cgp_teams_connector/templates/wide_adaptive_card.json.erb +19 -0
- data/lib/cgp_teams_connector/version.rb +5 -0
- data/lib/cgp_teams_connector.rb +56 -0
- data/sig/cgp_teams_connector.rbs +4 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 217d25edd1f919964c84812bb532f2f4e9888b46726e9af2c51e90594e1f984e
|
4
|
+
data.tar.gz: 6614fefbc11cd690a53a452ed931f1fab7ed91f5311fd5dca0189fe38ee5f2a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5c596a5bdb1c93b4f00cc2bc78c1c9aba49be0dbe0b09927f4b0b10c5af460625bc8404102cd4f9da02588b260b33affd5d78fa5f6be167697bbb95dbd452e42
|
7
|
+
data.tar.gz: '0293dcde0dd00786f33038dd0998dd45860ca6548b129f0486d573e081a1e3701d396dacdd3d2ab124beb83efd79180b78e8e2c5af1e91864176f916f0471dfd'
|
data/.rspec
ADDED
data/.rspec_status
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 masciugo
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# CgpTeamsConnector
|
2
|
+
|
3
|
+
Wrapper od teams_connector gem for CGP microservices usage
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile after sidekiq (if in use):
|
8
|
+
|
9
|
+
$ gem "cgp_teams_connector"
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Two notifications example:
|
14
|
+
|
15
|
+
$ CgpTeamsConnector.notify_error(:server, exception, request.uuid)
|
16
|
+
$ CgpTeamsConnector.notify_error(:job, exception, job['jid'])
|
17
|
+
|
18
|
+
## License
|
19
|
+
|
20
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/cgp_teams_connector/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cgp_teams_connector"
|
7
|
+
spec.version = CgpTeamsConnector::VERSION
|
8
|
+
spec.authors = ["masciugo"]
|
9
|
+
spec.email = ["masciugo@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A gem to send error notifications to Microsoft Teams"
|
12
|
+
spec.description = "Uses teams_connector to send adaptive card messages for server/job errors"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 3.1.0"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(__dir__) do
|
19
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
(File.expand_path(f) == __FILE__) ||
|
21
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "teams_connector", "~> 0.1"
|
27
|
+
spec.add_dependency "rails", "~> 6.0"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "byebug"
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "teams_connector"
|
2
|
+
|
3
|
+
module CgpTeamsConnector
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :channel, :ignored_exceptions, :method, :app_name
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@ignored_exceptions = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def method=(arg)
|
12
|
+
TeamsConnector.configuration.method=(arg)
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_channel=(arg)
|
16
|
+
TeamsConnector.configuration.channel :default, arg
|
17
|
+
TeamsConnector.configuration.default = :default
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "teams_connector"
|
2
|
+
|
3
|
+
class TeamsConnector::Notification
|
4
|
+
def find_template
|
5
|
+
spec = Gem::Specification.find_by_name('cgp_teams_connector')
|
6
|
+
path = File.join(spec.gem_dir,'lib', 'cgp_teams_connector','templates', "#{@template}.json.erb")
|
7
|
+
raise ArgumentError, "The template '#{@template}' is not available." unless File.exist? path
|
8
|
+
path
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"type": "message",
|
3
|
+
"attachments": [
|
4
|
+
{
|
5
|
+
"contentType": "application/vnd.microsoft.card.adaptive",
|
6
|
+
"contentUrl": null,
|
7
|
+
"padding": "None",
|
8
|
+
"content": {
|
9
|
+
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
|
10
|
+
"type": "AdaptiveCard",
|
11
|
+
"version": "1.2",
|
12
|
+
"msteams": { "width": "full" },
|
13
|
+
"body": [
|
14
|
+
<%= @content[:card].map {|k| k.to_json}.join(", ") %>
|
15
|
+
]
|
16
|
+
}
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "cgp_teams_connector/version"
|
3
|
+
require_relative "cgp_teams_connector/initializer"
|
4
|
+
require_relative "cgp_teams_connector/configuration"
|
5
|
+
|
6
|
+
module CgpTeamsConnector
|
7
|
+
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :config
|
12
|
+
|
13
|
+
def configure
|
14
|
+
self.config ||= Configuration.new
|
15
|
+
yield(config) if block_given?
|
16
|
+
end
|
17
|
+
|
18
|
+
def notify_error(type, exception, id = nil)
|
19
|
+
return if config.ignored_exceptions.include?(exception.class)
|
20
|
+
|
21
|
+
content = {
|
22
|
+
card: [
|
23
|
+
{
|
24
|
+
type: "Container",
|
25
|
+
items: [
|
26
|
+
{
|
27
|
+
type: "TextBlock",
|
28
|
+
text: "[#{config.app_name}] #{type.to_s.upcase} ERROR",
|
29
|
+
size: "ExtraLarge",
|
30
|
+
weight: "Bolder",
|
31
|
+
color: "Attention"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
type: "TextBlock",
|
35
|
+
text: "**#{exception.class}**#{id ? " [#{type} ID: #{id}]" : nil}"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
type: "CodeBlock",
|
39
|
+
codeSnippet: exception.message,
|
40
|
+
language: "PlainText"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
type: "CodeBlock",
|
44
|
+
codeSnippet: exception.backtrace.first(5).join("\n"),
|
45
|
+
language: "bash"
|
46
|
+
}
|
47
|
+
]
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
msg = TeamsConnector::Notification::Message.new(:wide_adaptive_card, nil, content)
|
52
|
+
msg.deliver_later
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cgp_teams_connector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- masciugo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: teams_connector
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Uses teams_connector to send adaptive card messages for server/job errors
|
70
|
+
email:
|
71
|
+
- masciugo@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".rspec"
|
77
|
+
- ".rspec_status"
|
78
|
+
- CHANGELOG.md
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- cgp_teams_connector.gemspec
|
83
|
+
- lib/cgp_teams_connector.rb
|
84
|
+
- lib/cgp_teams_connector/configuration.rb
|
85
|
+
- lib/cgp_teams_connector/initializer.rb
|
86
|
+
- lib/cgp_teams_connector/templates/wide_adaptive_card.json.erb
|
87
|
+
- lib/cgp_teams_connector/version.rb
|
88
|
+
- sig/cgp_teams_connector.rbs
|
89
|
+
homepage:
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 3.1.0
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubygems_version: 3.4.14
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A gem to send error notifications to Microsoft Teams
|
112
|
+
test_files: []
|