Module: Zanshin::SDK::Alerts
- Included in:
- Client
- Defined in:
- lib/zanshin/alerts.rb
Overview
Zanshin SDK Alerts
Instance Method Summary collapse
-
#create_alert_comment(organization_id, scan_target_id, alert_id, comment) ⇒ Object
Create comment in alert #reference.
-
#get_alert(alert_id) ⇒ Object
Returns the detailed object that describes an alert #reference.
-
#iter_alert_comments(alert_id) ⇒ Object
Alert Comments Enumerator over the comment of an alert #reference.
-
#iter_alert_history(alert_id) ⇒ Object
Alert History Enumerator over the history of an alert #reference.
-
#iter_alerts(organization_id, scan_target_ids: [], rule: nil, states: nil, severities: nil, page_size: 100, language: nil, created_at_start: nil, created_at_end: nil, updated_at_start: nil, updated_at_end: nil) ⇒ Object
Alerts Enumerator of an organization by loading them, transparently paginating on the API #reference.
-
#iter_alerts_following_history(organization_id, following_ids: [], page_size: 100, language: nil, cursor: nil) ⇒ Object
Alerts Following History Enumerator of an organization by loading them, transparently paginating on the API #reference.
-
#iter_alerts_history(organization_id, scan_target_ids: [], page_size: 100, language: nil, cursor: nil) ⇒ Object
Alerts History Enumerator of an organization by loading them, transparently paginating on the API #reference.
-
#iter_following_alerts(organization_id, following_ids: [], rule: nil, states: nil, severities: nil, page_size: 100, language: nil, created_at_start: nil, created_at_end: nil, updated_at_start: nil, updated_at_end: nil) ⇒ Object
Alerts Following Enumerator over the following alerts froms organizations being followed by transparently paginating on the API #reference.
-
#iter_grouped_alerts(organization_id, scan_target_ids: [], states: nil, severities: nil, page_size: 100) ⇒ Object
Grouped Alerts Enumerator of an organization by loading them, transparently paginating on the API #reference.
-
#iter_grouped_following_alerts(organization_id, following_ids: [], states: nil, severities: nil, page_size: 100) ⇒ Object
Grouped Alerts Following Enumerator of an organization by loading them, transparently paginating on the API #reference.
-
#update_alert(organization_id, scan_target_id, alert_id, state = nil, labels = nil, comment = nil) ⇒ Object
Update alert #reference.
Instance Method Details
#create_alert_comment(organization_id, scan_target_id, alert_id, comment) ⇒ Object
Create comment in alert #reference
354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/zanshin/alerts.rb', line 354 def create_alert_comment(organization_id, scan_target_id, alert_id, comment) body = { 'comment' => comment } @http.request( 'POST', "/organizations/#{validate_uuid(organization_id)}/scantargets/#{ validate_uuid(scan_target_id)}/alerts/#{validate_uuid(alert_id)}/comments", body.compact ) end |
#get_alert(alert_id) ⇒ Object
Returns the detailed object that describes an alert #reference
287 288 289 |
# File 'lib/zanshin/alerts.rb', line 287 def get_alert(alert_id) @http.request('GET', "/alerts/#{validate_uuid(alert_id)}") end |
#iter_alert_comments(alert_id) ⇒ Object
Alert Comments Enumerator over the comment of an alert #reference
311 312 313 314 315 316 317 |
# File 'lib/zanshin/alerts.rb', line 311 def iter_alert_comments(alert_id) Enumerator.new do |yielder| @http.request('GET', "/alerts/#{validate_uuid(alert_id)}/comments").each do |e| yielder.yield e end end end |
#iter_alert_history(alert_id) ⇒ Object
Alert History Enumerator over the history of an alert #reference
297 298 299 300 301 302 303 |
# File 'lib/zanshin/alerts.rb', line 297 def iter_alert_history(alert_id) Enumerator.new do |yielder| @http.request('GET', "/alerts/#{validate_uuid(alert_id)}/history").each do |e| yielder.yield e end end end |
#iter_alerts(organization_id, scan_target_ids: [], rule: nil, states: nil, severities: nil, page_size: 100, language: nil, created_at_start: nil, created_at_end: nil, updated_at_start: nil, updated_at_end: nil) ⇒ Object
Alerts Enumerator of an organization by loading them, transparently paginating on the API #reference
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/zanshin/alerts.rb', line 29 def iter_alerts(organization_id, scan_target_ids: [], rule: nil, states: nil, severities: nil, page_size: 100, language: nil, created_at_start: nil, created_at_end: nil, updated_at_start: nil, updated_at_end: nil) body = { 'organizationId' => validate_uuid(organization_id), 'page' => 0, 'pageSize' => page_size, 'scanTargetIds' => scan_target_ids.each { |scan_target_id| validate_uuid(scan_target_id) }, 'rule' => rule, 'states' => states, 'severities' => severities, 'lang' => language, 'CreatedAtStart' => created_at_start, 'CreatedAtEnd' => created_at_end, 'UpdatedAtStart' => updated_at_start, 'UpdatedAtEnd' => updated_at_end } Enumerator.new do |yielder| loop do body['page'] += 1 data = @http.request('POST', '/alerts', body.compact) data['data'].each do |e| yielder.yield e end break if body['page'] == (data['total'] / body['pageSize']).ceil end end end |
#iter_alerts_following_history(organization_id, following_ids: [], page_size: 100, language: nil, cursor: nil) ⇒ Object
Alerts Following History Enumerator of an organization by loading them, transparently paginating on the API #reference
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/zanshin/alerts.rb', line 176 def iter_alerts_following_history(organization_id, following_ids: [], page_size: 100, language: nil, cursor: nil) body = { 'organizationId' => validate_uuid(organization_id), 'page' => 0, 'pageSize' => page_size, 'followingIds' => following_ids.each { |following_id| validate_uuid(following_id) }, 'lang' => language, 'cursor' => cursor } Enumerator.new do |yielder| loop do body['page'] += 1 data = @http.request('POST', '/alerts/history/following', body.compact) break if data['data'].empty? body['cursor'] = data['data'].last['cursor'] data['data'].each do |e| yielder.yield e end end end end |
#iter_alerts_history(organization_id, scan_target_ids: [], page_size: 100, language: nil, cursor: nil) ⇒ Object
Alerts History Enumerator of an organization by loading them, transparently paginating on the API #reference
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/zanshin/alerts.rb', line 136 def iter_alerts_history(organization_id, scan_target_ids: [], page_size: 100, language: nil, cursor: nil) body = { 'organizationId' => validate_uuid(organization_id), 'page' => 0, 'pageSize' => page_size, 'scanTargetIds' => scan_target_ids.each { |scan_target_id| validate_uuid(scan_target_id) }, 'lang' => language, 'cursor' => cursor } Enumerator.new do |yielder| loop do body['page'] += 1 data = @http.request('POST', '/alerts/history', body.compact) break if data['data'].empty? body['cursor'] = data['data'].last['cursor'] data['data'].each do |e| yielder.yield e end end end end |
#iter_following_alerts(organization_id, following_ids: [], rule: nil, states: nil, severities: nil, page_size: 100, language: nil, created_at_start: nil, created_at_end: nil, updated_at_start: nil, updated_at_end: nil) ⇒ Object
Alerts Following Enumerator over the following alerts froms organizations being followed by transparently paginating on the API #reference
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/zanshin/alerts.rb', line 87 def iter_following_alerts(organization_id, following_ids: [], rule: nil, states: nil, severities: nil, page_size: 100, language: nil, created_at_start: nil, created_at_end: nil, updated_at_start: nil, updated_at_end: nil) body = { 'organizationId' => validate_uuid(organization_id), 'page' => 0, 'pageSize' => page_size, 'followingIds' => following_ids.each { |following_id| validate_uuid(following_id) }, 'rule' => rule, 'states' => states, 'severities' => severities, 'lang' => language, 'CreatedAtStart' => created_at_start, 'CreatedAtEnd' => created_at_end, 'UpdatedAtStart' => updated_at_start, 'UpdatedAtEnd' => updated_at_end } Enumerator.new do |yielder| loop do body['page'] += 1 data = @http.request('POST', '/alerts/following', body.compact) data['data'].each do |e| yielder.yield e end break if body['page'] == (data['total'] / body['pageSize']).ceil end end end |
#iter_grouped_alerts(organization_id, scan_target_ids: [], states: nil, severities: nil, page_size: 100) ⇒ Object
Grouped Alerts Enumerator of an organization by loading them, transparently paginating on the API #reference
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/zanshin/alerts.rb', line 216 def iter_grouped_alerts(organization_id, scan_target_ids: [], states: nil, severities: nil, page_size: 100) body = { 'organizationId' => validate_uuid(organization_id), 'page' => 0, 'pageSize' => page_size, 'scanTargetIds' => scan_target_ids.each { |scan_target_id| validate_uuid(scan_target_id) }, 'states' => states, 'severities' => severities } Enumerator.new do |yielder| loop do body['page'] += 1 data = @http.request('POST', '/alerts/rules', body.compact) data['data'].each do |e| yielder.yield e end break if body['page'] == (data['total'] / body['pageSize']).ceil end end end |
#iter_grouped_following_alerts(organization_id, following_ids: [], states: nil, severities: nil, page_size: 100) ⇒ Object
Grouped Alerts Following Enumerator of an organization by loading them, transparently paginating on the API #reference
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/zanshin/alerts.rb', line 255 def iter_grouped_following_alerts(organization_id, following_ids: [], states: nil, severities: nil, page_size: 100) body = { 'organizationId' => validate_uuid(organization_id), 'page' => 0, 'pageSize' => page_size, 'followingIds' => following_ids.each { |following_id| validate_uuid(following_id) }, 'states' => states, 'severities' => severities } Enumerator.new do |yielder| loop do body['page'] += 1 data = @http.request('POST', '/alerts/rules/following', body.compact) data['data'].each do |e| yielder.yield e end break if body['page'] == (data['total'] / body['pageSize']).ceil end end end |
#update_alert(organization_id, scan_target_id, alert_id, state = nil, labels = nil, comment = nil) ⇒ Object
Update alert #reference
330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/zanshin/alerts.rb', line 330 def update_alert(organization_id, scan_target_id, alert_id, state = nil, labels = nil, comment = nil) body = { 'state' => state, 'labels' => labels, 'comment' => comment } @http.request( 'PUT', "/organizations/#{validate_uuid(organization_id)}/scantargets/#{ validate_uuid(scan_target_id)}/alerts/#{validate_uuid(alert_id)}", body.compact ) end |