summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-03-25 00:03:20 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-03-25 00:03:20 (GMT)
commit38458154d1d5e61294f7461debf1a3add1123380 (patch)
tree9903f86ec83c7d20eec4fc442122497eade16350 /switchctl.c
parent537fcc5aaf66c9cba993af12f4f2a8b04c36dde1 (diff)
added command for health status
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/switchctl.c b/switchctl.c
index e62a5a5..7ccfabd 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -233,8 +233,6 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
send_response(client->fd, buf[0]);
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 status to %d additional listeners", listener_cnt);
@@ -564,10 +562,52 @@ int process_cmd_heartbeat(const char* param, int fd, cmd_t **cmd_q, client_t* cl
return 0;
}
+int send_health_status(int fd, client_t* client_lst)
+{
+ bool mc, sc, hmc, hsc;
+ mc = sc = hmc = hsc = 0;
+
+ client_t* client;
+ for(client = client_lst; client; client = client->next) {
+ switch(client->type) {
+ case MASTER: mc=1; break;
+ case STANDBY: sc=1; break;
+ case HB_MASTER: hmc=1; break;
+ case HB_STANDBY: hsc=1; break;
+ default: break;
+ }
+ }
+
+ 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(fd >= 0) {
+ send_response(fd, buf[0]);
+ send_response(fd, buf[1]);
+ send_response(fd, buf[2]);
+ send_response(fd, buf[3]);
+ }
+
+ int listener_cnt = 0;
+ for(client = client_lst; client; client = client->next)
+ if(client->health_listener && client->fd != fd) {
+ send_response(client->fd, buf[0]);
+ send_response(client->fd, buf[1]);
+ send_response(client->fd, buf[2]);
+ send_response(client->fd, buf[3]);
+ listener_cnt++;
+ }
+ log_printf(DEBUG, "sent health info to %d additional listeners", listener_cnt);
+ return 0;
+}
+
int process_cmd_health(const char* param, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt)
{
send_response(fd, "EEE: health not yet implemented!");
- return 0;
+ return send_health_status(fd, client_lst);
}
void process_cmd_listen(const char* param, int fd, client_t* client_lst)
@@ -939,6 +979,7 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
return_value = nonblock_recvline(&(lst->buffer), lst->fd, &cmd_q, client_lst, opt);
if(return_value == 2) {
log_printf(DEBUG, "removing closed command connection (fd=%d)", lst->fd);
+ send_health_status(-1, client_lst);
client_t* deletee = lst;
lst = lst->next;
FD_CLR(deletee->fd, &readfds);