summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/switchctl.c b/switchctl.c
index f4a8b0e..5396d3d 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -358,7 +358,7 @@ int process_cmd_channel(const char* cmd, const char* param, int fd, cmd_t **cmd_
return 0;
}
-int send_health_status(int fd, client_t* client_lst)
+int update_send_health_status(int fd, client_t* client_lst)
{
bool mc, sc, hmc, hsc;
mc = sc = hmc = hsc = 0;
@@ -374,17 +374,22 @@ int send_health_status(int fd, client_t* client_lst)
}
}
- char buf[4][50];
- snprintf(buf[0], 50, "Master: %s", (mc) ? "connected" : "offline");
- snprintf(buf[1], 50, "Standby: %s", (sc) ? "connected" : "offline");
- snprintf(buf[2], 50, "Hearbeat Master: %s,%s", (hmc) ? "connected" : "offline", (state_.hb_state_master_) ? "present" : "offline");
- snprintf(buf[3], 50, "Hearbeat Standby: %s,%s", (hsc) ? "connected" : "offline", (state_.hb_state_standby_) ? "present" : "offline");
+ if(!hmc) state_.hb_state_master_ = 0;
+ if(!hsc) state_.hb_state_standby_ = 0;
+
+ char buf[5][50];
+ snprintf(buf[0], 50, "Health: %s", (mc && sc && hmc && hsc && state_.hb_state_master_ && state_.hb_state_standby_) ? "ok" : "error");
+ snprintf(buf[1], 50, "Master: %s", (mc) ? "connected" : "offline");
+ snprintf(buf[2], 50, "Standby: %s", (sc) ? "connected" : "offline");
+ snprintf(buf[3], 50, "Hearbeat Master: %s, %s", (hmc) ? "connected" : "offline", (state_.hb_state_master_) ? "present" : "timeout");
+ snprintf(buf[4], 50, "Hearbeat Standby: %s, %s", (hsc) ? "connected" : "offline", (state_.hb_state_standby_) ? "present" : "timeout");
if(fd >= 0) {
send_response(fd, buf[0]);
send_response(fd, buf[1]);
send_response(fd, buf[2]);
send_response(fd, buf[3]);
+ send_response(fd, buf[4]);
}
int listener_cnt = 0;
@@ -394,6 +399,7 @@ int send_health_status(int fd, client_t* client_lst)
send_response(client->fd, buf[1]);
send_response(client->fd, buf[2]);
send_response(client->fd, buf[3]);
+ send_response(client->fd, buf[4]);
listener_cnt++;
}
log_printf(DEBUG, "sent health info to %d additional listeners", listener_cnt);
@@ -424,7 +430,7 @@ void process_cmd_type(const char* param, int fd, client_t* client_lst)
return;
}
log_printf(DEBUG, "client %d type set to %s", fd, param);
- send_health_status(-1, client_lst);
+ update_send_health_status(-1, client_lst);
}
else {
log_printf(ERROR, "unable to set client type for %d: type already set to %s", fd, client_type_tostring(client->type));
@@ -548,7 +554,7 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
break;
}
}
- send_health_status(-1, client_lst);
+ update_send_health_status(-1, client_lst);
switchctl_mode_t old_mode = state_.mode_;
if(state_.mode_ == MODE_MASTER) {
if(!state_.hb_state_master_) {
@@ -580,7 +586,7 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
int process_cmd_health(const char* param, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt)
{
- return send_health_status(fd, client_lst);
+ return update_send_health_status(fd, client_lst);
}
void process_cmd_listen(const char* param, int fd, client_t* client_lst)
@@ -956,7 +962,7 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
lst = lst->next;
FD_CLR(deletee->fd, &readfds);
client_remove(&client_lst, deletee->fd);
- send_health_status(-1, client_lst);
+ update_send_health_status(-1, client_lst);
return_value = 0;
continue;
}