pager_tree-integrations 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/pager_tree/integrations/alert.rb +3 -1
  3. data/app/models/pager_tree/integrations/app_dynamics/v3.rb +74 -0
  4. data/app/models/pager_tree/integrations/auvik/v3.rb +94 -0
  5. data/app/models/pager_tree/integrations/aws_cloudwatch/v3.rb +108 -0
  6. data/app/models/pager_tree/integrations/azure_monitor/v3.rb +79 -0
  7. data/app/models/pager_tree/integrations/boolean_store_accessor.rb +42 -0
  8. data/app/models/pager_tree/integrations/channel/hangouts/v3.rb +176 -0
  9. data/app/models/pager_tree/integrations/channel/mattermost/v3.rb +6 -0
  10. data/app/models/pager_tree/integrations/channel/microsoft_teams/v3.rb +142 -0
  11. data/app/models/pager_tree/integrations/channel/slack/v3.rb +136 -0
  12. data/app/models/pager_tree/integrations/cronitor/v3.rb +64 -0
  13. data/app/models/pager_tree/integrations/datadog/v3.rb +72 -0
  14. data/app/models/pager_tree/integrations/dead_mans_snitch/v3.rb +76 -0
  15. data/app/models/pager_tree/integrations/elast_alert/v3.rb +63 -0
  16. data/app/models/pager_tree/integrations/form/v3.rb +114 -0
  17. data/app/models/pager_tree/integrations/freshdesk/v3.rb +103 -0
  18. data/app/models/pager_tree/integrations/freshservice/v3.rb +103 -0
  19. data/app/models/pager_tree/integrations/grafana/v3.rb +67 -0
  20. data/app/models/pager_tree/integrations/healthchecks/v3.rb +68 -0
  21. data/app/models/pager_tree/integrations/honeybadger/v3.rb +76 -0
  22. data/app/models/pager_tree/integrations/hyperping/v3.rb +60 -0
  23. data/app/models/pager_tree/integrations/integration.rb +27 -5
  24. data/app/models/pager_tree/integrations/jira_server/v3.rb +61 -0
  25. data/app/models/pager_tree/integrations/jotform/v3.rb +50 -0
  26. data/app/models/pager_tree/integrations/kapacitor/v3.rb +65 -0
  27. data/app/models/pager_tree/integrations/logic_monitor/v3.rb +79 -0
  28. data/app/models/pager_tree/integrations/mattermost/outgoing_webhook/v3.rb +77 -0
  29. data/app/models/pager_tree/integrations/new_relic/v3.rb +67 -0
  30. data/app/models/pager_tree/integrations/outgoing_event.rb +2 -0
  31. data/app/models/pager_tree/integrations/outgoing_webhook/v3.rb +37 -6
  32. data/app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb +8 -6
  33. data/app/models/pager_tree/integrations/outgoing_webhook_delivery.rb +1 -1
  34. data/app/models/pager_tree/integrations/pingdom/v3.rb +71 -0
  35. data/app/models/pager_tree/integrations/prometheus/v3.rb +79 -0
  36. data/app/models/pager_tree/integrations/prtg/v3.rb +58 -0
  37. data/app/models/pager_tree/integrations/server_guard24/v3.rb +74 -0
  38. data/app/models/pager_tree/integrations/site24x7/v3.rb +68 -0
  39. data/app/models/pager_tree/integrations/solar_winds/v3.rb +77 -0
  40. data/app/models/pager_tree/integrations/stackdriver/v3.rb +60 -0
  41. data/app/models/pager_tree/integrations/status_cake/v3.rb +65 -0
  42. data/app/models/pager_tree/integrations/twilio/incoming_sms/v3.rb +78 -0
  43. data/app/models/pager_tree/integrations/typeform/v3.rb +43 -0
  44. data/app/models/pager_tree/integrations/uptime/v3.rb +68 -0
  45. data/app/models/pager_tree/integrations/uptime_robot/v3.rb +79 -0
  46. data/app/models/pager_tree/integrations/webhook/v3.rb +112 -0
  47. data/app/models/pager_tree/integrations/zendesk/v3.rb +83 -0
  48. data/app/views/pager_tree/integrations/app_dynamics/v3/_form_options.html.erb +0 -0
  49. data/app/views/pager_tree/integrations/app_dynamics/v3/_show_options.html.erb +0 -0
  50. data/app/views/pager_tree/integrations/auvik/v3/_form_options.html.erb +0 -0
  51. data/app/views/pager_tree/integrations/auvik/v3/_show_options.html.erb +0 -0
  52. data/app/views/pager_tree/integrations/aws_cloudwatch/v3/_form_options.html.erb +0 -0
  53. data/app/views/pager_tree/integrations/aws_cloudwatch/v3/_show_options.html.erb +0 -0
  54. data/app/views/pager_tree/integrations/azure_monitor/v3/_form_options.html.erb +0 -0
  55. data/app/views/pager_tree/integrations/azure_monitor/v3/_show_options.html.erb +0 -0
  56. data/app/views/pager_tree/integrations/channel/hangouts/v3/_form_options.html.erb +34 -0
  57. data/app/views/pager_tree/integrations/channel/hangouts/v3/_show_options.html.erb +40 -0
  58. data/app/views/pager_tree/integrations/channel/mattermost/v3/_form_options.html.erb +1 -0
  59. data/app/views/pager_tree/integrations/channel/mattermost/v3/_show_options.html.erb +1 -0
  60. data/app/views/pager_tree/integrations/channel/microsoft_teams/v3/_form_options.html.erb +34 -0
  61. data/app/views/pager_tree/integrations/channel/microsoft_teams/v3/_show_options.html.erb +40 -0
  62. data/app/views/pager_tree/integrations/channel/slack/v3/_form_options.html.erb +34 -0
  63. data/app/views/pager_tree/integrations/channel/slack/v3/_show_options.html.erb +40 -0
  64. data/app/views/pager_tree/integrations/cronitor/v3/_form_options.html.erb +0 -0
  65. data/app/views/pager_tree/integrations/cronitor/v3/_show_options.html.erb +0 -0
  66. data/app/views/pager_tree/integrations/datadog/v3/_form_options.html.erb +0 -0
  67. data/app/views/pager_tree/integrations/datadog/v3/_show_options.html.erb +0 -0
  68. data/app/views/pager_tree/integrations/dead_mans_snitch/v3/_form_options.html.erb +0 -0
  69. data/app/views/pager_tree/integrations/dead_mans_snitch/v3/_show_options.html.erb +0 -0
  70. data/app/views/pager_tree/integrations/elast_alert/v3/_form_options.html.erb +0 -0
  71. data/app/views/pager_tree/integrations/elast_alert/v3/_show_options.html.erb +0 -0
  72. data/app/views/pager_tree/integrations/form/v3/_form_options.html.erb +64 -0
  73. data/app/views/pager_tree/integrations/form/v3/_show_options.html.erb +122 -0
  74. data/app/views/pager_tree/integrations/freshdesk/v3/_form_options.html.erb +0 -0
  75. data/app/views/pager_tree/integrations/freshdesk/v3/_show_options.html.erb +0 -0
  76. data/app/views/pager_tree/integrations/freshservice/v3/_form_options.html.erb +0 -0
  77. data/app/views/pager_tree/integrations/freshservice/v3/_show_options.html.erb +0 -0
  78. data/app/views/pager_tree/integrations/grafana/v3/_form_options.html.erb +0 -0
  79. data/app/views/pager_tree/integrations/grafana/v3/_show_options.html.erb +0 -0
  80. data/app/views/pager_tree/integrations/healthchecks/v3/_form_options.html.erb +0 -0
  81. data/app/views/pager_tree/integrations/healthchecks/v3/_show_options.html.erb +0 -0
  82. data/app/views/pager_tree/integrations/honeybadger/v3/_form_options.html.erb +7 -0
  83. data/app/views/pager_tree/integrations/honeybadger/v3/_show_options.html.erb +12 -0
  84. data/app/views/pager_tree/integrations/hyperping/v3/_form_options.html.erb +0 -0
  85. data/app/views/pager_tree/integrations/hyperping/v3/_show_options.html.erb +0 -0
  86. data/app/views/pager_tree/integrations/jira_server/v3/_form_options.html.erb +7 -0
  87. data/app/views/pager_tree/integrations/jira_server/v3/_show_options.html.erb +12 -0
  88. data/app/views/pager_tree/integrations/jotform/v3/_form_options.html.erb +0 -0
  89. data/app/views/pager_tree/integrations/jotform/v3/_show_options.html.erb +0 -0
  90. data/app/views/pager_tree/integrations/kapacitor/v3/_form_options.html.erb +0 -0
  91. data/app/views/pager_tree/integrations/kapacitor/v3/_show_options.html.erb +0 -0
  92. data/app/views/pager_tree/integrations/logic_monitor/v3/_form_options.html.erb +0 -0
  93. data/app/views/pager_tree/integrations/logic_monitor/v3/_show_options.html.erb +0 -0
  94. data/app/views/pager_tree/integrations/mattermost/outgoing_webhook/v3/_form_options.html.erb +7 -0
  95. data/app/views/pager_tree/integrations/mattermost/outgoing_webhook/v3/_show_options.html.erb +12 -0
  96. data/app/views/pager_tree/integrations/new_relic/v3/_form_options.html.erb +0 -0
  97. data/app/views/pager_tree/integrations/new_relic/v3/_show_options.html.erb +0 -0
  98. data/app/views/pager_tree/integrations/outgoing_webhook/v3/_form_options.html.erb +12 -4
  99. data/app/views/pager_tree/integrations/outgoing_webhook/v3/_show_options.html.erb +20 -2
  100. data/app/views/pager_tree/integrations/pingdom/v3/_form_options.html.erb +0 -0
  101. data/app/views/pager_tree/integrations/pingdom/v3/_show_options.html.erb +0 -0
  102. data/app/views/pager_tree/integrations/prometheus/v3/_form_options.html.erb +0 -0
  103. data/app/views/pager_tree/integrations/prometheus/v3/_show_options.html.erb +0 -0
  104. data/app/views/pager_tree/integrations/prtg/v3/_form_options.html.erb +0 -0
  105. data/app/views/pager_tree/integrations/prtg/v3/_show_options.html.erb +0 -0
  106. data/app/views/pager_tree/integrations/server_guard24/v3/_form_options.html.erb +7 -0
  107. data/app/views/pager_tree/integrations/server_guard24/v3/_show_options.html.erb +12 -0
  108. data/app/views/pager_tree/integrations/site24x7/v3/_form_options.html.erb +0 -0
  109. data/app/views/pager_tree/integrations/site24x7/v3/_show_options.html.erb +0 -0
  110. data/app/views/pager_tree/integrations/solar_winds/v3/_form_options.html.erb +0 -0
  111. data/app/views/pager_tree/integrations/solar_winds/v3/_show_options.html.erb +0 -0
  112. data/app/views/pager_tree/integrations/stackdriver/v3/_form_options.html.erb +0 -0
  113. data/app/views/pager_tree/integrations/stackdriver/v3/_show_options.html.erb +0 -0
  114. data/app/views/pager_tree/integrations/status_cake/v3/_form_options.html.erb +0 -0
  115. data/app/views/pager_tree/integrations/status_cake/v3/_show_options.html.erb +0 -0
  116. data/app/views/pager_tree/integrations/twilio/incoming_sms/v3/_form_options.html.erb +0 -0
  117. data/app/views/pager_tree/integrations/twilio/incoming_sms/v3/_show_options.html.erb +0 -0
  118. data/app/views/pager_tree/integrations/typeform/v3/_form_options.html.erb +0 -0
  119. data/app/views/pager_tree/integrations/typeform/v3/_show_options.html.erb +0 -0
  120. data/app/views/pager_tree/integrations/uptime/v3/_form_options.html.erb +0 -0
  121. data/app/views/pager_tree/integrations/uptime/v3/_show_options.html.erb +0 -0
  122. data/app/views/pager_tree/integrations/uptime_robot/v3/_form_options.html.erb +0 -0
  123. data/app/views/pager_tree/integrations/uptime_robot/v3/_show_options.html.erb +0 -0
  124. data/app/views/pager_tree/integrations/webhook/v3/_form_options.html.erb +15 -0
  125. data/app/views/pager_tree/integrations/webhook/v3/_show_options.html.erb +26 -0
  126. data/app/views/pager_tree/integrations/zendesk/v3/_form_options.html.erb +0 -0
  127. data/app/views/pager_tree/integrations/zendesk/v3/_show_options.html.erb +0 -0
  128. data/config/locales/en.yml +83 -23
  129. data/lib/generators/integration/integration_generator.rb +2 -1
  130. data/lib/generators/integration/templates/model.rb.tt +16 -6
  131. data/lib/pager_tree/integrations/version.rb +1 -1
  132. metadata +121 -3
