fluent-plugin-osmocom-spectrum-sense 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fluent-plugin-osmocom-spectrum-sense.gemspec +35 -0
- data/lib/fluent/plugin/in_osmocom_spectrum_sense.rb +129 -0
- data/samples/test.conf +18 -0
- data/spec/fluent/plugin/osmocom_spectrum_sense_spec.rb +7 -0
- data/spec/spec_helper.rb +2 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b2b963f9c62555f6159bf31bd5474ba3eaa3ee7
|
4
|
+
data.tar.gz: 3e6210ccfaf0b42e2885abe4829e4b48ad42c639
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37f935311f19ed99cc2e3567e0d85887169994d6e1fbcdbd97bef5f4ccfe7e6c13232e0f820db55de7b0e01038706323e281f5878dc2b8b9f78d730b5ea5a899
|
7
|
+
data.tar.gz: ef639a49cb96a8ce1b3378eb98d12c80add16cecb65147c849adc68c2eaaa1bc1f4db1be736d7eed09598a3cd80a4056e9c4229fb69fd25302084bf537ccb296
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 enukane
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Fluent::Plugin::OsmocomSpectrumSense
|
2
|
+
|
3
|
+
fluent-plugin-osmocom-spectrum-sense is an input plugin for Fluentd. It runs osmocom_spectrum_sense with specified arguments and extract frequencies, powers, noise floor (dBm) from its output.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'fluent-plugin-osmocom-spectrum-sense'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fluent-plugin-osmocom-spectrum-sense
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
See samples/text.conf
|
24
|
+
|
25
|
+
```
|
26
|
+
<source>
|
27
|
+
@type osmocom_spectrum_sense
|
28
|
+
|
29
|
+
tag osmocom
|
30
|
+
minfreq 79000000
|
31
|
+
maxfreq 83000000
|
32
|
+
sample_rate 3200000
|
33
|
+
dwell_delay 1
|
34
|
+
tune_delay 1
|
35
|
+
</source>
|
36
|
+
```
|
37
|
+
|
38
|
+
## Configuration
|
39
|
+
|
40
|
+
|name|type|required?|corresponds to...|default|description|
|
41
|
+
|:---|:---|:--------|:----------------|:------|:----------|
|
42
|
+
|minfreq|int|required|min_freq|none|Minimum Frequency|
|
43
|
+
|maxfreq|int|required|max_freq|none|Maximum Frequency|
|
44
|
+
|sample_rate|int|optional|-s, --sample-rate|3200000 (3.2Msps)|Sample rate|
|
45
|
+
|dwell_delay|float|optional|--dwell-delay|0.25 (0.25s)|Seconds to dwell at a given frequency|
|
46
|
+
|tune_delay|float|optional|--tune-delay|0.25 (0.25s)|Seconds to delay after changing frequency|
|
47
|
+
|channel_bandwidth|float|optional|-b, --channel-bandwidth|6250.0 (6.25KHz)|Channel bandwidth of fft bins in Hz|
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
52
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fluent/plugin/in_osmocom_spectrum_sense"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
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-osmocom-spectrum-sense"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["enukane"]
|
9
|
+
spec.email = ["enukane@glenda9.org"]
|
10
|
+
|
11
|
+
spec.summary = %q{nop}
|
12
|
+
spec.description = %q{nop}
|
13
|
+
spec.homepage = "https://github.com/enukane/fluent-plugin-osmocom-spectrum-sense"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
#if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
#else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
#end
|
23
|
+
|
24
|
+
#spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.files = `git ls-files`.split($/)
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
|
34
|
+
spec.add_runtime_dependency "fluentd"
|
35
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "fluent/input"
|
2
|
+
require "fluent/parser"
|
3
|
+
|
4
|
+
module Fluent
|
5
|
+
class OsmocomSpectrumSenseInput < Input
|
6
|
+
Plugin.register_input('osmocom_spectrum_sense', self)
|
7
|
+
require 'open3'
|
8
|
+
require 'time'
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
config_param :tag, :string, :default => "osmocom"
|
15
|
+
config_param :minfreq, :integer, :default => nil
|
16
|
+
config_param :maxfreq, :integer, :default => nil
|
17
|
+
config_param :sample_rate, :integer, :default => 3200000
|
18
|
+
config_param :dwell_delay, :float, :default => 0.25
|
19
|
+
config_param :tune_delay, :float, :default => 0.25
|
20
|
+
config_param :channel_bandwidth, :float, :default => 6250.0
|
21
|
+
|
22
|
+
def configure(conf)
|
23
|
+
super
|
24
|
+
|
25
|
+
if !@minfreq.is_a?(Integer) or !@maxfreq.is_a?(Integer)
|
26
|
+
raise ConfigError, "minfreq/maxfreq is required to be Integer"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def start
|
31
|
+
super
|
32
|
+
|
33
|
+
@thread = Thread.new(&method(:run))
|
34
|
+
end
|
35
|
+
|
36
|
+
def shutdown
|
37
|
+
if @th_osmocom and @th_osmocom.alive?
|
38
|
+
Process.kill("INT", @th_osmocom.pid)
|
39
|
+
end
|
40
|
+
@thread.join
|
41
|
+
rescue => e
|
42
|
+
log.error "osmocom_spectrum_sense failed to shutdown", :error => e.to_s,
|
43
|
+
:error_class => e.class.to_s
|
44
|
+
log.error_backtrace e.backtrace
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
48
|
+
options = build_options
|
49
|
+
cmdline = "osmocom_spectrum_sense #{options}"
|
50
|
+
print cmdline + "\n"
|
51
|
+
stdin, stdout, stderr, @th_osmocom = *Open3.popen3(cmdline)
|
52
|
+
|
53
|
+
while @th_osmocom.alive?
|
54
|
+
collect_osmocom_output(stdout)
|
55
|
+
end
|
56
|
+
rescue => e
|
57
|
+
log.error "unexpected error", :error => e.to_s
|
58
|
+
log.error_backtrace e.backtrace
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_options
|
62
|
+
options = ""
|
63
|
+
if @sample_rate
|
64
|
+
options += " -s #{@sample_rate}"
|
65
|
+
end
|
66
|
+
if @dwell_delay
|
67
|
+
options += " --dwell-delay=#{@dwell_delay}"
|
68
|
+
end
|
69
|
+
if @tune_delay
|
70
|
+
options += " --tune-delay=#{@tune_delay}"
|
71
|
+
end
|
72
|
+
if @channel_bandwidth
|
73
|
+
options += " -b #{@channel_bandwidth}"
|
74
|
+
end
|
75
|
+
|
76
|
+
options += " #{@minfreq} #{@maxfreq}"
|
77
|
+
return options
|
78
|
+
end
|
79
|
+
|
80
|
+
REG=/^(?<time>.+) center_freq (?<center_freq>\d+\.\d+) freq (?<freq>\d+\.\d+) power_db (?<power_db>-?\d+\.\d+) noise_floor_db (?<noise_floor_db>-?\d+\.\d+)$/
|
81
|
+
def collect_osmocom_output(stdout)
|
82
|
+
collected = []
|
83
|
+
begin
|
84
|
+
readlines_nonblock(stdout).each do |line|
|
85
|
+
# XXX: parse here
|
86
|
+
log.debug "line => '#{line}'"
|
87
|
+
match = line.match(REG)
|
88
|
+
next unless match
|
89
|
+
obj = {
|
90
|
+
:time => Time.parse(match[:time]),
|
91
|
+
:center_freq => match[:center_freq].to_f,
|
92
|
+
:freq => match[:freq].to_f,
|
93
|
+
:power_db => match[:power_db].to_f,
|
94
|
+
:noise_floor_db => match[:noise_floor_db].to_f,
|
95
|
+
}
|
96
|
+
log.debug "new osmocom_spectrum_sense input => #{obj}"
|
97
|
+
collected << obj
|
98
|
+
end
|
99
|
+
rescue => e
|
100
|
+
log.error "failed to read or parse line", :error => e.to_s,
|
101
|
+
:error_class => e.class.to_s
|
102
|
+
end
|
103
|
+
|
104
|
+
collected.each do |obj|
|
105
|
+
time = obj[:time].nil? ? Engine.now : Fluent::EventTime.from_time(obj[:time])
|
106
|
+
obj.delete(:time) # including time could problem in some output plugin
|
107
|
+
router.emit(@tag, time, obj)
|
108
|
+
end
|
109
|
+
rescue => e
|
110
|
+
log.error "failed to collect output from tshark",
|
111
|
+
:error => e.to_s,
|
112
|
+
:error_class => e.class.to_s
|
113
|
+
end
|
114
|
+
|
115
|
+
def readlines_nonblock(io)
|
116
|
+
@nbbuffer = "" if @nbbuffer == nil
|
117
|
+
@nbbuffer += io.read_nonblock(65535)
|
118
|
+
lines = []
|
119
|
+
while idx = @nbbuffer.index("\n")
|
120
|
+
lines << @nbbuffer[0..idx-1]
|
121
|
+
@nbbuffer = @nbbuffer[idx+1..-1]
|
122
|
+
end
|
123
|
+
return lines
|
124
|
+
rescue
|
125
|
+
return []
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
data/samples/test.conf
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<source>
|
2
|
+
@type osmocom_spectrum_sense
|
3
|
+
|
4
|
+
tag osmocom
|
5
|
+
minfreq 79000000
|
6
|
+
maxfreq 83000000
|
7
|
+
sample_rate 3200000
|
8
|
+
dwell_delay 1
|
9
|
+
tune_delay 1
|
10
|
+
</source>
|
11
|
+
|
12
|
+
#<source>
|
13
|
+
# @type snmp
|
14
|
+
#</source>
|
15
|
+
|
16
|
+
<match osmocom>
|
17
|
+
@type stdout
|
18
|
+
</match>
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-osmocom-spectrum-sense
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- enukane
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: nop
|
70
|
+
email:
|
71
|
+
- enukane@glenda9.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- fluent-plugin-osmocom-spectrum-sense.gemspec
|
86
|
+
- lib/fluent/plugin/in_osmocom_spectrum_sense.rb
|
87
|
+
- samples/test.conf
|
88
|
+
- spec/fluent/plugin/osmocom_spectrum_sense_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/enukane/fluent-plugin-osmocom-spectrum-sense
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.5
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: nop
|
114
|
+
test_files: []
|