circonus_api
The gem implements Active Resource pattern for Circonus API. The library maps Circonus' models to corresponding ruby classes and implements simple CRUD interface.
Contents
Installation
In your Gemfile:
gem 'circonus_api'
Require library in the project:
require 'circonus_api'
Initialize Circonus with client:
client = Circonus::Client.new(app_name, auth_token)
Circonus.init(client)
Check if it works:
> Circonus::Account.current
=> #<Circonus::Account:0x007f99bfac8090 ...
Models
There is a list of the Circonus models with links to API documentation:
- Account
- Acknowledgement
- Alert
- Annotation
- Broker
- Check
- Check Bundle
- Check Move
- Contact Group
- Data
- Graph
- Metric Cluster
- Maintenance
- Rebuild Broker
- Rule Set
- Rule Set Group
- Tag
- Template
- User
- Worksheet
CRUD
There are several basic CRUD methods:
Class methods:
::all - returns all records for corresponding model
Circonus::RuleSet.all
::find - find the record by id
Circonus::RuleSet.find(42)
::create - creates new record
Circonus::RuleSet.create(attribute_hash)
Instrance methods:
#update - updates the record on Circonus (performs PUT request) and returns new object.
rule_set = Circonus::RuleSet.find(42)
rule_set.metric_type = 'code'
rule_set.update
#create creates a new record on Circonus (performs POST request) and returns new object.
rule_set = Circonus::RuleSet.new({metric_type: 'code', ...})
rule_set.create
There is also the #save method which calls #update if record has id or #create if id is nil.
Some models don't implement all CRUD functionality. See Circonus documentation and specs.
Search
There is the ::search method which can filter results by attributes:
rule_sets = Circonus::RuleSet.search(metric_name: 'code', check: '/check/100500')