sysdig 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +5 -0
- data/lib/sysdig.rb +14 -6
- data/lib/sysdig/alert.rb +23 -12
- data/lib/sysdig/{notification.rb → alert_notification.rb} +1 -1
- data/lib/sysdig/{notifications.rb → alert_notifications.rb} +2 -2
- data/lib/sysdig/create_alert.rb +17 -1
- data/lib/sysdig/destroy_alert.rb +17 -0
- data/lib/sysdig/email_notification.rb +15 -0
- data/lib/sysdig/{get_notification.rb → get_alert_notification.rb} +1 -1
- data/lib/sysdig/{get_notifications.rb → get_alert_notifications.rb} +1 -1
- data/lib/sysdig/get_alerts.rb +20 -1
- data/lib/sysdig/get_user_notifications.rb +14 -0
- data/lib/sysdig/mock.rb +27 -0
- data/lib/sysdig/pager_duty_notification.rb +20 -0
- data/lib/sysdig/real.rb +18 -8
- data/lib/sysdig/sns_notification.rb +15 -0
- data/lib/sysdig/update_alert.rb +1 -2
- data/lib/sysdig/update_user_notifications.rb +31 -0
- data/lib/sysdig/user_notification.rb +31 -0
- data/lib/sysdig/user_notifications.rb +31 -0
- data/lib/sysdig/version.rb +1 -1
- metadata +14 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cec8df61179b00aff072de7f58a82be69c8c3d54
|
4
|
+
data.tar.gz: 8b2580b9f30040ce0802abbe7efcc4995c6221a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1d69d7e24782bea00e538acb84e8c1cfca952d23f833f67542712d295f49356e0c4286b20f80027122d5b52130e7438727e50bc6d625c19c4e25b7de5f3dce9
|
7
|
+
data.tar.gz: 0c6d24e5e651494f2837f4cda6b151225290d40182bab38aadd30854a6a79f230c994aca428ebb79f1ba9f510d9eb354dc497bffbfb14f4c15ff1d11698db5ac
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/sysdig.rb
CHANGED
@@ -11,8 +11,7 @@ require "ey/logger/faraday"
|
|
11
11
|
class Sysdig
|
12
12
|
include Cistern::Client
|
13
13
|
|
14
|
-
recognizes :url, :adapter, :logger
|
15
|
-
requires :username, :password
|
14
|
+
recognizes :url, :adapter, :logger, :token, :username, :password
|
16
15
|
|
17
16
|
end
|
18
17
|
|
@@ -27,11 +26,20 @@ require 'sysdig/login'
|
|
27
26
|
require 'sysdig/alert'
|
28
27
|
require 'sysdig/alerts'
|
29
28
|
require 'sysdig/create_alert'
|
29
|
+
require 'sysdig/destroy_alert'
|
30
30
|
require 'sysdig/get_alert'
|
31
31
|
require 'sysdig/get_alerts'
|
32
32
|
require 'sysdig/update_alert'
|
33
33
|
|
34
|
-
require 'sysdig/
|
35
|
-
require 'sysdig/
|
36
|
-
require 'sysdig/
|
37
|
-
require 'sysdig/
|
34
|
+
require 'sysdig/get_alert_notification'
|
35
|
+
require 'sysdig/get_alert_notifications'
|
36
|
+
require 'sysdig/alert_notification'
|
37
|
+
require 'sysdig/alert_notifications'
|
38
|
+
|
39
|
+
require 'sysdig/get_user_notifications'
|
40
|
+
require 'sysdig/update_user_notifications'
|
41
|
+
require 'sysdig/user_notification'
|
42
|
+
require 'sysdig/user_notifications'
|
43
|
+
require 'sysdig/sns_notification'
|
44
|
+
require 'sysdig/email_notification'
|
45
|
+
require 'sysdig/pager_duty_notification'
|
data/lib/sysdig/alert.rb
CHANGED
@@ -19,12 +19,12 @@ class Sysdig::Alert < Sysdig::Model
|
|
19
19
|
attribute :description
|
20
20
|
attribute :enabled, type: :boolean, default: true
|
21
21
|
attribute :filter, parser: lambda { |v, _| load_filter(v) }
|
22
|
-
attribute :group_aggregations, type: :array, alias:
|
23
|
-
attribute :group_by, type: :array, alias:
|
22
|
+
attribute :group_aggregations, type: :array, alias: "groupAggregations"
|
23
|
+
attribute :group_by, type: :array, alias: "groupBy"
|
24
24
|
attribute :group_condition, alias: "groupCondition"
|
25
25
|
attribute :modified_at, alias: "modifiedOn", parser: method(:epoch_time)
|
26
26
|
attribute :name
|
27
|
-
attribute :notification_count, type: :integer, alias:
|
27
|
+
attribute :notification_count, type: :integer, alias: "notificationCount"
|
28
28
|
attribute :notify, parser: lambda { |v, _| Array(v).map { |x| x.upcase } }
|
29
29
|
attribute :severity, type: :integer
|
30
30
|
attribute :segment_by, alias: "segmentBy"
|
@@ -34,17 +34,28 @@ class Sysdig::Alert < Sysdig::Model
|
|
34
34
|
attribute :type, parser: lambda { |v, _| v.to_s.upcase }
|
35
35
|
attribute :version, type: :integer
|
36
36
|
|
37
|
+
def destroy
|
38
|
+
requires :identity
|
39
|
+
|
40
|
+
service.destroy_alert(identity)
|
41
|
+
end
|
42
|
+
|
37
43
|
def save
|
38
44
|
params = {
|
39
|
-
"
|
40
|
-
"description"
|
41
|
-
"enabled"
|
42
|
-
"filter"
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"notify"
|
45
|
+
"condition" => self.condition,
|
46
|
+
"description" => self.description,
|
47
|
+
"enabled" => self.enabled,
|
48
|
+
"filter" => self.class.dump_filter(filter || {}),
|
49
|
+
"groupAggregations" => self.group_aggregations,
|
50
|
+
"groupBy" => self.group_by,
|
51
|
+
"groupCondition" => self.group_condition,
|
52
|
+
"name" => self.name,
|
53
|
+
"notify" => self.notify,
|
54
|
+
"segmentBy" => self.segment_by,
|
55
|
+
"segmentCondition" => self.segment_condition,
|
56
|
+
"severity" => self.severity,
|
57
|
+
"timespan" => self.timespan,
|
58
|
+
"type" => self.type,
|
48
59
|
}
|
49
60
|
|
50
61
|
data = (
|
data/lib/sysdig/create_alert.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
class Sysdig::
|
1
|
+
class Sysdig::CreateAlert < Sysdig::Request
|
2
|
+
def self.params
|
3
|
+
%w[name description enabled filter type condition timespan severity notify segmentBy segmentCondition groupCondition groupBy groupAggregations]
|
4
|
+
end
|
5
|
+
|
2
6
|
def real(alert)
|
3
7
|
service.request(
|
4
8
|
:method => :post,
|
@@ -6,4 +10,16 @@ class Sysdig::CreateAlerts < Sysdig::Request
|
|
6
10
|
:body => { "alert" => alert },
|
7
11
|
)
|
8
12
|
end
|
13
|
+
|
14
|
+
def mock(alert)
|
15
|
+
alert_id = service.serial_id
|
16
|
+
body = Cistern::Hash.slice(Cistern::Hash.stringify_keys(alert), *self.class.params)
|
17
|
+
|
18
|
+
service.data[:alerts][alert_id] = body.merge!("id" => alert_id)
|
19
|
+
|
20
|
+
service.response(
|
21
|
+
:status => 201,
|
22
|
+
:body => {"alert" => body},
|
23
|
+
)
|
24
|
+
end
|
9
25
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Sysdig::DestroyAlert < Sysdig::Request
|
2
|
+
def real(identity)
|
3
|
+
service.request(
|
4
|
+
:method => :delete,
|
5
|
+
:path => File.join("/api/alerts", identity.to_s)
|
6
|
+
)
|
7
|
+
end
|
8
|
+
|
9
|
+
def mock(identity)
|
10
|
+
service.data[:alerts].fetch(identity)
|
11
|
+
service.data[:alerts].delete(identity)
|
12
|
+
|
13
|
+
service.response(
|
14
|
+
:status => 204,
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Sysdig::EmailNotification < Sysdig::UserNotification
|
2
|
+
|
3
|
+
type :email
|
4
|
+
|
5
|
+
attribute :recipients, type: :array
|
6
|
+
|
7
|
+
def save
|
8
|
+
notification = service.update_user_notifications("email" => {
|
9
|
+
"enabled" => self.enabled,
|
10
|
+
"recipients" => self.receipents,
|
11
|
+
}).body.fetch("userNotification")
|
12
|
+
|
13
|
+
merge_attributes(notification.fetch("email"))
|
14
|
+
end
|
15
|
+
end
|
data/lib/sysdig/get_alerts.rb
CHANGED
@@ -1,8 +1,27 @@
|
|
1
1
|
class Sysdig::GetAlerts < Sysdig::Request
|
2
|
-
def real(
|
2
|
+
def real(from: nil, to: nil)
|
3
|
+
params = {}
|
4
|
+
|
5
|
+
if from
|
6
|
+
params.merge!(from.to_i * 1_000_000)
|
7
|
+
end
|
8
|
+
|
9
|
+
if to
|
10
|
+
params.merge!(to.to_i * 1_000_000)
|
11
|
+
end
|
12
|
+
|
3
13
|
service.request(
|
4
14
|
:method => :get,
|
5
15
|
:path => "/api/alerts",
|
16
|
+
:params => params,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def mock(from: nil, to: nil)
|
21
|
+
alerts = service.data[:alerts].values
|
22
|
+
|
23
|
+
service.response(
|
24
|
+
:body => { "alerts" => alerts },
|
6
25
|
)
|
7
26
|
end
|
8
27
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Sysdig::GetUserNotifications < Sysdig::Request
|
2
|
+
def real
|
3
|
+
service.request(
|
4
|
+
:method => :get,
|
5
|
+
:path => "/api/settings/notifications",
|
6
|
+
)
|
7
|
+
end
|
8
|
+
|
9
|
+
def mock
|
10
|
+
service.response(
|
11
|
+
:body => { "userNotification" => service.data[:user_notifications] }
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
data/lib/sysdig/mock.rb
CHANGED
@@ -1,8 +1,30 @@
|
|
1
1
|
class Sysdig::Mock
|
2
|
+
def self.reset!
|
3
|
+
super
|
4
|
+
|
5
|
+
@id = 0
|
6
|
+
end
|
7
|
+
|
2
8
|
def self.data
|
3
9
|
@@data ||= Hash.new { |h,url|
|
4
10
|
h[url] = {
|
5
11
|
:alerts => {},
|
12
|
+
:user_notifications => {
|
13
|
+
"email" => {
|
14
|
+
"enabled" => false,
|
15
|
+
"recipients" => []
|
16
|
+
},
|
17
|
+
"sns" => {
|
18
|
+
"enabled" => false,
|
19
|
+
"topics" => []
|
20
|
+
},
|
21
|
+
"pagerDuty" => {
|
22
|
+
"enabled" => false,
|
23
|
+
"integrated" => false,
|
24
|
+
"resolveOnOk" => false,
|
25
|
+
"connectUrl" => "https://connect.pagerduty.com/connect?vendor=x&callback=https://app.sysdigcloud.com/api/pagerDuty/callback/y/z"
|
26
|
+
}
|
27
|
+
}
|
6
28
|
}
|
7
29
|
}
|
8
30
|
end
|
@@ -44,4 +66,9 @@ class Sysdig::Mock
|
|
44
66
|
def data
|
45
67
|
self.class.data[self.url]
|
46
68
|
end
|
69
|
+
|
70
|
+
def serial_id
|
71
|
+
@id ||= 0
|
72
|
+
@id += 1
|
73
|
+
end
|
47
74
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Sysdig::PagerDutyNotification < Sysdig::UserNotification
|
2
|
+
|
3
|
+
type :pagerDuty
|
4
|
+
|
5
|
+
attribute :enabled, type: :boolean
|
6
|
+
attribute :integrated, type: :boolean
|
7
|
+
attribute :bind_resolution, type: :boolean, alias: "resolveOnOk"
|
8
|
+
attribute :connect_url, alias: "connectUrl"
|
9
|
+
|
10
|
+
def save
|
11
|
+
notification = service.update_user_notifications("pagerDuty" => {
|
12
|
+
"enabled" => self.enabled,
|
13
|
+
"integrated" => self.integrated,
|
14
|
+
"resolveOnOk" => self.bind_resolution,
|
15
|
+
"connectUrl" => self.connect_url,
|
16
|
+
}).body.fetch("userNotification")
|
17
|
+
|
18
|
+
merge_attributes(notification.fetch("pagerDuty"))
|
19
|
+
end
|
20
|
+
end
|
data/lib/sysdig/real.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class Sysdig::Real
|
2
|
-
|
2
|
+
|
3
|
+
attr_reader :url, :path, :connection, :parser, :logger, :adapter, :authentication, :token
|
3
4
|
|
4
5
|
def initialize(options={})
|
5
6
|
@url = URI.parse(options[:url] || "https://app.sysdigcloud.com")
|
@@ -8,6 +9,15 @@ class Sysdig::Real
|
|
8
9
|
connection_options = options[:connection_options] || {}
|
9
10
|
logger, @logger = options[:logger] || Logger.new(nil)
|
10
11
|
|
12
|
+
@username, @password = *options.values_at(:username, :password)
|
13
|
+
|
14
|
+
unless @username && @password
|
15
|
+
token = @token = options.fetch(:token)
|
16
|
+
end
|
17
|
+
|
18
|
+
@authentication = Mutex.new
|
19
|
+
@authenticated = false
|
20
|
+
|
11
21
|
@connection = Faraday.new({url: @url}.merge(connection_options)) do |builder|
|
12
22
|
# response
|
13
23
|
builder.response :json
|
@@ -20,22 +30,22 @@ class Sysdig::Real
|
|
20
30
|
:backoff_factor => 2
|
21
31
|
builder.request :multipart
|
22
32
|
builder.request :json
|
23
|
-
|
33
|
+
|
34
|
+
if token
|
35
|
+
builder.authorization :Bearer, token
|
36
|
+
else
|
37
|
+
builder.use :cookie_jar
|
38
|
+
end
|
24
39
|
|
25
40
|
builder.use Faraday::Response::RaiseError
|
26
41
|
builder.use Ey::Logger::Faraday, format: :machine, device: logger
|
27
42
|
|
28
43
|
builder.adapter(*adapter)
|
29
44
|
end
|
30
|
-
|
31
|
-
@username, @password = *options.values_at(:username, :password)
|
32
|
-
|
33
|
-
@authentication = Mutex.new
|
34
|
-
@authenticated = false
|
35
45
|
end
|
36
46
|
|
37
47
|
def request_with_authentication(options={})
|
38
|
-
if !@authenticated
|
48
|
+
if !@authenticated && token.nil?
|
39
49
|
@authentication.synchronize {
|
40
50
|
if !@authenticated
|
41
51
|
login(@username, @password)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Sysdig::SnsNotification < Sysdig::UserNotification
|
2
|
+
|
3
|
+
type :sns
|
4
|
+
|
5
|
+
attribute :topics, type: :array
|
6
|
+
|
7
|
+
def save
|
8
|
+
notification = service.update_user_notifications(self.identity => {
|
9
|
+
"enabled" => self.enabled,
|
10
|
+
"topics" => self.topics,
|
11
|
+
}).body.fetch("userNotification")
|
12
|
+
|
13
|
+
merge_attributes(notification.fetch(self.identity))
|
14
|
+
end
|
15
|
+
end
|
data/lib/sysdig/update_alert.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
class Sysdig::UpdateAlert < Sysdig::Request
|
2
|
+
# @note alert[version] might mean lock version which should be fun
|
2
3
|
def real(alert_id, alert)
|
3
|
-
#{"alert":{"version":7,"createdOn":1438965688000,"modifiedOn":1442349562000,"name":"Memory usage critical","description":"Memory utilization is currently >= 98%","enabled":false,"filter":null,"type":"MANUAL","condition":"timeAvg(memory.used.percent) >= 98","timespan":60000000,"severity":2,"notify":["SNS"],"segmentBy":["agent.tag.id"],"segmentCondition":{"type":"ANY"}}}
|
4
|
-
# @todo alert[version] might mean lock version which should be fun
|
5
4
|
service.request(
|
6
5
|
:method => :put,
|
7
6
|
:path => File.join("/api/alerts", alert_id.to_s),
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Sysdig::UpdateUserNotifications < Sysdig::Request
|
2
|
+
def real(notification)
|
3
|
+
service.request(
|
4
|
+
:method => :put,
|
5
|
+
:path => "/api/settings/notifications",
|
6
|
+
:body => { "userNotification" => notification },
|
7
|
+
)
|
8
|
+
end
|
9
|
+
|
10
|
+
def mock(notification)
|
11
|
+
user_notification = Cistern::Hash.slice(Cistern::Hash.stringify_keys(notification), "sns", "email", "pagerDuty")
|
12
|
+
|
13
|
+
schema = {
|
14
|
+
"sns" => %w[enabled topics],
|
15
|
+
"email" => %w[enabled recipients],
|
16
|
+
"pagerDuty" => %w[enabled integrated resolveOnOk connectUrl],
|
17
|
+
}
|
18
|
+
|
19
|
+
sliced = schema.each_with_object({}) { |(type, keys), r|
|
20
|
+
u = user_notification[type]
|
21
|
+
|
22
|
+
if u
|
23
|
+
r.merge!(type => Cistern::Hash.slice(u, *keys))
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
service.response(
|
28
|
+
:body => { "userNotification" => service.data[:user_notifications].merge!(sliced) },
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Sysdig::UserNotification < Sysdig::Model
|
2
|
+
|
3
|
+
def self.types
|
4
|
+
@_types ||= Hash.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.type(k=nil)
|
8
|
+
if k.nil?
|
9
|
+
@key
|
10
|
+
else
|
11
|
+
key = k.to_s
|
12
|
+
Sysdig::UserNotification.types[key] = self
|
13
|
+
@key = key
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.inherited(klass)
|
18
|
+
klass.identity :category
|
19
|
+
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
attribute :enabled, type: :boolean
|
24
|
+
|
25
|
+
def initialize(attributes={})
|
26
|
+
self.identity = self.class.type
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Sysdig::UserNotifications < Sysdig::Collection
|
2
|
+
|
3
|
+
model Sysdig::UserNotification
|
4
|
+
|
5
|
+
def all(options={})
|
6
|
+
load(service.get_user_notifications.body.fetch("userNotification")).tap { |_| self.records.compact! }
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(type)
|
10
|
+
all.find { |r| r.identity == type.to_s }
|
11
|
+
end
|
12
|
+
|
13
|
+
def new(args)
|
14
|
+
type, attributes = *args
|
15
|
+
|
16
|
+
unless attributes.is_a?(::Hash)
|
17
|
+
raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"))
|
18
|
+
end
|
19
|
+
|
20
|
+
concrete_model = model.types[type]
|
21
|
+
|
22
|
+
if concrete_model
|
23
|
+
concrete_model.new(
|
24
|
+
{
|
25
|
+
:collection => self,
|
26
|
+
:service => service,
|
27
|
+
}.merge(attributes)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/sysdig/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sysdig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,20 +143,28 @@ files:
|
|
143
143
|
- bin/setup
|
144
144
|
- lib/sysdig.rb
|
145
145
|
- lib/sysdig/alert.rb
|
146
|
+
- lib/sysdig/alert_notification.rb
|
147
|
+
- lib/sysdig/alert_notifications.rb
|
146
148
|
- lib/sysdig/alerts.rb
|
147
149
|
- lib/sysdig/create_alert.rb
|
150
|
+
- lib/sysdig/destroy_alert.rb
|
151
|
+
- lib/sysdig/email_notification.rb
|
148
152
|
- lib/sysdig/get_alert.rb
|
153
|
+
- lib/sysdig/get_alert_notification.rb
|
154
|
+
- lib/sysdig/get_alert_notifications.rb
|
149
155
|
- lib/sysdig/get_alerts.rb
|
150
|
-
- lib/sysdig/
|
151
|
-
- lib/sysdig/get_notifications.rb
|
156
|
+
- lib/sysdig/get_user_notifications.rb
|
152
157
|
- lib/sysdig/login.rb
|
153
158
|
- lib/sysdig/mock.rb
|
154
159
|
- lib/sysdig/model.rb
|
155
|
-
- lib/sysdig/
|
156
|
-
- lib/sysdig/notifications.rb
|
160
|
+
- lib/sysdig/pager_duty_notification.rb
|
157
161
|
- lib/sysdig/real.rb
|
158
162
|
- lib/sysdig/response.rb
|
163
|
+
- lib/sysdig/sns_notification.rb
|
159
164
|
- lib/sysdig/update_alert.rb
|
165
|
+
- lib/sysdig/update_user_notifications.rb
|
166
|
+
- lib/sysdig/user_notification.rb
|
167
|
+
- lib/sysdig/user_notifications.rb
|
160
168
|
- lib/sysdig/version.rb
|
161
169
|
- sysdig.gemspec
|
162
170
|
homepage: https://github.com/engineyard/sysdig-client
|