4 #include "mrln_logging.h"
5 #include <nagios/lib/dkhash.h>
7 #define HOST_STATES_HASH_BUCKETS 4096
8 #define SERVICE_STATES_HASH_BUCKETS (HOST_STATES_HASH_BUCKETS * 4)
9 static dkhash_table
*host_states
, *svc_states
;
13 host_states
= dkhash_create(HOST_STATES_HASH_BUCKETS
);
17 svc_states
= dkhash_create(SERVICE_STATES_HASH_BUCKETS
);
27 static inline int has_state_change(int *old
, int state
, int type
)
30 * A state change is considered to consist of a change
31 * to either state_type or state, so we OR the two
32 * together to form a complete state. This will make
33 * the module log as follows:
34 * service foo;poo is HARD OK initially
35 * service foo;poo goes to SOFT WARN, attempt 1 (logged)
36 * service foo;poo goes to SOFT WARN, attempt 2 (not logged)
37 * service foo;poo goes to HARD WARN (logged)
39 state
= CAT_STATE(state
, type
);
48 int host_has_new_state(char *host
, int state
, int type
)
53 lerr("host_has_new_state() called with NULL host");
56 old_state
= dkhash_get(host_states
, host
, NULL
);
60 cur_state
= malloc(sizeof(*cur_state
));
61 *cur_state
= CAT_STATE(state
, type
);
62 dkhash_insert(host_states
, strdup(host
), NULL
, 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
)
74 lerr("service_has_new_state() called with NULL host");
78 lerr("service_has_new_state() called with NULL desc");
81 old_state
= dkhash_get(svc_states
, host
, desc
);
85 cur_state
= malloc(sizeof(*cur_state
));
86 *cur_state
= CAT_STATE(state
, type
);
87 dkhash_insert(svc_states
, strdup(host
), strdup(desc
), cur_state
);
91 return has_state_change(old_state
, state
, type
);