perus 0.1.9 → 0.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4911b71f00064a5f01539c97568c31b26d0d5063
4
- data.tar.gz: 981d5cab3874924a489e37f65db1a5bd56e052fa
3
+ metadata.gz: a4c31e7e80547a4efe91311c2f149e943eb52ea4
4
+ data.tar.gz: 676cbbb27a25a6a2778e540cb9c9641ee0c07601
5
5
  SHA512:
6
- metadata.gz: fb415cc96cd26f0c28f427877e89cadb1b0d45a94f03ee08e02e3e6bf1f4a0e3192f46c14ae2da0e27850dff46e3fa8e2f9732bb1cb8e4986d150313b72959bf
7
- data.tar.gz: 2f5986c3718a2628379955c59cbbda33cea524a16909d8256476ef5f33cb78ae193e98a1c50ab8035ada4edb4df7f3c42ee1d698c38e3276797a2e33a68e1bf5
6
+ metadata.gz: d5926cc09e9a6267fc6b00d6a6449791c464431a55446624dd56a51ba8b35f5cf1e56e38202bf53d712fa31806dc9ba329e43f8193e7b71195f08f9713d167d8
7
+ data.tar.gz: 3dfd536f991cf0f7b125901fea602361b667027a6a1e36ff76353798ae5e2e4abe3204480a933f7ce6fba7159c83ddfe3dd818b383c629ef579c0420e49f83e0
@@ -3,7 +3,7 @@ module Perus::Pinger
3
3
  description 'Kills all instances of a process. Valid values for
4
4
  "process_name" are contained in the pinger config file.'
5
5
  option :process_name, restricted: true
6
- option :signal, default: 'KILL'
6
+ option :signal, default: 'TERM'
7
7
 
8
8
  def run
9
9
  result = shell("killall -#{options.signal} #{options.process_name}")
@@ -6,7 +6,6 @@ require 'uri'
6
6
 
7
7
  DEFAULT_PINGER_OPTIONS = {
8
8
  '__anonymous__' => {
9
- 'system_id' => 1,
10
9
  'server' => 'http://127.0.0.1:3000/'
11
10
  },
12
11
 
@@ -72,15 +71,7 @@ module Perus::Pinger
72
71
 
73
72
  def initialize(options_path = DEFAULT_PINGER_OPTIONS_PATH)
74
73
  Pinger.options.load(options_path, DEFAULT_PINGER_OPTIONS)
75
-
76
- # cache urls on initialisation since the urls depend on values known
77
- # at startup and that won't change over the object lifetime
78
- config_path = URI("systems/#{Pinger.options.system_id}/config")
79
- pinger_path = URI("systems/#{Pinger.options.system_id}/ping")
80
- server_uri = URI(Pinger.options.server)
81
-
82
- @config_url = (server_uri + config_path).to_s
83
- @pinger_url = (server_uri + pinger_path).to_s
74
+ @server_uri = URI(Pinger.options.server)
84
75
 
85
76
  @metrics = []
86
77
  @metric_results = {}
@@ -103,10 +94,19 @@ module Perus::Pinger
103
94
  # configuration
104
95
  #----------------------
105
96
  def load_config
97
+ if Pinger.options.system_id.nil?
98
+ config_path = URI("systems/config_for_ip")
99
+ else
100
+ config_path = URI("systems/#{Pinger.options.system_id}/config")
101
+ end
102
+
103
+ config_url = (@server_uri + config_path).to_s
104
+
106
105
  # load the system config by requesting it from the perus server
107
- json = JSON.parse(RestClient.get(@config_url))
106
+ json = JSON.parse(RestClient.get(config_url))
108
107
  json['metrics'] ||= []
109
108
  json['actions'] ||= []
109
+ @system_id = json['id']
110
110
 
111
111
  # load metric and command modules based on the config
112
112
  json['metrics'].each do |config|
@@ -207,8 +207,11 @@ module Perus::Pinger
207
207
  @metric_errors.reject! {|metric, errors| errors.empty?}
208
208
  add_to_payload(payload, 'metric_errors', @metric_errors)
209
209
 
210
+ pinger_path = URI("systems/#{@system_id}/ping")
211
+ pinger_url = (@server_uri + pinger_path).to_s
212
+
210
213
  begin
211
- RestClient.post(@pinger_url, payload)
214
+ RestClient.post(pinger_url, payload)
212
215
  rescue => e
213
216
  puts 'Ping failed with exception'
214
217
  puts format_exception(e)
@@ -148,7 +148,7 @@ module Perus::Server
148
148
  system = System.with_pk!(params['id'])
149
149
  system.last_updated = timestamp
150
150
 
151
- if request.ip == '127.0.0.1'
151
+ if request.ip == '127.0.0.1' && ENV['RACK_ENV'] == 'production'
152
152
  system.ip = request.env['HTTP_X_FORWARDED_FOR']
153
153
  else
154
154
  system.ip = request.ip
@@ -173,12 +173,21 @@ module Perus::Server
173
173
  # system config
174
174
  get '/systems/:id/config' do
175
175
  system = System.with_pk!(params['id'])
176
- config = {
177
- metrics: system.config.metric_hashes,
178
- actions: system.pending_actions.map(&:config_hash).flatten
179
- }
180
176
  content_type :json
181
- config.to_json
177
+ system.config_hash.to_json
178
+ end
179
+
180
+ # config of system based on request ip
181
+ get '/systems/config_for_ip' do
182
+ if request.ip == '127.0.0.1' && ENV['RACK_ENV'] == 'production'
183
+ ip = request.env['HTTP_X_FORWARDED_FOR']
184
+ else
185
+ ip = request.ip
186
+ end
187
+
188
+ system = System.where(ip: ip).first
189
+ content_type :json
190
+ system.config_hash.to_json
182
191
  end
183
192
 
184
193
  # render all errors in html to replace the shortened subset on the system page
@@ -33,8 +33,14 @@ module Perus::Server
33
33
  end
34
34
 
35
35
  def values_over_period(period)
36
- raise 'invalid period' unless period.keys.include?(:hours)
37
- min_timeout = Time.now.to_i - (period[:hours] * 60 * 60)
36
+ if period.keys.include?(:hours)
37
+ min_timeout = Time.now.to_i - (period[:hours] * 60 * 60)
38
+ elsif period.keys.include?(:mins)
39
+ min_timeout = Time.now.to_i - (period[:mins] * 60)
40
+ else
41
+ raise 'invalid period - must be :hours or :mins'
42
+ end
43
+
38
44
  values_dataset.where("timestamp >= #{min_timeout}")
39
45
  end
40
46
 
@@ -52,6 +52,14 @@ module Perus::Server
52
52
  pending_actions.collect(&:config_hashes).flatten
53
53
  end
54
54
 
55
+ def config_hash
56
+ {
57
+ id: id,
58
+ metrics: config.metric_hashes,
59
+ actions: pending_actions.map(&:config_hash).flatten
60
+ }
61
+ end
62
+
55
63
 
56
64
  # ---------------------------------------
57
65
  # metrics
@@ -1,5 +1,6 @@
1
1
  <%= @form.field :name %>
2
2
  <%= @form.field :logical_name %>
3
+ <%= @form.field :ip %>
3
4
  <%= @form.field :links %>
4
5
  <%= @form.field :orientation, 'select', %w{Other Portrait Landscape} %>
5
6
  <%= @form.field :group %>
data/lib/perus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Perus
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Cannings