From 77a727d5c4fc2440550a32f0df17c8c38d2111a6 Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Tue, 26 Dec 2017 10:40:20 +0100 Subject: [PATCH] Added check_hpux_kernel_params --- .../etc/check_hpux_kernel_params.conf.dist | 17 +++ .../hp-ux/check_hpux_kernel_params.sh | 135 ++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 configs/etc/check_hpux_kernel_params.conf.dist create mode 100644 sources/lib/platform/hp-ux/check_hpux_kernel_params.sh diff --git a/configs/etc/check_hpux_kernel_params.conf.dist b/configs/etc/check_hpux_kernel_params.conf.dist new file mode 100644 index 0000000..eccb227 --- /dev/null +++ b/configs/etc/check_hpux_kernel_params.conf.dist @@ -0,0 +1,17 @@ +#****************************************************************************** +# @(#) check_hpux_kernel_params.conf +#****************************************************************************** +# This is a configuration file for the check_hpux_kernel_params HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# specify kernal parameters and their values or expression (as reported by kctune) +# [param::] +param:nproc:5000 +param:filecache_max:50% + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/sources/lib/platform/hp-ux/check_hpux_kernel_params.sh b/sources/lib/platform/hp-ux/check_hpux_kernel_params.sh new file mode 100644 index 0000000..cfd9eb7 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_kernel_params.sh @@ -0,0 +1,135 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_kernel_params.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 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_hpux_kernel_params +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-12-22: orginal version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_kernel_params +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _KCTUNE_BIN="/usr/sbin/kctune" +typeset _VERSION="2017-12-22" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _PARAM_NAME="" +typeset _CONFIG_VALUE="" +typeset _CURR_VALUE="" +typeset _EXPR_VALUE="" +typeset _REPORTED_VALUE="" +typeset _DUMMY="" + +# 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 + +# collect data (mount only) +${_KCTUNE_BIN} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +if (( $? != 0 )) +then + _MSG="unable to gather kctune information (not HP-UX 11.31?)" + log_hc "$0" 1 "${_MSG}" + return 0 +fi + +# check for each configured parameter +grep -i '^param:' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read _DUMMY _PARAM_NAME _CONFIG_VALUE +do + # check for actual values and expression values + _CURR_VALUE=$(grep -E -e "^${_PARAM_NAME}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null | awk '{ print $2 }') + _EXPR_VALUE=$(grep -E -e "^${_PARAM_NAME}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null | awk '{ print $3 }') + + if [[ "${_EXPR_VALUE}" = @(Default|default) ]] + then + if [[ "${_CONFIG_VALUE}" = "${_CURR_VALUE}" ]] + then + _MSG="${_PARAM_NAME} is set with the right value (${_CURR_VALUE})" + else + _MSG="${_PARAM_NAME} has a wrong value (${_CONFIG_VALUE} != ${_CURR_VALUE})" + _REPORTED_VALUE="${_CURR_VALUE}" + _STC=1 + fi + else + if [[ "${_CONFIG_VALUE}" = "${_EXPR_VALUE}" ]] + then + _MSG="${_PARAM_NAME} is set with the right expression (${_EXPR_VALUE})" + else + _MSG="${_PARAM_NAME} has a wrong expression (${_CONFIG_VALUE} != ${_EXPR_VALUE})" + _REPORTED_VALUE="${_EXPR_VALUE}" + _STC=1 + fi + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" "${_REPORTED_VALUE}" "${_CONFIG_VALUE}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with formatted stanzas: + param:: +PURPOSE : Checks kernel parameters have a correct run-time value/expression + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#******************************************************************************