sysdig 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/sysdig.rb +2 -0
- data/lib/sysdig/alert.rb +6 -18
- data/lib/sysdig/alert_filter.rb +21 -0
- data/lib/sysdig/create_alert.rb +8 -4
- data/lib/sysdig/create_user.rb +152 -0
- data/lib/sysdig/get_alert.rb +6 -0
- data/lib/sysdig/mock.rb +7 -3
- data/lib/sysdig/update_alert.rb +11 -1
- data/lib/sysdig/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0584253cc25878e18a5933ce1b8462474c5816dc
|
4
|
+
data.tar.gz: a6860512f09060d382985131bb1cd8553cbb5ba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cac5de1d482b9d7296e042a128286b706ed6fd4f977b269c68111d8738b2dd083fc72ef704248579aed8c3fe10b316a51e64e247d852ed04a36628c6fdceeda
|
7
|
+
data.tar.gz: 978b39ec9831166510a94774ce82d3aa07004eef3e684fa554d5a2aadbfbd7425543f33e13aa498699f21fc9d0107944bb49770c8708ebb672093a2262f57465
|
data/Gemfile
CHANGED
data/lib/sysdig.rb
CHANGED
data/lib/sysdig/alert.rb
CHANGED
@@ -1,36 +1,24 @@
|
|
1
1
|
class Sysdig::Alert < Sysdig::Model
|
2
2
|
|
3
|
-
def self.dump_filter(hash)
|
4
|
-
hash.map { |k,v| [k, normalize_filter_condition(v).inspect].join(" = ") }.join(", ")
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.load_filter(string)
|
8
|
-
string.split(", ").map { |t| t.split(" = ") }.inject({}) { |r,(k,c)| r.merge(k => normalize_filter_condition(c)) }
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.normalize_filter_condition(string)
|
12
|
-
string.gsub(/(^\\?\")|(\\?\"$)/, "")
|
13
|
-
end
|
14
|
-
|
15
3
|
identity :id, type: :integer
|
16
4
|
|
17
5
|
attribute :condition
|
18
6
|
attribute :created_at, alias: "createdOn", parser: method(:epoch_time)
|
19
7
|
attribute :description
|
20
8
|
attribute :enabled, type: :boolean, default: true
|
21
|
-
attribute :filter, parser: lambda { |v, _|
|
9
|
+
attribute :filter, parser: lambda { |v, _| Sysdig::AlertFilter.load(v) }
|
22
10
|
attribute :group_aggregations, type: :array, alias: "groupAggregations"
|
23
11
|
attribute :group_by, type: :array, alias: "groupBy"
|
24
12
|
attribute :group_condition, alias: "groupCondition"
|
25
13
|
attribute :modified_at, alias: "modifiedOn", parser: method(:epoch_time)
|
26
14
|
attribute :name
|
27
15
|
attribute :notification_count, type: :integer, alias: "notificationCount"
|
28
|
-
attribute :notify, parser: lambda { |v, _| Array(v).map { |x| x.upcase } }
|
29
|
-
attribute :severity, type: :integer
|
16
|
+
attribute :notify, parser: lambda { |v, _| (Array(v) || []).map { |x| x.to_s.upcase } }
|
30
17
|
attribute :segment_by, alias: "segmentBy"
|
31
18
|
attribute :segment_condition, alias: "segmentCondition"
|
19
|
+
attribute :severity, type: :integer
|
32
20
|
attribute :targets, type: :array
|
33
|
-
attribute :timespan,
|
21
|
+
attribute :timespan, parser: lambda { |v, _| i = v.to_i; i > 1_000_000 ? i / 1_000_000 : i }
|
34
22
|
attribute :type, parser: lambda { |v, _| v.to_s.upcase }
|
35
23
|
attribute :version, type: :integer
|
36
24
|
|
@@ -45,7 +33,7 @@ class Sysdig::Alert < Sysdig::Model
|
|
45
33
|
"condition" => self.condition,
|
46
34
|
"description" => self.description,
|
47
35
|
"enabled" => self.enabled,
|
48
|
-
"filter" =>
|
36
|
+
"filter" => Sysdig::AlertFilter.dump(filter || {}),
|
49
37
|
"groupAggregations" => self.group_aggregations,
|
50
38
|
"groupBy" => self.group_by,
|
51
39
|
"groupCondition" => self.group_condition,
|
@@ -54,7 +42,7 @@ class Sysdig::Alert < Sysdig::Model
|
|
54
42
|
"segmentBy" => self.segment_by,
|
55
43
|
"segmentCondition" => self.segment_condition,
|
56
44
|
"severity" => self.severity,
|
57
|
-
"timespan" => self.timespan,
|
45
|
+
"timespan" => self.timespan * 1_000_000,
|
58
46
|
"type" => self.type,
|
59
47
|
}
|
60
48
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Sysdig::AlertFilter
|
2
|
+
def self.dump(hash)
|
3
|
+
hash.map { |k,v| [k, normalize_condition(v).inspect].join(" = ") }.join(", ")
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.load(hash_or_string)
|
7
|
+
case hash_or_string
|
8
|
+
when NilClass, Hash
|
9
|
+
hash_or_string
|
10
|
+
when String
|
11
|
+
hash_or_string.split(", ").map { |t| t.split(" = ") }.inject({}) { |r,(k,c)|
|
12
|
+
r.merge(k => normalize_condition(c))
|
13
|
+
}
|
14
|
+
else nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.normalize_condition(string)
|
19
|
+
string.gsub(/(^\\?\")|(\\?\"$)/, "")
|
20
|
+
end
|
21
|
+
end
|
data/lib/sysdig/create_alert.rb
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
class Sysdig::CreateAlert < Sysdig::Request
|
2
2
|
def self.params
|
3
|
-
%w[
|
3
|
+
%w[condition createdOn description enabled filter modifiedOn name notify segmentBy segmentCondition severity timespan type version]
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.slice(alert)
|
7
|
+
Cistern::Hash.slice(Cistern::Hash.stringify_keys(alert), *self.params)
|
4
8
|
end
|
5
9
|
|
6
10
|
def real(alert)
|
7
11
|
service.request(
|
8
12
|
:method => :post,
|
9
13
|
:path => "/api/alerts",
|
10
|
-
:body => { "alert" => alert },
|
14
|
+
:body => { "alert" => self.class.slice(alert) },
|
11
15
|
)
|
12
16
|
end
|
13
17
|
|
14
18
|
def mock(alert)
|
15
19
|
alert_id = service.serial_id
|
16
|
-
body
|
20
|
+
body = self.class.slice(alert).merge!("id" => alert_id)
|
17
21
|
|
18
|
-
service.data[:alerts][alert_id] = body
|
22
|
+
service.data[:alerts][alert_id] = body
|
19
23
|
|
20
24
|
service.response(
|
21
25
|
:status => 201,
|
@@ -0,0 +1,152 @@
|
|
1
|
+
class Sysdig::CreateUser < Sysdig::Request
|
2
|
+
def self.params
|
3
|
+
%w[username]
|
4
|
+
end
|
5
|
+
|
6
|
+
def real(email)
|
7
|
+
service.request(
|
8
|
+
:method => :post,
|
9
|
+
:path => "/api/users", # https://app.sysdigcloud.com/api/users
|
10
|
+
:body => { "username" => email },
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
#{
|
15
|
+
#"version" => 0,
|
16
|
+
#"username" => "jlane+dev2@engineyard.com",
|
17
|
+
#"enabled" => false,
|
18
|
+
#"status" => "registered", # confirmed
|
19
|
+
#"termsAndConditions" => false,
|
20
|
+
#"pictureUrl" => "http://www.gravatar.com/avatar/5abf7bc4cb5c22d5d98e51a717ff4d4d",
|
21
|
+
#"properties" => {},
|
22
|
+
#"customerSettings" => {
|
23
|
+
#"version" => 1,
|
24
|
+
#"sysdig" => {
|
25
|
+
#"enabled" => false,
|
26
|
+
#"buckets" => []
|
27
|
+
#},
|
28
|
+
#"plan" => {
|
29
|
+
#"maxAgents" => 10,
|
30
|
+
#"groupingEnabled" => false,
|
31
|
+
#"warnIfThresholdReached" => true,
|
32
|
+
#"subscriptions" => [
|
33
|
+
#[0] {
|
34
|
+
#"id" => 9942239,
|
35
|
+
#"state" => "active",
|
36
|
+
#"balance_in_cents" => 0,
|
37
|
+
#"total_revenue_in_cents" => 37079,
|
38
|
+
#"product_price_in_cents" => 0,
|
39
|
+
#"product_version_number" => 2,
|
40
|
+
#"current_period_ends_at" => 1445468379000,
|
41
|
+
#"next_assessment_at" => 1445468379000,
|
42
|
+
#"activated_at" => 1440197981000,
|
43
|
+
#"created_at" => 1440197979000,
|
44
|
+
#"updated_at" => 1444091709000,
|
45
|
+
#"cancel_at_end_of_period" => false,
|
46
|
+
#"current_period_started_at" => 1442876379000,
|
47
|
+
#"previous_state" => "active",
|
48
|
+
#"signup_payment_id" => 104989687,
|
49
|
+
#"signup_revenue" => "0.00",
|
50
|
+
#"payment_collection_method" => "invoice",
|
51
|
+
#"customer" => {
|
52
|
+
#"first_name" => "Engine Yard",
|
53
|
+
#"last_name" => "Internal",
|
54
|
+
#"email" => "sysdig+internal@engineyard.com",
|
55
|
+
#"organization" => "sysdig+internal@engineyard.com",
|
56
|
+
#"reference" => "2892",
|
57
|
+
#"id" => 9525077,
|
58
|
+
#"created_at" => 1438965926000,
|
59
|
+
#"updated_at" => 1442515339000,
|
60
|
+
#"address" => "",
|
61
|
+
#"address_2" => "",
|
62
|
+
#"city" => "",
|
63
|
+
#"state" => "",
|
64
|
+
#"zip" => "",
|
65
|
+
#"country" => "",
|
66
|
+
#"phone" => "1-866-518-9273",
|
67
|
+
#"verified" => false
|
68
|
+
#},
|
69
|
+
#"product" => {
|
70
|
+
#"id" => 3678636,
|
71
|
+
#"name" => "Sysdig Cloud - Monthly Subscription",
|
72
|
+
#"handle" => "monthly",
|
73
|
+
#"description" => "",
|
74
|
+
#"accounting_code" => "",
|
75
|
+
#"price_in_cents" => 0,
|
76
|
+
#"interval" => 1,
|
77
|
+
#"interval_unit" => "month",
|
78
|
+
#"expiration_interval_unit" => "never",
|
79
|
+
#"trial_interval_unit" => "day",
|
80
|
+
#"return_params" => "",
|
81
|
+
#"request_credit_card" => true,
|
82
|
+
#"require_credit_card" => false,
|
83
|
+
#"created_at" => 1428489497000,
|
84
|
+
#"updated_at" => 1436301416000,
|
85
|
+
#"update_return_url" => "",
|
86
|
+
#"product_family" => {
|
87
|
+
#"id" => 488513,
|
88
|
+
#"name" => "Basic",
|
89
|
+
#"handle" => "basic",
|
90
|
+
#"description" => ""
|
91
|
+
#},
|
92
|
+
#"public_signup_pages" => [],
|
93
|
+
#"taxable" => false,
|
94
|
+
#"version_number" => 2,
|
95
|
+
#"update_return_params" => ""
|
96
|
+
#},
|
97
|
+
#"agent_licenses" => 10,
|
98
|
+
#"components" => [
|
99
|
+
#[0] {
|
100
|
+
#"component_id" => 102746,
|
101
|
+
#"subscription_id" => 9942239,
|
102
|
+
#"allocated_quantity" => 10,
|
103
|
+
#"pricing_scheme" => "per_unit",
|
104
|
+
#"name" => "Monthly Agent License ($25)",
|
105
|
+
#"kind" => "quantity_based_component",
|
106
|
+
#"unit_name" => "agent",
|
107
|
+
#"unit_balance" => 0,
|
108
|
+
#"unit_price" => 25.0,
|
109
|
+
#"archived" => false
|
110
|
+
#}
|
111
|
+
#],
|
112
|
+
#"ondemand_agents" => 0,
|
113
|
+
#"On-demand agent cap" => "0",
|
114
|
+
#"next_product_id" => nil,
|
115
|
+
#"current_billing_amount_in_cents" => "15000"
|
116
|
+
#}
|
117
|
+
#]
|
118
|
+
#}
|
119
|
+
#},
|
120
|
+
#"roles" => [
|
121
|
+
#[0] "ROLE_USER"
|
122
|
+
#],
|
123
|
+
#"customer" => {
|
124
|
+
#"id" => 2892,
|
125
|
+
#"version" => 0,
|
126
|
+
#"name" => "Engine Yard",
|
127
|
+
#"accessKey" => "4a869ba9-dd0a-4262-8617-0abfb7d02f36",
|
128
|
+
#"dateCreated" => 1438965688000,
|
129
|
+
#"lastUpdated" => 1438965688000
|
130
|
+
#},
|
131
|
+
#"timezone" => "+00:00",
|
132
|
+
#"encodedToken" => "amxhbmUrZGV2MkBlbmdpbmV5YXJkLmNvbXw4MDg5OGVhNC0xMWUzLTQ5N2MtOGIxMS1mYjRjNzE0MWUyNmYtMTQ0NTUzMDgwNzE2M3x8",
|
133
|
+
#"dateCreated" => 1445530807000,
|
134
|
+
#"lastUpdated" => 1445530807000,
|
135
|
+
#"agentInstallParams" => {
|
136
|
+
#"accessKey" => "4a869ba9-dd0a-4262-8617-0abfb7d02f36"
|
137
|
+
#},
|
138
|
+
#"accessKey" => "4a869ba9-dd0a-4262-8617-0abfb7d02f36"
|
139
|
+
#}
|
140
|
+
|
141
|
+
def mock(alert)
|
142
|
+
alert_id = service.serial_id
|
143
|
+
body = Cistern::Hash.slice(Cistern::Hash.stringify_keys(alert), *self.class.params)
|
144
|
+
|
145
|
+
service.data[:alerts][alert_id] = body.merge!("id" => alert_id)
|
146
|
+
|
147
|
+
service.response(
|
148
|
+
:status => 201,
|
149
|
+
:body => {"alert" => body},
|
150
|
+
)
|
151
|
+
end
|
152
|
+
end
|
data/lib/sysdig/get_alert.rb
CHANGED
data/lib/sysdig/mock.rb
CHANGED
@@ -29,11 +29,15 @@ class Sysdig::Mock
|
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
|
-
attr_reader :url, :logger
|
32
|
+
attr_reader :url, :logger, :account_id
|
33
33
|
|
34
34
|
def initialize(options={})
|
35
35
|
@url = options[:url] || "https://langley.engineyard.com"
|
36
36
|
@logger = options[:logger] || Logger.new(nil)
|
37
|
+
|
38
|
+
username, password, token = *options.values_at(:username, :password, :token)
|
39
|
+
|
40
|
+
@account_id = (username && password) ? Digest::SHA256.hexdigest("#{username}:#{password}") : token
|
37
41
|
end
|
38
42
|
|
39
43
|
def url_for(*pieces)
|
@@ -44,7 +48,7 @@ class Sysdig::Mock
|
|
44
48
|
status = options[:status] || 200
|
45
49
|
body = options[:body]
|
46
50
|
headers = {
|
47
|
-
"Content-Type"
|
51
|
+
"Content-Type" => "application/json; charset=utf-8",
|
48
52
|
}.merge(options[:headers] || {})
|
49
53
|
|
50
54
|
logger.debug "MOCKED RESPONSE: #{status}"
|
@@ -64,7 +68,7 @@ class Sysdig::Mock
|
|
64
68
|
end
|
65
69
|
|
66
70
|
def data
|
67
|
-
self.class.data[self.
|
71
|
+
self.class.data[self.account_id]
|
68
72
|
end
|
69
73
|
|
70
74
|
def serial_id
|
data/lib/sysdig/update_alert.rb
CHANGED
@@ -4,7 +4,17 @@ class Sysdig::UpdateAlert < Sysdig::Request
|
|
4
4
|
service.request(
|
5
5
|
:method => :put,
|
6
6
|
:path => File.join("/api/alerts", alert_id.to_s),
|
7
|
-
:body => { "alert" => alert },
|
7
|
+
:body => { "alert" => Sysdig::CreateAlert.slice(alert) },
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def mock(alert_id, alert)
|
12
|
+
body = service.data[:alerts].fetch(alert_id.to_i)
|
13
|
+
|
14
|
+
body.merge!(Sysdig::CreateAlert.slice(alert))
|
15
|
+
|
16
|
+
service.response(
|
17
|
+
:body => {"alert" => body},
|
8
18
|
)
|
9
19
|
end
|
10
20
|
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.2.
|
4
|
+
version: 0.2.3
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,10 +143,12 @@ files:
|
|
143
143
|
- bin/setup
|
144
144
|
- lib/sysdig.rb
|
145
145
|
- lib/sysdig/alert.rb
|
146
|
+
- lib/sysdig/alert_filter.rb
|
146
147
|
- lib/sysdig/alert_notification.rb
|
147
148
|
- lib/sysdig/alert_notifications.rb
|
148
149
|
- lib/sysdig/alerts.rb
|
149
150
|
- lib/sysdig/create_alert.rb
|
151
|
+
- lib/sysdig/create_user.rb
|
150
152
|
- lib/sysdig/destroy_alert.rb
|
151
153
|
- lib/sysdig/email_notification.rb
|
152
154
|
- lib/sysdig/get_alert.rb
|