Blame SOURCES/bz1212632-nagios.patch

937446
diff -uNr a/doc/man/Makefile.am b/doc/man/Makefile.am
937446
--- a/doc/man/Makefile.am	2016-06-06 10:32:26.889194520 +0200
937446
+++ b/doc/man/Makefile.am	2016-06-06 10:33:28.850643243 +0200
937446
@@ -118,6 +118,7 @@
937446
                           ocf_heartbeat_lxc.7 \
937446
                           ocf_heartbeat_mysql.7 \
937446
                           ocf_heartbeat_mysql-proxy.7 \
937446
+                          ocf_heartbeat_nagios.7 \
937446
                           ocf_heartbeat_named.7 \
937446
                           ocf_heartbeat_nfsnotify.7 \
937446
                           ocf_heartbeat_nfsserver.7 \
937446
diff -uNr a/heartbeat/Makefile.am b/heartbeat/Makefile.am
937446
--- a/heartbeat/Makefile.am	2016-06-06 10:32:26.889194520 +0200
937446
+++ b/heartbeat/Makefile.am	2016-06-06 10:33:02.418878409 +0200
937446
@@ -97,6 +97,7 @@
937446
 			ManageVE		\
937446
 			mysql			\
937446
 			mysql-proxy		\
937446
+			nagios			\
937446
 			named			\
937446
 			nfsnotify		\
937446
 			nfsserver		\
