#!/usr/bin/env perl # Usage: ping-glusterd # # Sends one ping only to the GlusterFS server on the given host at the given # port. # # Copyright (C) Geoff Kassel, 2007. Released under the LGPL. use strict; use IO::Socket; my ($host, $port, $line); $host = "localhost"; $port = "6996"; if (@ARGV == 1) { ($host) = @ARGV; } if (@ARGV == 2) { ($host, $port) = @ARGV; } if (@ARGV > 2) { die "Usage: $0 "; } # Try to open a connection to the server. my $sock = new IO::Socket::INET ( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', ); die "Could not connect to GlusterFS server $host:$port: $!\n" unless $sock; # Set synchronous communication. $sock->autoflush(1); # Ping packet to send: print $sock "Block Start\n"; # Start of protocol print $sock "0000000000000042\n"; # Stream ID - 42 will do. print $sock "00000001\n"; # GF_OP_TYPE_MOP_REQUEST - management request. print $sock "00000002\n"; # GF_MOP_STATS - get server stats. print $sock "--------------------------------\n"; # Description of packet purpose. print $sock "00000000000000000000000000000022\n"; # Message contents size of 35 - 1 = 22 in hex. # Start of message contents - serialized dictionary type. print $sock "00000001\n"; # Number of keys in message dictionary. (len: 9) print $sock "00000006:00000002\n"; # Key length (incl. null) ':' value length (incl. null.) (len: 18) print $sock "FLAGS\00\0"; # Dummy dictionary entry required for message. (len: 8) # End of message contents. print $sock "Block End\n"; # End of protocol # Read in the response from the server. while (defined ($line = <$sock>)) { #print STDOUT $line; # Have we now read a full response message? if ($line =~ /Block End/) { close($sock); print "Received response from server.\n"; exit; } } close($sock); die "No response from server!\n";