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(nebstruct_host_check_data
*ds
)
56 old_state
= hash_find(host_states
, ds
->host_name
);
60 state
= malloc(sizeof(*state
));
61 *state
= CAT_STATE(ds
->state
, ds
->state_type
);
62 hash_add(host_states
, ds
->host_name
, state
);
66 return has_state_change(old_state
, ds
->state
, ds
->state_type
);
69 int service_has_new_state(nebstruct_service_check_data
*ds
)
73 old_state
= hash_find2(svc_states
, ds
->host_name
, ds
->service_description
);
77 state
= malloc(sizeof(*state
));
78 *state
= CAT_STATE(ds
->state
, ds
->state_type
);
79 hash_add2(svc_states
, ds
->host_name
, ds
->service_description
, state
);
83 return has_state_change(old_state
, ds
->state
, ds
->state_type
);