# MCilme.ctl:294: Collects Integrated Lights Out Manager (ILOM) Information # $Id: MCilme.ctl,v 1.8 2015/08/21 15:40:48 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/collect/EXPLORER/MCilme.ctl,v 1.8 2015/08/21 15:40:48 RDA Exp $ # # Change History # 20150821 MSC Improve time consistency. =head1 NAME EXPLORER:MCilme - Collects Integrated Lights Out Manager (ILOM) Snapshot Information =head1 DESCRIPTION This module collects Integrated Lights Out Manager (ILOM) snapshot information. The following reports can be generated and are regrouped under C: =cut use Buffer use Mrc use Remote # Initialization var $VALIDATE = true keep $VALIDATE section begin var $ERR = '---## Associated Errors' var $GRP = 'explorer:ilomsnp' var $TOC = '%TOC%' var $TOP = '[[#Top][Back to top]]' var $WRN = ' * Links point to files that have been collected in their \ original format. Opening them directly in your browser can \ present risks. To prevent them, access the file outside the \ browser or use the link to save them and use an adequate \ viewer.' run EXPLORER:XPLRlib('ilomsnapshot_finish') # Get commands syntax var $PING = check(${RDA.T_OS},\ 'solaris',concat(${CMD.PING:'ping'},' %s'),\ 'linux', concat(${CMD.PING:'ping'},' -c 1 %s'),\ 'cygwin', concat(${CMD.PING:'ping'},' %s 64 1')) var $SU = concat(${CMD.SU:'su'},' - "%s"') #------------------------------------------------------------------------------ # XPLR_ilomsnp_finish section #------------------------------------------------------------------------------ section XPLR_ilomsnp_finish # Validate the execution context if !${B_GLOBAL:true} return call log_run('Processing ILME sections ...') pretoc '2:Integrated Lights Out Manager (ILOM) Snapshot Finish' # Define a macro to obtain snapshot result response as a single line macro get_result {var ($buf) = @arg if $buf->grep('collecting data into\s*(.*)','if1') {var ($res) = last while {if match($res,'\/([\w\.\-]+\.zip(\.e)?)$',true) return first(last) break !?$buf->get_line var $res = concat($res,trim(chomp(last))) } } return undef } =head2 Integrated Lights Out Manager (ILOM) Snapshot Commands This module gathers the following Integrated Lights Out Manager (ILOM) command through SSH (requires a working Java environment): =over 2 =item o C =back =cut # Treat all requests loop $set (@{MOD.ILMB.N_SET}) {var ($a_u,$cln,$dir,$nod,$v_h,$v_u,%dsc) = \ (${MOD.ILMB.T_USER_${VAR.set}},\ ${RUN.EXPLORER.XPLR.ILME.T_CLN_${VAR.set}},\ ${RUN.EXPLORER.XPLR.ILME.T_DIR_${VAR.set}},\ ${MOD.ILMB.T_HOST_${VAR.set}},\ ${RUN.EXPLORER.XPLR.ILME.T_HOST_${VAR.set}},\ ${RUN.EXPLORER.XPLR.ILME.T_USER_${VAR.set}},\ CMD_CAT => ${RUN.EXPLORER.XPLR.ILME.T_CAT_${VAR.set}},\ CMD_FIND => ${RUN.EXPLORER.XPLR.ILME.T_FIND_${VAR.set}},\ CMD_RM => ${RUN.EXPLORER.XPLR.ILME.T_RM_${VAR.set}}) next !and(defined($nod),defined($v_h),exists($dsc{'CMD_CAT'})) # Connect to the service controller if !?$v_h next log_info('Missing ILOM host name') if !?$v_u next log_info('Missing ILOM user name') if !?$i_h = isHost($v_h,true) next log_info(concat('Bad ILOM host name or IP "',$v_h,'".')) if !?$i_u = isUser($v_u,true) next log_info(concat('Bad ILOM user name "',$v_u,'".')) debug ' Inside ILME collection, validating ',$i_h,' access' call command(sprintf($PING,$i_h)) if status() next log_info(concat('Host ',$i_h,' is not reachable.')) debug ' Inside ILME collection, gathering ',$i_h,' information (can take time)' call log_critical(concat('Collecting snapshot from ',$i_h,' (can take time)')) var $i_s = addRemoteSession('ILME',$i_h,$i_u) if and($i_s->set_type('da'),$i_s->set_type('jsch')) next log_error(concat('Unable to check snapshot status at ',$i_h)) # Login to the service controller if !$i_s->open next log_warning($i_s->get_message) if !?$i_s->login($i_u,{dis=>'exit',\ pat=>'m/>[\x20]?$/'}) next log_warning($i_s->get_message) var $buf = new('Buffer','L') call $buf->set_handle('eol',false) # Wait until snapshot has completed or timeout reached var ($cmd,$lim,$max) = ('show /X/diag/snapshot result',1200,0) while expr('>',$lim,0) {# Check snapshot execution status call $buf->write(concat('-> ',$cmd)) var $pos = $buf->get_pos call $i_s->collect($buf,{\ cln=>true,\ cmd=>$cmd,\ pat=>'m/->[\x20]?$/',\ skp=>true}) call $buf->set_pos($pos) break !$buf->grep('^\s*result\s+=\s+Running','r') sleep 15 decr $lim,15 } # Close the connection call $i_s->close # Genererate the collected command report pretoc '3:',$i_h,' Information' report concat('ilomsnp_e_',$i_h,'_cmd') title '---+!! Integrated Lights Out Manager (ILOM) Snapshot' title '---## ',$i_h,' Commands' title $TOC call do_exec(\ {cmd => 'BUFFER',\ buf => $buf,\ det => $cmd,\ nam => join('/','ilom',$i_h,'ilomsnapshot_finish.out'),\ ttl => '---++ Snapshot Execution Output'}) if isCreated(true) toc '4:[[',getFile(),'][rda_report][Snapshot Execution]]' =head2 Integrated Lights Out Manager (ILOM) Snapshot Files Produces an overview report of the collected snapshot files. =cut debug ' Inside ILME collection, verifying snapshot completion at ',$i_h if !$buf->grep('^\s*snapshot complete','fi') call log_error(concat('Snapshot not received from ',$i_h)) elsif !?get_result($buf) call log_error(concat('Snapshot not received from ',$i_h)) else {var $snp = last var $dir = replace($dir,'\%20',' ',true) # Connect to the archive host var ($a_f,$a_s) = (false) if !?$usr = isUser($a_u,true) next log_info(concat('Bad archive user name "',$a_u,'".')) if compare('eq',$nod,'-') var $hst = ${RDA.T_HOST} else {debug ' Inside ILME collection, validating ',$nod,' access' if !?$hst = isHost($nod,true) next log_info(concat('Bad archive host name or IP "',$nod,'".')) call command(sprintf($PING,$hst)) if status() next log_info(concat('Host ',$hst,' is not reachable.')) var $a_s = addRemoteSession('ARC',$hst,$usr) if and($a_s->set_type('da'),$a_s->set_type('jsch')) {if $a_s->set_type('ssh') next log_info(concat('Cannot create a session to host ',$hst)) var $a_f = true } # Make sure SSH agent is running if !$a_s->has_agent call $a_s->set_agent # Ask for the password when necessary if and($a_s->need_password,\ not(hasPassword('host',$hst,$usr))) call setPassword('host',$hst,$usr,askPassword(concat('Enter ',$usr,\ ' password for Archive host ',$hst,': '),'')) } # Create temporary file to be used to store outputs var $res = getTemp(concat('TMP',$hst)) debug ' Inside ILME collection, obtaining snapshot file from ',$hst if !?$a_s {output | concat(sprintf($SU,$usr),' >',quote($res)) write 'CMD_CAT="',$dsc{'CMD_CAT'},'"' write "cd \042",$dir,"\042 && \042$\173CMD_CAT\175\042 \042",$snp,"\042" close } else call $a_s->get($dir,$snp,dirname($res),basename($res)) if getSize($res) {# Generate the collected snapshot file report report concat('ilomsnp_e_',$i_h,'_fil') prefix {write '---+!! Integrated Lights Out Manager (ILOM) Snapshot' write '---## ',$i_h,' Files' write $WRN write '|*File Name*| *Size*|*Last Modified Date*|' } call collectData(join('/','ilom',$i_h,$snp),$res,\ ['C',concat('ILOM snapshot (',$snp,')')]) write '|[[../',last,'][_blank][',encode($snp),']] | ',getSize($res),\ '|',getLastModify($res,''),' |' if isCreated(true) {write $TOP toc '4:[[',getFile(),'][rda_report][Snapshot Files]]' } # Cleanup files debug ' Inside ILME collection, cleaning files from ',$hst if compare('eq',$cln,'ALL') var $pat = '*' elsif compare('eq',$cln,'NONE') var $pat = undef elsif match($cln,'^PAT:([\w\*][\w\*\.\-\_]*)$') var ($pat) = last else var $pat = $snp if ?$pat {set $cod {"${CMD_FIND}" ':1/.' -name . -o -prune -name ':2' -type f \ -exec "${CMD_RM}" -f '{}' \; 2>/dev/null } var $cod = bind($cod,$dir,$pat) # Provide step information when password can be requested by SSH if $a_f call log_critical('Cleaning files from archive directory') # Perform the cleanup if ?$a_s call rcollect('ARC',$cod,$res,{CMD_FIND => $dsc{'CMD_FIND'},\ CMD_RM => $dsc{'CMD_RM'}}) else {output | concat(sprintf($SU,$usr),'>',quote($res)) write 'CMD_FIND="',$dsc{'CMD_FIND'},'"' write 'CMD_RM="', $dsc{'CMD_RM'},'"' write $cod close } } # Indicate the successful completion call log_critical(concat('Data gathering complete for ',$i_h)) } else call log_error(concat('Empty snapshot received from ',$i_h)) } # Free the resources if ?$a_s call $a_s->close call $buf->close call unlinkTemp($res) unpretoc } # Adjust the table of content unpretoc =head1 SEE ALSO L, L =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut