1.0.3 • Published 10 years ago

coucheye v1.0.3

Weekly downloads
7
License
MIT
Repository
github
Last release
10 years ago

CouchEye

The CouchEye tool can be used to monitor changes in one or more CouchDb databases and send notifications to topics in the Amazon Simple Notification Service (SNS). Multiple databases can be monitored by one running CouchEye instance and changes can be routed to multiple topics, which may even be in different regions or require diferrent credentials.

To use CouchEye, simple install is using npm:

npm install --save coucheye

Below you'll find an example configuration using CoffeeScript syntax.

Configuration options

KeyDescription
redisObject as returned by createClient in the redis package
redisUrlURL of the Redis server; required unless redis option is given
redisPrefixSequence numbers for a feed are stored under #{redisPrefix}#{feedName}
feedsA set of CouchDb feeds
feeds.{name}.*Properties as accepted by the follow package
endpointsA set of Amazon AWS endpoints, including credentials
endpoints.{name}.*Properties as accepted by the aws-sdk package
topicsA set of SNS topics to which changes can be published
topics.{name}.arnARN of an SNS topic
pipesA set of pipes that connect feeds, endpoints and topics
pipes.{name}.feedName of the feed to draw change from
pipes.{name}.endpointName of the endpoint to send notifications to
pipes.{name}.topicName of the topic to send notifications to
pipes.{name}.transformChangeFunction to transform a change object
pipes.{name}.transformDocFunction to transform a change document; depends on feeds.<name>.include_docs options

The pipes.<name>.transformChange and pipes.<name>.transformDoc options are not required, but are mutually exclusive. When either of those is used, the return value is used as content for the notification. If null or undefined is returned, not notification is published.

Example configuration

coucheye = (require 'coucheye')
    redisUrl: 'redis://username:password@redis.domain:9356/'
    redisPrefix: 'coucheye.'
    feeds:
        examples:
            db: 'https://username:password@couchdb.domain/examples'
            include_docs: true
        extensions:
            db: 'https://username:password@couchdb.domain/extensions'
            include_docs: true
    endpoints:
        sns:
            accessKeyId: 'akid'
            secretAccessKey: 'secret'
            region: 'eu-west-1'
    topics:
        exampleUpdated: 'arn:aws:sns:eu-west-1:123456789012:ExampleUpdated'
        exampleCompleted: 'arn:aws:sns:eu-west-1:123456789012:ExampleCompleted'
        extensionCreated: 'arn:aws:sns:eu-west-1:123456789012:ExtensionCreated'
        extensionApproved: 'arn:aws:sns:eu-west-1:123456789012:ExtensionApproved'
    pipes:
        exampleUpdated:
            feed: 'examples'
            endpoint: 'sns'
            topic: 'exampleUpdated'
            transformChange: (change) ->
                # Ignore deletions
                return null if change.deleted
                exampleId: change.id
        exampleCompleted:
            feed: 'examples'
            endpoint: 'sns'
            topic: 'exampleCompleted'
            transformDocument: (doc) ->
                # Only notify for completed example
                return null unless doc.status is 'COMPLETED'
                exampleId: doc._id
        extentionCreated:
            feed: 'extensions'
            endpoint: 'sns'
            topic: 'extensionCreated'
            transformDocument: (doc) ->
                # First revision means document has just been created
                return null unless doc._rev.match(/^1-/)?
                extensionId: doc._id
        extensionApproved:
            feed: 'extensions'
            endpoint: 'sns'
            topic: 'extensionApproved'
            transformDocument: (doc) ->
                # Require an approval
                return null unless doc.approval?
                # But not an error
                return null if doc.error?
                extensionId: doc._id

coucheye.on 'error', (err) ->
    console.err err
    process.exit 1

coucheye.start()
1.0.3

10 years ago

1.0.2

10 years ago