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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 478e5b8157e689a30e2c06d19abedc270d92592930512cf4434d7a35beb5b4e1
4
- data.tar.gz: 38a8239fc2a787f6e6525af6d18342cdbe0c266d05af4be874b0b48ab9ce1545
3
+ metadata.gz: ef9ca8da6e30e183e34aa930cfde4c471ea473b00d30c58433cc1291a29bfd2b
4
+ data.tar.gz: f602308962db7aff3c2a35692ac931902a7010306f8b74f09fde46faf205a388
5
5
  SHA512:
6
- metadata.gz: c3cf0d374ab0fb0499d17c277438d3053828cf713cc7b76c3dd9204fc4d684ea89e35546bd69b91a729d71d6ccd7173f5d7866d455eb9b08674a7a875621ae76
7
- data.tar.gz: 22c58a0469166709474fe43849aa8af7274ceff37e76848348de50fca9c7aeefd9e335b2db568d34605e2570898f315ff12de6b856f3db1adaec1c9edeaf34f1
6
+ metadata.gz: 30f940b21eba507e46cfb659c9b00dd8d3456ff9c58d603588e59f9bfc5c6e2b046ff3fff13abc6149363b84f91e2f6e59862c159febd2c5222454d4094d1415
7
+ data.tar.gz: 3f9a6f459522eb355c14afa3ccdcdf7d59d3bdfac0ecd98c9f0f610b91954f453202a0fc00e5ce8e4a4a1ed345de3e918a2b4fb4a60c6623e956e4aa55397bfe
@@ -15,11 +15,12 @@ module PagerTree::Integrations
15
15
  attr_accessor :dedup_keys
16
16
  attr_accessor :additional_data
17
17
  attr_accessor :attachments
18
+ attr_accessor :tags
18
19
 
19
20
  validates :title, presence: true
20
21
  validates :urgency, inclusion: {in: ["silent", "low", "medium", "high", "critical"]}, if: ->(x) { x.urgency.present? }
21
22
  validates :incident, inclusion: {in: [true, false]}
22
- validates :incident_severity, presence: true, if: :incident?
23
+ validates :incident_severity, presence: true, inclusion: {in: ["SEV-1", "SEV-2", "SEV-3", "SEV-4", "SEV-5", "SEV-UNKNOWN"]}, if: :incident?
23
24
  validates :thirdparty_id, presence: true
24
25
 
25
26
  define_model_callbacks :initialize
@@ -42,6 +43,7 @@ module PagerTree::Integrations
42
43
  self.dedup_keys ||= []
43
44
  self.additional_data ||= []
44
45
  self.attachments ||= []
46
+ self.tags ||= []
45
47
  end
46
48
 
47
49
  def incident?
