2 * Copyright(C) 2005,2007 op5 AB
5 * See LICENSE.GPL for license details
7 * This code is taken from the mrm project and modified to suit
8 * the ndbneb database logger
16 #include "nagios/broker.h"
18 * sql_query() arguments are usually both numerous and extremely long,
19 * and the idiom is common enough that we want to shorten the syntax
20 * as much as possible, so do that with this macro
22 #define RQ return sql_query
23 #define esc(s) sql_escape(s)
30 int hook_host_result(int cb
, void *data
)
32 nebstruct_host_check_data
*ds
= (nebstruct_host_check_data
*)data
;
34 /* ignore unprocessed and passive checks */
35 if (ds
->type
!= NEBTYPE_HOSTCHECK_PROCESSED
||
36 cb
!= NEBCALLBACK_HOST_CHECK_DATA
)
41 linfo("Check result processed for host '%s'", ds
->host_name
);
43 if (!host_has_new_state(ds
)) {
44 linfo("state not changed for host '%s'", ds
->host_name
);
49 "timestamp, event_type, host_name, state, "
51 ") VALUES(%lu, %d, '%s', %d, %d, %d, '%s')",
53 ds
->timestamp
.tv_sec
, ds
->type
, esc(ds
->host_name
), ds
->state
,
54 ds
->state_type
== HARD_STATE
, ds
->current_attempt
,
58 int hook_service_result(int cb
, void *data
)
60 nebstruct_service_check_data
*ds
= (nebstruct_service_check_data
*)data
;
62 /* ignore unprocessed and passive checks */
63 if (ds
->type
!= NEBTYPE_SERVICECHECK_PROCESSED
64 || cb
!= NEBCALLBACK_SERVICE_CHECK_DATA
)
69 linfo("Check result processed for service '%s' on host '%s'",
70 ds
->service_description
, ds
->host_name
);
72 if (!service_has_new_state(ds
)) {
73 linfo("state not changed for service '%s' on host '%s'",
74 ds
->service_description
, ds
->host_name
);
79 "timestamp, event_type, host_name, service_description, state, "
80 "hard, retry, output) "
81 "VALUES(%lu, %d, '%s', '%s', '%d', '%d', '%d', '%s')",
83 ds
->timestamp
.tv_sec
, ds
->type
, esc(ds
->host_name
),
84 esc(ds
->service_description
), ds
->state
,
85 ds
->state_type
== HARD_STATE
, ds
->current_attempt
,
89 int hook_downtime(int cb
, void *data
)
91 nebstruct_downtime_data
*ds
= (nebstruct_downtime_data
*)data
;
95 case NEBTYPE_DOWNTIME_START
:
96 case NEBTYPE_DOWNTIME_STOP
:
102 if (ds
->service_description
) {
103 depth
= dt_depth_svc(ds
->type
, ds
->host_name
, ds
->service_description
);
105 linfo("Inserting service downtime entry");
107 "(timestamp, event_type, host_name,"
108 "service_description, downtime_depth) "
109 "VALUES(%lu, %d, '%s', '%s', %d)",
111 ds
->timestamp
.tv_sec
, ds
->type
, esc(ds
->host_name
),
112 esc(ds
->service_description
), depth
);
115 depth
= dt_depth_host(ds
->type
, ds
->host_name
);
116 linfo("Inserting host downtime_data");
118 "(timestamp, event_type, host_name, downtime_depth)"
119 "VALUES(%lu, %d, '%s', %d)",
121 ds
->timestamp
.tv_sec
, ds
->type
, esc(ds
->host_name
), depth
);
124 int hook_process_data(int cb
, void *data
)
126 nebstruct_process_data
*ds
= (nebstruct_process_data
*)data
;
129 case NEBTYPE_PROCESS_START
:
130 case NEBTYPE_PROCESS_SHUTDOWN
:
132 case NEBTYPE_PROCESS_RESTART
:
133 ds
->type
= NEBTYPE_PROCESS_SHUTDOWN
;
139 linfo("Logging Monitor process %s event",
140 ds
->type
== NEBTYPE_PROCESS_START
? "START" : "STOP");
142 RQ("INSERT INTO %s(timestamp, event_type) "
144 sql_table_name(), ds
->timestamp
.tv_sec
, ds
->type
);