cloud66_agent 0.0.1.pre7 → 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.
data/bin/cloud66_agent CHANGED
@@ -64,6 +64,12 @@ elsif command == 'job_end'
64
64
  opts.on('--results-file RESULTS_FILE', 'Results file') { |v| @results_file = v }
65
65
  end.order!
66
66
  Cloud66Agent.job_end(@job_uid, @run_uid, @run_status, @run_time, @results_file)
67
+ elsif command == 'fail2ban'
68
+ OptionParser.new do |opts|
69
+ opts.on('--is-banned IS_BANNED', 'Is this a ban action') { |v| @is_banned = v }
70
+ opts.on('--ip-address IP_ADDRESS', 'IP address to act on') { |v| @ip_address = v }
71
+ end.order!
72
+ Cloud66Agent.fail2ban(@is_banned, @ip_address)
67
73
  else
68
74
  begin
69
75
  Cloud66Agent.send command
@@ -0,0 +1,18 @@
1
+ require 'cloud66_agent/utils/server'
2
+
3
+ module Cloud66
4
+ module Commands
5
+ class Fail2ban
6
+ def self.perform(is_banned, ip_address)
7
+ data = {
8
+ is_banned: is_banned,
9
+ ip_address: ip_address
10
+ }
11
+ Utils::Server.send_fail2ban(data)
12
+ rescue => exc
13
+ $logger.error "Command \"fail2ban\" failed: #{exc.message}"
14
+ exit -1
15
+ end
16
+ end
17
+ end
18
+ end
@@ -4,8 +4,8 @@ module Cloud66
4
4
  module Commands
5
5
  class JobStart
6
6
  def self.perform(job_uid)
7
- result = Utils::Server.send_job_start job_uid
8
- # this is the only time we need a response value from the client
7
+ result = Utils::Server.send_job_start(job_uid)
8
+ # this is the response value for the script
9
9
  puts result['run_uid']
10
10
  exit 0
11
11
  rescue => exc
@@ -6,29 +6,36 @@ module Cloud66
6
6
 
7
7
  class Server
8
8
  include HTTParty
9
+ # set the default request timeout to 45 seconds
10
+ # this sets the open_timeout and the read_timeout
11
+ default_timeout 45
9
12
 
10
13
  def self.send_configure(data)
11
- process(do_post('/server/configure.json', build_content(data)))
14
+ process(do_request(:post, '/server/configure.json', build_content(data)))
12
15
  end
13
16
 
14
17
  def self.send_pulse
15
- process(do_get("/server/#{$config.agent_uid}/pulse.json", build_content))
18
+ process(do_request(:get, "/server/#{$config.agent_uid}/pulse.json", build_content))
16
19
  end
17
20
 
18
21
  def self.send_address(data)
19
- process(do_post("/server/#{$config.agent_uid}/address.json", build_content(data)))
22
+ process(do_request(:post, "/server/#{$config.agent_uid}/address.json", build_content(data)))
20
23
  end
21
24
 
22
25
  def self.send_vitals(data)
23
- process(do_post("/server/#{$config.agent_uid}/vitals.json", build_content(data)))
26
+ process(do_request(:post, "/server/#{$config.agent_uid}/vitals.json", build_content(data)))
24
27
  end
25
28
 
26
29
  def self.send_job_start(job_uid)
27
- process(do_get("/job/#{job_uid}/start.json", build_content))
30
+ process(do_request(:get, "/job/#{job_uid}/start.json", build_content))
28
31
  end
29
32
 
30
33
  def self.send_job_end(job_uid, data)
31
- process(do_post("/job/#{job_uid}/end.json", build_content(data)))
34
+ process(do_request(:post, "/job/#{job_uid}/end.json", build_content(data)))
35
+ end
36
+
37
+ def self.send_fail2ban(data)
38
+ process(do_request(:post, "/server/#{$config.agent_uid}/fail2ban.json", build_content(data)))
32
39
  end
33
40
 
34
41
  private
@@ -57,36 +64,12 @@ module Cloud66
57
64
  end
58
65
  end
59
66
 
60
- def self.do_post(url, content)
61
- $logger.debug "Sending (post) request..."
67
+ def self.do_request(verb, url, content)
68
+ $logger.debug "Sending (#{verb}) request..."
62
69
  $logger.debug "Request url: #{url}"
63
70
  $logger.debug "Request content: #{content}"
64
71
  base_uri $config.api_url
65
- post(url, content)
66
- end
67
-
68
- def self.do_delete(url, content)
69
- $logger.debug "Sending (delete) request..."
70
- $logger.debug "Request url: #{url}"
71
- $logger.debug "Request content: #{content}"
72
- base_uri $config.api_url
73
- delete(url, content)
74
- end
75
-
76
- def self.do_get(url, content)
77
- $logger.debug "Sending (get) request..."
78
- $logger.debug "Request url: #{url}"
79
- $logger.debug "Request content: #{content}"
80
- base_uri $config.api_url
81
- get(url, content)
82
- end
83
-
84
- def self.do_put(url, content)
85
- $logger.debug "Sending (put) request..."
86
- $logger.debug "Request url: #{url}"
87
- $logger.debug "Request content: #{content}"
88
- base_uri $config.api_url
89
- put(url, content)
72
+ self.send verb, url, content
90
73
  end
