istat 0.0.1

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.
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2011 Vincent Landgraf
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+ module Istat
21
+ module Frames
22
+ class RegisterRequest < Request
23
+ # create a new register request frame
24
+ # @param [String] hostname the hostname to use for registering (e.g. example.com)
25
+ # @param [String] duuid the duuid to use for registering (e.g. 19be1f6285ae9019254c93a880db7285)
26
+ def initialize(hostname, duuid)
27
+ super create([:h, hostname], [:duuid, duuid])
28
+ end
29
+ end
30
+
31
+ class RegisterResponse < Response
32
+ # check if the user has to authorize using password
33
+ # @return [Boolean] true if the user should authorize
34
+ def authorize?
35
+ @root.attributes["ath"].to_i == 1
36
+ end
37
+
38
+ # calculate the uptime value
39
+ # @return [Integer] a timestamp (Time.now - val)
40
+ def uptime
41
+ @root.attributes["n"].to_i
42
+ end
43
+
44
+ # calculate the next_uptime value
45
+ # @return [Integer] a timestamp (Time.now - val)
46
+ def next_uptime
47
+ @root.attributes["c"].to_i
48
+ end
49
+
50
+ # @return static value 6
51
+ def ss
52
+ @root.attributes["ss"].to_i
53
+ end
54
+
55
+ # @return static value 2
56
+ def pl
57
+ @root.attributes["pl"].to_i
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,35 @@
1
+ require "openssl"
2
+
3
+ # Copyright (c) 2011 Vincent Landgraf
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
13
+ # all 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
21
+ # THE SOFTWARE.
22
+ module Istat
23
+ module Utils
24
+ # generate a pseudo random uuid based on openssl random
25
+ # @return [String] the generated uuid
26
+ # @example
27
+ # Istat::Utils.uuid # => '19be1f6285ae9019254c93a880db7285'
28
+ #
29
+ def self.uuid(size = 16)
30
+ OpenSSL::Random.random_bytes(size).unpack("C" * size).map do |char|
31
+ "%02x" % char
32
+ end.join
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright (c) 2011 Vincent Landgraf
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+ module Istat
21
+ VERSION = "0.0.1"
22
+ end
data/lib/istat.rb ADDED
@@ -0,0 +1,9 @@
1
+ lib = File.dirname(__FILE__)
2
+ require File.join(lib, "istat", "utils")
3
+ require File.join(lib, "istat", "frames", "base")
4
+ require File.join(lib, "istat", "frames", "authentication")
5
+ require File.join(lib, "istat", "frames", "connection_test")
6
+ require File.join(lib, "istat", "frames", "register")
7
+ require File.join(lib, "istat", "frames", "measurement")
8
+ require File.join(lib, "istat", "client")
9
+ require File.join(lib, "istat", "version")
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Istat::Client do
4
+ before(:each) do
5
+ @client = Istat::Client.new(SERVER.host, SERVER.port, SERVER.password,
6
+ LOGGER)
7
+ end
8
+
9
+ it "should be possible to connect and disconnect to/from an istat server" do
10
+ @client.connect!.should be_true
11
+ @client.close!.should be_true
12
+ end
13
+
14
+ it "should be possible to test a connection" do
15
+ @client.connect!.should be_true
16
+ @client.online?.should be_true
17
+ @client.close!.should be_true
18
+ end
19
+
20
+ it "should be possible to register the host" do
21
+ @client.connect!.should be_true
22
+ @client.register!
23
+ @client.close!.should be_true
24
+ end
25
+
26
+ it "should be possible to authorize correctly" do
27
+ @client.connect!.should be_true
28
+ @client.register!
29
+ @client.authenticate!
30
+ @client.close!.should be_true
31
+ end
32
+
33
+ it "should be possible to use Client#start to start, authenticate, register and stop" do
34
+ @client.start do |session|
35
+ session.connection_frame.uptime.should > 0
36
+ end
37
+ end
38
+
39
+ it "should be possible to request host data" do
40
+ @client.start do |session|
41
+ response = session.fetch
42
+ response.network?.should be_true
43
+ response.cpu?.should be_true
44
+ response.memory?.should be_true
45
+ response.load?.should be_true
46
+ response.uptime?.should be_true
47
+ response.disks?.should be_true
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Authentication" do
4
+ context Istat::Frames::AuthenticationRequest do
5
+ it "should be possible to generate a correct password frame" do
6
+ frame = Istat::Frames::AuthenticationRequest.new("test")
7
+ frame.to_s.should == "test"
8
+ end
9
+ end
10
+
11
+ context Istat::Frames::AuthenticationResponse do
12
+ it "should be possible to parse the authentication response" do
13
+ xml = %{<?xml version="1.0" encoding="UTF-8"?><isr ready="1"></isr>}
14
+ frame = Istat::Frames::AuthenticationResponse.new(xml)
15
+ frame.ready?.should be_true
16
+ frame.rejected?.should be_false
17
+ xml = %{<?xml version="1.0" encoding="UTF-8"?><isr athrej="1"></isr>}
18
+ frame = Istat::Frames::AuthenticationResponse.new(xml)
19
+ frame.rejected?.should be_true
20
+ frame.ready?.should be_false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "ConnectionTest" do
4
+ context Istat::Frames::ConnectionTestRequest do
5
+ it "should be possible to generate a correct request" do
6
+ frame = Istat::Frames::ConnectionTestRequest.new
7
+ frame.to_s.should == "<?xml version='1.0' encoding='UTF-8'?><isr><conntest/></isr>"
8
+ end
9
+ end
10
+
11
+ context Istat::Frames::ConnectionTestResponse do
12
+ it "should be possible to parse a response" do
13
+ xml = %{<?xml version="1.0" encoding="UTF-8"?><isr></isr>}
14
+ frame = Istat::Frames::ConnectionTestResponse.new(xml)
15
+ frame.success?.should be_true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,117 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Measurement" do
4
+ context Istat::Frames::MeasurementRequest do
5
+ it "should be possible to generate a correct request" do
6
+ frame = Istat::Frames::MeasurementRequest.new(1)
7
+ frame.to_s.should == "<?xml version='1.0' encoding='UTF-8'?><isr><rid>1</rid><c>-1</c><n>-1</n><m>-1</m><lo>-1</lo><t>-1</t><f>-1</f><u>-1</u><d>-1</d></isr>"
8
+ end
9
+ end
10
+
11
+ context Istat::Frames::MeasurementResponse do
12
+ before(:each) do
13
+ @frame = Istat::Frames::MeasurementResponse.new(%Q{
14
+ <?xml version="1.0" encoding="UTF-8"?>
15
+ <isr ds="0" ts="0" fs="0" rid="1">
16
+ <CPU>
17
+ <c id="28388970" u="0" s="0" n="0"></c>
18
+ <c id="28388971" u="0" s="0" n="0"></c>
19
+ <c id="28388972" u="0" s="0" n="0"></c>
20
+ <c id="28388973" u="0" s="0" n="0"></c>
21
+ </CPU>
22
+ <NET if="1">
23
+ <n id="28388970" d="4177773" u="232278672" t="1304082088"></n>
24
+ <n id="28388971" d="4177773" u="232278672" t="1304082089"></n>
25
+ <n id="28388972" d="4177773" u="232278672" t="1304082090"></n>
26
+ <n id="28388973" d="4177773" u="232278672" t="1304082091"></n>
27
+ </NET>
28
+ <MEM w="25938" a="27620" i="11664" f="7983" t="73207" su="3" st="36861" pi="0" po="0"></MEM>
29
+ <LOAD one="0" fv="0" ff="0"></LOAD>
30
+ <UPT u="28388036"></UPT>
31
+ <DISKS>
32
+ <d n="/" uuid="/dev/vzfs" f="9226" p="39.931"></d>
33
+ </DISKS>
34
+ <TEMPS>
35
+ <t i="5" t="64"></t>
36
+ <t i="4" t="30"></t>
37
+ <t i="0" t="30"></t>
38
+ <t i="2" t="29"></t>
39
+ <t i="6" t="61"></t>
40
+ <t i="1" t="52"></t>
41
+ <t i="3" t="50"></t>
42
+ </TEMPS>
43
+ <FANS>
44
+ <f i="0" s="1999"></f>
45
+ </FANS>
46
+ </isr>
47
+ })
48
+ end
49
+
50
+ it "should be possible to parse the cpus" do
51
+ @frame.cpu?.should be_true
52
+ @frame.cpu.should == [
53
+ { :id => 28388970, :user => 0, :system => 0, :nice => 0 },
54
+ { :id => 28388971, :user => 0, :system => 0, :nice => 0 },
55
+ { :id => 28388972, :user => 0, :system => 0, :nice => 0 },
56
+ { :id => 28388973, :user => 0, :system => 0, :nice => 0 }
57
+ ]
58
+ end
59
+
60
+ it "should be possible to parse the network" do
61
+ @frame.network?.should be_true
62
+ @frame.network.should == {
63
+ 1 => [
64
+ { :id => 28388970, :d => 4177773, :u => 232278672, :t => 1304082088 },
65
+ { :id => 28388971, :d => 4177773, :u => 232278672, :t => 1304082089 },
66
+ { :id => 28388972, :d => 4177773, :u => 232278672, :t => 1304082090 },
67
+ { :id => 28388973, :d => 4177773, :u => 232278672, :t => 1304082091 }
68
+ ]
69
+ }
70
+ end
71
+
72
+ it "should be possible to parse the memory" do
73
+ @frame.memory?.should be_true
74
+ @frame.memory.should == {
75
+ :wired => 25938,
76
+ :active => 27620,
77
+ :inactive => 11664,
78
+ :free => 7983,
79
+ :total => 73207,
80
+ :swap_used => 3,
81
+ :swap_total => 36861,
82
+ :page_ins => 0,
83
+ :page_outs => 0
84
+ }
85
+ end
86
+
87
+ it "should be possible to parse the load" do
88
+ @frame.load?.should be_true
89
+ @frame.load.should == [0, 0, 0]
90
+ end
91
+
92
+ it "should be possible to parse the uptime" do
93
+ @frame.uptime?.should be_true
94
+ @frame.uptime.year.should == 2010
95
+ end
96
+
97
+ it "should be possible to parse the temps" do
98
+ @frame.temps?.should be_true
99
+ @frame.temps.should == [30, 52, 29, 50, 30, 64, 61]
100
+ end
101
+
102
+ it "should be possbile to parse the fans" do
103
+ @frame.fans?.should be_true
104
+ @frame.fans.should == [1999]
105
+ end
106
+
107
+ it "should be possible to parse the disks" do
108
+ @frame.disks?.should be_true
109
+ @frame.disks.should == [
110
+ :label => "/",
111
+ :uuid => "/dev/vzfs",
112
+ :free => 9226,
113
+ :percent_used => 39.931
114
+ ]
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Registration" do
4
+ context Istat::Frames::RegisterRequest do
5
+ it "should be possible to generate a correct password frame" do
6
+ frame = Istat::Frames::RegisterRequest.new("macbook.local", "42c4e086890f9e2c1b2b7221b2422136")
7
+ frame.to_s.should == "<?xml version='1.0' encoding='UTF-8'?><isr><h>macbook.local</h><duuid>42c4e086890f9e2c1b2b7221b2422136</duuid></isr>"
8
+ end
9
+ end
10
+
11
+ context Istat::Frames::RegisterResponse do
12
+ it "should be possible to parse the authentication response" do
13
+ xml = %Q{<?xml version="1.0" encoding="UTF-8"?><isr pl="2" ath="1" ss="6" c="28406490" n="28406489"></isr>}
14
+ frame = Istat::Frames::RegisterResponse.new(xml)
15
+ frame.ss.should == 6
16
+ frame.uptime == 28406489
17
+ frame.next_uptime.should == 28406490
18
+ frame.authorize?.should be_true
19
+ frame.pl.should == 2
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ $:.push(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
2
+ require "istat"
3
+ require "uri"
4
+ require "logger"
5
+ LOGGER = Logger.new("debug.log")
6
+ LOGGER.level = Logger::DEBUG
7
+
8
+ SERVER = URI.parse(ENV["TEST_SERVER"] || "istat://any:10946@localhost:5109/")
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Istat::Utils do
4
+ it "should be possible to generate a pseudo uuid" do
5
+ 10.times do
6
+ Istat::Utils.uuid.size.should == 32
7
+ end
8
+ end
9
+ end
data/test_rc.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ TEST_SERVER=istat://any:I8rAw1lhkJPMC9W0nJG7hA@ruby-consult.de:5109/ rspec spec
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: istat
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Vincent Landgaf
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-29 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 1
30
+ segments:
31
+ - 2
32
+ - 1
33
+ version: "2.1"
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: |
37
+ an istat client library for ruby
38
+
39
+ email: vilandgr+github@googlemail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - debug.log
48
+ - doc/_index.html
49
+ - doc/class_list.html
50
+ - doc/css/common.css
51
+ - doc/css/full_list.css
52
+ - doc/css/style.css
53
+ - doc/file.README.html
54
+ - doc/file_list.html
55
+ - doc/frames.html
56
+ - doc/index.html
57
+ - doc/js/app.js
58
+ - doc/js/full_list.js
59
+ - doc/js/jquery.js
60
+ - doc/method_list.html
61
+ - doc/top-level-namespace.html
62
+ - istat.gemspec
63
+ - lib/istat/client.rb
64
+ - lib/istat/frames/authentication.rb
65
+ - lib/istat/frames/base.rb
66
+ - lib/istat/frames/connection_test.rb
67
+ - lib/istat/frames/measurement.rb
68
+ - lib/istat/frames/register.rb
69
+ - lib/istat/utils.rb
70
+ - lib/istat/version.rb
71
+ - lib/istat.rb
72
+ - README.md
73
+ - spec/client_spec.rb
74
+ - spec/frames/authentication_spec.rb
75
+ - spec/frames/connection_test_spec.rb
76
+ - spec/frames/measurement_request_spec.rb
77
+ - spec/frames/register_spec.rb
78
+ - spec/spec_helper.rb
79
+ - spec/utils_spec.rb
80
+ - test_rc.sh
81
+ has_rdoc: true
82
+ homepage: https://github.com/threez/istat
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: an istat client library for ruby
115
+ test_files:
116
+ - spec/client_spec.rb
117
+ - spec/frames/authentication_spec.rb
118
+ - spec/frames/connection_test_spec.rb
119
+ - spec/frames/measurement_request_spec.rb
120
+ - spec/frames/register_spec.rb
121
+ - spec/spec_helper.rb
122
+ - spec/utils_spec.rb