1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*
** 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;
zabbix_log(LOG_LEVEL_DEBUG, "In send_heartbeat()");
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 == 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_DEBUG, "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);
}
}
}
|