liebert 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98e05ff2de3c77d7a10f2d974236bb2708073d98
4
- data.tar.gz: c2b820e320e303b16e7f54d9f9423dd9b6e0cc46
3
+ metadata.gz: c85ef4549047d09be9ec6147c18c699619896cea
4
+ data.tar.gz: b0843a4878d0410d7e7fbb0ed0a7487793668de1
5
5
  SHA512:
6
- metadata.gz: cd3f5caa8801bfe53218607ecc881961332b284dab5da6b745d0b739c918ff5691863d2f86f625831934340688622ab57f3567be135f05b72881f3c7600132ce
7
- data.tar.gz: ecf45fd8881a0b0e191c281bb7dda8dd0ff1d36e8a16eb6411ff7a6f82fbff0adf250b1626c7580b8c9ccdee7ceffa8f2601e7598dcafee83dca4c1efa48d74d
6
+ metadata.gz: 1da1ecc3585fc157594bae93f39fd8d0154d78ec7843891bb84c769a1bf678078e1cabda863a7fb7dc17c977838df1c589b2723d9d8a38ec1dc28843dec4732e
7
+ data.tar.gz: 5a1ff453ad6af1bcda59570bdc6fb4b3bd17a31b485c694c6ce3d13819fd7f336b264c7133693facc07649a1f6b25a7679436361bb68060eb727c412914abd37
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Liebert
2
2
 
