Name: synthetics
Owner: looker
Description: HTTP client for New Relic Synthetics API
Forked from: swipely/synthetics
Created: 2018-04-17 14:42:35.0
Updated: 2018-04-17 15:59:10.0
Pushed: 2018-04-20 23:06:17.0
Size: 29
Language: Ruby
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Synthetics is a rubygem that interfaces with New Relic Synthetics' HTTP API. It can be used to manage monitors and labels programatically. The above link is useful for finding the possible options that can be passed to each method, particularly creating and updating monitors.
Add this line to your application's Gemfile:
'synthetics'
And then execute:
ndle
Or install it yourself as:
m install synthetics
All interaction with the API starts by creating an API client. The client requires an admin API key, which can be generated in the Web UI. Once you have your API key, there are two ways you can pass it to the client:
Set API key directly:
nthetics = Synthetics.new('<YOUR-API-KEY>')
Set API key via environment variable:
V['SYNTHETICS_API_KEY'] = 'YOUR-API-KEY'
nthetics = Synthetics.new
List locations:
nthetics.locations.list
private=>false, :name=>"AWS_US_EAST_1", :label=>"Washington, DC, USA"},
.
List monitors:
nthetics.monitors.list
onitors => [
{
:id => "SOME-VALID-UUID",
:name => "Ping Google",
:type => "SIMPLE",
:frequency => 1440,
:uri => "https://google.com",
:locations => ["AWS_US_EAST_1", "AWS_EU_WEST_1"],
:status => "ENABLED",
:sla_threshold => 7.0,
:modified_at => "2016-02-26T15:10:58.515+0000",
:created_at => "2016-02-26T15:10:58.515+0000",
:user_id => 123,
:api_version => "0.2.2"
}
ount => 1
Create monitor:
nthetics.monitors.create(
. name: 'Google Monitor',
. frequency: 15,
. uri: 'https://google.com',
. locations: %w(AWS_US_WEST_1),
. type: 'simple'
. )
These examples assume you have a valid monitor UUID, such as:
id = 'SOME-VAILD-UUID'
Show monitor:
nthetics.monitor(uuid).show
d => "SOME-VALID-UUID",
ame => "Ping Google",
ype => "SIMPLE",
requency => 15,
ri => "https://google.com",
ocations => ["AWS_US_EAST_1", "AWS_EU_WEST_1"],
tatus => "ENABLED",
la_threshold => 7.0,
odified_at => "2016-02-26T15:10:58.515+0000",
reated_at => "2016-02-26T15:10:58.515+0000",
ser_id => 123,
pi_version => "0.2.2"
Update monitor:
nthetics.monitor(uuid).update(
. name: 'Google Monitor',
. frequency: 30,
. uri: 'https://google.com',
. locations: %w(AWS_US_WEST_1),
. type: 'simple'
. )
d => "SOME-VALID-UUID",
ame => "Ping Google",
ype => "SIMPLE",
requency => 30,
ri => "https://google.com",
ocations => ["AWS_US_EAST_1", "AWS_EU_WEST_1"],
tatus => "ENABLED",
la_threshold => 7.0,
odified_at => "2016-02-26T15:10:58.515+0000",
reated_at => "2016-02-26T15:10:58.515+0000",
ser_id => 123,
pi_version => "0.2.2"
Update monitor script:
nthetics.monitor(uuid).update_script('var test = function() {};')
Destroy monitor:
nthetics.monitor(uuid).destroy
List labels:
nthetics.labels.list
abels => [
{
:type => 'sha',
:value => '8ace32a'
}
ount => 1
These examples assume you have a valid label, such as:
bel = 'sample:label'
Show monitors for a label:
nthetics.label(label).monitors
onitors => [
{
:id => "SOME-VALID-UUID",
:name => "Ping Google",
:type => "SIMPLE",
:frequency => 1440,
:uri => "https://google.com",
:locations => ["AWS_US_EAST_1", "AWS_EU_WEST_1"],
:status => "ENABLED",
:sla_threshold => 7.0,
:modified_at => "2016-02-26T15:10:58.515+0000",
:created_at => "2016-02-26T15:10:58.515+0000",
:user_id => 123,
:api_version => "0.2.2"
}
ount => 1
Attach a label to a monitor:
nthetics.label(label).attach(uuid)
Remove a label from a monitor:
nthetics.label(label).remove(uuid)