Hello community, here is the log from the commit of package monitoring-plugins-keepalived for openSUSE:Leap:15.2 checked in at 2020-02-25 12:17:18 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Leap:15.2/monitoring-plugins-keepalived (Old) and /work/SRC/openSUSE:Leap:15.2/.monitoring-plugins-keepalived.new.26092 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "monitoring-plugins-keepalived" Tue Feb 25 12:17:18 2020 rev:1 rq:771113 version:0.1.5 Changes: -------- New Changes file: --- /dev/null 2019-12-19 10:12:34.003146842 +0100 +++ /work/SRC/openSUSE:Leap:15.2/.monitoring-plugins-keepalived.new.26092/monitoring-plugins-keepalived.changes 2020-02-25 12:17:19.240449569 +0100 @@ -0,0 +1,33 @@ +------------------------------------------------------------------- +Fri Feb 23 13:33:06 UTC 2018 - [email protected] + +- Version 0.1.5 + + make sure that the state file get's written and is current when + invoking the script + + added SNMP functionality + + added URL +- Recommend net-snmp + +------------------------------------------------------------------- +Thu Jan 11 16:55:45 UTC 2018 - [email protected] + +- Version 0.0.5 +- provide a templated keepalived_notify_monitoring.conf +- added monitoring-plugins-keepalived-rpmlintrc + +------------------------------------------------------------------- +Sun Sep 17 18:21:31 UTC 2017 - [email protected] + +- STATEFILE should be readable by everyone, so the nagios user is + able to read the file + +------------------------------------------------------------------- +Tue Jan 26 10:18:58 UTC 2016 - [email protected] + +- add logging (and logrotate) for the notify script + +------------------------------------------------------------------- +Wed Jan 13 22:45:46 UTC 2016 - [email protected] + +- initial version + New: ---- check_keepalived keepalived_notify_monitoring.sh monitoring-plugins-keepalived-rpmlintrc monitoring-plugins-keepalived.changes monitoring-plugins-keepalived.spec ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ monitoring-plugins-keepalived.spec ++++++ # # spec file for package monitoring-plugins-keepalived # # Copyright (c) 2016 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via http://bugs.opensuse.org/ # Name: monitoring-plugins-keepalived Summary: Check keepalived License: BSD-3-Clause Group: System/Monitoring Version: 0.1.5 Release: 1 Url: https://en.opensuse.org/Monitoring-plugins-keepalived Source0: check_keepalived Source1: keepalived_notify_monitoring.sh Source2: monitoring-plugins-keepalived-rpmlintrc BuildRequires: keepalived Requires: awk Requires: bash Requires: coreutils Requires: grep Requires: keepalived Requires: logrotate Requires: monitoring-plugins-common Requires: procps Requires(pre): keepalived Recommends: net-snmp BuildArch: noarch BuildRequires: nagios-rpm-macros BuildRoot: %{_tmppath}/%{name}-%{version}-build %description This script either uses the 'notify' or snmp functionality of keepalived to inform an administrator about the current state of keepalived masters and slaves. While the SNMP part is simply querying a SNMP server for the keepalived part (via agentx), the 'notify' part needs some adaptions in the keepalived.conf to: * execute a script on changes during keepalived runtime, which writes the state change into a temporary file * read the file each time the monitoring server asks for the state if there is a keepalived up and running %prep %build %install # # "binaries" # install -D -m755 %{SOURCE0} %buildroot/%{nagios_plugindir}/check_keepalived install -D -m755 %{SOURCE1} %buildroot/%{_bindir}/keepalived_notify_monitoring.sh # # extra configuration file # mkdir -p %buildroot/%{_sysconfdir}/keepalived cat >> %buildroot/%{_sysconfdir}/keepalived/keepalived_notify_monitoring.conf << EOF # # Where to store the logs # LOGFILE='/var/log/keepalived_notify.log' # # The file with the current status information # Checked by %{nagios_plugindir}/check_keepalived # STATEFILE='/var/run/keepalived.state' # # Any additional script that should be executed. # Arguments given to the script: # $1 = "GROUP"|"INSTANCE" # $2 = name of the group or instance # $3 = target state of transition (stop only applies to instances) # ("MASTER"|"BACKUP"|"FAULT"|"STOP") # $4 = priority value # # Please uncomment the following line to activate... # EXEC_SCRIPT='' EOF # # logrotate # mkdir -p %buildroot/%{nrpe_sysconfdir} %buildroot/%{_sysconfdir}/logrotate.d cat >> %buildroot/%{_sysconfdir}/logrotate.d/%{name} << EOF /var/log/keepalived_notify.log { compress dateext maxage 365 rotate 99 missingok notifempty size +4096k create 640 root root sharedscripts } EOF # # nrpe config # cat >> %buildroot/%{nrpe_sysconfdir}/check_keepalived.cfg <<EOF # example command definition for check_keepalived # please run # %{nagios_plugindir}/check_keepalived -h # for a complete list of options command[check_keepalived]=%{nagios_plugindir}/check_keepalived EOF %clean rm -rf %buildroot %files %defattr(-,root,root) # avoid build dependecy of nagios - own the dirs %dir %{nagios_libdir} %dir %{nagios_plugindir} %dir %{nrpe_sysconfdir} %config(noreplace) %{_sysconfdir}/keepalived/keepalived_notify_monitoring.conf %config(noreplace) %{nrpe_sysconfdir}/check_keepalived.cfg %config(noreplace) %{_sysconfdir}/logrotate.d/%{name} %{nagios_plugindir}/check_keepalived %{_bindir}/keepalived_notify_monitoring.sh %changelog ++++++ check_keepalived ++++++ #!/bin/bash # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # * Neither the name of the Novell nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # export PATH="/usr/local/bin:/usr/bin:/bin" REVISION=0.1.5 PROGNAME=$(basename "$0") PROGPATH=$(dirname "$PROGNAME") #STATEFILE='/var/run/keepalived.state' STATEFILE='/tmp/keepalived.stats' PIDFILE='/var/run/keepalived.pid' STATE='UNKOWN - no data processed' PROGPATH='/usr/lib/nagios/plugins/' USE_SNMP=false SNMP_VERSION='2c' SNMP_HOSTNAME='localhost' SNMP_COMMUNITY='public' SNMP_WALK='/usr/bin/snmpwalk' AWK='/usr/bin/awk' TR='/usr/bin/tr' KEEPALIVED_INSTANCE_STATE_OID='.1.3.6.1.4.1.9586.100.5.2.3.1.4.1' KEEPALIVED_WANTED_STATE_OID='.1.3.6.1.4.1.9586.100.5.2.3.1.6.1' if [ -r "$PROGPATH/utils.sh" ]; then . "$PROGPATH/utils.sh" fi print_usage() { echo "Usage: $PROGNAME [-F keepalived_statefile] [-p keepalived_pidfile] [-S|-M] [-h] [-v]" echo " -F keepalived_statefile : URI to the status file (default: $STATEFILE)" echo " -p keepalived_pidfile : URI to the pidfile of the keepalived process (default: $PIDFILE)" echo " -S : expect the machine to run in SLAVE state" echo " -M : expect the machine to run in MASTER state" echo " -h : print this usage" echo " -V : print version information" echo " -s : use SNMP" echo " -H <hostname> : SNMP host to query" echo " -v <snmp_version> : SNMP version (currently only 2c is supported, therefor default)" echo " -c <snmp_community> : SNMP v2 community string" echo echo "To successfully run this script via the 'notify'-script configuration, the following pre-requires need to be fulfilled:" echo "* in your keepalived.conf, add 'notify /usr/bin/keepalived_notify_monitoring.sh'" echo " in at least one vrrp_instance section (see 'keepalived_notify_monitoring.sh -h'" echo " output for more details" echo echo "In case of using the SNMP option, the following pre-requires need to be fulfilled:" echo "* a running SNMP daemon with agentx support" echo "* keepalived needs to be started with the '-x' or '--snmp' option" echo echo "In any of the above options:" echo "* keepalive should be restarted after the changes" echo echo "Check https://en.opensuse.org/Monitoring-plugins-keepalived for more information." echo } print_help() { print_revision $PROGNAME $REVISION echo print_usage echo support exit $STATE_OK } while getopts 'F:p:SMhVv:sH:c:' OPTION ; do case $OPTION in v|V) print_revision $PROGNAME $REVISION exit $STATE_OK ;; F) STATEFILE="$OPTARG" ;; M) MASTER='true' ;; p) PIDFILE="$OPTARG" ;; S) SLAVE='true' ;; h) print_help exit $STATE_OK ;; s) USE_SNMP=true ;; H) SNMP_HOSTNAME="$OPTARG" ;; v) SNMP_VERSION="$OPTARG" ;; c) SNMP_COMMUNITY="$OPTARG" ;; *) echo "Unkown argument: $OPTION" >&2 print_usage exit $STATE_UNKNOWN ;; esac done if [ -r "$PIDFILE" ]; then PID=$(cat "$PIDFILE") KEEPALIVERUN=$(cat "/proc/$PID/status" | grep ^State: | awk '" " { print $2 }') case $KEEPALIVERUN in S|R) KEEPALIVESTATE=$STATE_OK ;; Z) echo "WARNING: main keepalived process is a Zombie" exit $STATE_WARNING ;; *) echo "UNKOWN: found $PIDFILE but got no state for keepalived" exit $STATE_UNKNOWN ;; esac else KEEPALIVENUM=$(ps ax | grep [k]eepalived | wc -l | $TR -d "\n") if [ $KEEPALIVENUM -gt 0 ]; then KEEPALIVESTATE=$STATE_OK fi fi if [ $KEEPALIVESTATE -eq $STATE_OK ]; then if [ $USE_SNMP == "true" ]; then for command in $AWK $SNMP_WALK $TR ; do if [ ! -x $command ]; then echo "ERROR: $command not found or not executable" exit $STATE_CRITICAL fi done # snmpwalk -On -v2c -cpublic localhost .1.3.6.1.4.1.9586.100.5.2.3.1.4.1 SNMP_CURRENT_STATE=$($SNMP_WALK -v${SNMP_VERSION} -c${SNMP_COMMUNITY} $SNMP_HOSTNAME $KEEPALIVED_INSTANCE_STATE_OID | $AWK ' { print $4 }') case $SNMP_CURRENT_STATE in *1*) STATE="SLAVE" ;; *2*) STATE="MASTER" ;; *) STATE="UNKNOWN" ;; esac if [ "$MASTER" == "true" ]; then if [ "$STATE" = "MASTER" ]; then echo "OK: $SNMP_HOSTNAME is master" exit $STATE_OK else echo "CRIT: $SNMP_HOSTNAME is not master (state is: $STATE)" exit $STATE_CRITICAL fi elif [ "$SLAVE" == "true" ]; then if [ $STATE = "SLAVE" ]; then echo "OK: $SNMP_HOSTNAME is slave" exit $STATE_OK else echo "CRIT: $SNMP_HOSTNAME is not slave (state is: $STATE)" exit $STATE_CRITICAL fi else # snmpwalk -On -v2c -cpublic localhost .1.3.6.1.4.1.9586.100.5.2.3.1.6.1 SNMP_WANTED_STATE=$($SNMP_WALK -v${SNMP_VERSION} -c${SNMP_COMMUNITY} $SNMP_HOSTNAME $KEEPALIVED_WANTED_STATE_OID | $AWK ' { print $4 }') if [ "$SNMP_CURRENT_STATE" = "$SNMP_WANTED_STATE" ]; then echo "OK: $SNMP_HOSTNAME is in wanted state (state is: $STATE)" exit $STATE_OK else echo "CRIT: $SNMP_HOSTNAME is not in wanted state (state is: $STATE)" exit $STATE_CRITICAL fi fi else rm -f $STATEFILE kill -USR2 $PID sleep 1 if [ -r "$STATEFILE" ] ; then STATE1=$(grep "Became master:" "$STATEFILE") STATE2=$(grep "Released master:" "$STATEFILE") else echo "UNKOWN: could not read $STATEFILE" exit $STATE_UNKNOWN fi rm -f $STATEFILE if [[ $STATE1 == *"Became master: 0"* ]];then echo "$STATE1" exit $STATE_CRITICAL fi if [ "$MASTER" == "true" ]; then if [[ $STATE2 == *"Released master: 0"* ]]; then echo "$STATE1 $STATE2" exit $STATE_OK fi if [[ $STATE2 == *"Released master: 1"* ]]; then echo "$STATE1 $STATE2" exit $STATE_CRITICAL fi elif [ "$SLAVE" == "true" ]; then if [[ $STATE2 == *"Released master: 1"* ]]; then echo "$STATE1 $STATE2" exit $STATE_OK elif [[ $STATE2 == *"Released master: 0"* ]]; then echo "$STATE1 $STATE2" exit $STATE_CRITICAL else echo "UNKOWN: could not detect state from $STATEFILE : $STATE1 $STATE2" exit $STATE_UNKNOWN fi else if [[ $STATE2 == *"Released master: 0"* ]] || [[ $STATE2 == *"Released master: 1"* ]]; then echo "$STATE1 $STATE2" exit $STATE_OK else echo "UNKOWN: could not detect state from $STATEFILE : $STATE1 $STATE2" exit $STATE_UNKNOWN fi fi fi else echo "Keepalived is in UNKNOWN state" exit $STATE_UNKNOWN fi ++++++ keepalived_notify_monitoring.sh ++++++ #!/bin/bash # # Notify script for keepalived used by check_keepalived # # Please add the following in your Keepalived configuration: # vrrp_instance MyVRRPInstance { # [...] # notify /usr/bin/keepalived_notify_monitoring.sh # } # # The script is called after any state change with the following # parameters: # # $1 = "GROUP" or "INSTANCE" # $2 = name of group or instance # $3 = target state of transition (“MASTER”, “BACKUP”, “FAULT”) # $4 = priority value # # If you want to execute other scripts as well, please create a file # /etc/keepalived/keepalived_notify_monitoring.conf # and assign the path to your script in the variable EXEC_SCRIPT like: # EXEC_SCRIPT=/usr/local/bin/foo # this script here will execute your script with the parameters # from the initial call. # umask 0027 LOGFILE='/var/log/keepalived_notify.log' CONFIG='/etc/keepalived/keepalived_notify_monitoring.conf' STATEFILE='/var/run/keepalived.state' if [ -r "$CONFIG" ]; then . "$CONFIG" fi if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then echo "Usage: $(basename $0) <group or instance> <name of group or instance> <target state of transition>" echo echo " $(basename $0) should be used as notify script for keepalived and" echo " writes the given values into a statefile ($STATEFILE)" echo " for further processing (by check_keepalived for example)." echo echo " Please add the following in your Keepalived configuration:" echo " vrrp_instance MyVRRPInstance {" echo " [...]" echo " notify $0" echo " }" echo " After a reload, the script is called after any state change." echo echo " If you want to execute other scripts as well, please create a file" echo " /etc/keepalived/keepalived_notify_monitoring.conf" echo " and assign the path to your script in the variable EXEC_SCRIPT like:" echo " EXEC_SCRIPT=/usr/local/bin/foo" echo " this script here will execute your script with the parameters " echo " from the initial call." exit 0 fi DATE=$(date) echo "$DATE : $1 $2 is in $3 state (Priority: $4)" >> "$LOGFILE" touch "$STATEFILE" 2>/dev/null if [ $? -ne 0 ]; then echo "$0 : can not create $STATEFILE, exiting" >&2 exit 1 else echo "$1 $2 is in $3 state (Priority: $4)" > "$STATEFILE" chmod 644 "$STATEFILE" fi if [ -n "$EXEC_SCRIPT" ]; then "$EXEC_SCRIPT" "$1" "$2" "$3" "$4" fi ++++++ monitoring-plugins-keepalived-rpmlintrc ++++++ addFilter("macro-in-comment.*%{nagios_plugindir}"); addFilter("macro-in-comment.*%{nagios_plugindir}");
