fluent-plugin-everysense 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/everystamp/README.md +11 -11
- data/examples/everystamp/{piot-mapping.json → everysense-mapping.json} +0 -0
- data/examples/everystamp/everysense.conf +74 -0
- data/fluent-plugin-everysense.gemspec +1 -1
- data/lib/fluent/plugin/everysense_proxy.rb +8 -1
- metadata +4 -4
- data/examples/everystamp/fluent-everystamp.conf +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7baa88d228b7e1c9193ab88739eba098a1e6d44
|
4
|
+
data.tar.gz: fa6a38b9be0fa3c13e79a8351c2b999994e722ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fc0dd1c8fcbacd1b9409a1cb8f6c2f6c7ad09f47a66b9e430df17c7f2653fc9f063df6a83d28f1c61eaadf8ec42044f7814229d0e8140e83a66ab70cd4d7043
|
7
|
+
data.tar.gz: 61c7e9b78c9b023472b888831f295c1e4887e05e25f51984e39667ca1e7dc85d1eb0e39a822524b67d66394386ff1fcfb562aa25450542b83c2fda0d07237174
|
@@ -11,21 +11,21 @@ https://www.elastic.co/downloads/elasticsearch
|
|
11
11
|
|
12
12
|
Linuxの場合は以下のページにある方法でパッケージ管理システム (apt, yum) を用いてインストールするのが簡単です.
|
13
13
|
|
14
|
-
https://www.elastic.co/guide/en/elasticsearch/reference/
|
14
|
+
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/deb.html
|
15
|
+
|
15
16
|
|
16
17
|
Kibanaも同様にパッケージ管理システムを用いてインストールできます.
|
17
18
|
|
18
|
-
https://www.elastic.co/guide/en/kibana/
|
19
|
+
https://www.elastic.co/guide/en/kibana/5.0/deb.html
|
19
20
|
|
20
21
|
インストールが完了したらサービスを開始します.
|
21
22
|
|
22
|
-
https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-service.html
|
23
|
-
|
24
23
|
```
|
25
24
|
sudo /bin/systemctl daemon-reload
|
26
25
|
sudo /bin/systemctl enable elasticsearch.service
|
27
26
|
sudo /bin/systemctl start elasticsearch.service
|
28
27
|
sudo /bin/systemctl enable kibana.service
|
28
|
+
sudo /bin/systemctl start kibana.service
|
29
29
|
```
|
30
30
|
|
31
31
|
ブラウザで http://localhost:5601/ にアクセスするとKibanaの画面が表示されます.
|
@@ -48,8 +48,8 @@ source ~/.bashrc
|
|
48
48
|
### ruby-buildのインストール
|
49
49
|
git clone https://github.com/rbenv/ruby-build.git /usr/local/rbenv/plugins/ruby-build
|
50
50
|
### rubyのインストール
|
51
|
-
rbenv install 2.
|
52
|
-
rbenv global 2.
|
51
|
+
rbenv install 2.4.1
|
52
|
+
rbenv global 2.4.1
|
53
53
|
```
|
54
54
|
以下fluentdと必要なpluginのインストールです.
|
55
55
|
|
@@ -61,11 +61,11 @@ gem install fluent-plugin-everysense fluent-plugin-elasticsearch
|
|
61
61
|
|
62
62
|
## ElasticSearchでのmappingの作成
|
63
63
|
|
64
|
-
|
64
|
+
everysense-mapping.json ファイルを用いてmappingを作成します.
|
65
65
|
|
66
66
|
```
|
67
|
-
curl -XPUT 'http://localhost:9200/
|
68
|
-
|
67
|
+
curl -XPUT 'http://localhost:9200/everysense'
|
68
|
+
curl -XPUT 'http://localhost:9200/everysense/everystamp/_mapping' -d @everysense-mapping.json
|
69
69
|
```
|
70
70
|
|
71
71
|
KibanaのSettingsのindex nameとしてpiotを指定し,時間属性としてtimestampを指定して,index patternを作成します.
|
@@ -73,10 +73,10 @@ KibanaのSettingsのindex nameとしてpiotを指定し,時間属性としてt
|
|
73
73
|
|
74
74
|
## fluentdの設定
|
75
75
|
|
76
|
-
|
76
|
+
everysense.conf ファイルを用いてfluentdを立ち上げます.
|
77
77
|
|
78
78
|
```
|
79
|
-
fluentd -c
|
79
|
+
fluentd -c everysense.conf -vvv
|
80
80
|
```
|
81
81
|
|
82
82
|
これでEverySense ServerにアップロードされたデータをElasticSearchに格納できるようになりました.
|
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
<source>
|
2
|
+
# fluent-plugin-everysense の input plugin を指定します.
|
3
|
+
@type everysense
|
4
|
+
tag location1.everystamp
|
5
|
+
# ここではラベルを用いていますが,tagを用いることもできます.
|
6
|
+
@label @everystamp
|
7
|
+
# EverySense Serverのアカウント名を指定してください.
|
8
|
+
login_name username
|
9
|
+
# EverySense Serverのアカウントパスワードを指定してください.
|
10
|
+
password XXXXXXXXXXXX
|
11
|
+
# EverySense Server上に作成したレシピのレシピIDを指定してください.
|
12
|
+
recipe_id XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
13
|
+
# 取得間隔は変更可能です.
|
14
|
+
polling_interval 30
|
15
|
+
# 現状JSONフォーマットのみ対応しています.
|
16
|
+
format json
|
17
|
+
<parse>
|
18
|
+
@type json
|
19
|
+
</parse>
|
20
|
+
</source>
|
21
|
+
|
22
|
+
<label @everystamp>
|
23
|
+
# fluent-plugin-everysense の filter plugin で複数センサの情報を同時に取得した場合にfluentd上の複数イベントに変換します.
|
24
|
+
<filter location1.*>
|
25
|
+
@type everysense
|
26
|
+
</filter>
|
27
|
+
# EverySense Serverの出力をElasticSearchのmappingの形式に変換します.
|
28
|
+
# センサごとの変換ロジックが必要ですが,ここではEveryStamp, EveryPostで
|
29
|
+
# 利用可能なセンサについて変換例を示しています.
|
30
|
+
<filter location1.*>
|
31
|
+
@type record_transformer
|
32
|
+
enable_ruby true
|
33
|
+
auto_typecast true
|
34
|
+
<record>
|
35
|
+
timestamp ${Time.parse(record["data"]["at"]).utc.strftime("%Y-%m-%d %H:%M:%S")}
|
36
|
+
accelerometer ${if record["data_class_name"] == "Accelerometer" then return {"x": record["data"]["values"][0], "y": record["data"]["values"][1], "z": record["data"]["values"][2]} end}
|
37
|
+
air_hygrometer ${if record["data_class_name"] == "AirHygrometer" then return record["data"]["value"] end}
|
38
|
+
air_temperature ${if record["data_class_name"] == "AirTemperature" then return record["data"]["value"] end}
|
39
|
+
angular_velocity ${if record["data_class_name"] == "AngularVelocity" then return {"x": record["data"]["values"][0], "y": record["data"]["values"][1], "z": record["data"]["values"][2]} end}
|
40
|
+
barometric_pressure ${if record["data_class_name"] == "BarometricPressure" then return record["data"]["value"] end}
|
41
|
+
environmental_sound ${if record["data_class_name"] == "EnvironmentalSound" then return record["data"]["values"] end}
|
42
|
+
earth_magnetometer ${if record["data_class_name"] == "EarthMagnetometer" then return {"x": record["data"]["values"][0], "y": record["data"]["values"][1], "z": record["data"]["values"][2]} end}
|
43
|
+
illuminance ${if record["data_class_name"] == "Illuminance" then return record["data"]["value"] end}
|
44
|
+
location ${if record["data_class_name"] == "Location" then if record["data"]["location"].nil? then return {"lon": record["data"]["values"][0], "lat": record["data"]["values"][1]} else return {"lon": record["data"]["location"]["longitude"], "lat": record["data"]["location"]["latitude"]} end end}
|
45
|
+
motion_activity ${if record["data_class_name"] == "MotionActivity" then return record["data"]["value"] end}
|
46
|
+
switch ${if record["data_class_name"] == "Switch" then if record["data"]["value"] == "true" then return true else return false end end}
|
47
|
+
uv_figure ${if record["data_class_name"] == "UV_Figure" then return record["data"]["value"] end}
|
48
|
+
</record>
|
49
|
+
</filter>
|
50
|
+
# デバッグ用に標準出力だけで確認したい場合は以下を有効にしてください.
|
51
|
+
#<match location1.*>
|
52
|
+
# @type stdout
|
53
|
+
#</match>
|
54
|
+
# ElasticSearchに格納しながら,標準出力でも格納された内容を確認したい
|
55
|
+
# 場合は,以下でコメントアウトされている箇所を有効にしてください.
|
56
|
+
<match location1.*>
|
57
|
+
#@type copy
|
58
|
+
#<store>
|
59
|
+
@type elasticsearch
|
60
|
+
# ElasticSearchを立ち上げたホストを指定してください.
|
61
|
+
host localhost
|
62
|
+
port 9200
|
63
|
+
index_name everysense
|
64
|
+
type_name everystamp
|
65
|
+
logstash_format false
|
66
|
+
include_tag_key true
|
67
|
+
time_key data.at
|
68
|
+
flush_interval 30s
|
69
|
+
#</store>
|
70
|
+
#<store>
|
71
|
+
# @type stdout
|
72
|
+
#</store>
|
73
|
+
</match>
|
74
|
+
</label>
|
@@ -35,7 +35,13 @@ module Fluent::Plugin
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def valid_session?
|
38
|
-
|
38
|
+
# TODO validate @session_key using EverySense API
|
39
|
+
if !@session_key.nil?
|
40
|
+
if Time.now < @session_expires_in
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
return false
|
39
45
|
end
|
40
46
|
|
41
47
|
def create_session_request
|
@@ -51,6 +57,7 @@ module Fluent::Plugin
|
|
51
57
|
session_res = @https.request(@session_req)
|
52
58
|
return nil if !error_handler(session_res, 'create_session failed.')
|
53
59
|
@session_key = JSON.parse(session_res.body)["session_key"]
|
60
|
+
@session_expires_in = Time.now + 60 * 60 * 12 # assuming time out in a half day
|
54
61
|
end
|
55
62
|
|
56
63
|
def delete_session_request
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-everysense
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toyokazu Akiyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -80,8 +80,8 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- examples/everystamp/README.md
|
83
|
-
- examples/everystamp/
|
84
|
-
- examples/everystamp/
|
83
|
+
- examples/everystamp/everysense-mapping.json
|
84
|
+
- examples/everystamp/everysense.conf
|
85
85
|
- fluent-plugin-everysense.gemspec
|
86
86
|
- lib/fluent/plugin/everysense_proxy.rb
|
87
87
|
- lib/fluent/plugin/filter_everysense.rb
|
@@ -1,70 +0,0 @@
|
|
1
|
-
<source>
|
2
|
-
# fluent-plugin-everysense の input plugin を指定します.
|
3
|
-
@type everysense
|
4
|
-
# ここではラベルを用いていますが,tagを用いることもできます.
|
5
|
-
@label @test
|
6
|
-
# EverySense Serverのアカウント名を指定してください.
|
7
|
-
login_name username
|
8
|
-
# EverySense Serverのアカウントパスワードを指定してください.
|
9
|
-
password XXXXXXXXXXXX
|
10
|
-
# EverySense Server上に作成したレシピのレシピIDを指定してください.
|
11
|
-
recipe_id XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
12
|
-
# 取得間隔は変更可能です.
|
13
|
-
polling_interval 30
|
14
|
-
# 現状JSONフォーマットのみ対応しています.
|
15
|
-
format json
|
16
|
-
</source>
|
17
|
-
|
18
|
-
<label @test>
|
19
|
-
# fluent-plugin-everysense の filter plugin で複数センサの情報を同時に取得した場合にfluentd上の複数イベントに変換します.
|
20
|
-
<filter **>
|
21
|
-
@type everysense
|
22
|
-
</filter>
|
23
|
-
# EverySense Serverの出力をElasticSearchのmappingの形式に変換します.
|
24
|
-
# センサごとの変換ロジックが必要ですが,ここではEveryStamp, EveryPostで
|
25
|
-
# 利用可能なセンサについて変換例を示しています.
|
26
|
-
<filter **>
|
27
|
-
@type record_transformer
|
28
|
-
enable_ruby true
|
29
|
-
auto_typecast true
|
30
|
-
<record>
|
31
|
-
timestamp ${Time.parse(data["at"]).utc.strftime("%Y-%m-%d %H:%M:%S")}
|
32
|
-
accelerometer ${if data_class_name == "Accelerometer" then return {"x": data["values"][0], "y": data["values"][1], "z": data["values"][2]} end}
|
33
|
-
air_hygrometer ${if data_class_name == "AirHygrometer" then return data["value"] end}
|
34
|
-
air_temperature ${if data_class_name == "AirTemperature" then return data["value"] end}
|
35
|
-
angular_velocity ${if data_class_name == "AngularVelocity" then return {"x": data["values"][0], "y": data["values"][1], "z": data["values"][2]} end}
|
36
|
-
barometric_pressure ${if data_class_name == "BarometricPressure" then return data["value"] end}
|
37
|
-
environmental_sound ${if data_class_name == "EnvironmentalSound" then return data["values"] end}
|
38
|
-
earth_magnetometer ${if data_class_name == "EarthMagnetometer" then return {"x": data["values"][0], "y": data["values"][1], "z": data["values"][2]} end}
|
39
|
-
illuminance ${if data_class_name == "Illuminance" then return data["value"] end}
|
40
|
-
location ${if data_class_name == "Location" then if data["location"].nil? then return {"lon": data["values"][0], "lat": data["values"][1]} else return {"lon": data["location"]["longitude"], "lat": data["location"]["latitude"]} end end}
|
41
|
-
motion_activity ${if data_class_name == "MotionActivity" then return data["value"] end}
|
42
|
-
switch ${if data_class_name == "Switch" then if data["value"] == "true" then return true else return false end end}
|
43
|
-
uv_figure ${if data_class_name == "UV_Figure" then return data["value"] end}
|
44
|
-
</record>
|
45
|
-
</filter>
|
46
|
-
# デバッグ用に標準出力だけで確認したい場合は以下を有効にしてください.
|
47
|
-
#<match **>
|
48
|
-
# @type stdout
|
49
|
-
#</match>
|
50
|
-
# ElasticSearchに格納しながら,標準出力でも格納された内容を確認したい
|
51
|
-
# 場合は,以下でコメントアウトされている箇所を有効にしてください.
|
52
|
-
<match **>
|
53
|
-
#@type copy
|
54
|
-
#<store>
|
55
|
-
@type elasticsearch
|
56
|
-
# ElasticSearchを立ち上げたホストを指定してください.
|
57
|
-
host localhost
|
58
|
-
port 9200
|
59
|
-
index_name piot
|
60
|
-
type_name everystamp
|
61
|
-
logstash_format false
|
62
|
-
include_tag_key true
|
63
|
-
time_key data.at
|
64
|
-
flush_interval 30s
|
65
|
-
#</store>
|
66
|
-
#<store>
|
67
|
-
# @type stdout
|
68
|
-
#</store>
|
69
|
-
</match>
|
70
|
-
</label>
|