fluent-plugin-festival 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +191 -0
- data/README.md +83 -0
- data/Rakefile +10 -0
- data/docs/tutorial.md +61 -0
- data/fluent-plugin-festival.gemspec +28 -0
- data/lib/fluent/plugin/festival_proxy.rb +139 -0
- data/lib/fluent/plugin/in_festival.rb +117 -0
- data/test/helper.rb +26 -0
- data/test/plugin/test_in_festival.rb +39 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 65118a3fdff6acac8946e966df03ad64ba9df8fe
|
4
|
+
data.tar.gz: 8a8bd176b47e749a8577937168f3b63bf5dc84f6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3eb2e8b9bdbe262a64e21a90c94f9ddea11450b7fd77de699691349532156553109e0be57c45cedc108318827c8d398a146b89200637d12d62c49e267665124
|
7
|
+
data.tar.gz: 7b4227e0dd0416522303f184727f7005f2625ce45bb3075441a4897126d37de743b48e346b8533e9ab467cb70c51e83fe796aa41b4d76f25654331b8fcbb2be6
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
https://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
Copyright 2016-2017 Toyokazu Akiyama
|
180
|
+
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
182
|
+
you may not use this file except in compliance with the License.
|
183
|
+
You may obtain a copy of the License at
|
184
|
+
|
185
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
186
|
+
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
190
|
+
See the License for the specific language governing permissions and
|
191
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# fluent-plugin-festival
|
2
|
+
Fluentd Input Plugin for FESTIVAL platform
|
3
|
+
|
4
|
+
## What is FESTIVAL?
|
5
|
+
|
6
|
+
The development of the Internet of Things is set to have a strong impact on many aspects of society. Test-beds and experimental facilities, both of small scale and up to city scale, will be an essential enabler to facilitate the development of this vision. Facilitating the access to these test-beds to a large community of experimenters approach is a key asset to the development of a large and active community of application developers, necessary to address the many challenges faced by European and Japanese societies.
|
7
|
+
|
8
|
+
[FESTIVAL project](http://www.festival-project.eu/)’s vision is to provide IoT experimentation platforms providing interaction facility with physical environments and end-users, where experimenters can validate their Smart ICT service developments in various domains such as smart city, smart building, smart public services, smart shopping, participatory sensing, etc. FESTIVAL testbeds will connect cyber world to the physical world, from large scale deployments at a city scale, to small platforms in lab environments and dedicated physical spaces simulating real-life settings. Those platforms will be connected and federated via homogeneous access APIs with an “Experimentation as a Service” (EaaS) model for experimenters to test their added value services.
|
9
|
+
|
10
|
+
fluent-plugin-festival provides input plugin for FESTIVAL platform.
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install fluent-plugin-festival
|
17
|
+
```
|
18
|
+
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
fluent-plugin-festival has Input Plugins for FESTIVAL platform.
|
23
|
+
|
24
|
+
|
25
|
+
### Input Plugin (Fluent::FestivalInput)
|
26
|
+
|
27
|
+
Input Plugin can receive events from FESTIVAL EaaS API Server. It can be used via source directive in the configuration. Since FESTIVAL platform requires an authentication, before subscribing resource information, the user needs to create own FESTIVAL platform account via [FESTIVAL portal](https://experiments.festival-project.eu/). After creating an account, please make a configuration file with source directive. detail options of source directive is as follows.
|
28
|
+
|
29
|
+
```
|
30
|
+
<source>
|
31
|
+
@type festival
|
32
|
+
tag tag_name
|
33
|
+
username festival_portal_login_name
|
34
|
+
password festival_portal_password
|
35
|
+
polling_interval 30
|
36
|
+
<resource>
|
37
|
+
path /aggregators/IOT-0/testbeds/jose/resources/hyogo001_barometer-info-value
|
38
|
+
</resource>
|
39
|
+
<resource>
|
40
|
+
path /aggregators/IOT-0/testbeds/jose/resources/kyoto001_barometer-info-value
|
41
|
+
</resource>
|
42
|
+
</source>
|
43
|
+
|
44
|
+
<source>
|
45
|
+
@type festival
|
46
|
+
tag tag_name
|
47
|
+
username festival_portal_login_name
|
48
|
+
password festival_portal_password
|
49
|
+
polling_interval 180
|
50
|
+
<resource>
|
51
|
+
path /aggregators/IOT-0/testbeds/smartsantander/resources/smartsantander_u7jcfa_f3176-chemicalAgentAtmosphericConcentration:airParticles-sensor
|
52
|
+
</resource>
|
53
|
+
</source>
|
54
|
+
```
|
55
|
+
|
56
|
+
- **tag** (required): Tag name appended to the input data inside fluentd network
|
57
|
+
- **login_name** (required): login_name to login https://experiments.festival-project.eu/
|
58
|
+
- **password** (required): password for the login_name
|
59
|
+
- **polling_interval** (optional): Polling interval (seconds) for accessing EaaS API (default: 60 seconds)
|
60
|
+
- **resource** (at least one entry is required): The target resources to obtain sensor data. multiple resources can be specified by multiple <resource> tags. If a user wants to specify different polling interval for each resource, it must be specified different <source> tags.
|
61
|
+
- **path** (at least one entry is required): The target resource path name should be specified. The pathname should specify only under aggregator part and target data type, i.e. current_data or historical_data, should be omitted
|
62
|
+
(e.g. /aggregators/IOT-0/testbeds/jose/resources/hyogo001_barometer-info-value).
|
63
|
+
|
64
|
+
If the time field is empty, this plugin automatically set the finished time of data downloading. If multiple sensor data specified simultaneously, the time difference may become larger than single datum case. A sample data format is shown below.
|
65
|
+
|
66
|
+
```
|
67
|
+
{
|
68
|
+
"dataValue": "1001.16"
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
1. Fork it ( http://github.com/toyokazu/fluent-plugin-festival/fork )
|
75
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
5. Create new Pull Request
|
79
|
+
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
|
data/Rakefile
ADDED
data/docs/tutorial.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# fluent-plugin-festival tutorial
|
2
|
+
|
3
|
+
## Install fluentd
|
4
|
+
|
5
|
+
```
|
6
|
+
gem install fluent-plugin-festival
|
7
|
+
```
|
8
|
+
|
9
|
+
fluentd 0.14.x will be installed automatically.
|
10
|
+
|
11
|
+
|
12
|
+
## Create a sample configuration file
|
13
|
+
|
14
|
+
Create a sample configuration file as follows. You need to change festival_portal_login_name and festival_portal_password to your account information.
|
15
|
+
|
16
|
+
```
|
17
|
+
% vi fluent.conf
|
18
|
+
---
|
19
|
+
<source>
|
20
|
+
@type festival
|
21
|
+
tag test1
|
22
|
+
username festival_portal_login_name
|
23
|
+
password festival_portal_password
|
24
|
+
polling_interval 30
|
25
|
+
<resource>
|
26
|
+
path /aggregators/IOT-0/testbeds/jose/resources/hyogo001_barometer-info-value
|
27
|
+
</resource>
|
28
|
+
<resource>
|
29
|
+
path /aggregators/IOT-0/testbeds/jose/resources/kyoto001_barometer-info-value
|
30
|
+
</resource>
|
31
|
+
</source>
|
32
|
+
|
33
|
+
<source>
|
34
|
+
@type festival
|
35
|
+
tag test2
|
36
|
+
username festival_portal_login_name
|
37
|
+
password festival_portal_password
|
38
|
+
polling_interval 180
|
39
|
+
<resource>
|
40
|
+
path /aggregators/IOT-0/testbeds/smartsantander/resources/smartsantander_u7jcfa_f3176-chemicalAgentAtmosphericConcentration:airParticles-sensor
|
41
|
+
</resource>
|
42
|
+
</source>
|
43
|
+
|
44
|
+
<match *>
|
45
|
+
@type stdout
|
46
|
+
</match>
|
47
|
+
---
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
## Start fluentd with debug mode
|
52
|
+
|
53
|
+
Start fluentd with debug mode as follows.
|
54
|
+
|
55
|
+
```
|
56
|
+
fluentd -c fluent.conf -vvv
|
57
|
+
```
|
58
|
+
|
59
|
+
Then, you can confirm the sensor values are output to your console.
|
60
|
+
|
61
|
+
You can try the other resources by browsing resources via FESTIVAL portal and change target resource URI to the ones listed in the resource information.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-festival"
|
7
|
+
spec.version = "0.0.2"
|
8
|
+
spec.authors = ["Toyokazu Akiyama"]
|
9
|
+
spec.email = ["toyokazu@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Fluent Input/Output plugin for FESTIVAL platform}
|
12
|
+
spec.description = %q{Fluent Input/Output plugin for FESTIVAL platform}
|
13
|
+
spec.homepage = "https://github.com/toyokazu/fluent-plugin-festival"
|
14
|
+
spec.license = "Apache License Version 2.0"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.gsub(/.+images\/[\w\.-]+\n/, "").split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.1.0'
|
22
|
+
|
23
|
+
spec.add_dependency 'fluentd', '~> 0.14.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
26
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
27
|
+
spec.add_development_dependency "test-unit"
|
28
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module Fluent::Plugin
|
2
|
+
module FestivalProxy
|
3
|
+
require 'uri'
|
4
|
+
require 'pathname'
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require 'time'
|
8
|
+
|
9
|
+
class FestivalProxyError
|
10
|
+
end
|
11
|
+
|
12
|
+
def start_proxy
|
13
|
+
$log.debug "start festival proxy #{@api_uri}"
|
14
|
+
|
15
|
+
@uri = URI.parse(@api_uri)
|
16
|
+
@https = Net::HTTP.new(@uri.host, @uri.port)
|
17
|
+
@https.use_ssl = (@uri.scheme == 'https')
|
18
|
+
@session = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def shutdown_proxy
|
22
|
+
$log.debug "shutdown_proxy #{@session.inspect}"
|
23
|
+
delete_session
|
24
|
+
@https.finish() if @https.active?
|
25
|
+
end
|
26
|
+
|
27
|
+
def error_handler(response, message)
|
28
|
+
if response.code != "200"
|
29
|
+
$log.error :error => message
|
30
|
+
$log.debug "code: #{response.code}"
|
31
|
+
$log.debug "message: #{response.message}"
|
32
|
+
$log.debug "body: #{response.body}"
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid_session?
|
39
|
+
# TODO validate @session by FESTIVAL EaaS API
|
40
|
+
if !@session.nil?
|
41
|
+
if Time.now < @session_expires_in
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
return false
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_session_request
|
49
|
+
session_req = Net::HTTP::Post.new(@uri + '/festival/eaas/security/token')
|
50
|
+
session_req.body = {email: @email, password: @password}.to_json
|
51
|
+
session_req.content_type = 'application/json'
|
52
|
+
session_req
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_session
|
56
|
+
return @session if valid_session?
|
57
|
+
@session_req ||= create_session_request
|
58
|
+
session_res = @https.request(@session_req)
|
59
|
+
return nil if !error_handler(session_res, 'create_session failed.')
|
60
|
+
# access_token is returned as follows
|
61
|
+
# {"access_token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","expires_in":86400}
|
62
|
+
@session = JSON.parse(session_res.body)
|
63
|
+
# the expiration time is set to 5 minutes before expiration
|
64
|
+
@session_expires_in = Time.now + @session["expires_in"] - 5 * 60
|
65
|
+
end
|
66
|
+
|
67
|
+
# TODO: to be implemented
|
68
|
+
def delete_session_request
|
69
|
+
#Net::HTTP::Delete.new(@uri + "/session/#{@session_key}")
|
70
|
+
end
|
71
|
+
|
72
|
+
# TODO: to be implemented
|
73
|
+
def delete_session
|
74
|
+
#return if !valid_session?
|
75
|
+
#del_session_res = @https.request(delete_session_request)
|
76
|
+
#error_handler(del_session_res, 'delete_session failed.')
|
77
|
+
end
|
78
|
+
|
79
|
+
# type: "current_data", "historical_data"
|
80
|
+
#def target_path(type)
|
81
|
+
# if !@aggregator_id.nil? && !@testbed_id.nil? && !@resource_id.nil?
|
82
|
+
# return "/festival/eaas/experimentation/aggregators/#{@aggregator_id}/testbeds/#{@testbed_id}/resources/#{@resource_id}/#{type}"
|
83
|
+
# else
|
84
|
+
# raise Fluent::ConfigError, "aggregator_id, testbed_id and resource_id must be specified."
|
85
|
+
# end
|
86
|
+
#end
|
87
|
+
|
88
|
+
def get_data_request(path, type)
|
89
|
+
#get_data_req = @uri + target_path(type)
|
90
|
+
|
91
|
+
get_data_req = @uri + Pathname("/festival/eaas/experimentation/#{path}/#{type}").cleanpath.to_s
|
92
|
+
#get_data_req.query = URI.encode_www_form(get_data_params)
|
93
|
+
$log.debug "#{get_data_req}"
|
94
|
+
# currently time window is automatically updated
|
95
|
+
#@from = Time.now.iso8601
|
96
|
+
get_data_req
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_data_header
|
100
|
+
{
|
101
|
+
"Accept": "application/json",
|
102
|
+
"x-nick-name": @email,
|
103
|
+
"X-Auth-Token": @session["access_token"]
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_current_data
|
108
|
+
if !valid_session?
|
109
|
+
return nil if create_session.nil?
|
110
|
+
$log.debug "session #{@session} created."
|
111
|
+
end
|
112
|
+
data = []
|
113
|
+
#require 'pry-byebug'
|
114
|
+
$log.debug "@resources: #{@resources.inspect}"
|
115
|
+
@resources.each do |resource|
|
116
|
+
$log.debug "get_current_data: request #{get_data_request(resource.path, "current_data")}, #{get_data_header.inspect}"
|
117
|
+
get_current_data_res = @https.get(get_data_request(resource.path, "current_data"), get_data_header)
|
118
|
+
return nil if !error_handler(get_current_data_res,"get_data failed.")
|
119
|
+
$log.debug "get_current_data: #{get_current_data_res.body}"
|
120
|
+
data << {"dataValue": JSON.parse(get_current_data_res.body)["dataValue"]}
|
121
|
+
end
|
122
|
+
if data.size > 1
|
123
|
+
return data
|
124
|
+
end
|
125
|
+
data[0]
|
126
|
+
end
|
127
|
+
|
128
|
+
# curl --request GET \
|
129
|
+
# --url 'http://sensinact-cea.ddns.net:8099/festival/driver/testbeds/jose/resources/hyogo001_barometer-info-valueasfloat/historical_data?startDate=2017-03-01T00%3A05%3A55Z' \
|
130
|
+
# --header 'cache-control: no-cache' \
|
131
|
+
# --header 'content-type: application/json' \
|
132
|
+
# --header 'postman-token: 6bceac9e-5d14-3c9e-d34c-acbd4922ebfc' \
|
133
|
+
# --header 'userid: me' \
|
134
|
+
# --data '{"options":{"rows":20}}'
|
135
|
+
def get_historical_data
|
136
|
+
# TODO: to be implemented
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'fluent/plugin/input'
|
2
|
+
require 'fluent/event'
|
3
|
+
require 'fluent/time'
|
4
|
+
require 'fluent/plugin/festival_proxy'
|
5
|
+
|
6
|
+
module Fluent::Plugin
|
7
|
+
class FestivalInput < Input
|
8
|
+
include FestivalProxy
|
9
|
+
|
10
|
+
Fluent::Plugin.register_input('festival', self)
|
11
|
+
|
12
|
+
helpers :thread, :compat_parameters
|
13
|
+
|
14
|
+
desc 'FESTIVAL EaaS API URI'
|
15
|
+
config_param :api_uri, :string, :default => 'https://api.festival-project.eu'
|
16
|
+
desc 'email (login_name) for FESTIVAL EaaS API'
|
17
|
+
config_param :email, :string
|
18
|
+
desc 'password for FESTIVAL EaaS API'
|
19
|
+
config_param :password, :string
|
20
|
+
#base.config_param :keep_alive, :integer, :default => 2
|
21
|
+
#base.desc 'Start date of historical data'
|
22
|
+
#base.config_param :start_date, :string, :default => Time.now.iso8601
|
23
|
+
#base.desc 'End date of historical data'
|
24
|
+
#base.config_param :end_date, :string, :default => Time.now.iso8601
|
25
|
+
desc 'The tag of the event.'
|
26
|
+
config_param :tag, :string
|
27
|
+
desc 'Polling interval to get message from FESTIVAL EaaS API'
|
28
|
+
config_param :polling_interval, :integer, :default => 60
|
29
|
+
|
30
|
+
# <resoruce> tag can be used for specifying multiple resources in a <source> tag
|
31
|
+
# If the user wants to specify different format or polling interval for each resource,
|
32
|
+
# it should be specified in separated <source> tags.
|
33
|
+
# The resources can be specified two types of form URI and id list.
|
34
|
+
# Currently, only IOT Gateway aggregator with current_data type is supported.
|
35
|
+
# URI case:
|
36
|
+
# A resource URI example
|
37
|
+
# https://api.festival-project.eu/festival/eaas/experimentation/aggregators/IOT-0/testbeds/jose/resources/hyogo001_barometer-info-value/current_data
|
38
|
+
# <resource>
|
39
|
+
# path /aggregators/IOT-0/testbeds/jose/resources/hyogo001_barometer-info-value
|
40
|
+
# </resource>
|
41
|
+
#
|
42
|
+
# Resource ID case (not supported now):
|
43
|
+
# <resource>
|
44
|
+
# aggregator_id IOT-0
|
45
|
+
# testbed_id jose
|
46
|
+
# resource_id hyogo001_barometer-info-value
|
47
|
+
# </resource>
|
48
|
+
#
|
49
|
+
# If you want to specify historical data
|
50
|
+
config_section :resource, param_name: :resources, required: true, multi: true do
|
51
|
+
desc 'Resource path'
|
52
|
+
# e.g. /aggregators/IOT-0/testbeds/jose/resources/hyogo001_barometer-info-value
|
53
|
+
config_param :path, :string
|
54
|
+
# e.g. IT-0, OD-0, IOT-0, LL-0
|
55
|
+
#base.config_param :aggregator_id, :string, :default => nil
|
56
|
+
# e.g. sensinact, jose
|
57
|
+
#base.config_param :testbed_id, :string, :default => nil
|
58
|
+
# e.g. airsensors_firenze-airsensors-location, hyogo001_barometer-info-valuesfloat
|
59
|
+
#base.config_param :resource_id, :string, :default => nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def configure(conf)
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
def start
|
67
|
+
#raise StandardError.new if @tag.nil?
|
68
|
+
super
|
69
|
+
start_proxy
|
70
|
+
@proxy_thread = Thread.new(&method(:get_loop))
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_loop
|
74
|
+
while (true)
|
75
|
+
begin
|
76
|
+
data = get_current_data
|
77
|
+
emit(data) if !(data.nil? || data.empty?)
|
78
|
+
sleep @polling_interval
|
79
|
+
rescue Exception => e
|
80
|
+
$log.error :error => e.to_s
|
81
|
+
$log.debug(e.backtrace.join("\n"))
|
82
|
+
#$log.debug_backtrace(e.backtrace)
|
83
|
+
sleep @polling_interval
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Sample data from FESTIVAL IoT Gateway (sensinact)
|
89
|
+
# time_key must be set to "date"
|
90
|
+
# {"dataValue": "1017.57", "date": "2017-03-29T16:19:15Z"}
|
91
|
+
def emit(record)
|
92
|
+
begin
|
93
|
+
time = Fluent::EventTime.now
|
94
|
+
if record.is_a?(Array) # Multiple values case
|
95
|
+
mes = Fluent::MultiEventStream.new
|
96
|
+
record.each do |single_record|
|
97
|
+
# use timestamp of the first sensor (single_record[0])
|
98
|
+
mes.add(time, single_record)
|
99
|
+
end
|
100
|
+
router.emit_stream(@tag, mes)
|
101
|
+
else # Single value case
|
102
|
+
# use timestamp of the first sensor (single_record[0])
|
103
|
+
router.emit(@tag, time, record)
|
104
|
+
end
|
105
|
+
rescue Exception => e
|
106
|
+
$log.error :error => e.to_s
|
107
|
+
$log.debug_backtrace(e.backtrace)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def shutdown
|
112
|
+
@proxy_thread.kill
|
113
|
+
shutdown_proxy
|
114
|
+
super
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/test/driver/input'
|
3
|
+
require 'fluent/plugin/in_festival'
|
4
|
+
|
5
|
+
class FestivalInputTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Fluent::Test.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
CONFIG = %[
|
12
|
+
]
|
13
|
+
|
14
|
+
def create_driver(conf = CONFIG, opts = {})
|
15
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::FestivalInput, opts: opts).configure(conf)
|
16
|
+
end
|
17
|
+
|
18
|
+
sub_test_case "configure" do
|
19
|
+
test "tag email password aggregator_id testbed_id resource_id polling_interval" do
|
20
|
+
d = create_driver %[
|
21
|
+
tag test
|
22
|
+
email hoge@foobar.com
|
23
|
+
password login_password
|
24
|
+
polling_interval 30
|
25
|
+
<resource>
|
26
|
+
path /aggregators/IOT-0/testbeds/jose/resources/hyogo001_barometer-info-value
|
27
|
+
</resource>
|
28
|
+
<resource>
|
29
|
+
path /aggregators/IOT-0/testbeds/jose/resources/kyoto001_barometer-info-value
|
30
|
+
</resource>
|
31
|
+
]
|
32
|
+
assert_equal 'test', d.instance.tag
|
33
|
+
assert_equal 'login_password', d.instance.password
|
34
|
+
assert_equal 30, d.instance.polling_interval
|
35
|
+
assert_equal '/aggregators/IOT-0/testbeds/jose/resources/hyogo001_barometer-info-value', d.instance.resources[0].path
|
36
|
+
assert_equal '/aggregators/IOT-0/testbeds/jose/resources/kyoto001_barometer-info-value', d.instance.resources[1].path
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-festival
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toyokazu Akiyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Fluent Input/Output plugin for FESTIVAL platform
|
70
|
+
email:
|
71
|
+
- toyokazu@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- docs/tutorial.md
|
81
|
+
- fluent-plugin-festival.gemspec
|
82
|
+
- lib/fluent/plugin/festival_proxy.rb
|
83
|
+
- lib/fluent/plugin/in_festival.rb
|
84
|
+
- test/helper.rb
|
85
|
+
- test/plugin/test_in_festival.rb
|
86
|
+
homepage: https://github.com/toyokazu/fluent-plugin-festival
|
87
|
+
licenses:
|
88
|
+
- Apache License Version 2.0
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 2.1.0
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.6.8
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Fluent Input/Output plugin for FESTIVAL platform
|
110
|
+
test_files:
|
111
|
+
- test/helper.rb
|
112
|
+
- test/plugin/test_in_festival.rb
|