@@ -0,0 +1,142 @@
1
+ module PagerTree::Integrations
2
+ class Channel::MicrosoftTeams::V3 < Integration
3
+ OPTIONS = [
4
+ {key: :incoming_webhook_url, type: :string, default: nil},
5
+ {key: :alert_open, type: :boolean, default: false},
6
+ {key: :alert_acknowledged, type: :boolean, default: false},
7
+ {key: :alert_resolved, type: :boolean, default: false},
8
+ {key: :alert_dropped, type: :boolean, default: false},
9
+ {key: :outgoing_rules, type: :string, default: nil}
10
+ ]
11
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
12
+
13
+ validates :option_incoming_webhook_url, presence: true, url: {no_local: true}
14
+
15
+ after_initialize do
16
+ self.option_incoming_webhook_url ||= nil
17
+ self.option_alert_open ||= false
18
+ self.option_alert_acknowledged ||= false
19
+ self.option_alert_resolved ||= false
20
+ self.option_alert_dropped ||= false
21
+ self.option_outgoing_rules ||= ""
22
+ end
23
+
24
+ def adapter_supports_incoming?
25
+ false
26
+ end
27
+
28
+ def adapter_supports_outgoing?
29
+ true
30
+ end
31
+
32
+ def adapter_show_outgoing_webhook_delivery?
33
+ true
34
+ end
35
+
36
+ def adapter_supports_title_template?
37
+ false
38
+ end
39
+
40
+ def adapter_supports_description_template?
41
+ false
42
+ end
43
+
44
+ def adapter_outgoing_interest?(event_name)
45
+ try("option_#{event_name}") || false
46
+ end
47
+
48
+ def adapter_process_outgoing
49
+ url = adapter_outgoing_event.outgoing_rules_data.dig("webhook_url") || self.option_incoming_webhook_url
50
+ body = _blocks.merge(adapter_outgoing_event.outgoing_rules_data.except("webhook_url"))
51
+
52
+ outgoing_webhook_delivery = OutgoingWebhookDelivery.factory(
53
+ resource: self,
54
+ url: url,
55
+ body: body
56
+ )
57
+ outgoing_webhook_delivery.save!
58
+ outgoing_webhook_delivery.deliver_later
59
+
60
+ outgoing_webhook_delivery
61
+ end
62
+
63
+ private
64
+
65
+ def _alert
66
+ @_alert ||= adapter_outgoing_event.item
67
+ end
68
+
69
+ def _blocks
70
+ {
71
+ "@type": "MessageCard",
72
+ "@context": "http://schema.org/extensions",
73
+ themeColor: _color,
74
+ summary: _title,
75
+ sections: [{
76
+ activityTitle: _title,
77
+ activitySubtitle: _alert.description&.try(:to_plain_text),
78
+ facts: [
79
+ {
80
+ name: "Status",
81
+ value: _alert.status.upcase
82
+ },
83
+ {
84
+ name: "Urgency",
85
+ value: _alert.urgency.upcase
86
+ },
87
+ {
88
+ name: "Created",
89
+ value: _alert.created_at.utc
90
+ },
91
+ {
92
+ name: "Source",
93
+ value: _alert.source&.name
94
+ },
95
+ {
96
+ name: "Destinations",
97
+ value: _alert.alert_destinations&.map { |d| d.destination.name }&.join(", ")
98
+ },
99
+ {
100
+ name: "User",
101
+ value: _alert.alert_responders&.where(role: :incident_commander)&.includes(account_user: :user)&.first&.account_user&.name
102
+ }
103
+ ],
104
+ markdown: true
105
+ }],
106
+ potentialAction: [
107
+ {
108
+ "@context": "http://schema.org",
109
+ "@type": "ViewAction",
110
+ name: "View in PagerTree",
111
+ target: [
112
+ Rails.application.routes.url_helpers.try(:alert_url, _alert, script_name: "/#{_alert.account_id}")
113
+ ]
114
+ }
115
+ ]
116
+ }
117
+ end
118
+
119
+ def _title
120
+ return @_title if @_title.present?
121
+
122
+ @_title = if _alert.incident?
123
+ "Incident ##{_alert.tiny_id} [#{_alert.incident_severity.upcase.dasherize}] #{_alert.incident_message} - #{_alert.title}"
124
+ else
125
+ "Alert ##{_alert.tiny_id} #{_alert.title}"
126
+ end
127
+ end
128
+
129
+ def _color
130
+ case _alert.status
131
+ when "open", "dropped"
132
+ "#ff5252"
133
+ when "acknowledged"
134
+ "#fb8c00"
135
+ when "resolved"
136
+ "#4caf50"
137
+ else
138
+ "#555555"
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,136 @@
1
+ module PagerTree::Integrations
2
+ class Channel::Slack::V3 < Integration
3
+ OPTIONS = [
4
+ {key: :incoming_webhook_url, type: :string, default: nil},
5
+ {key: :alert_open, type: :boolean, default: false},
6
+ {key: :alert_acknowledged, type: :boolean, default: false},
7
+ {key: :alert_resolved, type: :boolean, default: false},
8
+ {key: :alert_dropped, type: :boolean, default: false},
9
+ {key: :outgoing_rules, type: :string, default: nil}
10
+ ]
11
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
12
+
13
+ validates :option_incoming_webhook_url, presence: true, url: {no_local: true}
14
+
15
+ after_initialize do
16
+ self.option_incoming_webhook_url ||= nil
17
+ self.option_alert_open ||= false
18
+ self.option_alert_acknowledged ||= false
19
+ self.option_alert_resolved ||= false
20
+ self.option_alert_dropped ||= false
21
+ self.option_outgoing_rules ||= ""
22
+ end
23
+
24
+ def adapter_supports_incoming?
25
+ false
26
+ end
27
+
28
+ def adapter_supports_outgoing?
29
+ true
30
+ end
31
+
32
+ def adapter_show_outgoing_webhook_delivery?
33
+ true
34
+ end
35
+
36
+ def adapter_supports_title_template?
37
+ false
38
+ end
39
+
40
+ def adapter_supports_description_template?
41
+ false
42
+ end
43
+
44
+ def adapter_outgoing_interest?(event_name)
45
+ try("option_#{event_name}") || false
46
+ end
47
+
48
+ def adapter_process_outgoing
49
+ url = adapter_outgoing_event.outgoing_rules_data.dig("webhook_url") || self.option_incoming_webhook_url
50
+ body = _blocks.merge(adapter_outgoing_event.outgoing_rules_data.except("webhook_url"))
51
+
52
+ outgoing_webhook_delivery = OutgoingWebhookDelivery.factory(
53
+ resource: self,
54
+ url: url,
55
+ body: body
56
+ )
57
+ outgoing_webhook_delivery.save!
58
+ outgoing_webhook_delivery.deliver_later
59
+
60
+ outgoing_webhook_delivery
61
+ end
62
+
63
+ private
64
+
65
+ def _alert
66
+ @_alert ||= adapter_outgoing_event.item
67
+ end
68
+
69
+ def _blocks
70
+ @_blocks ||= {
71
+ username: "PagerTree",
72
+ icon_url: "https://pagertree.com/assets/img/logo/pagertree-icon-256-256.png",
73
+ text: "",
74
+ attachments: [
75
+ {
76
+ fallback: _title,
77
+ color: _color,
78
+ title: _title,
79
+ title_link: Rails.application.routes.url_helpers.try(:alert_url, _alert, script_name: "/#{_alert.account_id}"),
80
+ text: _alert.description&.try(:to_plain_text),
81
+ fields: [
82
+ {
83
+ title: "Status",
84
+ value: _alert.status,
85
+ short: "true"
86
+ },
87
+ {
88
+ title: "Urgency",
89
+ value: _alert.urgency,
90
+ short: "true"
91
+ },
92
+ {
93
+ title: "Created",
94
+ value: "<!date^#{_alert.created_at.utc.to_i}^{date_num} {time_secs}|#{_alert.created_at.utc.to_i}>",
95
+ short: "true"
96
+ },
97
+ {
98
+ title: "Source",
99
+ value: _alert.source&.name,
100
+ short: "true"
101
+ },
102
+ {
103
+ title: "Destinations",
104
+ value: _alert.alert_destinations&.map { |d| d.destination.name }&.join(", "),
105
+ short: "false"
106
+ }
107
+ ]
108
+ }
109
+ ]
110
+ }
111
+ end
112
+
113
+ def _title
114
+ return @_title if @_title.present?
115
+
116
+ @_title = if _alert.incident?
117
+ "Incident ##{_alert.tiny_id} [#{_alert.incident_severity.upcase.dasherize}] #{_alert.incident_message} - #{_alert.title}"
118
+ else
119
+ "Alert ##{_alert.tiny_id} #{_alert.title}"
120
+ end
121
+ end
122
+
123
+ def _color
124
+ case _alert.status
125
+ when "open", "dropped"
126
+ "#ff5252"
127
+ when "acknowledged"
128
+ "#fb8c00"
129
+ when "resolved"
130
+ "#4caf50"
131
+ else
132
+ "#555555"
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,64 @@
1
+ module PagerTree::Integrations
2
+ class Cronitor::V3 < Integration
3
+ OPTIONS = []
4
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
5
+
6
+ after_initialize do
7
+ end
8
+
9
+ def adapter_supports_incoming?
10
+ true
11
+ end
12
+
13
+ def adapter_supports_outgoing?
14
+ false
15
+ end
16
+
17
+ def adapter_incoming_can_defer?
18
+ true
19
+ end
20
+
21
+ def adapter_thirdparty_id
22
+ adapter_incoming_request_params.dig("id")
23
+ end
24
+
25
+ def adapter_action
26
+ case _type
27
+ when "Alert" then :create
28
+ when "Recovery" then :resolve
29
+ else
30
+ :other
31
+ end
32
+ end
33
+
34
+ def adapter_process_create
35
+ Alert.new(
36
+ title: _title,
37
+ description: _description,
38
+ thirdparty_id: adapter_thirdparty_id,
39
+ dedup_keys: [adapter_thirdparty_id],
40
+ additional_data: _additional_datums
41
+ )
42
+ end
43
+
44
+ private
45
+
46
+ def _title
47
+ adapter_incoming_request_params.dig("monitor")
48
+ end
49
+
50
+ def _description
51
+ adapter_incoming_request_params.dig("description")
52
+ end
53
+
54
+ def _type
55
+ adapter_incoming_request_params.dig("type")
56
+ end
57
+
58
+ def _additional_datums
59
+ [
60
+ AdditionalDatum.new(format: "text", label: "Rule Violated", value: adapter_incoming_request_params.dig("rule"))
61
+ ]
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,72 @@
1
+ module PagerTree::Integrations
2
+ class Datadog::V3 < Integration
3
+ OPTIONS = []
4
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
5
+
6
+ after_initialize do
7
+ end
8
+
9
+ def adapter_supports_incoming?
10
+ true
11
+ end
12
+
13
+ def adapter_supports_outgoing?
14
+ false
15
+ end
16
+
17
+ def adapter_incoming_can_defer?
18
+ true
19
+ end
20
+
21
+ def adapter_thirdparty_id
22
+ adapter_incoming_request_params.dig("ALERT_ID")
23
+ end
24
+
25
+ def adapter_action
26
+ case _transition
27
+ when "Triggered" then :create
28
+ when "Recovered" then :resolve
29
+ else
30
+ :other
31
+ end
32
+ end
33
+
34
+ def adapter_process_create
35
+ Alert.new(
36
+ title: _title,
37
+ description: _description,
38
+ thirdparty_id: adapter_thirdparty_id,
39
+ dedup_keys: [adapter_thirdparty_id, adapter_incoming_request_params.dig("AGGREG_KEY")].compact,
40
+ additional_data: _additional_datums,
41
+ tags: _tags
42
+ )
43
+ end
44
+
45
+ private
46
+
47
+ def _title
48
+ adapter_incoming_request_params.dig("ALERT_TITLE")
49
+ end
50
+
51
+ def _description
52
+ adapter_incoming_request_params.dig("ALERT_STATUS")
53
+ end
54
+
55
+ def _tags
56
+ (adapter_incoming_request_params.dig("TAGS") || "").split(",").map(&:strip).uniq.compact
57
+ end
58
+
59
+ def _transition
60
+ adapter_incoming_request_params.dig("ALERT_TRANSITION")
61
+ end
62
+
63
+ def _additional_datums
64
+ [
65
+ AdditionalDatum.new(format: "link", label: "Link", value: adapter_incoming_request_params.dig("LINK")),
66
+ AdditionalDatum.new(format: "text", label: "Priority", value: adapter_incoming_request_params.dig("PRIORITY")),
67
+ AdditionalDatum.new(format: "text", label: "Event Type", value: adapter_incoming_request_params.dig("EVENT_TYPE")),
68
+ AdditionalDatum.new(format: "text", label: "Event Title", value: adapter_incoming_request_params.dig("EVENT_TITLE"))
69
+ ]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,76 @@
1
+ module PagerTree::Integrations
2
+ class DeadMansSnitch::V3 < Integration
3
+ OPTIONS = []
4
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
5
+
6
+ after_initialize do
7
+ end
8
+
9
+ def adapter_supports_incoming?
10
+ true
11
+ end
12
+
13
+ def adapter_supports_outgoing?
14
+ false
15
+ end
16
+
17
+ def adapter_incoming_can_defer?
18
+ true
19
+ end
20
+
21
+ def adapter_thirdparty_id
22
+ adapter_incoming_request_params.dig("data", "snitch", "token")
23
+ end
24
+
25
+ def adapter_action
26
+ if _type == "snitch.missing" && _current_status == "missing" && _previous_status == "healthy"
27
+ :create
28
+ elsif _type == "snitch.reporting" && _current_status == "healthy" && _previous_status == "missing"
29
+ :resolve
30
+ else
31
+ :other
32
+ end
33
+ end
34
+
35
+ def adapter_process_create
36
+ Alert.new(
37
+ title: _title,
38
+ description: _description,
39
+ thirdparty_id: adapter_thirdparty_id,
40
+ dedup_keys: [adapter_thirdparty_id],
41
+ additional_data: _additional_datums,
42
+ tags: _tags
43
+ )
44
+ end
45
+
46
+ private
47
+
48
+ def _type
49
+ adapter_incoming_request_params.dig("type")
50
+ end
51
+
52
+ def _current_status
53
+ adapter_incoming_request_params.dig("data", "snitch", "status")
54
+ end
55
+
56
+ def _previous_status
57
+ adapter_incoming_request_params.dig("data", "snitch", "previous_status")
58
+ end
59
+
60
+ def _title
61
+ adapter_incoming_request_params.dig("data", "snitch", "name")
62
+ end
63
+
64
+ def _description
65
+ adapter_incoming_request_params.dig("data", "snitch", "notes")
66
+ end
67
+
68
+ def _tags
69
+ adapter_incoming_request_params.dig("data", "snitch", "tags")
70
+ end
71
+
72
+ def _additional_datums
73
+ []
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,63 @@
1
+ module PagerTree::Integrations
2
+ class ElastAlert::V3 < Integration
3
+ OPTIONS = []
4
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
5
+
6
+ after_initialize do
7
+ end
8
+
9
+ def adapter_supports_incoming?
10
+ true
11
+ end
12
+
13
+ def adapter_supports_outgoing?
14
+ false
15
+ end
16
+
17
+ def adapter_incoming_can_defer?
18
+ true
19
+ end
20
+
21
+ def adapter_thirdparty_id
22
+ adapter_incoming_request_params.dig("Id")
23
+ end
24
+
25
+ def adapter_action
26
+ case _event_type
27
+ when "create" then :create
28
+ when "resolve" then :resolve
29
+ else
30
+ :other
31
+ end
32
+ end
33
+
34
+ def adapter_process_create
35
+ Alert.new(
36
+ title: _title,
37
+ description: _description,
38
+ thirdparty_id: adapter_thirdparty_id,
39
+ dedup_keys: [adapter_thirdparty_id],
40
+ additional_data: _additional_datums
41
+ )
42
+ end
43
+
44
+ private
45
+
46
+ # See https://github.com/Yelp/elastalert/pull/2001 for details
47
+ def _event_type
48
+ adapter_incoming_request_params.dig("event_type")
49
+ end
50
+
51
+ def _title
52
+ adapter_incoming_request_params.dig("Title")
53
+ end
54
+
55
+ def _description
56
+ adapter_incoming_request_params.dig("Description")
57
+ end
58
+
59
+ def _additional_datums
60
+ []
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,114 @@
1
+ module PagerTree::Integrations
2
+ class Form::V3 < Integration
3
+ OPTIONS = [
4
+ {key: :form_title, type: :string, default: ""},
5
+ {key: :form_header, type: :string, default: ""},
6
+ {key: :form_instructions, type: :string, default: ""},
7
+ {key: :form_footer_text, type: :string, default: ""},
8
+ {key: :form_footer_link, type: :string, default: ""},
9
+ {key: :form_email_required, type: :boolean, default: false},
10
+ {key: :form_phone_required, type: :boolean, default: false},
11
+ {key: :form_description_required, type: :boolean, default: false},
12
+ {key: :form_urgency_required, type: :boolean, default: false}
13
+ ]
14
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
15
+
16
+ has_one_attached :option_form_logo
17
+
18
+ validates :option_form_footer_link, url: {no_local: true, allow_blank: true, allow_nil: true}
19
+ validates :option_form_email_required, inclusion: {in: [true, false]}
20
+ validates :option_form_phone_required, inclusion: {in: [true, false]}
21
+ validates :option_form_description_required, inclusion: {in: [true, false]}
22
+ validates :option_form_urgency_required, inclusion: {in: [true, false]}
23
+
24
+ after_initialize do
25
+ self.option_form_title ||= ""
26
+ self.option_form_header ||= ""
27
+ self.option_form_instructions ||= ""
28
+ self.option_form_footer_text ||= ""
29
+ self.option_form_footer_link ||= ""
30
+ self.option_form_email_required ||= false
31
+ self.option_form_phone_required ||= false
32
+ self.option_form_description_required ||= false
33
+ self.option_form_urgency_required ||= false
34
+ end
35
+
36
+ def adapter_supports_incoming?
37
+ true
38
+ end
39
+
40
+ def adapter_supports_outgoing?
41
+ false
42
+ end
43
+
44
+ def adapter_incoming_can_defer?
45
+ true
46
+ end
47
+
48
+ def adapter_supports_cnames?
49
+ true
50
+ end
51
+
52
+ def adapter_response_inactive_subscription
53
+ adapter_controller&.render(status: :payment_required, json: {code: Rack::Utils.status_code(:payment_required), errors: ["Customer must subscribe service plan to use this integration"]})
54
+ end
55
+
56
+ def adapter_response_upgrade
57
+ adapter_controller&.render(status: :payment_required, json: {code: Rack::Utils.status_code(:payment_required), errors: ["Customer must upgrade service plan to use this integration"]})
58
+ end
59
+
60
+ def adapter_response_maintenance_mode
61
+ adapter_controller&.render(status: :service_unavailable, json: {code: Rack::Utils.status_code(:service_unavailable), errors: ["Integration currently in maintenance mode"]})
62
+ end
63
+
64
+ def adapter_thirdparty_id
65
+ @adapter_thirdparty_id ||= SecureRandom.uuid
66
+ end
67
+
68
+ def adapter_action
69
+ :create
70
+ end
71
+
72
+ def adapter_process_create
73
+ Alert.new(
74
+ title: _title,
75
+ description: _description,
76
+ urgency: _urgency,
77
+ thirdparty_id: adapter_thirdparty_id,
78
+ dedup_keys: [adapter_thirdparty_id],
79
+ additional_data: _additional_datums
80
+ )
81
+ end
82
+
83
+ private
84
+
85
+ def _title
86
+ adapter_incoming_request_params.dig("title")
87
+ end
88
+
89
+ def _description
90
+ adapter_incoming_request_params.dig("description")
91
+ end
92
+
93
+ def _urgency
94
+ case adapter_incoming_request_params.dig("urgency")
95
+ when "low"
96
+ "low"
97
+ when "medium"
98
+ "medium"
99
+ when "high"
100
+ "high"
101
+ when "critical"
102
+ "critical"
103
+ end
104
+ end
105
+
106
+ def _additional_datums
107
+ [
108
+ AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")),
109
+ AdditionalDatum.new(format: "email", label: "Email", value: adapter_incoming_request_params.dig("email")),
110
+ AdditionalDatum.new(format: "phone", label: "Phone", value: adapter_incoming_request_params.dig("phone"))
111
+ ]
112
+ end
113
+ end
114
+ end