Skip to content

Commit

Permalink
Merge pull request #17 from dbradf/v2
Browse files Browse the repository at this point in the history
Version 2
  • Loading branch information
dbradf committed Feb 9, 2017
2 parents e244813 + e66267e commit 844a804
Show file tree
Hide file tree
Showing 19 changed files with 1,412 additions and 54 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 2.0.0 / 2017-02-09

* Format synthetics.json file to make it human readable
* Add Developer documentation
* Add Contribution guide
* Add ability to update alerting
* Add command to get available locations
* Add ability to update synthetics configuration
* Add support for non-SCRIPTED_BROWSER synthetics
* Better handling of New Relic errors

# 1.0.1 / 2017-01-04

* Updated README
Expand Down
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing

When contributing to this repository, please first discuss the change you wish to make via github issues before making the change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Pull Request Process

* Update the README.md with details of changes to the interface.
* Ensure the travis build is passing for the given change (npm test).
* Increase the version numbers in any examples files and the README.md to the new version that this pull request would represent. The versioning scheme we use is http://semver.org/
* Ensure any correlated issue numbers are included in the pull request.

## Code of Conduct

http://contributor-covenant.org/version/1/2/0/

43 changes: 43 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Development information

## Prerequisites

* node.js v6 or higher

## Code Structure

* bin/
* command line interface and command line parsing code. bin/synthmanager.js is the entry point. yargs is used to do the command line parsing.
* lib/
* code that implements the command line functionality.
* test/
* tests. The tests use mocha, chai and testdouble.js.
* index.js
* library entrypoint that provides webdriver functionality for running tests locally.

## Command Tasks

### Linting

```
gulp lint
```

### Testing

```
gulp test
```

### Lint and Test in one Tasks

```
gulp
```

or

```
npm test
```

48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,44 @@ $ synthmanager update --name "New Synthetic Name"
### Create a new synthetic

```
synthmanager create --name <synthetic_name> --file <filename>
synthmanager create
```


Create a synthetic in New Relic and a file to contain the synthetic code. The local file will be created in the directory the command was run. This is where you will put your test code.

* --name <synthetic_name> - Name of synthetic. This is the name used in New Relic as well as how it should be refered to by other commands
* --file <filename> - Filename where the synthethics code should go. This file will be created under the 'synthetics' directory. The file should not already exist.
* --filename <filename> - Filename where the synthethics code should go. This file will be created under the 'synthetics' directory. The file should not already exist (required for SCRIPT_BROWSER and SCRIPT_API synthetics).
* --frequency <frequency> - Frequency to run the synthetic in minutes. This should be an integer. Possible values are: 1, 5, 10, 15, 30, 60, 360, 720, or 1440. The default is 10.
* --locations <location> - Locations to run the synthetic. This can be specified multiple times to specify multiple locations.
* --type <type> - Type of synthetic to create. Possible values are: SIMPLE, BROWSER, SCRIPT_BROWSER, SCRIPT_API.
* --uri <uri> - URI that synthetic should check (required for SIMPLE and BROWSER synthetics).
* --emails <email> - Email to send synthetic alerts to (can be specified multiple times).


### Update New Relic with synthetics code

```
synthmanager update --name <synthetic_name>
synthmanager update
```

Update New Relic with the latest synthetic code for the specified synthetic.

* --name <synthetic_name> - name of synthetic to update. This should be the name used when the synthetic was created.
* --filename <synthetic_filename> - filename of synthetic to update.


### Import a synthetic from New Relic

In order to import a New Relic Synthetic, the synthetic id is needed. This can be obtained from the New Relic Synthetics website. Navigate to the Synthetic to import and the id will be the last part of the URL (It is made up of 5 hexidecimal numbers separated by dashes).

```
synthmanager import --name <synthetic_name> --id <synthetic_id> --file <filename>
synthmanager import
```

--id <synthetic_id> - ID of synthetic in New Relic (this is part of the url when viewing the synthetic in New Relic)
--filename <filename> - File to store the synthetic code.

Import an existing synthetic from New Relic.

### Global options
Expand All @@ -106,6 +114,38 @@ These options can be used with any command:
* --verbose - Provide verbose logging output.
* --debug - Provide debug logging output.

### See a list of available loctions

Synthetics run from specified locations. You can get a list of available locations from the following command.

```
synthmanager locations
```

### Change synthetics configuration

A synthetics configuration can be changed with the following command:

```
synthmanager config
```

The synthetic to change must be specified with one of the following options:

* --name <name> - name of synthetic to change.
* --id <id> - id of synthetic to change.

The following configuration changes can be made:

* --frequency <frequency> - Frequency to run the synthetic in minutes. This should be an integer. Possible values are: 1, 5, 10, 15, 30, 60, 360, 720, or 1440. The default is 10.
* --locations <location> - Locations to run the synthetic. This can be specified multiple times to specify multiple locations.
* --uri <uri> - URI that synthetic should check (only for SIMPLE and BROWSER synthetics).
* --status <status> - Is the synthetic enabled? (possible values: "ENABLED", "DISABLED", "MUTED")
* --rename <new_name> - Change the name of the synthetic.
* --addemail <email> - Add the specified email to alerting for the synthetic (this option can be specified multiple times).
* --rmemail <email> - Remove the specified email from alerting for the synthetic.


## Configuration

Configuration options can be changed by adding a 'synthetics.config.json' file in the base of the project.
Expand Down
98 changes: 98 additions & 0 deletions bin/cmds/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const dependencies = require('../../lib/dependency');
const logger = require('winston');
const _ = require('lodash');

