7 #define HOST_STATES_HASH_BUCKETS 4096
8 #define SERVICE_STATES_HASH_BUCKETS (HOST_STATES_HASH_BUCKETS * 4)
11 * The hooks are called from broker.c in Nagios.
13 static hash_table
*host_states
;
14 static hash_table
*svc_states
;
18 host_states
= hash_init(HOST_STATES_HASH_BUCKETS
);
22 svc_states
= hash_init(SERVICE_STATES_HASH_BUCKETS
);
29 return prime_initial_states(host_states
, svc_states
);
32 static inline int has_state_change(int *old
, int state
, int type
)
35 * A state change is considered to consist of a change
36 * to either state_type or state, so we OR the two
37 * together to form a complete state. This will make
38 * the module log as follows:
39 * service foo;poo is HARD OK initially
40 * service foo;poo goes to SOFT WARN, attempt 1 (logged)
41 * service foo;poo goes to SOFT WARN, attempt 2 (not logged)
42 * service foo;poo goes to HARD WARN (logged)
44 state
= CAT_STATE(state
, type
);
53 int host_has_new_state(char *host
, int state
, int type
)
57 old_state
= hash_find(host_states
, host
);
61 cur_state
= malloc(sizeof(*cur_state
));
62 *cur_state
= CAT_STATE(state
, type
);
63 hash_add(host_states
, strdup(host
), cur_state
);
67 return has_state_change(old_state
, state
, type
);
70 int service_has_new_state(char *host
, char *desc
, int state
, int type
)
74 old_state
= hash_find2(svc_states
, host
, desc
);
78 cur_state
= malloc(sizeof(*cur_state
));
79 *cur_state
= CAT_STATE(state
, type
);
80 hash_add2(svc_states
, strdup(host
), strdup(desc
), cur_state
);
84 return has_state_change(old_state
, state
, type
);