@@ -0,0 +1,74 @@
1
+ module PagerTree::Integrations
2
+ class AppDynamics::V3 < Integration
3
+ OPTIONS = []
4
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
5
+
6
+ def adapter_supports_incoming?
7
+ true
8
+ end
9
+
10
+ def adapter_action
11
+ if _is_create?
12
+ :create
13
+ elsif _is_resolve?
14
+ :resolve
15
+ else
16
+ :other
17
+ end
18
+ end
19
+
20
+ def adapter_thirdparty_id
21
+ _thirdparty_id
22
+ end
23
+
24
+ def adapter_process_create
25
+ Alert.new(
26
+ title: _title,
27
+ description: _description,
28
+ thirdparty_id: _thirdparty_id,
29
+ dedup_keys: [_thirdparty_id],
30
+ additional_data: _additional_datums
31
+ )
32
+ end
33
+
34
+ private
35
+
36
+ def _thirdparty_id
37
+ adapter_incoming_request_params.dig("details", "event_id")
38
+ end
39
+
40
+ def _state
41
+ adapter_incoming_request_params.dig("event_type")
42
+ end
43
+
44
+ def _is_create?
45
+ _state == "trigger"
46
+ end
47
+
48
+ def _is_resolve?
49
+ _state == "resolve"
50
+ end
51
+
52
+ def _title
53
+ adapter_incoming_request_params.dig("incident_key")
54
+ end
55
+
56
+ def _description
57
+ [
58
+ adapter_incoming_request_params.dig("description"),
59
+ adapter_incoming_request_params.dig("details", "summary")
60
+ ].join("\n\n")
61
+ end
62
+
63
+ def _additional_datums
64
+ [
65
+ AdditionalDatum.new(format: "text", label: "Event Name", value: adapter_incoming_request_params.dig("details", "event_name")),
66
+ AdditionalDatum.new(format: "datetime", label: "Event Time", value: adapter_incoming_request_params.dig("details", "event_time")),
67
+ AdditionalDatum.new(format: "text", label: "Application Name", value: adapter_incoming_request_params.dig("details", "application_name")),
68
+ AdditionalDatum.new(format: "text", label: "Node Name", value: adapter_incoming_request_params.dig("details", "node_name")),
69
+ AdditionalDatum.new(format: "img", label: adapter_incoming_request_params.dig("contexts", 0, "alt"), value: adapter_incoming_request_params.dig("contexts", 0, "src")),
70
+ AdditionalDatum.new(format: "link", label: adapter_incoming_request_params.dig("contexts", 1, "text"), value: adapter_incoming_request_params.dig("contexts", 1, "href"))
71
+ ]
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,94 @@
1
+ module PagerTree::Integrations
2
+ class Auvik::V3 < Integration
3
+ AUVIK_SEVERITY = {
4
+ emergency: 1,
5
+ critical: 2,
6
+ warning: 3,
7
+ info: 4
8
+ }
9
+
10
+ OPTIONS = []
11
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
12
+
13
+ after_initialize do
14
+ end
15
+
16
+ def adapter_supports_incoming?
17
+ true
18
+ end
19
+
20
+ def adapter_supports_outgoing?
21
+ false
22
+ end
23
+
24
+ def adapter_incoming_can_defer?
25
+ true
26
+ end
27
+
28
+ def adapter_thirdparty_id
29
+ _correlation_id
30
+ end
31
+
32
+ def adapter_action
33
+ case _alert_status
34
+ when 0 then :create
35
+ when 1 then :resolve
36
+ else
37
+ :other
38
+ end
39
+ end
40
+
41
+ def adapter_process_create
42
+ Alert.new(
43
+ title: _title,
44
+ description: _description,
45
+ urgency: _urgency,
46
+ thirdparty_id: adapter_thirdparty_id,
47
+ dedup_keys: [adapter_thirdparty_id],
48
+ additional_data: _additional_datums
49
+ )
50
+ end
51
+
52
+ private
53
+
54
+ def _correlation_id
55
+ adapter_incoming_request_params.dig("correlationId")
56
+ end
57
+
58
+ def _alert_status
59
+ adapter_incoming_request_params.dig("alertStatus")
60
+ end
61
+
62
+ def _title
63
+ adapter_incoming_request_params.dig("alertName")
64
+ end
65
+
66
+ def _description
67
+ adapter_incoming_request_params.dig("alertDescription")
68
+ end
69
+
70
+ def _urgency
71
+ case adapter_incoming_request_params.dig("alertSeverity")
72
+ when AUVIK_SEVERITY[:info] then "low"
73
+ when AUVIK_SEVERITY[:warning] then "medium"
74
+ when AUVIK_SEVERITY[:critical] then "high"
75
+ when AUVIK_SEVERITY[:emergency] then "critical"
76
+ end
77
+ end
78
+
79
+ def _additional_datums
80
+ [
81
+ AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("link")),
82
+ AdditionalDatum.new(format: "text", label: "Alert Severity", value: adapter_incoming_request_params.dig("alertSeverityString")),
83
+ AdditionalDatum.new(format: "text", label: "Correlation ID", value: adapter_incoming_request_params.dig("correlationId")),
84
+ AdditionalDatum.new(format: "text", label: "Alert ID", value: adapter_incoming_request_params.dig("alertId")),
85
+ AdditionalDatum.new(format: "text", label: "Entity ID", value: adapter_incoming_request_params.dig("entityId")),
86
+ AdditionalDatum.new(format: "text", label: "Entity Name", value: adapter_incoming_request_params.dig("entityName")),
87
+ AdditionalDatum.new(format: "text", label: "Entity Type", value: adapter_incoming_request_params.dig("entityType")),
88
+ AdditionalDatum.new(format: "text", label: "Entity ID", value: adapter_incoming_request_params.dig("entityId")),
89
+ AdditionalDatum.new(format: "text", label: "Company Name", value: adapter_incoming_request_params.dig("companyName")),
90
+ AdditionalDatum.new(format: "datetime", label: "Date", value: adapter_incoming_request_params.dig("date"))
91
+ ]
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,108 @@
1
+ module PagerTree::Integrations
2
+ class AwsCloudwatch::V3 < Integration
3
+ OPTIONS = []
4
+ store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
5
+
6
+ def adapter_supports_incoming?
7
+ true
8
+ end
9
+
10
+ def adapter_incoming_can_defer?
11
+ true
12
+ end
13
+
14
+ def adapter_should_block_incoming?(request)
15
+ !Aws::SNS::MessageVerifier.new.authentic?(request.params)
16
+ end
17
+
18
+ def adapter_thirdparty_id
19
+ _thirdparty_id
20
+ end
21
+
22
+ def adapter_action
23
+ if _is_create?
24
+ :create
25
+ elsif _is_resolve?
26
+ :resolve
27
+ else
28
+ :other
29
+ end
30
+ end
31
+
32
+ def adapter_process_create
33
+ Alert.new(
34
+ title: _title,
35
+ description: _description,
36
+ thirdparty_id: _thirdparty_id,
37
+ dedup_keys: [_thirdparty_id],
38
+ additional_data: _additional_datums
39
+ )
40
+ end
41
+
42
+ def adapter_process_other
43
+ if _type == "SubscriptionConfirmation" || _type == "UnsubscribeConfirmation"
44
+ url = adapter_incoming_request_params.dig("SubscribeURL")
45
+ HTTParty.get(url) if url
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def _type
52
+ @_type ||= adapter_incoming_request_params.dig("Type")
53
+ end
54
+
55
+ def _message
56
+ @_message ||= adapter_incoming_request_params.dig("Message")
57
+ end
58
+
59
+ def _json
60
+ @_json ||= {} if _type != "Notification" || _message.blank?
61
+ @_json ||= begin
62
+ JSON.parse(_message).with_indifferent_access
63
+ rescue
64
+ {}
65
+ end
66
+ end
67
+
68
+ def _thirdparty_id
69
+ [
70
+ adapter_incoming_request_params.dig("TopicArn"),
71
+ _json.dig("AlarmName")
72
+ ].join(":")
73
+ end
74
+
75
+ def _is_create?
76
+ _new_state == "ALARM" && (_old_state == "INSUFFICIENT_DATA" || _old_state == "OK")
77
+ end
78
+
79
+ def _is_resolve?
80
+ _new_state == "OK" && (_old_state == "INSUFFICIENT_DATA" || _old_state == "ALARM")
81
+ end
82
+
83
+ def _new_state
84
+ _json.dig("NewStateValue")
85
+ end
86
+
87
+ def _old_state
88
+ _json.dig("OldStateValue")
89
+ end
90
+
91
+ def _title
92
+ _json.dig("AlarmName")
93
+ end
94
+
95
+ def _description
96
+ _json.dig("NewStateReason")
97
+ end
98
+
99
+ def _additional_datums
100
+ [
101
+ AdditionalDatum.new(format: "text", label: "AWS Account ID", value: _json.dig("AWSAccountId")),
102
+ AdditionalDatum.new(format: "text", label: "Region", value: _json.dig("Region")),
103
+ AdditionalDatum.new(format: "text", label: "Alarm ARN", value: _json.dig("AlarmArn")),
104
+ AdditionalDatum.new(format: "datetime", label: "State Change Time", value: _json.dig("StateChangeTime"))
105
+ ]
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,79 @@
1
+ module PagerTree::Integrations
2
+ class AzureMonitor::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", "essentials", "alertId")
23
+ end
24
+
25
+ def adapter_action
26
+ case _monitor_condition
27
+ when "Fired" then :create
28
+ when "Resolved" 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
+ urgency: _urgency,
39
+ thirdparty_id: adapter_thirdparty_id,
40
+ dedup_keys: [adapter_thirdparty_id],
41
+ additional_data: _additional_datums
42
+ )
43
+ end
44
+
45
+ private
46
+
47
+ def _monitor_condition
48
+ adapter_incoming_request_params.dig("data", "essentials", "monitorCondition")
49
+ end
50
+
51
+ def _title
52
+ adapter_incoming_request_params.dig("data", "essentials", "alertRule")
53
+ end
54
+
55
+ def _description
56
+ adapter_incoming_request_params.dig("data", "essentials", "description")
57
+ end
58
+
59
+ def _urgency
60
+ case adapter_incoming_request_params.dig("data", "essentials", "severity")
61
+ when "Sev0" then "low"
62
+ when "Sev1" then "low"
63
+ when "Sev2" then "medium"
64
+ when "Sev3" then "high"
65
+ when "Sev4" then "critical"
66
+ end
67
+ end
68
+
69
+ def _additional_datums
70
+ essentials = adapter_incoming_request_params.dig("data", "essentials")
71
+ [
72
+ AdditionalDatum.new(format: "text", label: "Monitoring Service", value: essentials.dig("monitoringService")),
73
+ AdditionalDatum.new(format: "text", label: "Alert Rule", value: essentials.dig("alertRule")),
74
+ AdditionalDatum.new(format: "text", label: "Severity", value: essentials.dig("severity")),
75
+ AdditionalDatum.new(format: "datetime", label: "Fired At", value: essentials.dig("firedDateTime"))
76
+ ]
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,42 @@
1
+ # https://gist.github.com/ozgun/e062ff629708286f7211
2
+ # File: app/models/concerns/boolean_store_accessor.rb
3
+ #
4
+ # When we submit a form in order to update a model, a booelan/checkbox field is posted
5
+ # as '1' or '0', and if we are using ActiveRecord::Store, posted value is stored in
6
+ # database as '1' or '0'. By the help of this module, we store '1' and '0'
7
+ # values as `true` or `false`.
8
+ #
9
+ # Example usage:
10
+ #
11
+ # ```
12
+ # class Page < ActiveRecord::Base
13
+ # extend BooleanStoreAccessor
14
+ # store :settings, accessors: [:hide_from_navigation]
15
+ # boolean_store_accessor :hide_from_navigation
16
+ # end
17
+ #
18
+ # page = Page.first
19
+ # page.hide_from_navigation? #=> false
20
+ # page.hide_from_navigation = true
21
+ # page.save
22
+ # page.hide_from_navigation? #=> true
23
+ # page.settings #=> {"hide_from_navigation"=>true}
24
+ # ```
25
+ #
26
+ module PagerTree::Integrations::BooleanStoreAccessor
27
+ def boolean_store_accessor(attr_name)
28
+ define_method "#{attr_name}=".to_sym do |value|
29
+ values = ["1", true]
30
+ super(values.include?(value))
31
+ end
32
+
33
+ define_method attr_name do
34
+ values = [nil, false, "0"]
35
+ !values.include?(super())
36
+ end
37
+
38
+ define_method "#{attr_name}?".to_sym do
39
+ send(attr_name)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,176 @@
1
+ module PagerTree::Integrations
2
+ class Channel::Hangouts::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_hash = {
71
+ cards: [
72
+ {
73
+ header: {
74
+ title: _title,
75
+ subtitle: _alert.description&.try(:to_plain_text),
76
+ imageUrl: _color,
77
+ imageStyle: "AVATAR"
78
+ },
79
+ sections: [
80
+ {
81
+ widgets: [
82
+ {
83
+ textParagraph: {
84
+ text: _alert.description&.try(:to_plain_text)
85
+ }
86
+ },
87
+ {
88
+ keyValue: {
89
+ topLabel: "Status",
90
+ content: _alert.status.to_s.upcase
91
+ }
92
+ },
93
+ {
94
+ keyValue: {
95
+ topLabel: "Urgency",
96
+ content: _alert.urgency.to_s.upcase
97
+ }
98
+ },
99
+ {
100
+ keyValue: {
101
+ topLabel: "Created",
102
+ content: _alert.created_at.utc
103
+ }
104
+ },
105
+ {
106
+ keyValue: {
107
+ topLabel: "Source",
108
+ content: _alert.source&.name
109
+ }
110
+ },
111
+ {
112
+ keyValue: {
113
+ topLabel: "Destinations",
114
+ content: _alert.alert_destinations&.map { |d| d.destination.name }&.join(", ")
115
+ }
116
+ },
117
+ {
118
+ keyValue: {
119
+ topLabel: "User",
120
+ content: _alert.alert_responders&.where(role: :incident_commander)&.includes(account_user: :user)&.first&.account_user&.name
121
+ }
122
+ }
123
+ ]
124
+
125
+ }, {
126
+ widgets: [
127
+ {
128
+ buttons: [
129
+ {
130
+ textButton: {
131
+ text: "VIEW IN PAGERTREE",
132
+ onClick: {
133
+ openLink: {
134
+ url: nil
135
+ }
136
+ }
137
+ }
138
+ }
139
+ ]
140
+ }
141
+ ]
142
+ }
143
+ ]
144
+ }
145
+ ]
146
+ }
147
+
148
+ blocks_hash[:cards][0][:sections][0][:widgets].reject! { |x| x.dig(:keyValue, :content).blank? && x.dig(:textParagraph, :text).blank? }
149
+
150
+ blocks_hash
151
+ end
152
+
153
+ def _title
154
+ return @_title if @_title.present?
155
+
156
+ @_title = if _alert.incident?
157
+ "Incident ##{_alert.tiny_id} [#{_alert.incident_severity.upcase.dasherize}] #{_alert.incident_message} - #{_alert.title}"
158
+ else
159
+ "Alert ##{_alert.tiny_id} #{_alert.title}"
160
+ end
161
+ end
162
+
163
+ def _color
164
+ case _alert.status
165
+ when "open", "dropped"
166
+ "https://pagertree.com/assets/img/icon/red-square.png"
167
+ when "acknowledged"
168
+ "https://pagertree.com/assets/img/icon/yellow-square.png"
169
+ when "resolved"
170
+ "https://pagertree.com/assets/img/icon/green-square.png"
171
+ else
172
+ "https://pagertree.com/assets/img/icon/grey-square.png"
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,6 @@
1
+ module PagerTree::Integrations
2
+ class Channel::Mattermost::V3 < Channel::Slack::V3
3
+ # we can just piggy back the Channel::Slack::V3 since Mattermost is a clone of Slack
4
+ # both integrations have the same exact functionality
5
+ end
6
+ end