New ppkssh.ksh
  1 #!/usr/bin/ksh
  2 #
  3 # CDDL HEADER START
  4 #
  5 # The contents of this file are subject to the terms of the
  6 # Common Development and Distribution License (the License).
  7 # You may not use this file except in compliance with the License.
  8 #
  9 # You can obtain a copy of the license at usr/src/CDDL.txt
 10 # or http://www.opensolaris.org/os/licensing.
 11 # See the License for the specific language governing permissions
 12 # and limitations under the License.
 13 #
 14 # When distributing Covered Code, include this CDDL HEADER in each
 15 # file and include the License file at usr/src/CDDL.txt.
 16 # If applicable, add the following below this CDDL HEADER, with the
 17 # fields enclosed by brackets [] replaced with your own identifying
 18 # information: Portions Copyright [yyyy] [name of copyright owner]
 19 #
 20 # CDDL HEADER END
 21 #
 22 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 23 # Use is subject to license terms.
 24 #
 25 #ident   "@(#)ppkssh.ksh 1.1     08/11/19 SMI"
 26 #
 27 
 28 typeset opt
 29 
 30 while getopts 'P:' opt
 31 do
 32   case "${opt}" in
 33         P)      PARMS=${OPTARG};;
 34         *)      exit 1;;
 35    esac
 36 done
 37 
 38 shift $((${OPTIND} -1))
 39 
 40 TIMEOUT=$1
 41 
 42 echo ${PARMS} | /usr/bin/awk -F: '{print $1" "$2" "$3" "$4" "$5}' | read USER IDFILE HOST SERVICE STATE
 43 
 44 SERVICE=$(echo ${SERVICE} | /usr/xpg4/bin/tr -s '[:upper:]' '[:lower:]')
 45 
 46 # This probe can be viewed as a plugin probe to the agent probe. As such the agent probe performs
 47 # very basic domain checks whereas this plugin probe provides more user specific checks. Currently,
 48 # we only provide private/public key ssh authentication to the guest domain to check either a specific 
 49 # runlevel or SMF service. 
 50 # 
 51 # This plugin probe is passed the following colon separated parameter. 
 52 #
 53 # -P USER:IDFILE:HOST:SERVICE:STATE
 54 #
 55 # USER - User name of user for the prublic key ssh authentication.
 56 # IDFILE - The ssh identity file to read the private key.
 57 # HOST - The guest domain's hostname.
 58 # SERVICE - Either "runlvel" or SMF service.
 59 # STATE - The desired runlevel or online for the SMF service.
 60 #
 61 # For example, 
 62 #
 63 # /opt/SUNWscxvm/bin/ppkssh -P fmuser:/export/fmuser/.ssh/id_dsa:vzodio1a:multi-user-server:online
 64 # /opt/SUNWscxvm/bin/ppkssh -P fmuser:/export/fmuser/.ssh/id_dsa:vzodio2a:runlvel:3
 65 #
 66 # Note that the agent probe passes us a parameter which represents 90% of PROBE_TIMEOUT. As such 
 67 # this plugin probe must complete within that value.
 68 #
 69 # The agent probe will output whatever is output from this plugin probe, e.g.
 70 #
 71 # vzodio1a multi-user-server is online
 72 # vaodio2a runlevel is 3
 73 # 
 74 # The agent probe expects this plugin probe to exit with one of the following return codes.
 75 #
 76 #   0 - Indicates a successful probe.
 77 # 100 - Indicates a complete failure, the agent probe will then attempt to restart the domain.
 78 # 201 - Indicates a complete failure but requests an immeidate failover.
 79 #
 80 # Note that return code 201 requires that the resource has an appropriate value for extension
 81 # properties FAILOVER_MODE and FAILOVER_ENABLED=TRUE. For FAILOVER_MODE refer to the
 82 # r_properties(5) man page.
 83 
 84 if [ "${SERVICE}" = "runlevel" ]
 85 then
 86    output=$(/usr/cluster/bin/hatimerun -t ${TIMEOUT} /usr/bin/ssh -l ${USER} -i ${IDFILE} ${HOST} \
 87         "/sbin/runlevel | /usr/bin/awk '{print \$2}'" 2> /dev/null)
 88 else
 89    output=$(/usr/cluster/bin/hatimerun -t ${TIMEOUT} /usr/bin/ssh -l ${USER} -i ${IDFILE} ${HOST} \
 90         "/usr/bin/svcs -H -o STATE ${SERVICE}" 2> /dev/null)
 91 fi
 92 
 93 rc=$?
 94 
 95 [ "${rc}" -eq 99 ] && exit 99
 96 
 97 if [ "${rc}" -eq 0 ] && [ "${output}" = "${STATE}" ]
 98 then
 99         rc=0
100 else
101         rc=100
102 fi
103 
104 printf "${HOST} ${SERVICE} is ${output}\n"
105 
106 exit ${rc}