diff --git a/src/lyskom/Makefile b/src/lyskom/Makefile index 0255c75f341765d780bd03cd8e81b9c5d80bc71c..fbc27e53c1c5adca823204f012327d74d162fd86 100644 --- a/src/lyskom/Makefile +++ b/src/lyskom/Makefile @@ -8,10 +8,10 @@ boo: @echo "Enter 'make linux' or 'make solaris'" linux: - $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" all + $(MAKE) LIBS="-lrt" CC="$(CC)" CFLAGS="$(CFLAGS)" all solaris: - $(MAKE) LIBS="-lnsl -lsocket" CC="$(CC)" CFLAGS="$(CFLAGS)" all + $(MAKE) LIBS="-lrt -lnsl -lsocket" CC="$(CC)" CFLAGS="$(CFLAGS)" all all: notify_lyskom check_lyskom diff --git a/src/lyskom/check_lyskom.c b/src/lyskom/check_lyskom.c index 39b096389f76031d3539ff13ae72437dd7b864aa..68ec916d0009c9fcb0963948d50e9dc43b2d4c01 100644 --- a/src/lyskom/check_lyskom.c +++ b/src/lyskom/check_lyskom.c @@ -16,6 +16,10 @@ #include "lyskom.h" +#ifndef CLOCK_HIGHRES +#define CLOCK_HIGHRES CLOCK_REALTIME +#endif + char *host = "130.236.254.15"; int port = 4894; @@ -26,8 +30,15 @@ char *pass = NULL; char *argv0 = "check_lyskom"; +double time_crit = 2.0; /* 2 seconds */ +double time_warn = 1.0; /* 1 second */ + +double resp_crit = 1.0; /* 1 second */ +double resp_warn = 0.1; /* 0.1 seconds */ + int clients_crit = 10000; int clients_warn = 1000; + int rqclients_crit = 10; int rqclients_warn = 2; @@ -45,8 +56,83 @@ error(const char *msg, ...) } +int +time_get(const char *str, + double *t) +{ + char c1, c2; + int rc; + c1 = c2 = 0; + + rc = sscanf(str, "%lf%c%c", t, &c1, &c2); + if (rc >= 2) + { + switch (c1) + { + case 'h': + *t *= 60*60; + break; + + case 'm': + switch (c2) + { + case 0: + *t *= 60; + break; + case 's': + *t /= 1000.0; + break; + default: + return -1; + } + break; + + case 's': + break; + + case 'u': + case '�': + *t /= 1000000.0; + break; + + default: + return -1; + } + } + + if (rc > 0) + return 0; + + return -1; +} + + +char * +t2unit(double t) +{ + if (t > 60) + return "m"; + if (t < 0.0001) + return "�s"; + if (t < 0.1) + return "ms"; + return "s"; +} + +double +t2vis(double t) +{ + if (t > 60) + return t/60.0; + if (t < 0.0001) + return t*1000000.0; + if (t < 0.1) + return t*1000.0; + return t; +} + int main(int argc, char *argv[]) @@ -59,6 +145,8 @@ main(int argc, int proto; char *ksoft, *kver; #endif + struct timespec ts1, ts2; + double rd; argv0 = strdup(argv[0]); @@ -93,25 +181,69 @@ main(int argc, break; case 'c': - if (sscanf(argv[i]+2, "%u", &clients_crit) != 1) - error("Invalid argument: %s", argv[i]); + switch (argv[i][2]) + { + case 'c': + if (sscanf(argv[i]+3, "%u", &clients_crit) != 1) + error("Invalid argument: %s", argv[i]); + break; + case 'w': + if (sscanf(argv[i]+3, "%u", &clients_warn) != 1) + error("Invalid argument: %s", argv[i]); + break; + default: + error("Invalid switch: %s", argv[i]); + } break; - case 'w': - if (sscanf(argv[i]+2, "%u", &clients_warn) != 1) - error("Invalid argument: %s", argv[i]); + case 'q': + switch (argv[i][2]) + { + case 'c': + if (sscanf(argv[i]+3, "%u", &rqclients_crit) != 1) + error("Invalid argument: %s", argv[i]); + break; + case 'w': + if (sscanf(argv[i]+3, "%u", &rqclients_warn) != 1) + error("Invalid argument: %s", argv[i]); + break; + default: + error("Invalid switch: %s", argv[i]); + } break; - - case 'C': - if (sscanf(argv[i]+2, "%u", &rqclients_crit) != 1) - error("Invalid argument: %s", argv[i]); + + case 't': + switch (argv[i][2]) + { + case 'c': + if (time_get(argv[i]+3, &time_crit)) + error("Invalid argument: %s", argv[i]); + break; + case 'w': + if (time_get(argv[i]+3, &time_warn)) + error("Invalid argument: %s", argv[i]); + break; + default: + error("Invalid switch: %s", argv[i]); + } break; - - case 'W': - if (sscanf(argv[i]+2, "%u", &rqclients_warn) != 1) - error("Invalid argument: %s", argv[i]); + + case 'r': + switch (argv[i][2]) + { + case 'c': + if (time_get(argv[i]+3, &resp_crit)) + error("Invalid argument: %s", argv[i]); + break; + case 'w': + if (time_get(argv[i]+3, &resp_warn)) + error("Invalid argument: %s", argv[i]); + break; + default: + error("Invalid switch: %s", argv[i]); + } break; - + case 'h': printf("Usage: %s [options]\n", argv[0]); puts("Options:"); @@ -119,10 +251,14 @@ main(int argc, puts("\t-P<lyskom-server-port>"); puts("\t-u<lyskom-userid>"); puts("\t-p<password>"); - puts("\t-c<clients-connected-critical-level>"); - puts("\t-w<clients-connected-warning-level>"); - puts("\t-C<clients-runqueue-critical-level>"); - puts("\t-W<clients-runqueue-warning-level>"); + puts("\t-cc<clients-connected-critical-level>"); + puts("\t-cw<clients-connected-warning-level>"); + puts("\t-qc<clients-runqueue-critical-level>"); + puts("\t-qw<clients-runqueue-warning-level>"); + puts("\t-tc<system-time-offset-critical-level>"); + puts("\t-tw<system-time-offset-warning-level>"); + puts("\t-rc<response-time-critical-level>"); + puts("\t-rw<response-time-warning-level>"); return 0; default: @@ -138,28 +274,20 @@ main(int argc, if (kom_login(user, pass ? pass : "") != 0) error("Login failed: User=%u", user); } - + + clock_gettime(CLOCK_HIGHRES, &ts1); rc = kom_time(&tmb); + clock_gettime(CLOCK_HIGHRES, &ts2); if (rc != 0) error("Request failed: Server Time: rc=%u", rc); lyskom_t = mktime(&tmb); time(&our_t); - d = fabs(difftime(lyskom_t, our_t)); - if (d > 60.0) - { - printf("CRITICAL - Server time is %d minute(s) off\n", (int) (d/60.0)); - return 1; - } + rd = ((double) (ts2.tv_sec-ts1.tv_sec) + + (double)(ts2.tv_nsec-ts1.tv_nsec)/1000000000.0); - if (d > 1.0) - { - printf("WARNING - Server time is %d second(s) off\n", (int) d); - return 1; - } - #if 0 if (kom_version(&proto, &ksoft, &kver) != 0) error("Request failed: Server version"); @@ -167,34 +295,59 @@ main(int argc, if (kom_clients(&clients_c) != 0) error("Request failed: Connected clients"); + if (kom_runqueue(&clients_rq) != 0) + error("Request failed: Clients in run-queue"); + + + if (d > time_crit) + { + printf("CRITICAL - Server time is %f second(s) off\n", d); + return 1; + } + + if (clients_rq > rqclients_crit) + { + printf("CRITICAL - Clients in run-queue: %u\n", clients_rq); + return 2; + } + if (clients_c > clients_crit) { printf("CRITICAL - Connected clients: %u\n", clients_c); return 2; } - if (clients_c > clients_warn) + if (rd > resp_crit) { - printf("WARNING - Connected clients: %u\n", clients_c); + printf("CRITICAL - Response time is %f %s\n", t2vis(rd), t2unit(rd)); return 1; } - - if (kom_runqueue(&clients_rq) != 0) - error("Request failed: Clients in run-queue"); - if (clients_rq > rqclients_crit) + if (d > time_warn) { - printf("CRITICAL - Clients in run-queue: %u\n", clients_rq); - return 2; + printf("WARNING - Server time is %f second(s) off\n", d); + return 1; } - + if (clients_rq > rqclients_warn) { printf("WARNING - Clients in run-queue: %u\n", clients_rq); return 1; } - printf("OK - Clients: %u (%u in run-queue), Time: %s", - clients_c, clients_rq, asctime(&tmb)); + if (clients_c > clients_warn) + { + printf("WARNING - Connected clients: %u\n", clients_c); + return 1; + } + + if (rd > resp_warn) + { + printf("WARNING - Response time is %f %s\n", t2vis(rd), t2unit(rd)); + return 1; + } + + printf("OK - Resp: %.2f %s, Clients: %u (%u in run-queue), Time: %s", + t2vis(rd), t2unit(rd), clients_c, clients_rq, asctime(&tmb)); return 0; }