From 4288175ad1024f82cd3347c1fdb48103d44d3d3f Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 19 Aug 2010 18:58:00 +0200 Subject: [PATCH] modified IM ssh mad according to new MONITOR protocol --- install.sh | 54 +++--- share/etc/oned.conf | 4 +- .../scripts/im/common.d}/architecture.sh | 0 .../scripts/im/common.d}/cpu.sh | 0 .../scripts/im/common.d}/name.sh | 0 .../kvm => share/scripts/im/kvm.d}/kvm.rb | 0 share/scripts/im/run_probes | 28 ++++ .../xen => share/scripts/im/xen.d}/xen.rb | 0 src/im_mad/im_ssh/one_im_ssh.rb | 154 +++--------------- src/im_mad/kvm/im_kvm.conf | 8 - src/im_mad/xen/im_xen.conf | 8 - 11 files changed, 84 insertions(+), 172 deletions(-) rename {src/im_mad/host_probes => share/scripts/im/common.d}/architecture.sh (100%) rename {src/im_mad/host_probes => share/scripts/im/common.d}/cpu.sh (100%) rename {src/im_mad/host_probes => share/scripts/im/common.d}/name.sh (100%) rename {src/im_mad/kvm => share/scripts/im/kvm.d}/kvm.rb (100%) create mode 100755 share/scripts/im/run_probes rename {src/im_mad/xen => share/scripts/im/xen.d}/xen.rb (100%) delete mode 100644 src/im_mad/kvm/im_kvm.conf delete mode 100644 src/im_mad/xen/im_xen.conf diff --git a/install.sh b/install.sh index d142411efa..d3ef2793a6 100755 --- a/install.sh +++ b/install.sh @@ -164,7 +164,11 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \ $ETC_LOCATION/ec2query_templates \ $ETC_LOCATION/occi_templates" -LIB_DIRS="$LIB_LOCATION/im_probes \ +LIB_DIRS="$LIB_LOCATION/remotes \ + $LIB_LOCATION/remotes/im \ + $LIB_LOCATION/remotes/im/common.d \ + $LIB_LOCATION/remotes/im/kvm.d \ + $LIB_LOCATION/remotes/im/xen.d \ $LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/OpenNebula \ $LIB_LOCATION/ruby/cloud/ \ @@ -207,20 +211,23 @@ INSTALL_FILES[2]="LIB_FILES:$LIB_LOCATION" INSTALL_FILES[3]="RUBY_LIB_FILES:$LIB_LOCATION/ruby" INSTALL_FILES[4]="RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula" INSTALL_FILES[5]="MADS_LIB_FILES:$LIB_LOCATION/mads" -INSTALL_FILES[6]="IM_PROBES_LIB_FILES:$LIB_LOCATION/im_probes" -INSTALL_FILES[7]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs" -INSTALL_FILES[8]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh" -INSTALL_FILES[9]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy" -INSTALL_FILES[10]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm" -INSTALL_FILES[11]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples" -INSTALL_FILES[12]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm" -INSTALL_FILES[13]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks" -INSTALL_FILES[14]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud" -INSTALL_FILES[15]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe" -INSTALL_FILES[16]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views" -INSTALL_FILES[17]="ECO_BIN_FILES:$BIN_LOCATION" -INSTALL_FILES[18]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi" -INSTALL_FILES[19]="OCCI_BIN_FILES:$BIN_LOCATION" +INSTALL_FILES[6]="IM_PROBES_FILES:$LIB_LOCATION/remotes/im" +INSTALL_FILES[7]="IM_PROBES_COMMON_FILES:$LIB_LOCATION/remotes/im/common.d" +INSTALL_FILES[8]="IM_PROBES_KVM_FILES:$LIB_LOCATION/remotes/im/kvm.d" +INSTALL_FILES[9]="IM_PROBES_XEN_FILES:$LIB_LOCATION/remotes/im/xen.d" +INSTALL_FILES[10]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs" +INSTALL_FILES[11]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh" +INSTALL_FILES[12]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy" +INSTALL_FILES[13]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm" +INSTALL_FILES[14]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples" +INSTALL_FILES[15]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm" +INSTALL_FILES[16]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks" +INSTALL_FILES[17]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud" +INSTALL_FILES[18]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe" +INSTALL_FILES[19]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views" +INSTALL_FILES[20]="ECO_BIN_FILES:$BIN_LOCATION" +INSTALL_FILES[21]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi" +INSTALL_FILES[22]="OCCI_BIN_FILES:$BIN_LOCATION" INSTALL_ECO_CLIENT_FILES[0]="COMMON_CLOUD_CLIENT_LIB_FILES:$LIB_LOCATION/ruby/cloud" INSTALL_ECO_CLIENT_FILES[1]="ECO_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/econe" @@ -338,14 +345,19 @@ MADS_LIB_FILES="src/mad/sh/madcommon.sh \ src/authm_mad/one_auth_mad" #------------------------------------------------------------------------------- -# Information Manager Probes, to be installed under $LIB_LOCATION/im_probes +# Information Manager Probes, to be installed under $LIB_LOCATION/remotes #------------------------------------------------------------------------------- -IM_PROBES_LIB_FILES="src/im_mad/xen/xen.rb \ - src/im_mad/kvm/kvm.rb \ - src/im_mad/host_probes/architecture.sh \ - src/im_mad/host_probes/cpu.sh \ - src/im_mad/host_probes/name.sh" +IM_PROBES_FILES="share/scripts/im/run_probes" + +IM_PROBES_COMMON_FILES="share/scripts/im/common.d/architecture.sh \ + share/scripts/im/common.d/cpu.sh \ + share/scripts/im/common.d/name.sh" + +IM_PROBES_XEN_FILES="share/scripts/im/xen.d/xen.rb" + +IM_PROBES_KVM_FILES="share/scripts/im/kvm.d/kvm.rb" + #------------------------------------------------------------------------------- # Transfer Manager commands, to be installed under $LIB_LOCATION/tm_commands diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 5332b1c271..8842859b99 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -106,7 +106,7 @@ DEFAULT_DEVICE_PREFIX = "hd" #IM_MAD = [ # name = "im_xen", # executable = "one_im_ssh", -# arguments = "im_xen/im_xen.conf" ] +# arguments = "xen" ] #------------------------------------------------------------------------------- # KVM Information Driver Manager sample configuration @@ -114,7 +114,7 @@ DEFAULT_DEVICE_PREFIX = "hd" IM_MAD = [ name = "im_kvm", executable = "one_im_ssh", - arguments = "im_kvm/im_kvm.conf" ] + arguments = "kvm" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- diff --git a/src/im_mad/host_probes/architecture.sh b/share/scripts/im/common.d/architecture.sh similarity index 100% rename from src/im_mad/host_probes/architecture.sh rename to share/scripts/im/common.d/architecture.sh diff --git a/src/im_mad/host_probes/cpu.sh b/share/scripts/im/common.d/cpu.sh similarity index 100% rename from src/im_mad/host_probes/cpu.sh rename to share/scripts/im/common.d/cpu.sh diff --git a/src/im_mad/host_probes/name.sh b/share/scripts/im/common.d/name.sh similarity index 100% rename from src/im_mad/host_probes/name.sh rename to share/scripts/im/common.d/name.sh diff --git a/src/im_mad/kvm/kvm.rb b/share/scripts/im/kvm.d/kvm.rb similarity index 100% rename from src/im_mad/kvm/kvm.rb rename to share/scripts/im/kvm.d/kvm.rb diff --git a/share/scripts/im/run_probes b/share/scripts/im/run_probes new file mode 100755 index 0000000000..a24bee086c --- /dev/null +++ b/share/scripts/im/run_probes @@ -0,0 +1,28 @@ +#!/bin/bash + +HYPERVISOR_DIR=$1.d + +SCRIPTS_DIR=`dirname $0` +cd $SCRIPTS_DIR + + +function run_dir { + ( + DIR=$1 + cd $DIR + for i in `ls *`;do + if [ -x "$i" ]; then + ./$i + fi + done + ) +} + +data=$( + run_dir 'common.d' + if [ -d "$HYPERVISOR_DIR" ]; then + run_dir $HYPERVISOR_DIR + fi +) + +echo $data | tr '\n' ' ' diff --git a/src/im_mad/xen/xen.rb b/share/scripts/im/xen.d/xen.rb similarity index 100% rename from src/im_mad/xen/xen.rb rename to share/scripts/im/xen.d/xen.rb diff --git a/src/im_mad/im_ssh/one_im_ssh.rb b/src/im_mad/im_ssh/one_im_ssh.rb index 70340e11a1..408fe9120b 100755 --- a/src/im_mad/im_ssh/one_im_ssh.rb +++ b/src/im_mad/im_ssh/one_im_ssh.rb @@ -22,127 +22,19 @@ if !ONE_LOCATION RUBY_LIB_LOCATION="/usr/lib/one/ruby" ETC_LOCATION="/etc/one/" PROBE_LOCATION="/usr/lib/one/im_probes/" + REMOTES_LOCATION="/usr/lib/one/remotes" else RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" ETC_LOCATION=ONE_LOCATION+"/etc/" PROBE_LOCATION=ONE_LOCATION+"/lib/im_probes/" + REMOTES_LOCATION=ONE_LOCATION+"/lib/remotes/" end $: << RUBY_LIB_LOCATION - -require 'pp' -require 'digest/md5' -require 'fileutils' require 'OpenNebulaDriver' require 'CommandManager' -#------------------------------------------------------------------------------- -# This class holds the information of a IM probe and the methods to copy the -# script to the remote hosts and run it -#------------------------------------------------------------------------------- -class Sensor - - #--------------------------------------------------------------------------- - # Class constructor init the remote script name and working directory - #--------------------------------------------------------------------------- - def initialize(name, script, remote_dir) - id = Digest::MD5.hexdigest("#{name}#{script}") - - @script = script - @remote_script = "#{remote_dir}/one_im-#{id}" - @remote_dir = remote_dir - end - - #--------------------------------------------------------------------------- - # Sends the monitor probe script to the remote host and execute it - #--------------------------------------------------------------------------- - def execute(host, log_proc) - script_text = File.read @script - - src = "'mkdir -p #{@remote_dir}; cat > #{@remote_script};" \ - " if [ \"x$?\" != \"x0\" ]; then exit -1; fi;" \ - " chmod +x #{@remote_script}; #{@remote_script}'" - - cmd = SSHCommand.run(src, host, log_proc, script_text) - - case cmd.code - when 0 - # Splits the output by lines, strips each line and gets only - # lines that have something - value = cmd.stdout.split("\n").collect {|v| - v2 = v.strip - if v2 == "" - nil - else - v2 - end - }.compact.join(",") - else - nil - end - end -end - - -#------------------------------------------------------------------------------- -# This class is an array of sensor probes to be executed by the information -# driver. The class is built on top of the Sensor class -#------------------------------------------------------------------------------- -class SensorList < Array - #--------------------------------------------------------------------------- - # Initialize the class - #--------------------------------------------------------------------------- - def initialize(config_file, remote_dir) - super(0) - - @remote_dir = remote_dir - - load_sensors(config_file) - end - - #--------------------------------------------------------------------------- - # Execute all sensors in the list in the given host - #--------------------------------------------------------------------------- - def execute_sensors(host, log_proc) - results = Array.new - - self.each {|sensor| - results << sensor.execute(host, log_proc) - } - results - end - -private - #--------------------------------------------------------------------------- - # Load sensors from a configuration file - #--------------------------------------------------------------------------- - def load_sensors(file) - f = open(file, "r") - - f.each_line {|line| - l = line.strip.gsub(/#.*$/, "") - - case l - when "" - when /^[^=]+=[^=]+$/ - (name, script)=l.split("=") - - name.strip! - script.strip! - - script = "#{PROBE_LOCATION}#{script}" if script[0] != ?/ - - self << Sensor.new(name, script, @remote_dir) - else - STDERR.puts "Malformed line in configuration file: #{line}" - end - } - - f.close - end -end - #------------------------------------------------------------------------------- # The SSH Information Manager Driver #------------------------------------------------------------------------------- @@ -151,26 +43,33 @@ class InformationManager < OpenNebulaDriver #--------------------------------------------------------------------------- # Init the driver #--------------------------------------------------------------------------- - def initialize(config_file, remote_dir, num) + def initialize(remote_dir, hypervisor, num) super(num, true) - @sensor_list=SensorList.new(config_file, remote_dir) + @hypervisor = hypervisor + @remote_dir = remote_dir # register actions register_action(:MONITOR, method("action_monitor")) end #--------------------------------------------------------------------------- - # Execute the sensor array in the remote host + # Execute the run_probes in the remote host #--------------------------------------------------------------------------- - def action_monitor(number, host) + def action_monitor(number, host, do_update) + STDERR.puts Time.now.to_s + ": do_update=" +do_update.inspect + if do_update == "1" + STDERR.puts Time.now.to_s + ": Doing rsync" + sync_cmd = "rsync -Laz #{REMOTES_LOCATION} #{host}:#{@remote_dir}" + LocalCommand.run(sync_cmd) + else + end - results = @sensor_list.execute_sensors(host, log_method(number)) + cmd = SSHCommand.run("#{@remote_dir}/im/run_probes #{@hypervisor}", + host) - information=results.select{|res| res && !res.empty? }.join(",") - - if information and !information.empty? - send_message("MONITOR", RESULT[:success], number, information) + if cmd.code == 0 + send_message("MONITOR", RESULT[:success], number, cmd.stdout) else send_message("MONITOR", RESULT[:failure], number, "Could not monitor host #{host}.") @@ -184,22 +83,11 @@ end # Information Manager main program #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- -im_conf = ARGV.last - -if !im_conf || File.exists?(im_conf) - puts "You need to specify config file." - exit(-1) -end - -im_conf = "#{ETC_LOCATION}#{im_conf}" if im_conf[0] != ?/ - -if !File.exists?(im_conf) - puts "Configuration file #{im_conf} does not exists." - exit(-1) -end remote_dir = ENV["IM_REMOTE_DIR"] remote_dir = "/tmp/one-im" if !remote_dir -im = InformationManager.new(im_conf, "#{remote_dir}/", 15) +hypervisor = ARGV[0]||'' + +im = InformationManager.new(remote_dir, hypervisor, 15) im.start_driver diff --git a/src/im_mad/kvm/im_kvm.conf b/src/im_mad/kvm/im_kvm.conf deleted file mode 100644 index a891f402c6..0000000000 --- a/src/im_mad/kvm/im_kvm.conf +++ /dev/null @@ -1,8 +0,0 @@ -#------------------------------------------------------------------------------- -# Probes for KVM hosts add as many monitorization sensors as you need -#------------------------------------------------------------------------------- - -cpuarchitecture=architecture.sh -nodename=name.sh -cpu=cpu.sh -kvm=kvm.rb diff --git a/src/im_mad/xen/im_xen.conf b/src/im_mad/xen/im_xen.conf deleted file mode 100644 index b86c8630a8..0000000000 --- a/src/im_mad/xen/im_xen.conf +++ /dev/null @@ -1,8 +0,0 @@ -#------------------------------------------------------------------------------- -# Probes for Xen hosts add as many monitorization sensors as you need -#------------------------------------------------------------------------------- - -cpuarchitecture=architecture.sh -nodename=name.sh -cpu=cpu.sh -xen=xen.rb