Skip to content
Browse files

Basic working ping agent.

- Added usage and example to header
- Fixed ddl
- README.markdown for agent
  • Loading branch information...
1 parent afafddf commit c74e27a6d135e8fe01d41abb5728fb6f8856ff25 @deasmi deasmi committed with ripienaar
Showing with 156 additions and 0 deletions.
  1. +79 −0 agent/ping/README.markdown
  2. +31 −0 agent/ping/ping.ddl
  3. +46 −0 agent/ping/ping.rb
View
79 agent/ping/README.markdown
@@ -0,0 +1,79 @@
+# MCollective Ping Agent
+
+This is a simple agent that will execute a ping remotely on mcollective hosts
+
+I often find myself logging onto boxed to ping different sites to diagnose local or remote network issues, this means I can now just issue a single command and get results from anywhere I'm running mcollective.
+
+## Usage
+
+`mc-rpc ping ping fqdn="hostname"`
+
+## Requirements
+
+1. Ruby Gem net-ping (http://raa.ruby-lang.org/project/net-ping/)
+2. mcollective running as root as uses ICMP pings, see gem for details
+
+## Example
+
+<code>
+[root@host1 agent]$mc-rpc ping ping fqdn=google.com
+ Determining the amount of hosts matching filter for 2 seconds .... 9
+
+ * [ ============================================================> ] 9 / 9
+
+
+ host1.example.com
+ Time: Fri Oct 01 14:06:19 +0100 2010
+ RTT: 1.827
+ FQDN: google.com
+
+ host2.example.com
+ Time: Fri Oct 01 15:06:19 +0200 2010
+ RTT: 6.679
+ FQDN: google.com
+
+ host3.london.example.com
+ Time: Fri Oct 01 14:06:19 +0100 2010
+ RTT: 9.417
+ FQDN: google.com
+
+ host4.london.example.com
+ Time: Fri Oct 01 14:06:19 +0100 2010
+ RTT: 10.202
+ FQDN: google.com
+
+ host5.london.example.com
+ Time: Fri Oct 01 14:06:19 +0100 2010
+ RTT: 10.199
+ FQDN: google.com
+
+ host6.anotherdomain.co.uk
+ Time: Fri Oct 01 14:06:48 +0100 2010
+ RTT: 4.084
+ FQDN: google.com
+
+ host7
+ Time: Fri Oct 01 14:06:19 +0100 2010
+ RTT: 15.072
+ FQDN: google.com
+
+ host8.london.example.com
+ Time: Fri Oct 01 14:06:19 +0100 2010
+ RTT: 10.251
+ FQDN: google.com
+
+ host9.london.example.com
+ Time: Fri Oct 01 14:06:19 +0100 2010
+ RTT: 10.87
+ FQDN: google.com
+
+
+ Finished processing 9 / 9 hosts in 179.58 ms
+</code>
+
+## TODO
+
+Make a more general remote check agent to support
+
+1. HTTP status
+2. Arbitrary port connect
View
31 agent/ping/ping.ddl
@@ -0,0 +1,31 @@
+metadata :name => "Ping",
+ :description => "Agent to ping from a location",
+ :author => "Dean Smith <dean@zelotus.com>",
+ :license => "GPL2",
+ :version => "1.0",
+ :url => "http://github.com/deasmi/mcollective-plugins",
+ :timeout => 60
+
+action "ping", :description => "Returns rrt of ping to host" do
+ display :always
+
+ input :fqdn,
+ :prompt => "FQDN",
+ :description => "The fully qualified domain name to ping",
+ :type => :string,
+ :validation => '^.+$',
+ :optional => false,
+ :maxlength => 80
+
+ output :rtt,
+ :description => "The round trip time in ms",
+ :display_as=>"RTT"
+
+ output :fqdn,
+ :description=>"The hosts fqdn",
+ :display_as=>"FQDN"
+
+ output :time,
+ :description => "The time the ping was received",
+ :display_as => "Time"
+end
View
46 agent/ping/ping.rb
@@ -0,0 +1,46 @@
+# Simple agent to ping locations from mcollective hosts
+# Useful if you have a network of servers around the world and want
+# to test connectivity to ensure faults aren't just local
+#
+# GPL v2 License
+#
+#
+# Usage: mc-rpc ping ping fqdn="<hostname>"
+# Example: mc-rpc ping ping fqdn="google.com"
+
+
+require 'rubygems'
+require 'net/ping'
+
+module MCollective
+ module Agent
+ class Ping<RPC::Agent
+
+
+ metadata :name => "Ping",
+ :description => "Agent to ping from a location",
+ :author => "Dean Smith",
+ :license => "BSD",
+ :version => "1.0",
+ :url => "http://github.com/deasmi",
+ :timeout => 60
+
+ action "ping" do
+ validate :fqdn,String
+
+ fqdn = request[:fqdn]
+
+ icmp = Net::Ping::ICMP.new(fqdn)
+
+ if icmp.ping? then
+ reply[:rtt] = (icmp.duration*1000).to_s
+ reply[:fqdn] = fqdn
+ reply[:time] = Time.now.to_s
+ else
+ reply.fail "Could not ping host "
+ end
+ end
+ end
+ end
+end
+

0 comments on commit c74e27a

Please sign in to comment.
Something went wrong with that request. Please try again.