sysdig 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/sysdig/alert.rb +58 -0
- data/lib/sysdig/alerts.rb +12 -0
- data/lib/sysdig/create_alert.rb +9 -0
- data/lib/sysdig/get_alert.rb +8 -0
- data/lib/sysdig/get_alerts.rb +8 -0
- data/lib/sysdig/get_notification.rb +7 -0
- data/lib/sysdig/get_notifications.rb +11 -0
- data/lib/sysdig/login.rb +9 -0
- data/lib/sysdig/mock.rb +47 -0
- data/lib/sysdig/model.rb +5 -0
- data/lib/sysdig/notification.rb +17 -0
- data/lib/sysdig/notifications.rb +11 -0
- data/lib/sysdig/real.rb +87 -0
- data/lib/sysdig/response.rb +63 -0
- data/lib/sysdig/update_alert.rb +11 -0
- data/lib/sysdig/version.rb +3 -0
- data/lib/sysdig.rb +37 -0
- data/sysdig.gemspec +39 -0
- metadata +187 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: e3790850725c9f17424b02c5a0338ab5a9b8b757
         | 
| 4 | 
            +
              data.tar.gz: b2aded05c614ab191c4ce75632550e8550f6d172
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: c95da8e9830383b4b3571724226f044f9e87827d455c2eece59a0ff31430de3bafad91647a8b4435320cbaf5cad7433e1b1ce8d08f856c0db7641783e5ad0bb0
         | 
| 7 | 
            +
              data.tar.gz: 1ea57891abfef711cc68979bc9061521e54afaec4d943984bef3ed6a93dec08edf1da6dc8b2fbddf279c80b18479d9957471b5873fe645c5f00dd8c44dd463ed
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/CODE_OF_CONDUCT.md
    ADDED
    
    | @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            # Contributor Code of Conduct
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2015 Josh Lane
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 13 | 
            +
            all copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 21 | 
            +
            THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            # Sysdig
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sysdig`. To experiment with that code, run `bin/console` for an interactive prompt.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            TODO: Delete this and the text above, and describe your gem
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## Installation
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Add this line to your application's Gemfile:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ```ruby
         | 
| 12 | 
            +
            gem 'sysdig'
         | 