3
- Liebert is a gem that allows you to gather metrics from Liebert based products and display them in a format digestable by Ganglia.
3
+ Liebert is a gem that allows you to gather metrics from [Liebert](http://www.emersonnetworkpower.com/en-US/Brands/liebert/Pages/default.aspx) based products and display them in a format digestable by [Ganglia](http://ganglia.sourceforge.net/).
4
4
 
5
5
  ## Installation
6
6
 
@@ -30,6 +30,21 @@ UPS Unit:
30
30
  export LIEBERT_UPS_URI='http://liebertups.mydomain.com/graphic/smallUps.htm'
31
31
  ```
32
32
 
33
+ And then you can run:
34
+
35
+ ```
36
+ liebert <unit> --params
37
+ ```
38
+
39
+ e.g.
40
+
41
+ ```
42
+ liebert ac --all
43
+ liebert ac --temperature
44
+ liebert ac
45
+ leibert ups
46
+ ```
47
+
33
48
  ## Contributing
34
49
 
35
50
  1. Fork it
data/lib/liebert.rb CHANGED
@@ -9,4 +9,4 @@ def pass_arguments(object)
9
9
  puts object.send(sanitized_arg.to_sym) if object.respond_to? sanitized_arg
10
10
  end
11
11
  puts object.all if ARGV[1].nil?
12
- end
12
+ end
@@ -6,13 +6,9 @@ class AirConditioner
6
6
 
7
7
  include Scrapable
8
8
 
9
- def initialize(endpoint_uri)
9
+ def initialize(endpoint_uri = nil)
10
10
  @endpoint_uri = endpoint_uri
11
-
12
11
  create_getters
13
- if get_webpage
14
- ATTRS.each { |attr| eval "scrape_#{attr}" }
15
- end
16
12
  end
17
13
 
18
14
  def scrape_temperature
@@ -5,25 +5,36 @@ module Scrapable
5
5
  # Create a summary of all attributes and values in a format digestable by Ganglia
6
6
  def all
7
7
  self.class::ATTRS.inject(String.new) do |string, attr|
8
+ get_webpage
9
+ self.class::ATTRS.each { |attr| eval("scrape_#{attr}") }
8
10
  string << "#{attr.capitalize}\t#{eval("@#{attr}")}\n"
9
11
  end
10
12
  end
11
13
 
14
+ private
15
+
12
16
  # Dynamically create custom getters for each attribute that displays in a format digestable by Ganglia
13
17
  def create_getters
14
18
  self.class::ATTRS.each do |method_name|
15
19
  self.class.class_eval do
16
20
  define_method(method_name) do
21
+ get_webpage
22
+ eval("scrape_#{method_name}")
17
23
  "#{method_name.capitalize}\t#{eval("@#{method_name}")}"
18
24
  end
19
25
  end
20
26
  end
21
27
  end
22
28
 
23
- private
24
-
25
29
  def get_webpage
26
- response = RestClient.get(self.endpoint_uri)
27
- @parsed_response = Nokogiri::HTML.parse(response.body)
30
+ unless @parsed_response
31
+ begin
32
+ response = RestClient.get(self.endpoint_uri)
33
+ @parsed_response = Nokogiri::HTML.parse(response.body)
34
+ rescue
35
+ raise "You forgot to set the URL to your Liebert unit. More information can be found here: https://github.com/bswinnerton/liebert/blob/master/README.md"
36
+ end
37
+ end
38
+ @parsed_response
28
39
  end
29
40
  end
data/lib/liebert/ups.rb CHANGED
@@ -6,13 +6,9 @@ class UPS
6
6
 
7
7
  include Scrapable
8
8
 
9
- def initialize(endpoint_uri)
9
+ def initialize(endpoint_uri = nil)
10
10
  @endpoint_uri = endpoint_uri
11
-
12
11
  create_getters
13
- if get_webpage
14
- ATTRS.each { |attr| eval "scrape_#{attr}" }
15
- end
16
12
  end
17
13
 
18
14
  def scrape_input_amps
@@ -1,3 +1,3 @@
1
1
  module Liebert
2
- VERSION = '0.0.2'
3
- end
2
+ VERSION = '0.0.3'
3
+ end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AirConditioner do
3
+ vcr_options = { cassette_name: 'airconditioner' }
4
+
5
+ describe AirConditioner, vcr: vcr_options do
4
6
  before :all do
5
- VCR.use_cassette 'airconditioner' do
6
- @ac = AirConditioner.new(ENV['LIEBERT_AIRCONDITIONER_URI'])
7
- end
7
+ @ac = AirConditioner.new(ENV['LIEBERT_AIRCONDITIONER_URI'])
8
8
  end
9
9
 
10
10
  it 'responds to temperature' do
@@ -12,10 +12,10 @@ describe AirConditioner do
12
12
  end
13
13
 
14
14
  it 'responds to humidity' do
15
- expect(@ac.humidity).to eq "Humidity\t48.0"
15
+ expect(@ac.humidity).to eq "Humidity\t47.0"
16
16
  end
17
17
 
18
18
  it 'responds to all' do
19
- expect(@ac.all).to eq "Temperature\t65.0\nHumidity\t48.0\n"
19
+ expect(@ac.all).to eq "Temperature\t65.0\nHumidity\t47.0\n"
20
20
  end
21
21
  end
@@ -111,7 +111,7 @@ http_interactions:
111
111
  deviceInfo.heating=false;
112
112
 
113
113
  deviceInfo.humidify=false;
114
- deviceInfo.dehumidify=true;
114
+ deviceInfo.dehumidify=false;
115
115
 
116
116
  deviceInfo.econCycle=false;
117
117
  deviceInfo.unitOn=true;
@@ -121,7 +121,7 @@ http_interactions:
121
121
  deviceInfo.tempSetpt=65;
122
122
  deviceInfo.tempTol=2.0;
123
123
 
124
- deviceInfo.humid=48;
124
+ deviceInfo.humid=47;
125
125
  deviceInfo.humidSetpt=48;
126
126
  deviceInfo.humidTol=5;
127
127
  // -->
@@ -151,7 +151,7 @@ http_interactions:
151
151
  <td class="leftAlignAreaStyle">Stage</td><td class="leftAlignAreaStyle">
152
152
  0 </td></tr><tr>
153
153
  <td class="leftAlignAreaStyle">Capacity&nbsp;</td><td class="leftAlignAreaStyle">
154
- 30 %
154
+ 13 %
155
155
  </td></tr></table></div><div id="HumidityFrame" class="humidityFrame">
156
156
  <table border="1" width="485" height="110">
157
157
  <tr><td>&nbsp;</td></tr></table></div><div id="HumidityArea" class="humidityArea">
@@ -171,5 +171,5 @@ http_interactions:
171
171
  <td class="headerTextStyle" width="250">Active Alarms:</td></tr></table></div>
172
172
  </body></html>
173
173
  http_version:
174
- recorded_at: Thu, 05 Dec 2013 17:09:54 GMT
174
+ recorded_at: Thu, 05 Dec 2013 21:26:29 GMT
175
175
  recorded_with: VCR 2.8.0
@@ -208,23 +208,23 @@ http_interactions:
208
208
  <td>Volts:</td><td></td><td><script language="JavaScript" type="text/javascript">if(deviceInfo.numBypassLines <= 1)document.write("V");</script>
209
209
  </td><td></td><td class="unitColumnStyle"><script language="JavaScript" type="text/javascript">if(deviceInfo.numBypassLines >= 3)document.write("V");</script></td></tr><tr id="BypassAmps" class="bypassAmps">
210
210
  <td>Amps:</td><td></td><td class="unitColumnStyle">A</td></tr><tr>
211
- <td>Freq:</td><td>60.0</td><td class="unitColumnStyle">Hz</td></tr></table></center></td></tr></table></div><div id="Input" class="upsInputArea">
211
+ <td>Freq:</td><td>59.9</td><td class="unitColumnStyle">Hz</td></tr></table></center></td></tr></table></div><div id="Input" class="upsInputArea">
212
212
  <table border="1">
213
213
  <tr><td><center>
214
214
  <a href="../monitor/upsInput.htm"><b>INPUT</b></a><table border="0" width="135" align=center cellspacing="0" cellpadding="1">
215
215
  <tr>
216
216
  <td>Volts:</td><td></td><td><script language="JavaScript" type="text/javascript">if(deviceInfo.numInputLines <= 1)document.write("V");</script>
217
217
  </td><td></td><td class="unitColumnStyle"><script language="JavaScript" type="text/javascript">if(deviceInfo.numInputLines >= 3)document.write("V");</script></td></tr><tr id="InputAmps" class="inputAmps">
218
- <td>Amps:</td><td>16.5 </td><td class="unitColumnStyle">A</td></tr><tr>
219
- <td>Freq:</td><td>60.0 </td><td class="unitColumnStyle">Hz</td></tr></table></center></td></tr></table></div><div id="Output" class="upsOutputArea">
218
+ <td>Amps:</td><td>16.4 </td><td class="unitColumnStyle">A</td></tr><tr>
219
+ <td>Freq:</td><td>60.1 </td><td class="unitColumnStyle">Hz</td></tr></table></center></td></tr></table></div><div id="Output" class="upsOutputArea">
220
220
  <table border="1">
221
221
  <tr><td><center>
222
222
  <a href="../monitor/upsOutput.htm"><b>OUTPUT</b></a><table border="0" width="135" align=center cellspacing="0" cellpadding="1">
223
223
  <tr>
224
224
  <td>Volts:</td><td></td><td><script language="JavaScript" type="text/javascript">if(deviceInfo.numOutputLines <= 1)document.write("V");</script>
225
225
  </td><td></td><td class="unitColumnStyle"><script language="JavaScript" type="text/javascript">if(deviceInfo.numOutputLines >= 3)document.write("V");</script></td></tr><tr id="OutputAmps" class="outputAmps">
226
- <td>Amps:</td><td>33.5 </td><td class="unitColumnStyle">A</td></tr><tr id="OutputFreq" class="outputFreq">
227
- <td>Freq:</td><td>60.0 </td><td class="unitColumnStyle">Hz</td></tr></table></center></td></tr></table></div><div id="Battery" class="upsBatteryArea">
226
+ <td>Amps:</td><td>33.3 </td><td class="unitColumnStyle">A</td></tr><tr id="OutputFreq" class="outputFreq">
227
+ <td>Freq:</td><td>59.9 </td><td class="unitColumnStyle">Hz</td></tr></table></center></td></tr></table></div><div id="Battery" class="upsBatteryArea">
228
228
  <table border="1">
229
229
  <tr><td><center>
230
230
  <a href="../monitor/upsBattery.htm"><b>BATTERY</b></a><table border="0" width="110" align=center cellspacing="0" cellpadding="1">
@@ -269,5 +269,5 @@ http_interactions:
269
269
 
270
270
  </body></html>
271
271
  http_version:
272
- recorded_at: Thu, 05 Dec 2013 17:23:32 GMT
272
+ recorded_at: Thu, 05 Dec 2013 21:26:30 GMT
273
273
  recorded_with: VCR 2.8.0
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Scrapable do
4
+ it 'tells the user they forgot to enter a URI' do
5
+ ac = AirConditioner.new
6
+ expect { ac.temperature }.to raise_error
7
+ end
8
+ end
data/spec/support/vcr.rb CHANGED
@@ -3,4 +3,5 @@ VCR.configure do |c|
3
3
  c.hook_into :webmock
4
4
  c.filter_sensitive_data('<AIRCONDITIONER_URI>') { ENV['LIEBERT_AIRCONDITIONER_URI'] }
5
5
  c.filter_sensitive_data('<UPS_URI>') { ENV['LIEBERT_UPS_URI'] }
6
+ c.configure_rspec_metadata!
6
7
  end
data/spec/ups_spec.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe UPS do
3
+ vcr_options = { cassette_name: 'ups' }
4
+
5
+ describe UPS, vcr: vcr_options do
4
6
  before :all do
5
- VCR.use_cassette 'ups' do
6
- @ups = UPS.new(ENV['LIEBERT_UPS_URI'])
7
- end
7
+ @ups = UPS.new(ENV['LIEBERT_UPS_URI'])
8
8
  end
9
9
 
10
10
  it 'responds to input_amps' do
11
- expect(@ups.input_amps).to eq "Input_amps\t16.5"
11
+ expect(@ups.input_amps).to eq "Input_amps\t16.4"
12
12
  end
13
13
 
14
14
  it 'responds to output_amps' do
15
- expect(@ups.output_amps).to eq "Output_amps\t33.5"
15
+ expect(@ups.output_amps).to eq "Output_amps\t33.3"
16
16
  end
17
17
 
18
18
  it 'responds to battery_voltage' do
@@ -24,6 +24,6 @@ describe UPS do
24
24
  end
25
25
 
26
26
  it 'responds to all' do
27
- expect(@ups.all).to eq "Input_amps\t16.5\nOutput_amps\t33.5\nBattery_voltage\t548.0\nCharge\t100.0\n"
27
+ expect(@ups.all).to eq "Input_amps\t16.4\nOutput_amps\t33.3\nBattery_voltage\t548.0\nCharge\t100.0\n"
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liebert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooks Swinnerton
@@ -145,6 +145,7 @@ files:
145
145
  - spec/airconditioner_spec.rb
146
146
  - spec/cassettes/airconditioner.yml
147
147
  - spec/cassettes/ups.yml
148
+ - spec/scrapable_spec.rb
148
149
  - spec/spec_helper.rb
149
150
  - spec/support/vcr.rb
150
151
  - spec/ups_spec.rb
@@ -176,6 +177,7 @@ test_files:
176
177
  - spec/airconditioner_spec.rb
177
178
  - spec/cassettes/airconditioner.yml
178
179
  - spec/cassettes/ups.yml
180
+ - spec/scrapable_spec.rb
179
181
  - spec/spec_helper.rb
180
182
  - spec/support/vcr.rb
181
183
  - spec/ups_spec.rb