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
|
#include "../../uwsgi.h"
extern struct uwsgi_server uwsgi;
int use_nagios = 0;
struct uwsgi_option nagios_options[] = {
{"nagios", no_argument, 0, "nagios check", uwsgi_opt_true, &use_nagios, UWSGI_OPT_NO_INITIAL},
{0, 0, 0, 0, 0, 0, 0},
};
int nagios() {
struct uwsgi_header uh;
char *buf = NULL;
if (!use_nagios) {
return 1;
}
if (!uwsgi.sockets) {
fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n");
exit(3);
}
int fd = uwsgi_connect(uwsgi.sockets->name, uwsgi.socket_timeout, 0);
if (fd < 0) {
fprintf(stdout, "UWSGI CRITICAL: could not connect() to workers %s\n", strerror(errno));
if (errno == EPERM || errno == EACCES) {
exit(3);
}
exit(2);
}
uh.modifier1 = UWSGI_MODIFIER_PING;
uh.pktsize = 0;
uh.modifier2 = 0;
if (write(fd, &uh, 4) != 4) {
uwsgi_error("write()");
fprintf(stdout, "UWSGI CRITICAL: could not send ping packet to workers\n");
exit(2);
}
int ret = uwsgi_read_response(fd, &uh, uwsgi.socket_timeout, &buf);
if (ret == -2) {
fprintf(stdout, "UWSGI CRITICAL: timed out waiting for response\n");
exit(2);
}
else if (ret == -1) {
fprintf(stdout, "UWSGI CRITICAL: error reading response\n");
exit(2);
}
else {
if (uh.pktsize > 0 && buf) {
fprintf(stdout, "UWSGI WARNING: %.*s\n", uh.pktsize, buf);
exit(1);
}
else {
fprintf(stdout, "UWSGI OK: armed and ready\n");
exit(0);
}
}
// never here
fprintf(stdout, "UWSGI UNKNOWN: probably you hit a bug of uWSGI !!!\n");
exit(3);
}
struct uwsgi_plugin nagios_plugin = {
.name = "nagios",
.options = nagios_options,
.init = nagios,
};
|