Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-who committed Feb 11, 2024
1 parent f0c0dbf commit b84dfec
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spit/sat.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,48 @@ void *receiver(void *arg) {
keyvalueSetLong(kv, "NodesGood", nodesGood);
keyvalueSetLong(kv, "NodesBad", nodesBad);

char *json = keyvalueDumpAsJSON(kv);
if (socksend(connfd, json, 0, 1) < 0) {
perror("socksendcluster");
}
free(json);
keyvalueFree(kv);
} else if (strncmp(buffer,"bad",3)==0) {
keyvalueType *kv = keyvalueInit();
size_t nodesGood = 0, nodesBad = 0;
for (int cc = 0; cc < tc->cluster->id; cc++) {
if (timeAsDouble() - tc->cluster->node[cc]->seen <= 10) {
nodesGood++;
} else {
nodesBad++;
char str[100];
sprintf(str, "badNode%02zd", nodesBad);
keyvalueSetString(kv, str, tc->cluster->node[cc]->nodename);
sprintf(str, "badNode%02zd_ip", nodesBad);
keyvalueSetString(kv, str, tc->cluster->node[cc]->ipaddress);
}
}
char *json = keyvalueDumpAsJSON(kv);
if (socksend(connfd, json, 0, 1) < 0) {
perror("socksendcluster");
}
free(json);
keyvalueFree(kv);
} else if (strncmp(buffer,"good",4)==0) {
keyvalueType *kv = keyvalueInit();
size_t nodesGood = 0, nodesBad = 0;
for (int cc = 0; cc < tc->cluster->id; cc++) {
if (timeAsDouble() - tc->cluster->node[cc]->seen <= 10) {
nodesGood++;
char str[100];
sprintf(str, "goodNode%02zd", nodesGood);
keyvalueSetString(kv, str, tc->cluster->node[cc]->nodename);
sprintf(str, "goodNode%02zd_ip", nodesGood);
keyvalueSetString(kv, str, tc->cluster->node[cc]->ipaddress);
} else {
nodesBad++;
}
}
char *json = keyvalueDumpAsJSON(kv);
if (socksend(connfd, json, 0, 1) < 0) {
perror("socksendcluster");
Expand Down
26 changes: 26 additions & 0 deletions spit/stush.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ COMMAND commands[] = {
{"authqr", "Show the TOTP QR code", "admin"},
{"authset", "Set the TOTP key", "admin"},
{"authtok", "Show the current TOTP token", "admin"},
{"bad", "Show bad cluster noes", ""},
{"booking", "Manage bookings", "admin"},
{"cidr", "Handy CIDR calc", ""},
{"cluster", "Show Cluster info", ""},
Expand All @@ -239,6 +240,7 @@ COMMAND commands[] = {
{"dropbear", "Dropbear SSH config", "admin"},
{"entropy", "Calc entropy of a string", ""},
{"env", "List environment variables", "admin"},
{"good", "Show good cluster noes", ""},
{"h2d", "Hex to decimal", ""},
{"host", "Convert hostname to IP", ""},
{"hwserial", "Unique HW serial", "admin"},
Expand Down Expand Up @@ -572,6 +574,26 @@ void cmd_sum(const int tty) {
sockclose(fd);
}

void cmd_clusternodes(const int tty, int good) {
if (tty) {}
int fd = sockconnect("127.0.0.1", 1600, 10);
if (fd > 0) {
if (socksend(fd, good ? "good\n" : "bad\n", 0, 1)) {
char *buffer = calloc(1024, 1); assert(buffer);
int ret;
while ((ret = sockrec(fd, buffer, 1024, 0, 1)) > 0) {
printf("%s", buffer);
}
free(buffer);
} else {
perror("socksend2");
}
} else {
perror("connect");
}
sockclose(fd);
}

void cmd_cluster(const int tty) {
if (tty) {}
int fd = sockconnect("127.0.0.1", 1600, 5);
Expand Down Expand Up @@ -1686,6 +1708,10 @@ int run_command(const int tty, char *line, const char *username, const char *hos
cmd_cidr(tty, rest);
} else if (strcasecmp(commands[i].name, "sum") == 0) {
cmd_sum(tty);
} else if (strcasecmp(commands[i].name, "good") == 0) {
cmd_clusternodes(tty, 1);
} else if (strcasecmp(commands[i].name, "bad") == 0) {
cmd_clusternodes(tty, 0);
} else if (strcasecmp(commands[i].name, "cluster") == 0) {
cmd_cluster(tty);
} else if (strcasecmp(commands[i].name, "mailserver") == 0) {
Expand Down

0 comments on commit b84dfec

Please sign in to comment.