January 2009


Front Page27 Jan 2009 04:08 pm
System Admin26 Jan 2009 12:31 pm

I’m learning Ruby, and as an early project, I thought I’d write a little SOAP server for exposing Solaris “kstat” output to the network.

It’s embryonic, but it works. I’d like to do a little more input sanitation, since it’s certainly possible to really hurt your server by requesting a kstat value of “::” (which returns all stats).

Here’s the server code:


require 'soap/rpc/standaloneServer'

class StatServ < SOAP::RPC::StandaloneServer
        def initialize(*args)
          super
          add_method(self, 'kstat', 'stat')
        end
        def kstat(stat)
                stat.gsub!(/[^a-zA-z0-9_:+]/i,'%');
                f = IO.popen("kstat -p #{stat}")
                return f.readlines
        end
end

server = StatServ.new('StatServ,'urn:StatServ','0.0.0.0',8888)
trap('INT') { server.shutdown ; puts "Server shutdown."}
trap('TERM') { server.shutdown ; puts "Server shutdown."}
puts "Starting server..."
server.start

…and the client code:


require 'soap/rpc/driver'
def usage
        puts "Usage: #{$0} hostname kstatvalue"
        puts "   Retrieves a kstat value from a remote machine's StatServ SOAP Server."
end

hostname = ARGV[0]
value    = ARGV[1];


if ! value
        usage;
        exit 1;
end

driver = SOAP::RPC::Driver.new("http://#{hostname}:8888/", 'urn:StatServ')
driver.add_method('kstat', 'stat')

val = driver.kstat("#{value}")

val.each do |s|
puts "#{s}"
end
Front Page20 Jan 2009 04:03 pm
Front Page14 Jan 2009 04:08 pm
Front Page04 Jan 2009 11:59 pm
  • First day at work in a week. It’s like I just got back from a vacation. #
  • Need new year’s party! #
  • Where are the good parties in Portland this New Year? #
  • Sounds like Backspace/Ground Kontrol will be fun, as does Someday Lounge, and Saucebox has DJ Mr. Mumu and DJ The Perfect Syn. What else? #
  • The portland indoor smoking ban is now in effect! Wish it were before my clothes got saturated with smoke. #
  • Eating pho and watching Shogun. #
  • Another night of Pho and Shogun! My life rocks! #
  • Mmm.. Wiibrew. #

Powered by Twitter Tools.