Skip to content

Commit

Permalink
Merge pull request #41 from id774/issue32
Browse files Browse the repository at this point in the history
#32 Create Plugin Publish::Fluentd
  • Loading branch information
id774 committed Jun 21, 2013
2 parents b717b38 + cb96215 commit 3f09b8d
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version:20130523
# Version:20130621

source "http://rubygems.org"
source "http://gems.github.com"
Expand All @@ -17,6 +17,7 @@ gem 'twitter'
gem 'weather_hacker'
gem 'pocket-ruby'
gem 'hipchat'
gem 'fluent-logger'

group :test do
gem 'rspec'
Expand Down
27 changes: 26 additions & 1 deletion doc/PLUGINS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

<source>
type forward
port 9999
</source>

[Syntax]
- module: PublishFluentd
config:
host: HOSTNAME
port: PORT_NUMBER
tag: TAGS (example: automatic.feed)


PublishHatenaBookmark
---------------------
[Path]
Expand Down
25 changes: 25 additions & 0 deletions doc/PLUGINS.ja
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,31 @@ PublishConsole
- module: PublishConsole


PublishFluentd
--------------
[パス]
/plugins/publish/fluentd.rb

[概要]
fluentd にフィードを出力する

[説明]
このプラグインは fluentd にフィードを出力する
受け手側では以下のように fluentd を設定し起動しておく

<source>
type forward
port 9999
</source>

[レシピ記法]
- module: PublishFluentd
config:
host: ホスト名
port: ポート番号
tag: タグ (例 automatic.feed)


PublishHatenaBookmark
---------------------
[パス]
Expand Down
43 changes: 43 additions & 0 deletions plugins/publish/fluentd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Name:: Automatic::Plugin::Publish::Fluentd
# Author:: 774 <http://id774.net>
# 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
39 changes: 39 additions & 0 deletions spec/plugins/publish/fluentd_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Name:: Automatic::Plugin::Publish::Fluentd
# Author:: 774 <http://id774.net>
# 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",
"<a>fuga</a>"
}
}
)
}

its (:run) {
fluentd = mock("fluentd")
subject.run.should have(1).feed
}
end

end
end
20 changes: 20 additions & 0 deletions test/integration/test_fluentd.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f09b8d

Please sign in to comment.