diff --git a/Gemfile b/Gemfile index 2df8d37..7d2ded5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -# Version:20130523 +# Version:20130621 source "http://rubygems.org" source "http://gems.github.com" @@ -17,6 +17,7 @@ gem 'twitter' gem 'weather_hacker' gem 'pocket-ruby' gem 'hipchat' +gem 'fluent-logger' group :test do gem 'rspec' diff --git a/doc/PLUGINS b/doc/PLUGINS index c92c1dc..56e9dd7 100644 --- a/doc/PLUGINS +++ b/doc/PLUGINS @@ -266,7 +266,7 @@ FilterOne [Syntax] - module: FilterOne config: - pick: last (If none, pick the first item.) + pick: last (If none, pick the first item.) FilterRand @@ -402,6 +402,31 @@ PublishConsole - module: PublishConsole +PublishFluentd +-------------- +[Path] + /plugins/publish/fluentd.rb + +[Abstract] + Output to fluentd with fluent-logger. + +[Description] + This plugin outputs feed to fluentd. + Following fluentd config example. + + + type forward + port 9999 + + +[Syntax] + - module: PublishFluentd + config: + host: HOSTNAME + port: PORT_NUMBER + tag: TAGS (example: automatic.feed) + + PublishHatenaBookmark --------------------- [Path] diff --git a/doc/PLUGINS.ja b/doc/PLUGINS.ja index 58e60c5..ade162c 100644 --- a/doc/PLUGINS.ja +++ b/doc/PLUGINS.ja @@ -402,6 +402,31 @@ PublishConsole - module: PublishConsole +PublishFluentd +-------------- +[パス] + /plugins/publish/fluentd.rb + +[概要] + fluentd にフィードを出力する + +[説明] + このプラグインは fluentd にフィードを出力する + 受け手側では以下のように fluentd を設定し起動しておく + + + type forward + port 9999 + + +[レシピ記法] + - module: PublishFluentd + config: + host: ホスト名 + port: ポート番号 + tag: タグ (例 automatic.feed) + + PublishHatenaBookmark --------------------- [パス] diff --git a/plugins/publish/fluentd.rb b/plugins/publish/fluentd.rb new file mode 100644 index 0000000..10eb5e8 --- /dev/null +++ b/plugins/publish/fluentd.rb @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Name:: Automatic::Plugin::Publish::Fluentd +# Author:: 774 +# Created:: Jun 21, 2013 +# Updated:: Jun 21, 2013 +# Copyright:: 774 Copyright (c) 2013 +# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. + +module Automatic::Plugin + class PublishFluentd + require 'fluent-logger' + + def initialize(config, pipeline=[]) + @config = config + @pipeline = pipeline + end + + def run + @fluentd = Fluent::Logger + Fluent::Logger::FluentLogger.open(nil, + host = @config['host'], + port = @config['port']) + @pipeline.each {|feeds| + unless feeds.nil? + feeds.items.each {|feed| + begin + Fluent::Logger.post(@config['tag'], { + :title => feed.title, + :link => feed.link, + :description => feed.description, + :content => feed.content_encoded, + :created_at => Time.now.strftime("%Y/%m/%d %X") + }) + rescue + Automatic::Log.puts("warn", "Skip feed due to fault in save.") + end + } + end + } + @pipeline + end + end +end diff --git a/spec/plugins/publish/fluentd_spec.rb b/spec/plugins/publish/fluentd_spec.rb new file mode 100644 index 0000000..e558ae9 --- /dev/null +++ b/spec/plugins/publish/fluentd_spec.rb @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Name:: Automatic::Plugin::Publish::Fluentd +# Author:: 774 +# Created:: Jun 21, 2013 +# Updated:: Jun 21, 2013 +# Copyright:: 774 Copyright (c) 2013 +# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. + +require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper') + +require 'publish/fluentd' + +describe Automatic::Plugin::PublishFluentd do + context 'when feed' do + describe 'should forward the feeds' do + subject { + Automatic::Plugin::PublishFluentd.new( + { + 'host' => "localhost", + 'port' => "9999", + 'tag' => "debug.forward" + }, + AutomaticSpec.generate_pipeline{ + feed { + item "http://github.com", "hoge", + "fuga" + } + } + ) + } + + its (:run) { + fluentd = mock("fluentd") + subject.run.should have(1).feed + } + end + + end +end diff --git a/test/integration/test_fluentd.yml b/test/integration/test_fluentd.yml new file mode 100644 index 0000000..31ba51f --- /dev/null +++ b/test/integration/test_fluentd.yml @@ -0,0 +1,20 @@ +global: + timezone: Asia/Tokyo + cache: + base: /tmp + log: + level: info + +plugins: + - module: SubscriptionFeed + config: + feeds: + - http://blog.id774.net/post/feed/ + + - module: PublishFluentd + config: + host: localhost + port: 3001 + tag: automatic.feed + + # - module: PublishConsole