summaryrefslogtreecommitdiffstats
path: root/src/zabbix_proxy/heart
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-03-14 14:55:37 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-03-14 14:55:37 +0000
commitebec5b63bb5dad1eb3d2badb32e55a319ebca147 (patch)
treeccd9a674a2c9f013369973d221b50cb057bda766 /src/zabbix_proxy/heart
parent9909bafb823b9231e33e569744e2ddb0baa3a294 (diff)
downloadzabbix-ebec5b63bb5dad1eb3d2badb32e55a319ebca147.tar.gz
zabbix-ebec5b63bb5dad1eb3d2badb32e55a319ebca147.tar.xz
zabbix-ebec5b63bb5dad1eb3d2badb32e55a319ebca147.zip
- [DEV-110] Heartbeat messages
git-svn-id: svn://svn.zabbix.com/trunk@5488 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_proxy/heart')
-rw-r--r--src/zabbix_proxy/heart/Makefile.am5
-rw-r--r--src/zabbix_proxy/heart/heart.c116
-rw-r--r--src/zabbix_proxy/heart/heart.h27
3 files changed, 148 insertions, 0 deletions
diff --git a/src/zabbix_proxy/heart/Makefile.am b/src/zabbix_proxy/heart/Makefile.am
new file mode 100644
index 00000000..ff70f185
--- /dev/null
+++ b/src/zabbix_proxy/heart/Makefile.am
@@ -0,0 +1,5 @@
+## Process this file with automake to produce Makefile.in
+
+noinst_LIBRARIES = libzbxheart.a
+
+libzbxheart_a_SOURCES = heart.c heart.h
diff --git a/src/zabbix_proxy/heart/heart.c b/src/zabbix_proxy/heart/heart.c
new file mode 100644
index 00000000..e7bc690a
--- /dev/null
+++ b/src/zabbix_proxy/heart/heart.c
@@ -0,0 +1,116 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "daemon.h"
+#include "log.h"
+#include "zbxjson.h"
+
+#include "heart.h"
+#include "../servercomms.h"
+
+/******************************************************************************
+ * *
+ * Function: process_nodes *
+ * *
+ * Purpose: calculates checks sum of config data *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Aleksander Vladishev *
+ * *
+ * Comments: never returns *
+ * *
+ ******************************************************************************/
+static void send_heartbeat()
+{
+ zbx_sock_t sock;
+ struct zbx_json j;
+ int res;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In process_configuration_sync()");
+
+ zbx_json_init(&j, 128);
+ zbx_json_addstring(&j, "request", ZBX_PROTO_VALUE_PROXY_HEARTBEAT, ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&j, "host", CONFIG_HOSTNAME, ZBX_JSON_TYPE_STRING);
+
+ if (FAIL == connect_to_server(&sock, CONFIG_HEARTBEAT_FREQUENCY)) /* alarm */
+ return;
+
+ if (FAIL == (res = put_data_to_server(&sock, &j)))
+ zabbix_log(LOG_LEVEL_WARNING, "Heartbeat message sendig failed");
+
+ disconnect_server(&sock);
+}
+
+/******************************************************************************
+ * *
+ * Function: main_watchdog_loop *
+ * *
+ * Purpose: periodically send heartbeat message to the server *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: check database availability every 60 seconds (hardcoded) *
+ * *
+ ******************************************************************************/
+void main_heart_loop()
+{
+ struct sigaction phan;
+ int start, sleeptime;
+
+ zabbix_log(LOG_LEVEL_WARNING, "In main_heart_loop()");
+
+ phan.sa_handler = child_signal_handler;
+ sigemptyset(&phan.sa_mask);
+ phan.sa_flags = 0;
+ sigaction(SIGALRM, &phan, NULL);
+
+ if (CONFIG_HEARTBEAT_FREQUENCY == 0) {
+ zbx_setproctitle("heartbeat sender [do nothing]");
+
+ for (;;) /* Do nothing */
+ sleep(3600);
+ }
+
+
+ for (;;) {
+ start = time(NULL);
+
+ zbx_setproctitle("heartbeat sender [sending heartbeat message]");
+
+ send_heartbeat();
+
+ sleeptime = CONFIG_HEARTBEAT_FREQUENCY - (time(NULL) - start);
+
+ if (sleeptime > 0) {
+ zbx_setproctitle("heartbeat sender [sleeping for %d seconds]",
+ sleeptime);
+ zabbix_log(LOG_LEVEL_DEBUG, "Sleeping for %d seconds",
+ sleeptime);
+ sleep(sleeptime);
+ }
+ }
+}
diff --git a/src/zabbix_proxy/heart/heart.h b/src/zabbix_proxy/heart/heart.h
new file mode 100644
index 00000000..6f4e565a
--- /dev/null
+++ b/src/zabbix_proxy/heart/heart.h
@@ -0,0 +1,27 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_HEART_H
+#define ZABBIX_HEART_H
+
+extern int CONFIG_HEARTBEAT_FREQUENCY;
+
+void main_heart_loop();
+
+#endif