huginn_agent_status_agent 0.1.11

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 13c519c616d259697540806cbe8bbc4e7b2e40dfe2aea82e468635dd0b57d3a5
4
+ data.tar.gz: 4e01993d81dae5905047cfd36ef7a7a6f85eb0d2fe58df7b076dc8d8302a70bb
5
+ SHA512:
6
+ metadata.gz: 4c0b4068cce01a5db19f7b413f24b82e128c433a870b448430344e6cbd8653b9968e9956a42f8d79d9a052ede59270b2a61685b847a0d18aa431985e210faaae
7
+ data.tar.gz: 8f2d47e7ba988b46e60eb9122d3f7d62db93866a262b28465429997dd141e7e437ceb692559ae2a6f6d79034e2e8db2704af7792cf14ebe73ef0be515182fd99
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2022 Nicolas Germain
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,126 @@
1
+ module Agents
2
+ class AgentStatusAgent < Agent
3
+ include FormConfigurable
4
+ can_dry_run!
5
+ no_bulk_receive!
6
+ default_schedule 'every_5m'
7
+
8
+ description do
9
+ <<-MD
10
+ The huginn agent status creates an event when an agent has status "not working".
11
+
12
+ `debug` is used to verbose mode.
13
+
14
+ `changes_only` is only used to emit event about a currency's change.
15
+
16
+ `expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
17
+ that you anticipate passing without this Agent receiving an incoming Event.
18
+ MD
19
+ end
20
+
21
+ event_description <<-MD
22
+ Events look like this:
23
+
24
+ {
25
+ "id"=>46,
26
+ "user_id"=>1,
27
+ "type"=>"Agents::ActivisionGamesStatusAgent",
28
+ "name"=>"test",
29
+ "schedule"=>"never",
30
+ "guid"=>"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
31
+ }
32
+ MD
33
+
34
+ def default_options
35
+ {
36
+ 'debug' => 'false',
37
+ 'expected_receive_period_in_days' => '2',
38
+ 'changes_only' => 'true'
39
+ }
40
+ end
41
+
42
+ form_configurable :expected_receive_period_in_days, type: :string
43
+ form_configurable :changes_only, type: :boolean
44
+ form_configurable :debug, type: :boolean
45
+ def validate_options
46
+
47
+ if options.has_key?('changes_only') && boolify(options['changes_only']).nil?
48
+ errors.add(:base, "if provided, changes_only must be true or false")
49
+ end
50
+
51
+ if options.has_key?('debug') && boolify(options['debug']).nil?
52
+ errors.add(:base, "if provided, debug must be true or false")
53
+ end
54
+
55
+ unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
56
+ errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
57
+ end
58
+ end
59
+
60
+ def working?
61
+ event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
62
+ end
63
+
64
+ def check
65
+ check_status
66
+ end
67
+
68
+ private
69
+
70
+ def check_status()
71
+
72
+ client = Mysql2::Client.new(
73
+ :host => "#{ENV['DATABASE_HOST']}",
74
+ :username => "#{ENV['DATABASE_USERNAME']}",
75
+ :password => "#{ENV['DATABASE_PASSWORD']}",
76
+ :database => "#{ENV['DATABASE_NAME']}",
77
+ :encoding => "#{ENV['DATABASE_ENCODING']}"
78
+ )
79
+ results = client.query("select id,user_id,type,name,schedule,guid from agents where disabled = 0 and ((last_check_at IS NOT NULL and JSON_EXTRACT(options, '$.expected_receive_period_in_days') IS NOT NULL and last_event_at <= NOW() - INTERVAL JSON_EXTRACT(options, '$.expected_receive_period_in_days') DAY) OR (JSON_EXTRACT(options, '$.expected_update_period_in_days') IS NOT NULL and last_event_at <= NOW() - INTERVAL JSON_EXTRACT(options, '$.expected_update_period_in_days') DAY)) order by id desc")
80
+ payload = []
81
+ results.each do |row|
82
+ payload.push row
83
+ end
84
+
85
+
86
+ if interpolated['changes_only'] == 'true'
87
+ if payload != memory['last_status']
88
+ if "#{memory['last_status']}" == ''
89
+ payload.each do |agent|
90
+ create_event payload: agent
91
+ end
92
+ else
93
+ last_status = memory['last_status']
94
+ payload.each do |agent|
95
+ found = false
96
+ if interpolated['debug'] == 'true'
97
+ log "agent"
98
+ log agent
99
+ end
100
+ last_status.each do |agentbis|
101
+ if agent == agentbis
102
+ found = true
103
+ end
104
+ end
105
+ if found == false
106
+ if interpolated['debug'] == 'true'
107
+ log "found is #{found}! so event created"
108
+ log agent
109
+ end
110
+ create_event payload: agent
111
+ end
112
+ end
113
+ end
114
+ memory['last_status'] = payload
115
+ else
116
+ log "no diff"
117
+ end
118
+ else
119
+ create_event payload: payload
120
+ if payload != memory['last_status']
121
+ memory['last_status'] = payload
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_agent_status_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_agent_status_agent/agent_status_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::AgentStatusAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::AgentStatusAgent.new.default_options
7
+ @checker = Agents::AgentStatusAgent.new(:name => "AgentStatusAgent", :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,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huginn_agent_status_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.11
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Germain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-01-28 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: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
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
+ description: Write a longer description or delete this line.
56
+ email:
57
+ - ngermain@hihouhou.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - lib/huginn_agent_status_agent.rb
64
+ - lib/huginn_agent_status_agent/agent_status_agent.rb
65
+ - spec/agent_status_agent_spec.rb
66
+ homepage: https://github.com/hihouhou/huginn_agent_status_agent
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Write a short summary, because Rubygems requires one.
89
+ test_files:
90
+ - spec/agent_status_agent_spec.rb