Clean impl of stats
This commit is contained in:
Родитель
5d1f56faf0
Коммит
f5ac7d71b1
|
@ -11,6 +11,7 @@
|
|||
#include "commands/help.h"
|
||||
#include "commands/notifications.h"
|
||||
#include "commands/problems.h"
|
||||
#include "commands/stats.h"
|
||||
#include "commands/status.h"
|
||||
|
||||
// COMMANDS
|
||||
|
@ -46,6 +47,7 @@ commands[] = {
|
|||
{ "unacknowledge", nez_cmd_unacknowledge },
|
||||
{ "problems", nez_cmd_problems },
|
||||
{ "muted", nez_cmd_show_muted },
|
||||
{ "stats", nez_cmd_stats},
|
||||
};
|
||||
|
||||
nez_handler_t
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#include <nagios/nagios.h>
|
||||
|
||||
#include "../helper.h"
|
||||
|
||||
#include "stats.h"
|
||||
|
||||
int
|
||||
nez_cmd_stats(int sd, char* object, char* rest)
|
||||
{
|
||||
// we take no arguments
|
||||
(void)object;
|
||||
(void)rest;
|
||||
|
||||
// track object counts
|
||||
int ok = 0;
|
||||
int warning = 0;
|
||||
int critical = 0;
|
||||
int unknown = 0;
|
||||
|
||||
for (service* svc = service_list; svc; svc = svc->next) {
|
||||
switch(svc->current_state) {
|
||||
case STATE_OK:
|
||||
ok++;
|
||||
break;
|
||||
case STATE_WARNING:
|
||||
warning++;
|
||||
break;
|
||||
case STATE_CRITICAL:
|
||||
critical++;
|
||||
break;
|
||||
case STATE_UNKNOWN:
|
||||
unknown++;
|
||||
break;;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nsock_printf_nul(sd,
|
||||
"ok: %d, warning: %d, critical: %d, unknown: %d",
|
||||
ok,
|
||||
warning,
|
||||
critical,
|
||||
unknown);
|
||||
|
||||
return 200;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef NEZ_COMMANDS_STATS_H
|
||||
#define NEZ_COMMANDS_STATS_H
|
||||
|
||||
int
|
||||
nez_cmd_stats(int sd, char* object, char* rest);
|
||||
|
||||
#endif NEZ_COMMANDS_STATS_H
|
Загрузка…
Ссылка в новой задаче