937446
diff -uNr a/heartbeat/nagios b/heartbeat/nagios
937446
--- a/heartbeat/nagios	1970-01-01 01:00:00.000000000 +0100
937446
+++ b/heartbeat/nagios	2016-06-06 10:33:02.418878409 +0200
937446
@@ -0,0 +1,246 @@
937446
+#!/bin/sh
937446
+#
937446
+#  License:      GNU General Public License (GPL)
937446
+#  (c) 2015 T.J. Yang, O. Albrigtsen
937446
+#           and Linux-HA contributors
937446
+#
937446
+# -----------------------------------------------------------------------------
937446
+#      O C F    R E S O U R C E    S C R I P T   S P E C I F I C A T I O N
937446
+# -----------------------------------------------------------------------------
937446
+#
937446
+# NAME
937446
+#       nagios : OCF resource agent script for Nagios Server
937446
+#
937446
+
937446
+# Initialization:
937446
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
937446
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
937446
+
937446
+# Defaults
937446
+OCF_RESKEY_user_default="nagios"
937446
+OCF_RESKEY_group_default="nagios"
937446
+OCF_RESKEY_binary_default="/usr/sbin/nagios"
937446
+OCF_RESKEY_config_default="/etc/nagios/nagios.cfg"
937446
+OCF_RESKEY_log_default="/var/log/nagios/nagios.log"
937446
+OCF_RESKEY_retention_default="/var/log/nagios/retention.dat"
937446
+OCF_RESKEY_command_default="/var/log/nagios/rw/nagios.cmd"
937446
+OCF_RESKEY_pid_default="/var/run/nagios.pid"
937446
+
937446
+: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}
937446
+: ${OCF_RESKEY_group=${OCF_RESKEY_group_default}}
937446
+: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
937446
+: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}}
937446
+: ${OCF_RESKEY_log=${OCF_RESKEY_log_default}}
937446
+: ${OCF_RESKEY_retention=${OCF_RESKEY_retention_default}}
937446
+: ${OCF_RESKEY_command=${OCF_RESKEY_command_default}}
937446
+: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
937446
+
937446
+
937446
+nagios_usage() {
937446
+  cat <
937446
+    usage: $0 (start|stop|validate-all|meta-data|help|usage|monitor)
937446
+    $0 manages a Nagios instance as an OCF HA resource.
937446
+    The 'start' operation starts the instance.
937446
+    The 'stop' operation stops the instance.
937446
+    The 'status' operation reports whether the instance is running
937446
+    The 'monitor' operation reports whether the instance seems to be working
937446
+    The 'validate-all' operation reports whether the parameters are valid
937446
+END
937446
+}
937446
+
937446
+nagios_meta_data() {
937446
+        cat <
937446
+
937446
+
937446
+<resource-agent name="nagios">
937446
+<version>0.75</version>
937446
+
937446
+<longdesc lang="en">OCF Resource script for Nagios 3.x or 4.x. It manages a Nagios instance as a HA resource.</longdesc>
937446
+<shortdesc lang="en">Nagios resource agent</shortdesc>
937446
+
937446
+<parameters>
937446
+
937446
+<parameter name="user">
937446
+    <longdesc lang="en">User running Nagios daemon (for file permissions)</longdesc>
937446
+    <shortdesc lang="en">Nagios user</shortdesc>
937446
+    <content type="string" default="${OCF_RESKEY_user_default}" />
937446
+</parameter>
937446
+
937446
+<parameter name="group">
937446
+    <longdesc lang="en">Group running Nagios daemon (for file permissions)</longdesc>
937446
+    <shortdesc lang="en">Nagios group</shortdesc>
937446
+    <content type="string" default="${OCF_RESKEY_group_default}" />
937446
+</parameter>
937446
+
937446
+<parameter name="binary">
937446
+    <longdesc lang="en">Location of the Nagios binary</longdesc>
937446
+    <shortdesc lang="en">Nagios binary</shortdesc>
937446
+    <content type="string" default="${OCF_RESKEY_binary_default}" />
937446
+</parameter>
937446
+
937446
+<parameter name="config">
937446
+    <longdesc lang="en">Configuration file</longdesc>
937446
+    <shortdesc lang="en">Nagios config</shortdesc>
937446
+    <content type="string" default="${OCF_RESKEY_config_default}" />
937446
+</parameter>
937446
+
937446
+<parameter name="log">
937446
+    <longdesc lang="en">Location of the Nagios log</longdesc>
937446
+    <shortdesc lang="en">Nagios log</shortdesc>
937446
+    <content type="string" default="${OCF_RESKEY_log_default}" />
937446
+</parameter>
937446
+
937446
+<parameter name="retention">
937446
+    <longdesc lang="en">Location of the Nagios retention file</longdesc>
937446
+    <shortdesc lang="en">Nagios retention file</shortdesc>
937446
+    <content type="string" default="${OCF_RESKEY_retention_default}" />
937446
+</parameter>
937446
+
937446
+<parameter name="command">
937446
+    <longdesc lang="en">Location of the Nagios external command file</longdesc>
937446
+    <shortdesc lang="en">Nagios command file</shortdesc>
937446
+    <content type="string" default="${OCF_RESKEY_command_default}" />
937446
+</parameter>
937446
+
937446
+<parameter name="pid">
937446
+    <longdesc lang="en">Location of the Nagios pid/lock</longdesc>
937446
+    <shortdesc lang="en">Nagios pid file</shortdesc>
937446
+    <content type="string" default="${OCF_RESKEY_pid_default}" />
937446
+</parameter>
937446
+
937446
+</parameters>
937446
+
937446
+<actions>
937446
+<action name="start" timeout="20" />
937446
+<action name="stop" timeout="20" />
937446
+<action name="status" timeout="20" />
937446
+<action name="monitor" depth="0" timeout="20" interval="10" start-delay="10" />
937446
+<action name="validate-all" timeout="20" />
937446
+<action name="meta-data" timeout="20" />
937446
+</actions>
937446
+</resource-agent>
937446
+END
937446
+}
937446
+
937446
+
937446
+nagios_start() {
937446
+    nagios_validate_all
937446
+    rc=$?
937446
+    if [ $rc -ne 0 ]; then
937446
+        return $rc
937446
+    fi
937446
+
937446
+
937446
+    # if resource is already running,no need to continue code after this.
937446
+    if nagios_monitor; then
937446
+        ocf_log info "Nagios is already running"
937446
+        return $OCF_SUCCESS
937446
+    fi
937446
+
937446
+    # Remove ${OCF_RESKEY_pid} if it exists
937446
+    rm -f ${OCF_RESKEY_pid}
937446
+
937446
+    ocf_run -q touch ${OCF_RESKEY_log} ${OCF_RESKEY_retention} ${OCF_RESKEY_pid}
937446
+    chown ${OCF_RESKEY_user}:${OCF_RESKEY_group} ${OCF_RESKEY_log} ${OCF_RESKEY_retention} ${OCF_RESKEY_pid}
937446
+    rm -f ${OCF_RESKEY_command}
937446
+    [ -x /sbin/restorecon ] && /sbin/restorecon ${OCF_RESKEY_pid}
937446
+    ocf_run -q ${OCF_RESKEY_binary} -d ${OCF_RESKEY_config}
937446
+
937446
+    while ! nagios_monitor; do
937446
+        sleep 1
937446
+    done
937446
+
937446
+    if [ $? -eq "0" ]; then
937446
+        ocf_log info "Nagios started"
937446
+        return ${OCF_SUCCESS}
937446
+    fi
937446
+
937446
+    return $OCF_SUCCESS
937446
+}
937446
+
937446
+nagios_stop() {
937446
+    nagios_monitor
937446
+    if [ "$?" -ne "$OCF_SUCCESS" ]; then
937446
+        # Currently not running. Nothing to do.
937446
+        ocf_log info "Resource is already stopped"
937446
+        rm -f ${OCF_RESKEY_pid}
937446
+
937446
+        return $OCF_SUCCESS
937446
+    fi
937446
+
937446
+    kill `cat ${OCF_RESKEY_pid}`
937446
+
937446
+    # Wait for process to stop
937446
+    while nagios_monitor; do
937446
+        sleep 1
937446
+    done
937446
+    
937446
+    return $OCF_SUCCESS
937446
+}
937446
+
937446
+nagios_monitor(){
937446
+    ocf_pidfile_status ${OCF_RESKEY_pid} > /dev/null 2>&1
937446
+    case "$?" in
937446
+        0)
937446
+            rc=$OCF_SUCCESS
937446
+            ;;
937446
+        1|2)
937446
+            rc=$OCF_NOT_RUNNING
937446
+            ;;
937446
+        *)
937446
+            rc=$OCF_ERR_GENERIC
937446
+            ;;
937446
+    esac
937446
+    return $rc
937446
+}
937446
+
937446
+nagios_validate_all(){
937446
+    check_binary ${OCF_RESKEY_binary}
937446
+    
937446
+    if [ ! -f ${OCF_RESKEY_config} ]; then
937446
+        ocf_exit_reason "Configuration file ${OCF_RESKEY_config} not found"
937446
+        return ${OCF_ERR_INSTALLED}
937446
+    fi
937446
+    
937446
+    ${OCF_RESKEY_binary} -v ${OCF_RESKEY_config} > /dev/null 2>&1;
937446
+    if [ $? -ne "0" ]; then
937446
+        ocf_exit_reason "Configuration check failed"
937446
+        return ${OCF_ERR_INSTALLED}
937446
+    fi
937446
+}
937446
+
937446
+
937446
+# **************************** MAIN SCRIPT ************************************
937446
+
937446
+# Make sure meta-data and usage always succeed
937446
+case $__OCF_ACTION in
937446
+meta-data)      nagios_meta_data
937446
+                exit $OCF_SUCCESS
937446
+                ;;
937446
+usage|help)     nagios_usage
937446
+                exit $OCF_SUCCESS
937446
+                ;;
937446
+esac
937446
+
937446
+# This OCF agent script need to be run as root user.
937446
+if ! ocf_is_root; then
937446
+        echo  "$0 agent script need to be run as root user."
937446
+        ocf_log debug "$0 agent script need to be run as root user."
937446
+        exit $OCF_ERR_GENERIC
937446
+fi
937446
+
937446
+# Translate each action into the appropriate function call
937446
+case $__OCF_ACTION in
937446
+start)          nagios_start;;
937446
+stop)           nagios_stop;;
937446
+status|monitor) nagios_monitor;;
937446
+validate-all)   nagios_validate_all;;
937446
+*)              nagios_usage
937446
+                exit $OCF_ERR_UNIMPLEMENTED
937446
+                ;;
937446
+esac
937446
+rc=$?
937446
+
937446
+exit $rc
937446
+  
937446
+# End of this script