huginn_sqlite3_agent 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +7 -0
- data/lib/huginn_sqlite3_agent.rb +3 -0
- data/lib/huginn_sqlite3_agent/sqlite3_agent.rb +68 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e2951a871135a650ed36aab2ab6e24c51aac90f6b432b2806eb8b975efb8c291
|
4
|
+
data.tar.gz: e94d85208b6e984946a8d5433669a1d9abc11e6c625406b9a681629c117e9f28
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e87cc0841b5756b8ca985287649b657bb39329c9276ad3432cd2fe3b6a2a6f8b9b7429202da668aa8a0b7d7c32b25941d70925601f20aeadfd4d586d9f373f5
|
7
|
+
data.tar.gz: fec988e750e7c99278864532d5dec0e4c3cbda606248d21e9dcd694867ffe4dd748b55bbf0a9966f38eabeec97769872b9abc68c564f5b100a08dc445af9d5a8
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2021 Steve Gattuso
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
|
3
|
+
module Agents
|
4
|
+
class Sqlite3WriteAgent < Agent
|
5
|
+
include FormConfigurable
|
6
|
+
|
7
|
+
cannot_be_scheduled!
|
8
|
+
|
9
|
+
description <<-MD
|
10
|
+
This agent allows data to be written to a SQLite3 database. You can use
|
11
|
+
this as a means to pass data into a format that is perhaps a more durable
|
12
|
+
than Huginn's internal database + be a bit more queryable than the
|
13
|
+
`events` table. Generally you'll want to use this in combination with a
|
14
|
+
Javascript agent, which will allow you to intake arbitrary events and
|
15
|
+
properly format them into the event schema expected by this agent.
|
16
|
+
|
17
|
+
Note that the agent expects the sqlite3 database at `database_path` to
|
18
|
+
already exist. You are responsible for setting up this db file and its
|
19
|
+
tables yourself.
|
20
|
+
|
21
|
+
## Writing Data
|
22
|
+
This agent accepts events in the following format:
|
23
|
+
|
24
|
+
{
|
25
|
+
"query": "INSERT INTO some_table (col1, col2) VALUES(?, ?)",
|
26
|
+
"parameters": ["abc", 123]
|
27
|
+
}
|
28
|
+
|
29
|
+
Regardless of the result, the agent will _not_ transmit any outgoing
|
30
|
+
events. It will, however, log whether or not the query was successful.
|
31
|
+
MD
|
32
|
+
|
33
|
+
form_configurable :database_path, type: :string
|
34
|
+
def validate_options
|
35
|
+
if options['database_path'].blank?
|
36
|
+
errors.add(:database_path, 'cannot be blank')
|
37
|
+
elsif !File.file?(options['database_path'])
|
38
|
+
errors.add(:database_path, 'does not exist')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_options
|
43
|
+
{
|
44
|
+
'database_path' => '/path/to/some/sqlite3.db',
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def working?
|
49
|
+
if memory['last_success'].nil?
|
50
|
+
true
|
51
|
+
else
|
52
|
+
memory['last_success']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def receive(incoming_events)
|
57
|
+
memory['last_success'] = false
|
58
|
+
|
59
|
+
db = SQLite3::Database.new options['database_path']
|
60
|
+
incoming_events.each do |event|
|
61
|
+
db.execute event.payload['query'], event.payload['parameters']
|
62
|
+
log("Executed query '#{event.payload['query']}' with params: #{event.payload['parameters']}")
|
63
|
+
end
|
64
|
+
|
65
|
+
memory['last_success'] = true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_sqlite3_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Gattuso
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-17 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: huginn_agent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.2'
|
55
|
+
description: A huginn agent for writing data to SQLite3 databases
|
56
|
+
email:
|
57
|
+
- steve@stevegattuso.me
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- lib/huginn_sqlite3_agent.rb
|
64
|
+
- lib/huginn_sqlite3_agent/sqlite3_agent.rb
|
65
|
+
homepage: https://github.com/stevenleeg/huginn_sqlite3_agent
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.1.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: A huginn agent for writing data to SQLite3 databases
|
88
|
+
test_files: []
|