exports.command = 'config';
exports.desc = 'Change configuration options of a synthetic';
exports.builder = {
name: {
alias: 'n',
desc: 'Name of synthetic to configure',
type: 'string',
},
id: {
alias: 'i',
desc: 'Id of synthetic to configure',
type: 'string',
},
frequency: {
desc: 'Frequency to run synthetic(in minutes)',
choices: [1, 5, 10, 15, 30, 60, 360, 720, 1440],
type: 'number',
},
locations: {
desc: 'Locations to run synthetic',
type: 'array',
},
uri: {
alias: 'u',
desc: 'URI for synthetic',
type: 'string',
},
status: {
alias: 's',
desc: 'Is the synthetic enabled?',
choices: ['ENABLED', 'DISABLED', 'MUTED'],
},
rename: {
desc: 'New name to use for synthetic',
type: 'string',
},
addemail: {
desc: 'Add emails to alerting for synthetics (parameter can be specified multiple times)',
type: 'array',
},
rmemail: {
desc: 'Remove email from alerting for synthetics',
type: 'string',
},
}

function validate(argv) {
if (_.isNil(argv.name) && _.isNil(argv.id)) {
throw new Error('ERROR: Either name or id must be specified');
}

const allOptions = [argv.frequency, argv.locations, argv.uri, argv.status, argv.rename, argv.addemail, argv.rmemail];

if (_.every(allOptions, _.isNil)) {
throw new Error('Error: No changes specified');
}
}

exports.handler = function (argv) {
require('../../lib/config/LoggingConfig')(argv);

validate(argv);

const config = require('../../lib/config/SyntheticsConfig').getConfig(argv);

logger.verbose('Config: ' + argv.name + ':' + argv.id);
logger.verbose(argv);

const changeConfigOrchestrator = dependencies(config).changeConfigOrchestrator;

if (!_.isNil(argv.id)) {
changeConfigOrchestrator.changeConfigurationById(
argv.id,
argv.frequency,
argv.locations,
argv.uri,
argv.status,
argv.rename,
argv.addemail,
argv.rmemail
);
} else if (!_.isNil(argv.name)) {
changeConfigOrchestrator.changeConfigurationByName(
argv.name,
argv.frequency,
argv.locations,
argv.uri,
argv.status,
argv.rename,
argv.addemail,
argv.rmemail
);
}
}
53 changes: 47 additions & 6 deletions bin/cmds/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const dependencies = require('../../lib/dependency');
const logger = require('winston');
const _ = require('lodash');

exports.command = 'create';
exports.desc = 'Create new synthetics monitor';
Expand All @@ -11,27 +12,64 @@ exports.builder = {
},
filename: {
alias: 'f',
desc: 'Filename to place synthetic code',
demand: 1
desc: 'Filename to place synthetic code (require for SCRIPT_API and SCRIPT_BROWSER synthetics)'
},
type: {
alias: 't',
desc: 'Type of synthetic to create',
choices: ['SIMPLE', 'BROWSER', 'SCRIPT_BROWSER', 'SCRIPT_API'],
default: 'SCRIPT_BROWSER'
},
frequency: {
desc: 'Frequency to run synthetic',
default: 10
desc: 'Frequency to run synthetic(in minutes)',
choices: [1, 5, 10, 15, 30, 60, 360, 720, 1440],
default: 10,
type: 'number'
},
locations: {
desc: 'Locations to run synthetic',
default: ['AWS_US_WEST_1']
default: ['AWS_US_WEST_1'],
type: 'array'
},
uri: {
alias: 'u',
desc: 'URI for synthetic (required for SIMPLE and BROWSER synthetics)',
type: 'string'
},
emails: {
alias: 'e',
desc: 'Emails to send synthetic alerts to (can be specified multiple times)',
type: 'array',
}
}

function validate(argv) {
if ((argv.type === 'SIMPLE') || (argv.type === 'BROWSER')) {
if (_.isNil(argv.uri)) {
throw new Error('ERROR: Missing uri argument');
}

if (!_.isNil(argv.filename)) {
throw new Error('ERROR: Unexpected filename argument');
}
}

if ((argv.type ==='SCRIPT_API') || (argv.type === 'SCRIPT_BROWSER')) {
if (_.isNil(argv.filename)) {
throw new Error('ERROR: Missing filename argument');
}

if (!_.isNil(argv.uri)) {
throw new Error('ERROR: Unexpected uri argument');
}
}
}

exports.handler = function (argv) {
require('../../lib/config/LoggingConfig')(argv);

validate(argv);

const config = require('../../lib/config/SyntheticsConfig').getConfig(argv);

logger.verbose('Create: ' + argv.name + ':' + argv.filename);
Expand All @@ -42,6 +80,9 @@ exports.handler = function (argv) {
argv.locations,
argv.type,
argv.frequency,
argv.filename
argv.filename,
null,
argv.uri,
argv.emails
);
}
17 changes: 17 additions & 0 deletions bin/cmds/locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const dependencies = require('../../lib/dependency');
const logger = require('winston');
const _ = require('lodash');

exports.command = 'locations';
exports.desc = 'List available locations for synthetics to run';

exports.handler = function (argv) {
require('../../lib/config/LoggingConfig')(argv);

const config = require('../../lib/config/SyntheticsConfig').getConfig(argv);

logger.verbose('Locations');
logger.verbose(argv);

dependencies(config).listLocationsOrchestrator.listLocations();
}
Loading

0 comments on commit 844a804

Please sign in to comment.