github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

lennartkoopmann / scopeport-client-ruby

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 5
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Graphs
  • Tree: 665e4d6

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

ScopePort Client: Ruby/Multi-OS — Read more

  cancel

http://www.scopeport.org/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

First version of the Ruby client. Connects, logs in and sends sample 
sensor data every 60 seconds. 
Lennart Koopmann (author)
Fri Jun 12 14:40:00 -0700 2009
commit  665e4d69a93c73fd8055511aae55e88afcfb42c2
tree    e8d00f1d18480f1d44b8db99d0757d4ff63c1c3d
parent  4128b0de316caa3fd1f4c3fb447665915b432fa9
scopeport-client-ruby / scopeport-client.rb scopeport-client.rb
100755 126 lines (109 sloc) 2.926 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/ruby
 
# This file is part of ScopePort (Client Ruby).
#
# Copyright 2009 Lennart Koopmann
#
# ScopePort (Client Ruby) is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ScopePort (Client Ruby) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ScopePort (Client Ruby). If not, see <http://www.gnu.org/licenses/>.
 
hostname = "localhost"
port = 12200
host_id = 1
password = "secret"
 
require "socket"
 
class Conversation
  private
  def socket
    @socket
  end
 
  public
  def initialize hostname, port
    raise "Invalid port" if port < 0 or port > 65535
    @hostname = hostname
    @port = port
  
    # Try to open a socket.
    begin
      @socket = TCPSocket.open(@hostname, @port)
      # Check the answer.
      msg = @socket.recvfrom 100
      raise "Empty or no reply" if msg[0].length == 0
      raise msg[0] if msg[0] != "Okay"
    rescue => e
      raise e
    end
  end
 
  def close
    begin
      @socket.close
    rescue => e
      raise e
    end
  end
 
  def login host_id, password
    begin
      login_message = "#{host_id},login,#{password}"
      @socket.send login_message, login_message.length
      msg = @socket.recvfrom 100
      raise "Empty or no reply" if msg[0].length == 0
      raise msg[0] if msg[0] != "Okay"
    rescue => e
      raise e
    end
  end
 
  def send_sensor_data(host_id, sensor, value)
    raise "Missing host_id" if !host_id.integer?
    raise "Missing sensor name" if sensor.length <= 0
    raise "Missing sensor value" if value.length <= 0
    raise "Illegal characters" if sensor.include? "," or value.include? ","
 
    begin
      sensor_message = "#{host_id},#{sensor},#{value}"
      @socket.send sensor_message, sensor_message.length
      msg = @socket.recvfrom 100
      raise "Empty or no reply" if msg[0].length == 0
      raise msg[0] if msg[0] != "Okay"
    rescue => e
      raise e
    end
  end
end
 
while 1 do
 
  # Connect to the ScopePort server.
  begin
    con = Conversation.new hostname, port
  rescue => e
    puts "Could not connect to ScopePort server: #{e}"
    con.close
    sleep(60)
    next
  end
 
  # Log in
  begin
    con.login host_id, password
  rescue => e
    puts "Could not log in: #{e}"
    con.close
    sleep(60)
    next
  end
 
  # Send sensor data
  begin
    con.send_sensor_data host_id, "sensor_,cpu5", "5.2"
  rescue => e
    puts "Could not send sensor data: #{e}"
    con.close
    sleep(60)
    next
  end
  
  # All done. Close socket.
  con.close
 
  sleep 60
end
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server