argus-ruby 1.0.0
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 +7 -0
- data/.yardopts +5 -0
- data/LICENSE +21 -0
- data/README.md +45 -0
- data/lib/argus.rb +68 -0
- data/lib/handlers/eventbus.rb +18 -0
- data/lib/helpers/helpers.rb +14 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b30a47739574ce10ff19e938e82785da1ae44087b77d6b11f82ba37bafda6e1c
|
4
|
+
data.tar.gz: 23051f5382d53c7dba8e94088f45a9c87659ed88d1fb51e2cb71de6876bc7967
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f921326e1dd91f574c3204262e72c8c2d2ea5b4c114c7f6e7b00761fa936e7a9bffee89bd5662b962b8f85eb82c7b729315455c81414b1aea48a226469388f61
|
7
|
+
data.tar.gz: 1c3cd225c88ee62f586e228123675e7a6e43f5a7fdac3212d98305693e3c5a3409f6f0e1943f877d21d923159508a03a5162ea3ef2f014a20c335ea4d4de6b38
|
data/.yardopts
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Kelechi Onyekwere
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# ARGUS Ruby Client
|
2
|
+
|
3
|
+
This is the official Ruby library for the [ARGUS Engine](https://github.com/Khelechy/argus), this library helps Ruby developers and applications seamlessly integrate to the ARGUS Engine, authentication and event listening.
|
4
|
+
|
5
|
+
### Install via Gem
|
6
|
+
|
7
|
+
```sh
|
8
|
+
gem install argus-ruby
|
9
|
+
```
|
10
|
+
You can use Bundler to add Argus Ruby to your project
|
11
|
+
|
12
|
+
```sh
|
13
|
+
bundle add 'argus-ruby'
|
14
|
+
```
|
15
|
+
|
16
|
+
### Usage -
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
|
20
|
+
require 'argus'
|
21
|
+
```
|
22
|
+
|
23
|
+
Have a class to define the fucntion to be called when you receive an Argus Event
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class Testsub
|
27
|
+
def on_event(argus_event)
|
28
|
+
puts "#{argus_event.Action}"
|
29
|
+
puts "#{argus_event.ActionDescription}"
|
30
|
+
puts "#{argus_event.Name}"
|
31
|
+
puts "#{argus_event.Timestamp}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Finally use argus like so,
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
subscriber = Testsub.new
|
40
|
+
|
41
|
+
argus = Argus.new("testuser", "testpassword") // Optionally you can pass the host and port, and auth credentials inclusive.
|
42
|
+
|
43
|
+
argus.subscribe(subscriber, :on_event)
|
44
|
+
argus.connect
|
45
|
+
```
|
data/lib/argus.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
require 'socket'
|
3
|
+
require 'json'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require_relative 'helpers/helpers'
|
7
|
+
require_relative 'handlers/eventbus'
|
8
|
+
|
9
|
+
class Argus
|
10
|
+
|
11
|
+
def initialize(username = "", password = "", host = "", port = 0)
|
12
|
+
@username = username
|
13
|
+
@password = password
|
14
|
+
@host = host.empty? ? "127.0.0.1" : host
|
15
|
+
@port = port == 0 ? 1337 : port
|
16
|
+
|
17
|
+
@socket = nil
|
18
|
+
|
19
|
+
@event_bus = EventBus.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def connect
|
23
|
+
|
24
|
+
@socket = TCPSocket.open(@host, @port)
|
25
|
+
|
26
|
+
send_auth_data()
|
27
|
+
|
28
|
+
loop do
|
29
|
+
data = @socket.readpartial(1024)
|
30
|
+
|
31
|
+
if !data.nil? && !data.empty?
|
32
|
+
|
33
|
+
if Helpers.is_json_string(data)
|
34
|
+
publish_argus_data(data)
|
35
|
+
else
|
36
|
+
puts "Received: #{data}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
rescue EOFError
|
43
|
+
puts "Connection closed by server"
|
44
|
+
|
45
|
+
rescue StandardError => e
|
46
|
+
puts "Error receiving data: #{e.message}"
|
47
|
+
|
48
|
+
puts "Socket closed"
|
49
|
+
@socket.close
|
50
|
+
end
|
51
|
+
|
52
|
+
def subscribe(subscriber, method_name)
|
53
|
+
@event_bus.subscribe(subscriber, method_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def publish_argus_data(data)
|
59
|
+
argus_event = JSON.parse(data, object_class: OpenStruct)
|
60
|
+
@event_bus.publish(argus_event)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def send_auth_data()
|
65
|
+
connectionString = "<ArgusAuth>#{@username}:#{@password}</ArgusAuth>"
|
66
|
+
@socket.puts(connectionString)
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
class EventBus
|
3
|
+
ARGUSEVENTNAME = "argus.event.received"
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@subscribers = Hash.new{|h,k| h[k] = []}
|
7
|
+
end
|
8
|
+
|
9
|
+
def subscribe(subscriber, method_name)
|
10
|
+
@subscribers[ARGUSEVENTNAME] << [subscriber, method_name]
|
11
|
+
end
|
12
|
+
|
13
|
+
def publish(data = nil)
|
14
|
+
@subscribers[ARGUSEVENTNAME].each do |subscriber, method_name|
|
15
|
+
subscriber.send(method_name, data) if subscriber.respond_to?(method_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: argus-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kelechi Onyekwere
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: "This is the official Ruby library for the ARGUS Engine, \nthis library
|
14
|
+
helps Ruby developers and applications seamlessly integrate to the ARGUS Engine,
|
15
|
+
authentication and event listening.\n"
|
16
|
+
email:
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
- LICENSE
|
22
|
+
files:
|
23
|
+
- ".yardopts"
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- lib/argus.rb
|
27
|
+
- lib/handlers/eventbus.rb
|
28
|
+
- lib/helpers/helpers.rb
|
29
|
+
homepage: https://github.com/khelechy/argus-ruby
|
30
|
+
licenses:
|
31
|
+
- MIT
|
32
|
+
metadata:
|
33
|
+
source_code_uri: https://github.com/khelechy/argus-ruby
|
34
|
+
bug_tracker_uri: https://github.com/khelechy/argus-ruby/issues
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.4.19
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Argus Ruby client library
|
54
|
+
test_files: []
|