diff options
| author | ytti <saku@ytti.fi> | 2016-12-04 19:38:25 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-12-04 19:38:25 +0200 | 
| commit | b2e53088e457babfbfec74a03e730b3d91b9701f (patch) | |
| tree | f9aa3515d2d7bef8ca6e120b51d3f830c67cbdf0 | |
| parent | e0da3feeb2fc506af31df0b41e14a3f9c588ef82 (diff) | |
| parent | 0e26ca4e877570b5ba02370768fcd758c4b03cc8 (diff) | |
Merge pull request #628 from natm/master
New hook: awssns - Publish messages to AWS SNS topics
| -rw-r--r-- | README.md | 35 | ||||
| -rw-r--r-- | lib/oxidized/hook/awssns.rb | 27 | 
2 files changed, 59 insertions, 3 deletions
| @@ -307,17 +307,17 @@ this will bind port 8888 to all interfaces then expose port out. (Issue #445)  You can also use docker-compose to launch oxidized container:  ``` -# docker-compose.yml  +# docker-compose.yml  # docker-compose file example for oxidized that will start along with docker daemon  oxidized:    restart: always -  image: oxidized/oxidized:latest  +  image: oxidized/oxidized:latest    ports:      - 8888:8888/tcp    environment:      CONFIG_RELOAD_INTERVAL: 600    volumes: -    - /etc/oxidized:/root/.config/oxidized  +    - /etc/oxidized:/root/.config/oxidized  ```  create the `/etc/oxidized/router.db` @@ -815,6 +815,35 @@ hooks:      password: pass  ``` +## Hook type: awssns + +The `awssns` hook publishes messages to AWS SNS topics. This allows you to notify other systems of device configuration changes, for example a config orchestration pipeline. Multiple services can subscribe to the same AWS topic. + +Fields sent in the message: + +  * `event`: Event type (e.g. `node_success`) +  * `group`: Group name +  * `model`: Model name (e.g. `eos`) +  * `node`: Device hostname + +Configuration example: + +``` yaml +hooks: +  hook_script: +    type: awssns +    events: [node_fail,node_success,post_store] +    region: us-east-1 +    topic_arn: arn:aws:sns:us-east-1:1234567:oxidized-test-backup_events +``` + +AWS SNS hook requires the following configuration keys: + +  * `region`: AWS Region name +  * `topic_arn`: ASN Topic reference + +Your AWS credentials should be stored in `~/.aws/credentials`. +  # Ruby API  The following objects exist in Oxidized. diff --git a/lib/oxidized/hook/awssns.rb b/lib/oxidized/hook/awssns.rb new file mode 100644 index 0000000..dbc2d47 --- /dev/null +++ b/lib/oxidized/hook/awssns.rb @@ -0,0 +1,27 @@ +require 'aws-sdk' + +class AwsSns < Oxidized::Hook +  def validate_cfg! +    raise KeyError, 'hook.region is required' unless cfg.has_key?('region') +    raise KeyError, 'hook.topic_arn is required' unless cfg.has_key?('topic_arn') +  end + +  def run_hook(ctx) +    sns = Aws::SNS::Resource.new(region: cfg.region) +    topic = sns.topic(cfg.topic_arn) +    message = { +      :event => ctx.event.to_s +    } +    if ctx.node +      message.merge!( +        :group => ctx.node.group.to_s, +        :model => ctx.node.model.class.name.to_s.downcase, +        :node => ctx.node.name.to_s +      ) +    end +    topic.publish({ +      message: message.to_json +    }) +  end + +end | 
