[SCM] CTDB repository - branch master updated -
ctdb-1.0.77-4-g00d2213
Ronnie Sahlberg
sahlberg at samba.org
Tue Mar 31 09:48:36 GMT 2009
The branch, master has been updated
via 00d2213613822b758939019361a619bd7d7f4984 (commit)
via 42e2797271bc1cdb4eecf1227d4c2db668587193 (commit)
via ee52c0866e2b26c396fe60946159c559d47199eb (commit)
via ce534a83a05dbd40238e4eee0669d60ff396f935 (commit)
from 274a4a1fe2e016f33296ebfc5ed6337ce3141d06 (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 00d2213613822b758939019361a619bd7d7f4984
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Tue Mar 31 20:04:45 2009 +1100
new release 1.0.78
commit 42e2797271bc1cdb4eecf1227d4c2db668587193
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Tue Mar 31 20:00:00 2009 +1100
we should also install the 11.natgw eventscript if we want to be able to use it
commit ee52c0866e2b26c396fe60946159c559d47199eb
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Tue Mar 31 14:38:52 2009 +1100
install a default /etc/ctdb/notify.sh script as example on how to use
snmptrap/email to notify that a node has changed health status
commit ce534a83a05dbd40238e4eee0669d60ff396f935
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Tue Mar 31 14:23:31 2009 +1100
add a mechanism where the ctdb daemon will run a usercontrolled script when the node status changes to/from UNHEALTHY state.
This would allow a sysadmin to set up ctdb to send an email/snmptrap/... when the status of the node changes.
-----------------------------------------------------------------------
Summary of changes:
Makefile.in | 2 +
config/ctdb.init | 1 +
config/ctdb.sysconfig | 3 ++
config/notify.sh | 37 ++++++++++++++++++++++++
include/ctdb_private.h | 2 +
packaging/RPM/ctdb.spec | 7 ++++-
server/ctdb_monitor.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
server/ctdbd.c | 10 ++++++
8 files changed, 132 insertions(+), 1 deletions(-)
create mode 100755 config/notify.sh
Changeset truncated at 500 lines:
diff --git a/Makefile.in b/Makefile.in
index 2cacd99..b67818f 100755
--- a/Makefile.in
+++ b/Makefile.in
@@ -206,6 +206,7 @@ install: all
${INSTALLCMD} -m 644 doc/recovery-process.txt $(DESTDIR)$(docdir)/ctdb/recovery-process.txt
${INSTALLCMD} -m 755 config/events.d/00.ctdb $(DESTDIR)$(etcdir)/ctdb/events.d
${INSTALLCMD} -m 755 config/events.d/10.interface $(DESTDIR)$(etcdir)/ctdb/events.d
+ ${INSTALLCMD} -m 755 config/events.d/11.natgw $(DESTDIR)$(etcdir)/ctdb/events.d
${INSTALLCMD} -m 755 config/events.d/20.multipathd $(DESTDIR)$(etcdir)/ctdb/events.d
${INSTALLCMD} -m 755 config/events.d/40.vsftpd $(DESTDIR)$(etcdir)/ctdb/events.d
${INSTALLCMD} -m 755 config/events.d/41.httpd $(DESTDIR)$(etcdir)/ctdb/events.d
@@ -222,6 +223,7 @@ install: all
if [ -f doc/ctdb.1 ];then ${INSTALLCMD} -m 644 doc/ctdb.1 $(DESTDIR)$(mandir)/man1; fi
if [ -f doc/ctdbd.1 ];then ${INSTALLCMD} -m 644 doc/ctdbd.1 $(DESTDIR)$(mandir)/man1; fi
if [ -f doc/onnode.1 ];then ${INSTALLCMD} -m 644 doc/onnode.1 $(DESTDIR)$(mandir)/man1; fi
+ if [ ! -f $(DESTDIR)$(etcdir)/ctdb/notify.sh ];then ${INSTALLCMD} -m 644 config/notify.sh $(DESTDIR)$(etcdir)/ctdb; fi
test: all
tests/run_tests.sh
diff --git a/config/ctdb.init b/config/ctdb.init
index e263855..24a206d 100755
--- a/config/ctdb.init
+++ b/config/ctdb.init
@@ -64,6 +64,7 @@ CTDB_OPTIONS="$CTDB_OPTIONS --reclock=$CTDB_RECOVERY_LOCK"
[ -z "$CTDB_EVENT_SCRIPT_DIR" ] || CTDB_OPTIONS="$CTDB_OPTIONS --event-script-dir $CTDB_EVENT_SCRIPT_DIR"
[ -z "$CTDB_TRANSPORT" ] || CTDB_OPTIONS="$CTDB_OPTIONS --transport $CTDB_TRANSPORT"
[ -z "$CTDB_DEBUGLEVEL" ] || CTDB_OPTIONS="$CTDB_OPTIONS -d $CTDB_DEBUGLEVEL"
+[ -z "$CTDB_NOTIFY_SCRIPT" ] || CTDB_OPTIONS="$CTDB_OPTIONS --notification-script=$CTDB_NOTIFY_SCRIPT"
[ -z "$CTDB_START_AS_DISABLED" ] || [ "$CTDB_START_AS_DISABLED" != "yes" ] || {
CTDB_OPTIONS="$CTDB_OPTIONS --start-as-disabled"
}
diff --git a/config/ctdb.sysconfig b/config/ctdb.sysconfig
index ef3b0dc..f1f3676 100644
--- a/config/ctdb.sysconfig
+++ b/config/ctdb.sysconfig
@@ -95,6 +95,9 @@
# defaults to /etc/ctdb/nodes
# CTDB_NODES=/etc/ctdb/nodes
+# a script to run when node health changes
+# CTDB_NOTIFY_SCRIPT=/etc/ctdb/notify.sh
+
# the directory to put the local ctdb database files in
# defaults to /var/ctdb
# CTDB_DBDIR=/var/ctdb
diff --git a/config/notify.sh b/config/notify.sh
new file mode 100755
index 0000000..9c97ab9
--- /dev/null
+++ b/config/notify.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# This script is activated by setting CTDB_NOTIFY_SCRIPT=/etc/ctdb/notify.sh
+# in /etc/sysconfig/ctdb
+
+# This is script is invoked from ctdb when node UNHEALTHY flag changes.
+# and can be used to send SNMPtraps, email, etc
+# when the status of a node changes
+
+
+event="$1"
+shift
+
+case $event in
+ unhealthy)
+#
+# Send an snmptrap that the node is unhealthy :
+# snmptrap -m ALL -v 1 -c public 10.1.1.105 ctdb `hostname` 0 0 `date +"%s"` ctdb.nodeHealth.0 i 1
+#
+# or send an email :
+# mail foo at bar -s "`hostname` is UNHEALTHY" ...
+#
+# or do something else ...
+ ;;
+ healthy)
+#
+# Send an snmptrap that the node is healthy again :
+# snmptrap -m ALL -v 1 -c public 10.1.1.105 ctdb `hostname` 0 0 `date +"%s"` ctdb.nodeHealth.0 i 0
+#
+# or send an email :
+# mail foo at bar -s "`hostname` is HEALTHY" ...
+#
+# or do something else ...
+ ;;
+esac
+
+exit 0
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index cbd97d7..cf93eed 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -400,6 +400,7 @@ struct ctdb_context {
void *saved_scheduler_param;
struct _trbt_tree_t *server_ids;
const char *event_script_dir;
+ const char *notification_script;
const char *default_public_interface;
pid_t ctdbd_pid;
pid_t recoverd_pid;
@@ -1241,6 +1242,7 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
+int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
diff --git a/packaging/RPM/ctdb.spec b/packaging/RPM/ctdb.spec
index a917b58..7422150 100644
--- a/packaging/RPM/ctdb.spec
+++ b/packaging/RPM/ctdb.spec
@@ -4,7 +4,7 @@ Summary: Clustered TDB
Vendor: Samba Team
Packager: Samba Team <samba at samba.org>
Name: ctdb
-Version: 1.0.77
+Version: 1.0.78
Release: 1
Epoch: 0
License: GNU GPL version 3
@@ -97,6 +97,7 @@ fi
%defattr(-,root,root)
%config(noreplace) %{_sysconfdir}/sysconfig/ctdb
+%config(noreplace) %{_sysconfdir}/ctdb/notify.sh
%config(noreplace) %{_sysconfdir}/ctdb/functions
%attr(755,root,root) %{initdir}/ctdb
@@ -104,6 +105,7 @@ fi
%{_docdir}/ctdb/recovery-process.txt
%{_sysconfdir}/ctdb/events.d/00.ctdb
%{_sysconfdir}/ctdb/events.d/10.interface
+%{_sysconfdir}/ctdb/events.d/11.natgw
%{_sysconfdir}/ctdb/events.d/20.multipathd
%{_sysconfdir}/ctdb/events.d/40.vsftpd
%{_sysconfdir}/ctdb/events.d/41.httpd
@@ -128,6 +130,9 @@ fi
%{_includedir}/ctdb_private.h
%changelog
+* Tue Mar 31 2009 : Version 1.0.78
+ - Add a notify mechanism so we can send snmptraps/email to external management systems when the node becomes unhealthy
+ - include 11.natgw eventscript in thew install so that the NATGW feature works
* Tue Mar 31 2009 : Version 1.0.77
- Update the 99.routing eventscript to also try to add the routes (back) during a releaseip event. Similar to the reasons why we must add addresses back during releaseip in 10.interfaces
* Wed Mar 24 2009 : Version 1.0.76
diff --git a/server/ctdb_monitor.c b/server/ctdb_monitor.c
index 21f0382..46d9c63 100644
--- a/server/ctdb_monitor.c
+++ b/server/ctdb_monitor.c
@@ -34,6 +34,74 @@ static void ctdb_check_health(struct event_context *ev, struct timed_event *te,
struct timeval t, void *private_data);
/*
+ setup the notification script
+*/
+int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script)
+{
+ ctdb->notification_script = talloc_strdup(ctdb, script);
+ CTDB_NO_MEMORY(ctdb, ctdb->notification_script);
+ return 0;
+}
+
+static int ctdb_run_notification_script_child(struct ctdb_context *ctdb, const char *event)
+{
+ struct stat st;
+ int ret;
+ char *cmd;
+
+ if (stat(ctdb->notification_script, &st) != 0) {
+ DEBUG(DEBUG_ERR,("Could not stat notification script %s. Can not send notifications.\n", ctdb->notification_script));
+ return -1;
+ }
+ if (!(st.st_mode & S_IXUSR)) {
+ DEBUG(DEBUG_ERR,("Notification script %s is not executable.\n", ctdb->notification_script));
+ return -1;
+ }
+
+ cmd = talloc_asprintf(ctdb, "%s %s\n", ctdb->notification_script, event);
+ CTDB_NO_MEMORY(ctdb, cmd);
+
+ ret = system(cmd);
+ /* if the system() call was successful, translate ret into the
+ return code from the command
+ */
+ if (ret != -1) {
+ ret = WEXITSTATUS(ret);
+ }
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR,("Notification script \"%s\" failed with error %d\n", cmd, ret));
+ }
+
+ return ret;
+}
+
+static void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event)
+{
+ pid_t child;
+
+ if (ctdb->notification_script == NULL) {
+ return;
+ }
+
+ child = fork();
+ if (child == (pid_t)-1) {
+ DEBUG(DEBUG_ERR,("Failed to fork() a notification child process\n"));
+ return;
+ }
+ if (child == 0) {
+ int ret;
+
+ ret = ctdb_run_notification_script_child(ctdb, event);
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR,(__location__ " Notification script failed\n"));
+ }
+ _exit(0);
+ }
+
+ return;
+}
+
+/*
called when a health monitoring event script finishes
*/
static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p)
@@ -55,10 +123,13 @@ static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p)
node->flags |= NODE_FLAGS_DISABLED;
}
+ ctdb_run_notification_script(ctdb, "unhealthy");
} else if (status == 0 && (node->flags & NODE_FLAGS_UNHEALTHY)) {
DEBUG(DEBUG_NOTICE,("monitor event OK - node re-enabled\n"));
node->flags &= ~NODE_FLAGS_UNHEALTHY;
ctdb->monitor->next_interval = 1;
+
+ ctdb_run_notification_script(ctdb, "healthy");
}
next_interval = ctdb->monitor->next_interval;
diff --git a/server/ctdbd.c b/server/ctdbd.c
index 5670b93..de6c39f 100644
--- a/server/ctdbd.c
+++ b/server/ctdbd.c
@@ -33,6 +33,7 @@ static struct {
const char *myaddress;
const char *public_address_list;
const char *event_script_dir;
+ const char *notification_script;
const char *logfile;
const char *recovery_lock_file;
const char *db_dir;
@@ -119,6 +120,7 @@ int main(int argc, const char *argv[])
{ "logfile", 0, POPT_ARG_STRING, &options.logfile, 0, "log file location", "filename" },
{ "nlist", 0, POPT_ARG_STRING, &options.nlist, 0, "node list file", "filename" },
{ "node-ip", 0, POPT_ARG_STRING, &options.node_ip, 0, "node ip", "ip-address"},
+ { "notification-script", 0, POPT_ARG_STRING, &options.notification_script, 0, "notification script", "filename" },
{ "listen", 0, POPT_ARG_STRING, &options.myaddress, 0, "address to listen on", "address" },
{ "transport", 0, POPT_ARG_STRING, &options.transport, 0, "protocol transport", NULL },
{ "dbdir", 0, POPT_ARG_STRING, &options.db_dir, 0, "directory for the tdb files", NULL },
@@ -302,6 +304,14 @@ int main(int argc, const char *argv[])
exit(1);
}
+ if (options.notification_script != NULL) {
+ ret = ctdb_set_notification_script(ctdb, options.notification_script);
+ if (ret == -1) {
+ DEBUG(DEBUG_ALERT,("Unable to setup notification script\n"));
+ exit(1);
+ }
+ }
+
ctdb->do_setsched = !options.no_setsched;
ctdb->do_checkpublicip = !options.no_publicipcheck;
--
CTDB repository
More information about the samba-cvs
mailing list