| 13 | 
            +
            ```
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            And then execute:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ bundle
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Or install it yourself as:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                $ gem install sysdig
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ## Usage
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            TODO: Write usage instructions here
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ## Development
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ## Contributing
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sysdig. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
         | 
| 36 | 
            +
             | 
| 37 | 
            +
             | 
| 38 | 
            +
            ## License
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
         | 
| 41 | 
            +
             | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "bundler/setup"
         | 
| 4 | 
            +
            require "sysdig"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 7 | 
            +
            # with your gem easier. You can also use a different console, if you like.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 10 | 
            +
            # require "pry"
         | 
| 11 | 
            +
            # Pry.start
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            require "irb"
         | 
| 14 | 
            +
            IRB.start
         | 
    
        data/bin/setup
    ADDED
    
    
    
        data/lib/sysdig/alert.rb
    ADDED
    
    | @@ -0,0 +1,58 @@ | |
| 1 | 
            +
            class Sysdig::Alert < Sysdig::Model
         | 
| 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 | 
            +
              identity :id, type: :integer
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              attribute :condition
         | 
| 18 | 
            +
              attribute :created_at,         alias: "createdOn",  parser: method(:epoch_time)
         | 
| 19 | 
            +
              attribute :description
         | 
| 20 | 
            +
              attribute :enabled,            type:  :boolean,     default: true
         | 
| 21 | 
            +
              attribute :filter,             parser: lambda { |v, _| load_filter(v) }
         | 
| 22 | 
            +
              attribute :group_aggregations, type:  :array,       alias:  "groupAggregations"
         | 
| 23 | 
            +
              attribute :group_by,           type:  :array,       alias:  "groupBy"
         | 
| 24 | 
            +
              attribute :group_condition,    alias: "groupCondition"
         | 
| 25 | 
            +
              attribute :modified_at,        alias: "modifiedOn", parser: method(:epoch_time)
         | 
| 26 | 
            +
              attribute :name
         | 
| 27 | 
            +
              attribute :notification_count, type:  :integer,     alias:  "notificationCount"
         | 
| 28 | 
            +
              attribute :notify,             parser: lambda { |v, _| Array(v).map { |x| x.upcase } }
         | 
| 29 | 
            +
              attribute :severity,           type:  :integer
         | 
| 30 | 
            +
              attribute :segment_by,         alias: "segmentBy"
         | 
| 31 | 
            +
              attribute :segment_condition,  alias: "segmentCondition"
         | 
| 32 | 
            +
              attribute :targets,            type:  :array
         | 
| 33 | 
            +
              attribute :timespan,           type:  :integer
         | 
| 34 | 
            +
              attribute :type,               parser: lambda { |v, _| v.to_s.upcase }
         | 
| 35 | 
            +
              attribute :version,            type:  :integer
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              def save
         | 
| 38 | 
            +
                params = {
         | 
| 39 | 
            +
                  "name"        => self.name,
         | 
| 40 | 
            +
                  "description" => self.description,
         | 
| 41 | 
            +
                  "enabled"     => self.enabled,
         | 
| 42 | 
            +
                  "filter"      => self.class.dump_filter(filter || {}),
         | 
| 43 | 
            +
                  "type"        => self.type,
         | 
| 44 | 
            +
                  "condition"   => self.condition,
         | 
| 45 | 
            +
                  "timespan"    => self.timespan,
         | 
| 46 | 
            +
                  "severity"    => self.severity,
         | 
| 47 | 
            +
                  "notify"      => self.notify,
         | 
| 48 | 
            +
                }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                data = (
         | 
| 51 | 
            +
                  (new_record? && service.create_alert(params)) ||
         | 
| 52 | 
            +
                  service.update_alert(self.identity, params.merge("version" => self.version))
         | 
| 53 | 
            +
                ).body.fetch("alert")
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                merge_attributes(data)
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            end
         | 
    
        data/lib/sysdig/login.rb
    ADDED
    
    
    
        data/lib/sysdig/mock.rb
    ADDED
    
    | @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            class Sysdig::Mock
         | 
| 2 | 
            +
              def self.data
         | 
| 3 | 
            +
                @@data ||= Hash.new { |h,url|
         | 
| 4 | 
            +
                  h[url] = {
         | 
| 5 | 
            +
                    :alerts => {},
         | 
| 6 | 
            +
                  }
         | 
| 7 | 
            +
                }
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              attr_reader :url, :logger
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def initialize(options={})
         | 
| 13 | 
            +
                @url     = options[:url]    || "https://langley.engineyard.com"
         | 
| 14 | 
            +
                @logger  = options[:logger] || Logger.new(nil)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def url_for(*pieces)
         | 
| 18 | 
            +
                File.join(self.url, *pieces)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def response(options={})
         | 
| 22 | 
            +
                status  = options[:status] || 200
         | 
| 23 | 
            +
                body    = options[:body]
         | 
| 24 | 
            +
                headers = {
         | 
| 25 | 
            +
                  "Content-Type"  => "application/json; charset=utf-8"
         | 
| 26 | 
            +
                }.merge(options[:headers] || {})
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                logger.debug "MOCKED RESPONSE: #{status}"
         | 
| 29 | 
            +
                logger.debug('response') { headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n") }
         | 
| 30 | 
            +
                logger.debug caller[0]
         | 
| 31 | 
            +
                logger.debug('response.body') { body }
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                Sysdig::Response.new(
         | 
| 34 | 
            +
                  :status  => status,
         | 
| 35 | 
            +
                  :headers => headers,
         | 
| 36 | 
            +
                  :body    => body,
         | 
| 37 | 
            +
                  :request => {
         | 
| 38 | 
            +
                    :method  => :mocked,
         | 
| 39 | 
            +
                    :url     => caller[1],
         | 
| 40 | 
            +
                  }
         | 
| 41 | 
            +
                ).raise!
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              def data
         | 
| 45 | 
            +
                self.class.data[self.url]
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/lib/sysdig/model.rb
    ADDED
    
    
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            class Sysdig::Notification < Sysdig::Model
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              identity :id, type: :integer
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              attribute :timespan,           type: :integer
         | 
| 6 | 
            +
              attribute :severity,           type: :integer
         | 
| 7 | 
            +
              attribute :target
         | 
| 8 | 
            +
              attribute :alert_id,           type: :integer, alias: "alert"
         | 
| 9 | 
            +
              attribute :type
         | 
| 10 | 
            +
              attribute :criteria
         | 
| 11 | 
            +
              attribute :resolved,           type: :boolean
         | 
| 12 | 
            +
              attribute :condition
         | 
| 13 | 
            +
              attribute :state
         | 
| 14 | 
            +
              attribute :group_aggregations, type: :array,   alias: "groupAggregations"
         | 
| 15 | 
            +
              attribute :entities,           type: :array
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            end
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            class Sysdig::Notifications < Sysdig::Collection
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              model Sysdig::Notification
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              def all(options={})
         | 
| 6 | 
            +
                to   = options[:to]   || Time.now
         | 
| 7 | 
            +
                from = options[:from] || Time.at(Time.now.to_i - 86400) # 1 day
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                load(service.get_notifications(from, to).body.fetch("notifications"))
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
    
        data/lib/sysdig/real.rb
    ADDED
    
    | @@ -0,0 +1,87 @@ | |
| 1 | 
            +
            class Sysdig::Real
         | 
| 2 | 
            +
              attr_reader :url, :path, :connection, :parser, :logger, :adapter, :authentication
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              def initialize(options={})
         | 
| 5 | 
            +
                @url = URI.parse(options[:url] || "https://app.sysdigcloud.com")
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                adapter            = options[:adapter]            || Faraday.default_adapter
         | 
| 8 | 
            +
                connection_options = options[:connection_options] || {}
         | 
| 9 | 
            +
                logger, @logger    = options[:logger]             || Logger.new(nil)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                @connection = Faraday.new({url: @url}.merge(connection_options)) do |builder|
         | 
| 12 | 
            +
                  # response
         | 
| 13 | 
            +
                  builder.response :json
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  # request
         | 
| 16 | 
            +
                  builder.request :retry,
         | 
| 17 | 
            +
                    :max                 => 30,
         | 
| 18 | 
            +
                    :interval            => 1,
         | 
| 19 | 
            +
                    :interval_randomness => 0.05,
         | 
| 20 | 
            +
                    :backoff_factor      => 2
         | 
| 21 | 
            +
                  builder.request :multipart
         | 
| 22 | 
            +
                  builder.request :json
         | 
| 23 | 
            +
                  builder.use :cookie_jar
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  builder.use Faraday::Response::RaiseError
         | 
| 26 | 
            +
                  builder.use Ey::Logger::Faraday, format: :machine, device: logger
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  builder.adapter(*adapter)
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                @username, @password = *options.values_at(:username, :password)
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                @authentication = Mutex.new
         | 
| 34 | 
            +
                @authenticated  = false
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              def request_with_authentication(options={})
         | 
| 38 | 
            +
                if !@authenticated
         | 
| 39 | 
            +
                  @authentication.synchronize {
         | 
| 40 | 
            +
                    if !@authenticated
         | 
| 41 | 
            +
                      login(@username, @password)
         | 
| 42 | 
            +
                      @authenticated = true
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
                  }
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                request_without_authentication(options)
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              def request_without_authentication(options={})
         | 
| 51 | 
            +
                method  = (options[:method] || "get").to_s.downcase.to_sym
         | 
| 52 | 
            +
                url     = URI.parse(options[:url] || File.join(@url.to_s, options[:path] || "/"))
         | 
| 53 | 
            +
                params  = options[:params] || {}
         | 
| 54 | 
            +
                body    = options[:body]
         | 
| 55 | 
            +
                headers = options[:headers] || {}
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                headers["Content-Type"] ||= if body.nil?
         | 
| 58 | 
            +
                                              if !params.empty?
         | 
| 59 | 
            +
                                                "application/x-www-form-urlencoded"
         | 
| 60 | 
            +
                                              else # Rails infers a Content-Type and we must set it here for the canonical string to match
         | 
| 61 | 
            +
                                                "text/plain"
         | 
| 62 | 
            +
                                              end
         | 
| 63 | 
            +
                                            end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                response = @connection.send(method) do |req|
         | 
| 66 | 
            +
                  req.url(url.to_s)
         | 
| 67 | 
            +
                  req.headers.merge!(headers)
         | 
| 68 | 
            +
                  req.params.merge!(params)
         | 
| 69 | 
            +
                  req.body = body
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                Sysdig::Response.new(
         | 
| 73 | 
            +
                  :status  => response.status,
         | 
| 74 | 
            +
                  :headers => response.headers,
         | 
| 75 | 
            +
                  :body    => response.body,
         | 
| 76 | 
            +
                  :request => {
         | 
| 77 | 
            +
                    :method  => method,
         | 
| 78 | 
            +
                    :url     => url,
         | 
| 79 | 
            +
                    :headers => headers,
         | 
| 80 | 
            +
                    :body    => body,
         | 
| 81 | 
            +
                    :params  => params,
         | 
| 82 | 
            +
                  }
         | 
| 83 | 
            +
                ).raise!
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              alias_method :request, :request_with_authentication
         | 
| 87 | 
            +
            end
         | 
| @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            class Sysdig::Response
         | 
| 2 | 
            +
              class Error < StandardError
         | 
| 3 | 
            +
                attr_reader :response
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(response)
         | 
| 6 | 
            +
                  @response = response
         | 
| 7 | 
            +
                  super(
         | 
| 8 | 
            +
                    {
         | 
| 9 | 
            +
                      :body    => response.body,
         | 
| 10 | 
            +
                      :headers => response.headers,
         | 
| 11 | 
            +
                      :request => response.request,
         | 
| 12 | 
            +
                      :status  => response.status,
         | 
| 13 | 
            +
                    }.inspect
         | 
| 14 | 
            +
                  )
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def errors
         | 
| 18 | 
            +
                  response.body["errors"]
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def full_messages
         | 
| 22 | 
            +
                  if errors.is_a?(Hash)
         | 
| 23 | 
            +
                    errors.inject([]){|r,(k,v)| r += v.map{|s| "#{k.capitalize} #{s}"}}
         | 
| 24 | 
            +
                  else # Array or String
         | 
| 25 | 
            +
                    errors
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              BadRequest    = Class.new(Error)
         | 
| 31 | 
            +
              NotFound      = Class.new(Error)
         | 
| 32 | 
            +
              Unprocessable = Class.new(Error)
         | 
| 33 | 
            +
              Conflict      = Class.new(Error)
         | 
| 34 | 
            +
              Unexpected    = Class.new(Error)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              EXCEPTION_MAPPING = {
         | 
| 37 | 
            +
                400 => BadRequest,
         | 
| 38 | 
            +
                404 => NotFound,
         | 
| 39 | 
            +
                409 => Conflict,
         | 
| 40 | 
            +
                422 => Unprocessable,
         | 
| 41 | 
            +
                500 => Unexpected,
         | 
| 42 | 
            +
              }
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              attr_reader :headers, :status, :body, :request
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              def initialize(options={})
         | 
| 47 | 
            +
                @status  = options[:status]
         | 
| 48 | 
            +
                @headers = options[:headers]
         | 
| 49 | 
            +
                @body    = options[:body]
         | 
| 50 | 
            +
                @request = options[:request]
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              def successful?
         | 
| 54 | 
            +
                self.status >= 200 && self.status <= 299 || self.status == 304
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              def raise!
         | 
| 58 | 
            +
                if !successful?
         | 
| 59 | 
            +
                  raise((EXCEPTION_MAPPING[self.status] || Error).new(self))
         | 
| 60 | 
            +
                else self
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
            end
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            class Sysdig::UpdateAlert < Sysdig::Request
         | 
| 2 | 
            +
              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 | 
            +
                service.request(
         | 
| 6 | 
            +
                  :method => :put,
         | 
| 7 | 
            +
                  :path   => File.join("/api/alerts", alert_id.to_s),
         | 
| 8 | 
            +
                  :body   => { "alert" => alert },
         | 
| 9 | 
            +
                )
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
    
        data/lib/sysdig.rb
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            require "sysdig/version"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "cistern"
         | 
| 4 | 
            +
            require "faraday"
         | 
| 5 | 
            +
            require "faraday_middleware"
         | 
| 6 | 
            +
            require "faraday/cookie_jar"
         | 
| 7 | 
            +
            require "logger"
         | 
| 8 | 
            +
            require "ey/logger"
         | 
| 9 | 
            +
            require "ey/logger/faraday"
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            class Sysdig
         | 
| 12 | 
            +
              include Cistern::Client
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              recognizes :url, :adapter, :logger
         | 
| 15 | 
            +
              requires :username, :password
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            # clients
         | 
| 20 | 
            +
            require 'sysdig/real'
         | 
| 21 | 
            +
            require 'sysdig/mock'
         | 
| 22 | 
            +
            require 'sysdig/model'
         | 
| 23 | 
            +
            require 'sysdig/response'
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            require 'sysdig/login'
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            require 'sysdig/alert'
         | 
| 28 | 
            +
            require 'sysdig/alerts'
         | 
| 29 | 
            +
            require 'sysdig/create_alert'
         | 
| 30 | 
            +
            require 'sysdig/get_alert'
         | 
| 31 | 
            +
            require 'sysdig/get_alerts'
         | 
| 32 | 
            +
            require 'sysdig/update_alert'
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            require 'sysdig/get_notification'
         | 
| 35 | 
            +
            require 'sysdig/get_notifications'
         | 
| 36 | 
            +
            require 'sysdig/notification'
         | 
| 37 | 
            +
            require 'sysdig/notifications'
         | 
    
        data/sysdig.gemspec
    ADDED
    
    | @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'sysdig/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "sysdig"
         | 
| 8 | 
            +
              spec.version       = Sysdig::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Josh Lane"]
         | 
| 10 | 
            +
              spec.email         = ["jlane@engineyard.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.summary       = %q{Ruby Client for Sysdig Cloud}
         | 
| 13 | 
            +
              spec.description   = %q{Ruby Sysdig Cloud API Client}
         | 
| 14 | 
            +
              spec.homepage      = "https://github.com/engineyard/sysdig-client"
         | 
| 15 | 
            +
              spec.license       = "MIT"
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
         | 
| 18 | 
            +
              # delete this section to allow pushing this gem to any host.
         | 
| 19 | 
            +
              if spec.respond_to?(:metadata)
         | 
| 20 | 
            +
                spec.metadata['allowed_push_host'] = "https://rubygems.org"
         | 
| 21 | 
            +
              else
         | 
| 22 | 
            +
                raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 26 | 
            +
              spec.bindir        = "bin"
         | 
| 27 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 28 | 
            +
              spec.require_paths = ["lib"]
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              spec.add_development_dependency "bundler", "~> 1.10"
         | 
| 31 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 32 | 
            +
              spec.add_development_dependency "rspec"
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              spec.add_dependency "cistern",            "~> 2.2"
         | 
| 35 | 
            +
              spec.add_dependency "ey-logger",          "~> 0.0"
         | 
| 36 | 
            +
              spec.add_dependency "faraday",            "~> 0.9"
         | 
| 37 | 
            +
              spec.add_dependency "faraday_middleware", "~> 0.9"
         | 
| 38 | 
            +
              spec.add_dependency "faraday-cookie_jar", "~> 0.0"
         | 
| 39 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,187 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: sysdig
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Josh Lane
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2015-10-20 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '1.10'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.10'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '10.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '10.0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rspec
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: cistern
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '2.2'
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '2.2'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: ey-logger
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - "~>"
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0.0'
         | 
| 76 | 
            +
              type: :runtime
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0.0'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: faraday
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '0.9'
         | 
| 90 | 
            +
              type: :runtime
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0.9'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: faraday_middleware
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - "~>"
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0.9'
         | 
| 104 | 
            +
              type: :runtime
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - "~>"
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0.9'
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: faraday-cookie_jar
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - "~>"
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '0.0'
         | 
| 118 | 
            +
              type: :runtime
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - "~>"
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '0.0'
         | 
| 125 | 
            +
            description: Ruby Sysdig Cloud API Client
         | 
| 126 | 
            +
            email:
         | 
| 127 | 
            +
            - jlane@engineyard.com
         | 
| 128 | 
            +
            executables:
         | 
| 129 | 
            +
            - console
         | 
| 130 | 
            +
            - setup
         | 
| 131 | 
            +
            extensions: []
         | 
| 132 | 
            +
            extra_rdoc_files: []
         | 
| 133 | 
            +
            files:
         | 
| 134 | 
            +
            - ".gitignore"
         | 
| 135 | 
            +
            - ".rspec"
         | 
| 136 | 
            +
            - ".travis.yml"
         | 
| 137 | 
            +
            - CODE_OF_CONDUCT.md
         | 
| 138 | 
            +
            - Gemfile
         | 
| 139 | 
            +
            - LICENSE.txt
         | 
| 140 | 
            +
            - README.md
         | 
| 141 | 
            +
            - Rakefile
         | 
| 142 | 
            +
            - bin/console
         | 
| 143 | 
            +
            - bin/setup
         | 
| 144 | 
            +
            - lib/sysdig.rb
         | 
| 145 | 
            +
            - lib/sysdig/alert.rb
         | 
| 146 | 
            +
            - lib/sysdig/alerts.rb
         | 
| 147 | 
            +
            - lib/sysdig/create_alert.rb
         | 
| 148 | 
            +
            - lib/sysdig/get_alert.rb
         | 
| 149 | 
            +
            - lib/sysdig/get_alerts.rb
         | 
| 150 | 
            +
            - lib/sysdig/get_notification.rb
         | 
| 151 | 
            +
            - lib/sysdig/get_notifications.rb
         | 
| 152 | 
            +
            - lib/sysdig/login.rb
         | 
| 153 | 
            +
            - lib/sysdig/mock.rb
         | 
| 154 | 
            +
            - lib/sysdig/model.rb
         | 
| 155 | 
            +
            - lib/sysdig/notification.rb
         | 
| 156 | 
            +
            - lib/sysdig/notifications.rb
         | 
| 157 | 
            +
            - lib/sysdig/real.rb
         | 
| 158 | 
            +
            - lib/sysdig/response.rb
         | 
| 159 | 
            +
            - lib/sysdig/update_alert.rb
         | 
| 160 | 
            +
            - lib/sysdig/version.rb
         | 
| 161 | 
            +
            - sysdig.gemspec
         | 
| 162 | 
            +
            homepage: https://github.com/engineyard/sysdig-client
         | 
| 163 | 
            +
            licenses:
         | 
| 164 | 
            +
            - MIT
         | 
| 165 | 
            +
            metadata:
         | 
| 166 | 
            +
              allowed_push_host: https://rubygems.org
         | 
| 167 | 
            +
            post_install_message: 
         | 
| 168 | 
            +
            rdoc_options: []
         | 
| 169 | 
            +
            require_paths:
         | 
| 170 | 
            +
            - lib
         | 
| 171 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 172 | 
            +
              requirements:
         | 
| 173 | 
            +
              - - ">="
         | 
| 174 | 
            +
                - !ruby/object:Gem::Version
         | 
| 175 | 
            +
                  version: '0'
         | 
| 176 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 177 | 
            +
              requirements:
         | 
| 178 | 
            +
              - - ">="
         | 
| 179 | 
            +
                - !ruby/object:Gem::Version
         | 
| 180 | 
            +
                  version: '0'
         | 
| 181 | 
            +
            requirements: []
         | 
| 182 | 
            +
            rubyforge_project: 
         | 
| 183 | 
            +
            rubygems_version: 2.4.5.1
         | 
| 184 | 
            +
            signing_key: 
         | 
| 185 | 
            +
            specification_version: 4
         | 
| 186 | 
            +
            summary: Ruby Client for Sysdig Cloud
         | 
| 187 | 
            +
            test_files: []
         |