test_utils: Indent and prefix test topics
[nagios-reports-module.git] / utils.c
blobc079279f6720460009fdc81ffa37bb46d804c9b0
1 #define NSCORE
2 #include "nagios/objects.h"
3 #include "nagios/broker.h"
4 #include "utils.h"
6 /*
7 * Returns the current downtime depth of the given object.
8 * "type" should always either be NEBTYPE_DOWNTIME_START or
9 * NEBTYPE_DOWNTIME_STOP. In case of NEBTYPE_DOWNTIME_START,
10 * we know the downtime depth is at least 1, so return that.
11 * This nifty little hack make these functions usable with
12 * the import program, for which "find_host()" will always
13 * return NULL.
15 int dt_depth_host(int type, char *host_name)
17 host *hst;
18 int depth = (type == NEBTYPE_DOWNTIME_START);
20 if ((hst = find_host(host_name)))
21 depth += hst->scheduled_downtime_depth;
23 return depth;
26 int dt_depth_svc(int type, char *host_name, char *service_description)
28 service *svc;
29 int depth = (type == NEBTYPE_DOWNTIME_START);
31 if ((svc = find_service(host_name, service_description)))
32 depth += svc->scheduled_downtime_depth;
34 return depth;
37 extern host *host_list, *host_list_tail;
38 extern service *service_list, *service_list_tail;
39 extern sched_info scheduling_info;
41 int prime_initial_states(hash_table *host_states, hash_table *svc_states)
43 host *h;
44 service *s;
45 int *arena, i;
48 * no hosts = no services = nothing to do but warn about it
50 if (!host_list || !scheduling_info.total_hosts) {
51 return 0;
54 i = 0;
55 arena = cget_arena(scheduling_info.total_hosts, sizeof(int));
56 if (!arena)
57 return -1;
59 for (h = host_list; h && h != host_list_tail; h = h->next) {
60 int *state;
61 state = &arena[i];
63 *state = CAT_STATE(h->current_state, h->state_type);
64 hash_add(host_states, h->name, state);
67 i = 0;
68 arena = cget_arena(scheduling_info.total_services, sizeof(int));
69 if (!arena)
70 return -1;
72 for (s = service_list; s && s != service_list_tail; s = s->next) {
73 int *state;
74 state = &arena[i];
76 if (!state)
77 return -1;
79 *state = CAT_STATE(s->current_state, s->state_type);
80 hash_add2(svc_states, s->host_name, s->description, state);
83 return 0;