#!/usr/bin/env perl ############################################################################### ## ## $Id: gridftp-simple-probe,v 1.11 2007/10/23 20:42:06 agopu Exp $ ## ## Copyright 2007, The Trustees of Indiana University. ## ## Open Science Grid Operations Team, Indiana University ## Original Author: Arvind Gopu (http://peart.ucs.indiana.edu) ## Last modified by Arvind Gopu (on date shown in above Id line) ## ## ## This Perl script tests if GridFTP transfers work to/from a remote host ## Transfers a test file to the remote host, and back; then compares the ## two files. ## Type ./gridftp-simple-probe -h for more information ## ## ## REQUIRES ## 'OSG_RSV_Probe_Base' ## ## ################################################################################ ######## Perl modules to use use strict; use Getopt::Long; use OSG_RSV_Probe_Base; ######## Global variables go here ################################ our %o; ## Global hash to store "our" details i.e script's details our %m_gridftp; ## Global hash to store metric's details ## Defaults needed even before Initialize_Probe() is called (for Usage info) ## Define this value from RCS version# Needs single quote!! &Set_Revision('$Revision: 1.11 $'); ## What version of the WLCG specification does this probe conform to? ## AG: This should probably be set centrally &Set_Probe_Spec_Version ("0.91"); ## Define Metric here for listing purposes; and some defaults &Set_Metric (); ## Basic intro for the probe; This string will be used by Print_Usage () &Set_Help_Intro ("Probe to check if GridFTP works to and from remote host. A test file (which\n can be specified using argument shown below) is gridftp'ed to remote host,\n and back. Then the files are checked for consistency."); &Set_Help_Options (" [--test-file ] Test file to be used for testing\n (Default: `pwd`/gridftp-probe-test-file)"); ########## Process Command Line Arguments ######################## GetOptions( "uri|u=s" => \$o{'serviceUri'}, "metric|m=s" => \$o{'metric'}, "virtual-organization|v=s" => \$o{'virtualorganization|v'}, "timeout|t=i" => \$o{'timeout'}, "list-metric|l" => \$o{'listmetric'}, "vdt-location=s" => \$o{'VDT_LOCATION_LOCAL'}, "print-local-time" => \$o{'printLocalTimezone'}, "external-gridftpdoor" => \$o{'external-gridftpdoor'}, "test-file=s" => \$o{'globusurlcopyTestfile'}, "proxy|x=s" => \$o{'proxyFile'}, "warning|w=i" => \$o{'proxyExpiryWarningHours'}, "critical|c=i" => \$o{'proxyExpiryMinimumHours'}, "generate-gratia-script|ggs"=> \$o{'generateGratiaScript'}, "gratia-script-loc|gsl=s" => \$o{'gratiaLocationDir'}, "gratia-config-file|gmpcf=s"=> \$o{'gratiaMetricProbeConfigFile'}, "python-loc=s" => \$o{'pythonToUse'}, "version" => \$o{'version'}, "help|h" => \$o{'help'}, "verbose" => \$o{'verbose'} ) or &OSG_RSV_Probe_Base::Print_Usage(\%o,\%m_gridftp) && exit 1; ## Initialize our (probe's) hash with commands, etc. %o = %{&OSG_RSV_Probe_Base::Initialize_Probe (\%o)}; ## Process serviceURI for hostName, etc.; copy stuff from %o to metric hash %m_gridftp = %{&OSG_RSV_Probe_Base::Initialize_Metric(\%o, \%m_gridftp)}; ## Process some simple options, and exit if they're specified after acting ## i.e. --help or -l type arguments &OSG_RSV_Probe_Base::Process_Informational_Arguments (\%o, \%m_gridftp); ## Real tests begin now ## Ping host that we're testing; if it fails then we're done for now my $ping_cmd_exit_value=${&OSG_RSV_Probe_Base::Ping_Host (\%o,\%m_gridftp)}; if (($ping_cmd_exit_value != 0) && ($ping_cmd_exit_value != 1)) { ## Set metric status based on ping command's exit value %m_gridftp = %{&OSG_RSV_Probe_Base::Set_Ping_Metric_Results (\$ping_cmd_exit_value, \%m_gridftp)}; &OSG_RSV_Probe_Base::Print_Summary_Metric_Results (\%o,\%m_gridftp); exit (&OSG_RSV_Probe_Base::Get_Probe_Exit_Value(\%o,\%m_gridftp)); } if (defined($o{'external-gridftpdoor'})) { %m_gridftp = %{&OSG_RSV_Probe_Base::Set_Summary_Metric_Results ( \%o,\%m_gridftp, 3 , "URI ". $o{'serviceUri'} ." hosts gridftp on a separate " . "resource. Bailing now... ")}; &OSG_RSV_Probe_Base::Print_Summary_Metric_Results (\%o,\%m_gridftp); exit (&OSG_RSV_Probe_Base::Get_Probe_Exit_Value(\%o,\%m_gridftp)); } ## Is proxy valid; 'checkProxyValidityReturnValue' 0 good; 1 warning; 2 expired %m_gridftp = %{&OSG_RSV_Probe_Base::Check_Proxy_Validity (\%o,\%m_gridftp)}; if ($m_gridftp{'checkProxyValidityReturnValue'} == 2) { &OSG_RSV_Probe_Base::Print_Summary_Metric_Results (\%o,\%m_gridftp); exit (&OSG_RSV_Probe_Base::Get_Probe_Exit_Value(\%o,\%m_gridftp)); } ## If we've come this far ... Check if we can authenticate to host using proxy %m_gridftp = %{&OSG_RSV_Probe_Base::Check_Gram_Authentication (\%o,\%m_gridftp)}; ## If we can authenticate, then some gridftp action now ... if ($m_gridftp{'globusrunCmdExitValue'} == 0) { ## Transfer file to remote host; then back %m_gridftp = %{&OSG_RSV_Probe_Base::Do_Gridftp_File_Transfer_To (\%o,\%m_gridftp)}; %m_gridftp = %{&OSG_RSV_Probe_Base::Do_Gridftp_File_Transfer_From (\%o,\%m_gridftp)}; ## Compare remote file and the one copied back; set metric accordingly %m_gridftp = %{&OSG_RSV_Probe_Base::Diff_Files (\%o,\%m_gridftp)}; ## AG? Should I clean up those /tmp files?? } ## Append warning about expiring proxy if need be %m_gridftp = %{&OSG_RSV_Probe_Base::Append_Proxy_Validity_Warning (\%m_gridftp)}; ## Print metric, and we're all done! &OSG_RSV_Probe_Base::Print_Summary_Metric_Results (\%o,\%m_gridftp); exit (&OSG_RSV_Probe_Base::Get_Probe_Exit_Value(\%o,\%m_gridftp)); ## Main Program ends ## ################################################################################ ## None for now sub Set_Help_Intro { $o{'helpIntro'} = $_[0]; } sub Set_Help_Options { $o{'helpOptions'} = $_[0]; } sub Set_Metric { $m_gridftp{'metricType'} = "status"; $m_gridftp{'metricName'} = "org.osg.globus.gridftp-simple"; $m_gridftp{'serviceType'} = "globus-GSIFTP"; $m_gridftp{'serviceVersion'} = ">= OSG CE 0.6.0"; ## AG: Not sure ... } sub Set_Revision { $o{'revision'} = $_[0]; } sub Set_Probe_Spec_Version { $o{'probeSpecificationVersion'} = $_[0]; }