#!/usr/bin/env ksh #****************************************************************************** # @(#) check_aix_subsystems.sh #****************************************************************************** # @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. # # This program is a free software; you can redistribute it and/or modify # it under the same terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details #****************************************************************************** # # DOCUMENTATION (MAIN) # ----------------------------------------------------------------------------- # @(#) MAIN: check_aix_subsystems # DOES: see _show_usage() # EXPECTS: see _show_usage() # REQUIRES: data_comma2space(), init_hc(), log_hc() # # @(#) HISTORY: # @(#) 2013-05-07: initial version [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] # @(#) 2019-03-09: changed format of stanzas in configuration file & # @(#) added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** # ----------------------------------------------------------------------------- function check_aix_subsystems { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- # set defaults (( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 typeset _CFG_HEALTHY="" typeset _LOG_HEALTHY=0 typeset _STATUS="" typeset _IS_OLD_STYLE=0 # handle arguments (originally comma-separated) for _ARG in ${_ARGS} do case "${_ARG}" in help) _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 ;; esac done # handle configuration file [[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" if [[ ! -r ${_CONFIG_FILE} ]] then warn "unable to read configuration file at ${_CONFIG_FILE}" return 1 fi _CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy') case "${_CFG_HEALTHY}" in yes|YES|Yes) _LOG_HEALTHY=1 ;; *) # do not override hc_arg (( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0 ;; esac # check for old-style configuration file (non-prefixed stanzas) _IS_OLD_STYLE=$(grep -c -E -e "^subsys:" ${_CONFIG_FILE} 2>/dev/null) if (( _IS_OLD_STYLE == 0 )) then warn "no 'subsys:' stanza(s) found in ${_CONFIG_FILE}; possibly an old-style configuration?" return 1 fi # collect data lssrc -a >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} (( $? == 0)) || return $? # perform check grep -E -e "^subsys:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _SUBSYS do _STATUS="$(grep -E -e ${_SUBSYS} ${HC_STDOUT_LOG} 2>/dev/null)" case "${_STATUS}" in *active*) _MSG="${_SUBSYS} is running" ;; *inoperative*) _MSG="${_SUBSYS} is not running" _STC=1 ;; *) _MSG="${_SUBSYS} is not on file" ;; esac # report result if (( _LOG_HEALTHY > 0 || _STC > 0 )) then log_hc "$0" ${_STC} "${_MSG}" fi _STC=0 done return 0 } # ----------------------------------------------------------------------------- function _show_usage { cat <<- EOT NAME : $1 VERSION : $2 CONFIG : $3 with parameters: log_healthy= and formatted stanzas: subsys: PURPOSE : Checks whether subsystem(s) are active/operative {lssrc} LOG HEALTHY : Supported EOT return 0 } #****************************************************************************** # END of script #******************************************************************************