6 #define HOST_STATES_HASH_BUCKETS 4096
7 #define SERVICE_STATES_HASH_BUCKETS (HOST_STATES_HASH_BUCKETS * 4)
10 * The hooks are called from broker.c in Nagios.
12 static hash_table
*host_states
;
13 static hash_table
*svc_states
;
17 host_states
= hash_init(HOST_STATES_HASH_BUCKETS
);
21 svc_states
= hash_init(SERVICE_STATES_HASH_BUCKETS
);
28 return prime_initial_states(host_states
, svc_states
);
31 static inline int has_state_change(int *old
, int state
, int type
)
34 * A state change is considered to consist of a change
35 * to either state_type or state, so we OR the two
36 * together to form a complete state. This will make
37 * the module log as follows:
38 * service foo;poo is HARD OK initially
39 * service foo;poo goes to SOFT WARN, attempt 1 (logged)
40 * service foo;poo goes to SOFT WARN, attempt 2 (not logged)
41 * service foo;poo goes to HARD WARN (logged)
43 state
= CAT_STATE(state
, type
);
52 int host_has_new_state(char *host
, int state
, int type
)
56 old_state
= hash_find(host_states
, host
);
60 cur_state
= malloc(sizeof(*cur_state
));
61 *cur_state
= CAT_STATE(state
, type
);
62 hash_add(host_states
, host
, cur_state
);
66 return has_state_change(old_state
, state
, type
);
69 int service_has_new_state(char *host
, char *desc
, int state
, int type
)
73 old_state
= hash_find2(svc_states
, host
, desc
);
77 cur_state
= malloc(sizeof(*cur_state
));
78 *cur_state
= CAT_STATE(state
, type
);
79 hash_add2(svc_states
, host
, desc
, cur_state
);
83 return has_state_change(old_state
, state
, type
);