huginn_mongodb 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/lib/huginn_mongodb/mongodb.rb +65 -0
- data/lib/huginn_mongodb.rb +4 -0
- data/spec/mongodb_spec.rb +13 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b7427fa7fb8a3708aa2526585baeb9692a05113deb6726de6e78840bad6a9d1
|
4
|
+
data.tar.gz: 7dc32caf7bebfba94697a7d3e49ad8e868922d393ac63c0296eb11841c2e68bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e99cac0c078386469c6cc78927621f9a596e29ae6a4f525f829bad776aa37f6dfe0a139837e85e18fef159cc1d910708964035b21ad0845f7b3f468940b31a49
|
7
|
+
data.tar.gz: 28bddf127e661141c9d8c7534e6ef85886b62338c04639389c7384f0e5003a2fbfeb7e58d6e8dfb086611bfe6431475e320c540e61270aeca483953884e50213
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Agents
|
2
|
+
class Mongodb < Agent
|
3
|
+
include FormConfigurable
|
4
|
+
can_dry_run!
|
5
|
+
no_bulk_receive!
|
6
|
+
|
7
|
+
default_schedule "12h"
|
8
|
+
gem_dependency_check { defined?(Mongo::Client) }
|
9
|
+
form_configurable :host
|
10
|
+
form_configurable :database
|
11
|
+
form_configurable :user
|
12
|
+
form_configurable :password
|
13
|
+
form_configurable :collection
|
14
|
+
|
15
|
+
form_configurable :guid
|
16
|
+
form_configurable :data
|
17
|
+
|
18
|
+
description <<-MD
|
19
|
+
Mongo DB agent
|
20
|
+
MD
|
21
|
+
|
22
|
+
def default_options
|
23
|
+
{
|
24
|
+
host: "",
|
25
|
+
database: "",
|
26
|
+
user: "",
|
27
|
+
password: "",
|
28
|
+
collection: "",
|
29
|
+
guid: "{{guid}}",
|
30
|
+
data: "{{data}}"
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_options
|
35
|
+
end
|
36
|
+
|
37
|
+
def working?
|
38
|
+
received_event_without_error?
|
39
|
+
end
|
40
|
+
|
41
|
+
# def check
|
42
|
+
# end
|
43
|
+
|
44
|
+
def receive(incoming_events)
|
45
|
+
Mongo::Logger.logger.level = ::Logger::FATAL
|
46
|
+
mongo_client = Mongo::Client.new(
|
47
|
+
[ interpolated["host"] ],
|
48
|
+
user: interpolated["user"],
|
49
|
+
password: interpolated["password"],
|
50
|
+
database: interpolated["database"],
|
51
|
+
auth_source: "admin"
|
52
|
+
)
|
53
|
+
collection = mongo_client[interpolated["collection"]]
|
54
|
+
incoming_events.each do |event|
|
55
|
+
payload = interpolated(event)
|
56
|
+
payload["data"]["_id"] = payload["guid"]
|
57
|
+
result = collection.update_one(
|
58
|
+
{ _id: payload["guid"] },
|
59
|
+
payload["data"],
|
60
|
+
{ upsert: true }
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::Mongodb do
|
5
|
+
before(:each) do
|
6
|
+
@valid_options = Agents::Mongodb.new.default_options
|
7
|
+
@checker = Agents::Mongodb.new(:name => "Mongodb", :options => @valid_options)
|
8
|
+
@checker.user = users(:bob)
|
9
|
+
@checker.save!
|
10
|
+
end
|
11
|
+
|
12
|
+
pending "add specs here"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_mongodb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hadrien Froger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-20 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'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mongo
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
69
|
+
description: This gem connects to Mongo and upsert the given payloads using huginn
|
70
|
+
email:
|
71
|
+
- hadrien@octree.ch
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/huginn_mongodb.rb
|
77
|
+
- lib/huginn_mongodb/mongodb.rb
|
78
|
+
- spec/mongodb_spec.rb
|
79
|
+
homepage: https://github.com/octree-gva/huginn_agents
|
80
|
+
licenses: []
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.1.4
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Upsert data to a MongoDB database
|
101
|
+
test_files:
|
102
|
+
- spec/mongodb_spec.rb
|