diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am index 73ce6b6d0..e1fff0762 100644 --- a/heartbeat/Makefile.am +++ b/heartbeat/Makefile.am @@ -1,157 +1,158 @@ # Makefile.am for OCF RAs # # Author: Sun Jing Dong # Copyright (C) 2004 IBM # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # MAINTAINERCLEANFILES = Makefile.in EXTRA_DIST = $(ocf_SCRIPTS) $(ocfcommon_DATA) \ $(common_DATA) $(hb_DATA) $(dtd_DATA) \ README AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/linux-ha halibdir = $(libexecdir)/heartbeat ocfdir = $(OCF_RA_DIR_PREFIX)/heartbeat dtddir = $(datadir)/$(PACKAGE_NAME) dtd_DATA = ra-api-1.dtd if USE_IPV6ADDR_AGENT ocf_PROGRAMS = IPv6addr else ocf_PROGRAMS = endif if IPV6ADDR_COMPATIBLE halib_PROGRAMS = send_ua else halib_PROGRAMS = endif IPv6addr_SOURCES = IPv6addr.c IPv6addr_utils.c send_ua_SOURCES = send_ua.c IPv6addr_utils.c IPv6addr_LDADD = -lplumb $(LIBNETLIBS) send_ua_LDADD = $(LIBNETLIBS) ocf_SCRIPTS = ClusterMon \ CTDB \ Dummy \ IPaddr \ IPaddr2 \ anything \ AoEtarget \ apache \ asterisk \ nginx \ AudibleAlarm \ clvm \ conntrackd \ db2 \ dhcpd \ Delay \ dnsupdate \ docker \ eDir88 \ EvmsSCC \ Evmsd \ ethmonitor \ exportfs \ Filesystem \ fio \ galera \ ids \ iscsi \ ICP \ IPsrcaddr \ iSCSITarget \ iSCSILogicalUnit \ iface-bridge \ iface-vlan \ jboss \ kamailio \ LinuxSCSI \ LVM \ lxc \ MailTo \ ManageRAID \ ManageVE \ mysql \ mysql-proxy \ + nagios \ named \ nfsnotify \ nfsserver \ oracle \ oralsnr \ pingd \ portblock \ postfix \ pound \ pgsql \ proftpd \ Pure-FTPd \ rabbitmq-cluster \ Raid1 \ redis \ Route \ rsyncd \ rsyslog \ SAPDatabase \ SAPInstance \ SendArp \ ServeRAID \ slapd \ SphinxSearchDaemon \ Squid \ Stateful \ SysInfo \ scsi2reservation \ sfex \ sg_persist \ symlink \ syslog-ng \ tomcat \ VIPArip \ VirtualDomain \ varnish \ vmware \ WAS \ WAS6 \ WinPopup \ Xen \ Xinetd \ zabbixserver ocfcommondir = $(OCF_LIB_DIR_PREFIX)/heartbeat ocfcommon_DATA = ocf-shellfuncs \ ocf-binaries \ ocf-directories \ ocf-returncodes \ ocf-rarun \ apache-conf.sh \ http-mon.sh \ sapdb-nosha.sh \ sapdb.sh \ ora-common.sh \ mysql-common.sh \ findif.sh # Legacy locations hbdir = $(sysconfdir)/ha.d hb_DATA = shellfuncs diff --git a/heartbeat/nagios b/heartbeat/nagios new file mode 100755 index 000000000..4639a6f77 --- /dev/null +++ b/heartbeat/nagios @@ -0,0 +1,250 @@ +#!/bin/sh +# +# License: GNU General Public License (GPL) +# (c) 2015 T.J. Yang, O. Albrigtsen +# and Linux-HA contributors +# +# ----------------------------------------------------------------------------- +# 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 +# ----------------------------------------------------------------------------- +# +# NAME +# nagios : OCF resource agent script for Nagios Server +# + +# Initialization: +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +# Defaults +OCF_RESKEY_user_default="nagios" +OCF_RESKEY_group_default="nagios" +OCF_RESKEY_binary_default="/usr/sbin/nagios" +OCF_RESKEY_config_default="/etc/nagios/nagios.cfg" +OCF_RESKEY_log_default="/var/log/nagios/nagios.log" +OCF_RESKEY_retention_default="/var/log/nagios/retention.dat" +OCF_RESKEY_command_default="/var/log/nagios/rw/nagios.cmd" +OCF_RESKEY_pid_default="/var/run/nagios.pid" + +: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} +: ${OCF_RESKEY_group=${OCF_RESKEY_group_default}} +: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} +: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} +: ${OCF_RESKEY_log=${OCF_RESKEY_log_default}} +: ${OCF_RESKEY_retention=${OCF_RESKEY_retention_default}} +: ${OCF_RESKEY_command=${OCF_RESKEY_command_default}} +: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} + + +nagios_usage() { + cat < + + +0.75 + +OCF Resource script for Nagios 3.x or 4.x. It manages a Nagios instance as a HA resource. +Nagios resource agent + + + + + User running Nagios daemon (for file permissions) + Nagios user + + + + + Group running Nagios daemon (for file permissions) + Nagios group + + + + + Location of the Nagios binary + Nagios binary + + + + + Configuration file + Nagios config + + + + + Location of the Nagios log + Nagios log + + + + + Location of the Nagios retention file + Nagios retention file + + + + + Location of the Nagios external command file + Nagios command file + + + + + Location of the Nagios pid/lock + Nagios pid file + + + + + + + + + + + + + + +END +} + + +nagios_start() { + nagios_validate_all + rc=$? + if [ $rc -ne 0 ]; then + return $rc + fi + + + # if resource is already running,no need to continue code after this. + if nagios_monitor; then + ocf_log info "Nagios is already running" + return $OCF_SUCCESS + fi + + # Remove ${OCF_RESKEY_pid} if it exists + rm -f ${OCF_RESKEY_pid} + + ocf_run -q touch ${OCF_RESKEY_log} ${OCF_RESKEY_retention} ${OCF_RESKEY_pid} + chown ${OCF_RESKEY_user}:${OCF_RESKEY_group} ${OCF_RESKEY_log} ${OCF_RESKEY_retention} ${OCF_RESKEY_pid} + rm -f ${OCF_RESKEY_command} + [ -x /sbin/restorecon ] && /sbin/restorecon ${OCF_RESKEY_pid} + ocf_run -q ${OCF_RESKEY_binary} -d ${OCF_RESKEY_config} + + while ! nagios_monitor; do + sleep 1 + done + + if [ $? -eq "0" ]; then + ocf_log info "Nagios started" + return ${OCF_SUCCESS} + fi + + return $OCF_SUCCESS +} + +nagios_stop() { + nagios_monitor + if [ "$?" -ne "$OCF_SUCCESS" ]; then + # Currently not running. Nothing to do. + ocf_log info "Resource is already stopped" + rm -f ${OCF_RESKEY_pid} + + return $OCF_SUCCESS + fi + + kill `cat ${OCF_RESKEY_pid}` + + # Wait for process to stop + while nagios_monitor; do + sleep 1 + done + + return $OCF_SUCCESS +} + +nagios_monitor(){ + ocf_pidfile_status ${OCF_RESKEY_pid} > /dev/null 2>&1 + case "$?" in + 0) + rc=$OCF_SUCCESS + ;; + 1|2) + rc=$OCF_NOT_RUNNING + ;; + *) + rc=$OCF_ERR_GENERIC + ;; + esac + return $rc +} + +nagios_validate_all(){ + check_binary ${OCF_RESKEY_binary} + + if [ ! -f ${OCF_RESKEY_config} ]; then + ocf_exit_reason "Configuration file ${OCF_RESKEY_config} not found" + return ${OCF_ERR_INSTALLED} + fi + + ${OCF_RESKEY_binary} -v ${OCF_RESKEY_config} > /dev/null 2>&1; + if [ $? -ne "0" ]; then + ocf_exit_reason "Configuration check failed" + return ${OCF_ERR_INSTALLED} + fi +} + + +# **************************** MAIN SCRIPT ************************************ + +# This OCF agent script need to be run as root user. +if ! ocf_is_root; then + echo "$0 agent script need to be run as root user." + ocf_log debug "$0 agent script need to be run as root user." + exit $OCF_ERR_GENERIC +fi + +# Make sure meta-data and usage always succeed +case $__OCF_ACTION in +meta-data) nagios_meta_data + exit $OCF_SUCCESS + ;; +usage|help) nagios_usage + exit $OCF_SUCCESS + ;; +esac + +# Anything other than meta-data and usage must pass validation +# this will failed on Nagios slave when config files are in master:/dev/drbd0 +# nagios_validate_all || exit $? + +# Translate each action into the appropriate function call +case $__OCF_ACTION in +start) nagios_start;; +stop) nagios_stop;; +status|monitor) nagios_monitor;; +validate-all) nagios_validate_all;; +*) nagios_usage + exit $OCF_ERR_UNIMPLEMENTED + ;; +esac +rc=$? + +exit $rc + +# End of this script