-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdowntime.c
More file actions
102 lines (81 loc) · 2.64 KB
/
Copy pathdowntime.c
File metadata and controls
102 lines (81 loc) · 2.64 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <string.h>
#include <nagios/downtime.h>
#include <nagios/nagios.h>
#include "../helper.h"
#include "downtime.h"
static int
schedule_downtime_for_obj(int sd, host* hst, service* svc, unsigned long minutes, char* comment_data, int fixed)
{
if (hst || svc) {
int typedowntime = (svc ? SERVICE_DOWNTIME : HOST_DOWNTIME);
char* hst_name = (svc ? svc->host_name : hst->name);
char* svc_name = (svc ? svc->description : NULL);
time_t entry_time = time(NULL);
char* author = "nagioseasier";
time_t start_time = time(NULL);
time_t end_time = 0L; /* only used for fixed downtime */
unsigned long triggered_by = 0L; /* assume triggered by no obj in system? */
unsigned long duration = minutes * 60L; /* assuming duration is seconds */
unsigned long downtime_id = 0L;
end_time = start_time + duration;
if (svc_name) {
nsock_printf_nul(sd, "SCHEDULED %lu MINUTES OF DOWNTIME FOR %s/%s WITH MESSAGE: %s\n", minutes, hst_name, svc_name, comment_data);
} else {
nsock_printf_nul(sd, "SCHEDULED %lu MINUTES OF DOWNTIME FOR %s WITH MESSAGE: %s\n", minutes, hst_name, comment_data);
}
int retval = schedule_downtime(typedowntime,
hst_name,
svc_name,
entry_time,
author,
comment_data,
start_time,
end_time,
fixed,
triggered_by,
duration,
&downtime_id);
return (retval == OK ? 200 : 400);
}
return 404;
}
int
cmd_schedule_downtime(int sd, char* object, char* rest, int fixed)
{
unsigned long minutes;
char* comment_data;
// assume the next argument is number of minutes
if (rest) {
if ((comment_data = strchr(rest, ' '))) {
*(comment_data++) = 0;
}
minutes = strtoul(rest, NULL, 10);
}
minutes = (minutes > 1 ? minutes : 15L);
host* hst;
service* svc;
nez_find_host_or_service(object, &hst, &svc);
if (svc) {
schedule_downtime_for_obj(sd, NULL, svc, minutes, comment_data, fixed);
return 200;
}
if (hst) {
schedule_downtime_for_obj(sd, hst, NULL, minutes, comment_data, fixed);
for (servicesmember* svcmem = hst->services; svcmem; svcmem = svcmem->next) {
schedule_downtime_for_obj(sd, NULL, svcmem->service_ptr, minutes, comment_data, fixed);
}
return 200;
}
nsock_printf_nul(sd, "NO HOST OR SERVICE FOUND FOR: %s", object);
return 404;
}
int
nez_cmd_schedule_flex_downtime(int sd, char* object, char *rest)
{
cmd_schedule_downtime(sd, object, rest, 0);
}
int
nez_cmd_schedule_fixed_downtime(int sd, char* object, char *rest)
{
cmd_schedule_downtime(sd, object, rest, 1);
}