91
74
 
92
75
  def self.build_content(data = nil)
@@ -102,54 +85,4 @@ module Cloud66
102
85
 
103
86
  end
104
87
  end
105
- end
106
-
107
-
108
- =begin
109
- def get_job
110
- process(self.class.get("/queue/#{@agent_id}.json", { :headers => ClientAuth.build_headers(@api_key, @secret_key) } ))
111
- end
112
-
113
-
114
-
115
- def unregister(agent)
116
- process(self.class.delete("/agent/#{@agent_id}.json", :headers => ClientAuth.build_headers(@api_key, @secret_key)))
117
- end
118
-
119
- def post_results(job_id, data)
120
- process(self.class.post("/job/#{job_id}/complete.json", { :headers => ClientAuth.build_headers(@api_key, @secret_key).merge({'Content-Type' => 'application/json'}), :body => data.to_json } ))
121
- end
122
-
123
- def pulse_without_ip_address
124
- process(self.class.get("/agent/#{@agent_id}/pulse.json", { :headers => ClientAuth.build_headers(@api_key, @secret_key) } ))
125
- end
126
-
127
- def pulse_with_ip_address(data)
128
- process(self.class.post("/agent/#{@agent_id}/pulse.json", { :headers => ClientAuth.build_headers(@api_key, @secret_key).merge({'Content-Type' => 'application/json'}), :body => data.to_json } ))
129
- end
130
-
131
- def status(stat)
132
- data = { :status => stat }
133
- process(self.class.post("/agent/#{@agent_id}/status.json", { :headers => ClientAuth.build_headers(@api_key, @secret_key).merge({'Content-Type' => 'application/json'}), :body => data.to_json }))
134
- end
135
-
136
- def init(data)
137
- process(self.class.post("/agent/#{@agent_id}/initialize.json", { :headers => ClientAuth.build_headers(@api_key, @secret_key).merge({'Content-Type' => 'application/json'}), :body => data.to_json }))
138
- end
139
-
140
- def send_vital_signs(data)
141
- process(self.class.post("/agent/#{@agent_id}/vitalsigns.json", { :headers => ClientAuth.build_headers(@api_key, @secret_key).merge({'Content-Type' => 'application/json'}), :body => data.to_json } ))
142
- end
143
-
144
- private
145
-
146
- def process(response)
147
- if response.code != 200
148
- raise response.body
149
- else
150
- response.parsed_response
151
- end
152
- end
153
- end
154
- end
155
- =end
88
+ end
@@ -13,10 +13,10 @@ module Cloud66
13
13
  # Defines the minor version
14
14
  # PATCH:
15
15
  # Defines the patch version
16
- MAJOR, MINOR, PATCH = 0, 0, 1
16
+ MAJOR, MINOR, PATCH = 1, 0, 0
17
17
 
18
18
  #ie. PRERELEASE_MODIFIER = 'beta1'
19
- PRERELEASE_MODIFIER = "pre7"
19
+ PRERELEASE_MODIFIER = nil
20
20
 
21
21
  ##
22
22
  # Returns the major version ( big release based off of multiple minor releases )
data/lib/cloud66_agent.rb CHANGED
@@ -28,4 +28,9 @@ class Cloud66Agent
28
28
  raise ArgumentError.new if run_status.nil? || job_uid.nil? || run_uid.nil? || run_time.nil? || results_file.nil?
29
29
  Cloud66::Commands::JobEnd.perform(job_uid, run_uid, run_status, run_time, results_file)
30
30
  end
31
+
32
+ def self.fail2ban(is_banned, ip_address)
33
+ raise ArgumentError.new if is_banned.nil? || ip_address.nil?
34
+ Cloud66::Commands::Fail2ban.perform(is_banned, ip_address)
35
+ end
31
36
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud66_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre7
5
- prerelease: 6
4
+ version: 1.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cloud 66
@@ -61,6 +61,7 @@ files:
61
61
  - lib/cloud66_agent.rb
62
62
  - lib/cloud66_agent/commands/address.rb
63
63
  - lib/cloud66_agent/commands/configure.rb
64
+ - lib/cloud66_agent/commands/fail2ban.rb
64
65
  - lib/cloud66_agent/commands/job_end.rb
65
66
  - lib/cloud66_agent/commands/job_start.rb
66
67
  - lib/cloud66_agent/commands/pulse.rb
@@ -86,9 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
87
  required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  none: false
88
89
  requirements:
89
- - - ! '>'
90
+ - - ! '>='
90
91
  - !ruby/object:Gem::Version
91
- version: 1.3.1
92
+ version: '0'
92
93
  requirements: []
93
94
  rubyforge_project:
94
95
  rubygems_version: 1.8.25