import.c: Check if host is interesting in case no service is
[nagios-reports-module.git] / utils.c
blobadc9c97c63c479ad130bf77bd66d99f159a3eb1c
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 fprintf(stderr, "No host_list or total_hosts = 0, so nothing to do\n");
52 return 0;
55 i = 0;
56 arena = cget_arena(scheduling_info.total_hosts, sizeof(int));
57 if (!arena)
58 return -1;
60 for (h = host_list; h && h != host_list_tail; h = h->next) {
61 int *state;
62 state = &arena[i];
64 *state = CAT_STATE(h->current_state, h->state_type);
65 hash_add(host_states, h->name, state);
68 i = 0;
69 arena = cget_arena(scheduling_info.total_services, sizeof(int));
70 if (!arena)
71 return -1;
73 for (s = service_list; s && s != service_list_tail; s = s->next) {
74 int *state;
75 state = &arena[i];
77 if (!state)
78 return -1;
80 *state = CAT_STATE(s->current_state, s->state_type);
81 hash_add2(svc_states, s->host_name, s->description, state);
84 return 0;