Class: Mihari::Emitters::Webhook
- Inherits:
-
Base
show all
- Defined in:
- lib/mihari/emitters/webhook.rb
Constant Summary
collapse
- DEFAULT_TEMPLATE =
%{
json.rule do
json.id rule.id
json.title rule.title
json.description rule.description
end
json.artifacts artifacts.map(&:data)
json.tags rule.tags.map(&:name)
}
Concerns::Retriable::DEFAULT_CONDITION, Concerns::Retriable::RETRIABLE_ERRORS
Instance Attribute Summary collapse
Attributes inherited from Base
#rule
Attributes inherited from Actor
#options
Instance Method Summary
collapse
Methods inherited from Base
inherited, #result
Methods inherited from Actor
key, key_aliases, keys, #result, #retry_exponential_backoff, #retry_interval, #retry_times, #timeout, type, #validate_configuration!
#retry_on_error
#configuration_keys?
Constructor Details
#initialize(rule:, options: nil, **params) ⇒ Webhook
Returns a new instance of Webhook.
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/mihari/emitters/webhook.rb', line 38
def initialize(rule:, options: nil, **params)
super(rule: rule, options: options)
@url = Addressable::URI.parse(params[:url])
@headers = params[:headers] || {}
@method = params[:method] || "POST"
@template = params[:template] || DEFAULT_TEMPLATE
@artifacts = []
end
|
Instance Attribute Details
19
20
21
|
# File 'lib/mihari/emitters/webhook.rb', line 19
def artifacts
@artifacts
end
|
10
11
12
|
# File 'lib/mihari/emitters/webhook.rb', line 10
def
@headers
end
|
#method ⇒ String
13
14
15
|
# File 'lib/mihari/emitters/webhook.rb', line 13
def method
@method
end
|
#template ⇒ String
16
17
18
|
# File 'lib/mihari/emitters/webhook.rb', line 16
def template
@template
end
|
#url ⇒ Addressable::URI?
7
8
9
|
# File 'lib/mihari/emitters/webhook.rb', line 7
def url
@url
end
|
Instance Method Details
#call(artifacts) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/mihari/emitters/webhook.rb', line 68
def call(artifacts)
return if artifacts.empty?
@artifacts = artifacts
case method
when "GET"
http.get(url).body.to_s
when "POST"
http.post(url, json: json).body.to_s
end
end
|
52
53
54
55
56
|
# File 'lib/mihari/emitters/webhook.rb', line 52
def configured?
return false if url.nil?
%w[http https].include? url.scheme.downcase
end
|
#target ⇒ String
61
62
63
|
# File 'lib/mihari/emitters/webhook.rb', line 61
def target
URI(url).host || "N/A"
end
|