28 #ifndef MONITORING_DEFS_H_
29 #define MONITORING_DEFS_H_
51 #define STATUS_FLAG(status_type) (1<<(unsigned int)status_type)
53 #define FIRST_STATUS 0
57 #define DOM_ELEMENT_STATUS_MESSAGE_NAME "StatusMessage"
58 #define DOM_ELEMENT_STATE_NAME "State"
59 #define DOM_ELEMENT_STATE_LEVEL_NAME "StateLevel"
60 #define DOM_ELEMENT_STATE_DESCRIPTION_NAME "StateDescription"
62 #define MAX_DESCRIPTION_LENGTH 50
63 #define MONITORING_SERVER_PORT 8080
64 #define XML_STATUS_MESSAGE_MAX_SIZE 3000
66 #define XML_STATUS_MESSAGE_START "<StatusMessage>"
67 #define HTTP_ANSWER_PREFIX_FORMAT "HTTP/1.1 200 OK\nContent-Length: %u\nConnection: close\nContent-Type: text/xml; charset=UTF-8\n\n"
69 #define HTTP_ANSWER_PREFIX_MAX_LENGTH 100
85 #define NR_STATUS_TYPES stat_all
101 st_pay_aiInit, st_pay_aiShutdown,
102 st_pay_biAvailable, st_pay_biUnreachable, st_pay_biPermanentlyUnreachable,
103 st_pay_dbError, st_pay_dbErrorBiUnreachable, st_pay_dbErrorBiPermanentlyUnreachable,
125 ev_pay_aiInited = 0, ev_pay_aiShutdown,
126 ev_pay_biConnectionSuccess, ev_pay_biConnectionFailure, ev_pay_biConnectionCriticalSubseqFailures,
127 ev_pay_dbConnectionSuccess, ev_pay_dbConnectionFailure,
138 #define PAYMENT_STATUS_NAME "PaymentStatus"
139 #define NR_PAYMENT_STATES st_pay_overall
140 #define NR_PAYMENT_EVENTS ev_pay_overall
143 #define NETWORKING_STATUS_NAME "NetworkingStatus"
144 #define NR_NETWORKING_STATES st_net_overall
145 #define NR_NETWORKING_EVENTS ev_net_overall
147 #define SYSTEM_STATUS_NAME "SystemStatus"
148 #define NR_SYSTEM_STATES st_sys_overall
149 #define NR_SYSTEM_EVENTS ev_sys_overall
185 #define NR_STATE_LEVELS stl_all
189 "OK",
"WARNING",
"CRITICAL",
"UNKNOWN"
221 #define FINISH_STATE_DEFINITIONS(state_array) \
222 FINISH_NETWORKING_STATE_DEFINITIONS(state_array) \
223 FINISH_PAYMENT_STATE_DEFINITIONS(state_array) \
224 FINISH_SYSTEM_STATE_DEFINITIONS(state_array)
226 #define FINISH_EVENT_DEFINITIONS(event_array) \
227 FINISH_NETWORKING_EVENT_DEFINITIONS(event_array) \
228 FINISH_PAYMENT_EVENT_DEFINITIONS(event_array) \
229 FINISH_SYSTEM_EVENT_DEFINITIONS(event_array)
235 #define FINISH_NETWORKING_STATE_DEFINITIONS(state_array) \
236 NET_STATE_DEF(state_array, st_net_entry, \
237 "networking entry state", \
238 TRANS_NET_ENTRY, stl_unknown) \
239 NET_STATE_DEF(state_array, st_net_firstMixInit,\
240 "first mix initialized", \
241 TRANS_NET_FIRST_MIX_INIT, stl_warning) \
242 NET_STATE_DEF(state_array, st_net_firstMixConnectedToNext, \
243 "first mix connected to next mix", \
244 TRANS_NET_FIRST_MIX_CONNECTED_TO_NEXT, stl_warning) \
245 NET_STATE_DEF(state_array, st_net_firstMixOnline, \
246 "first mix online", \
247 TRANS_NET_FIRST_MIX_ONLINE, stl_ok) \
248 NET_STATE_DEF(state_array, st_net_middleMixInit, \
249 "middle mix initialized", \
250 TRANS_NET_MIDDLE_MIX_INIT, stl_warning) \
251 NET_STATE_DEF(state_array, st_net_middleMixConnectedToPrev, \
252 "middle mix connected to previous mix", \
253 TRANS_NET_MIDDLE_MIX_CONNECTED_TO_PREV, stl_warning) \
254 NET_STATE_DEF(state_array, st_net_middleMixConnectedToNext, \
255 "middle mix connected to next mix", \
256 TRANS_NET_MIDDLE_MIX_CONNECTED_TO_NEXT, stl_warning) \
257 NET_STATE_DEF(state_array, st_net_middleMixOnline, \
258 "middle mix online", \
259 TRANS_NET_MIDDLE_MIX_ONLINE, stl_ok) \
260 NET_STATE_DEF(state_array, st_net_lastMixInit, \
261 "last mix initialized", \
262 TRANS_NET_LAST_MIX_INIT, stl_warning) \
263 NET_STATE_DEF(state_array, st_net_lastMixConnectedToPrev, \
264 "last mix connected to previous mix", \
265 TRANS_NET_LAST_MIX_CONNECTED_TO_PREV, stl_warning) \
266 NET_STATE_DEF(state_array, st_net_lastMixOnline, \
268 TRANS_NET_LAST_MIX_ONLINE, stl_ok)
271 #define FINISH_NETWORKING_EVENT_DEFINITIONS(event_array) \
272 NET_EVENT_DEF(event_array, ev_net_firstMixInited, \
273 "first mix initialization finished") \
274 NET_EVENT_DEF(event_array, ev_net_middleMixInited, \
275 "middle mix initialization finished") \
276 NET_EVENT_DEF(event_array, ev_net_lastMixInited, \
277 "last mix initialization finished") \
278 NET_EVENT_DEF(event_array, ev_net_prevConnected, \
279 "connection to previous mix established") \
280 NET_EVENT_DEF(event_array, ev_net_nextConnected, \
281 "connection to next mix established") \
282 NET_EVENT_DEF(event_array, ev_net_keyExchangePrevSuccessful, \
283 "key exchange with previous mix successful") \
284 NET_EVENT_DEF(event_array, ev_net_keyExchangeNextSuccessful, \
285 "key exchange with next mix successful") \
286 NET_EVENT_DEF(event_array, ev_net_keyExchangePrevFailed, \
287 "key exchange with previous mix failed") \
288 NET_EVENT_DEF(event_array, ev_net_keyExchangeNextFailed, \
289 "key exchange with next mix failed") \
290 NET_EVENT_DEF(event_array, ev_net_prevConnectionClosed, \
291 "connection to previous mix closed") \
292 NET_EVENT_DEF(event_array, ev_net_nextConnectionClosed, \
293 "connection to next mix closed")
300 #define FINISH_PAYMENT_STATE_DEFINITIONS(state_array) \
301 PAY_STATE_DEF(state_array, st_pay_entry, \
302 "payment entry state", \
303 TRANS_PAY_ENTRY, stl_unknown) \
304 PAY_STATE_DEF(state_array, st_pay_aiInit, \
305 "accounting instance initialized", \
306 TRANS_PAY_AI_INIT, stl_ok) \
307 PAY_STATE_DEF(state_array, st_pay_aiShutdown, \
308 "accounting instance shutdown", \
309 TRANS_PAY_AI_SHUTDOWN, stl_critical) \
310 PAY_STATE_DEF(state_array, st_pay_biAvailable, \
311 "payment instance available", \
312 TRANS_PAY_BI_AVAILABLE, stl_ok) \
313 PAY_STATE_DEF(state_array, st_pay_biUnreachable, \
314 "payment instance temporarily unreachable", \
315 TRANS_PAY_BI_UNREACHABLE, stl_warning) \
316 PAY_STATE_DEF(state_array, st_pay_biPermanentlyUnreachable, \
317 "payment instance permanently unreachable", \
318 TRANS_PAY_BI_PERMANENTLY_UNREACHABLE, stl_critical) \
319 PAY_STATE_DEF(state_array, st_pay_dbError, \
320 "pay DB cannot be accessed ", \
321 TRANS_PAY_DB_ERROR, stl_critical) \
322 PAY_STATE_DEF(state_array, st_pay_dbErrorBiUnreachable, \
323 "pay DB cannot be accessed and Payment Instance temporarily unreachable", \
324 TRANS_PAY_DB_ERROR_BI_UNREACHABLE, stl_critical) \
325 PAY_STATE_DEF(state_array, st_pay_dbErrorBiPermanentlyUnreachable, \
326 "pay DB cannot be accessed and Payment Instance permanently unreachable", \
327 TRANS_PAY_DB_ERROR_BI_PERMANENTLY_UNREACHABLE, stl_critical)
330 #define FINISH_PAYMENT_EVENT_DEFINITIONS(event_array) \
331 PAY_EVENT_DEF(event_array, ev_pay_aiInited, \
332 "accounting instance initialization finished") \
333 PAY_EVENT_DEF(event_array, ev_pay_aiShutdown, \
334 "accounting instance shutdown finished") \
335 PAY_EVENT_DEF(event_array, ev_pay_biConnectionSuccess, \
336 "successfully connected to payment instance") \
337 PAY_EVENT_DEF(event_array, ev_pay_biConnectionFailure, \
338 "connection to payment instance failed") \
339 PAY_EVENT_DEF(event_array, ev_pay_biConnectionCriticalSubseqFailures, \
340 "connection to payment instance failed permanently") \
341 PAY_EVENT_DEF(event_array, ev_pay_dbConnectionSuccess, \
342 "pay DB access successful") \
343 PAY_EVENT_DEF(event_array, ev_pay_dbConnectionFailure, \
344 "pay DB access failed")
346 #define FINISH_PAYMENT_STATE_DEFINITIONS(state_array)
347 #define FINISH_PAYMENT_EVENT_DEFINITIONS(event_array)
354 #define FINISH_SYSTEM_STATE_DEFINITIONS(state_array) \
355 SYS_STATE_DEF(state_array, st_sys_entry, \
356 "system entry state", \
357 TRANS_SYS_ENTRY, stl_unknown) \
358 SYS_STATE_DEF(state_array, st_sys_initializing, \
359 "mix is initializing", \
360 TRANS_SYS_INITIALIZING, stl_warning) \
361 SYS_STATE_DEF(state_array, st_sys_operating, \
362 "mix is operating", \
363 TRANS_SYS_OPERATING, stl_ok) \
364 SYS_STATE_DEF(state_array, st_sys_restarting, \
365 "mix is restarting", \
366 TRANS_SYS_RESTARTING, stl_warning) \
367 SYS_STATE_DEF(state_array, st_sys_shuttingDown, \
368 "mix is shutting down", \
369 TRANS_SYS_SHUTTING_DOWN, stl_critical) \
370 SYS_STATE_DEF(state_array, st_sys_ShuttingDownAfterSegFault, \
371 "mix is shutting down due to a segmentation fault!", \
372 TRANS_SYS_SHUTTING_DOWN_AFTER_SEG_FAULT, stl_critical)
375 #define FINISH_SYSTEM_EVENT_DEFINITIONS(event_array) \
376 SYS_EVENT_DEF(event_array, ev_sys_start, \
378 SYS_EVENT_DEF(event_array, ev_sys_enterMainLoop, \
379 "mix entering main loop") \
380 SYS_EVENT_DEF(event_array, ev_sys_leavingMainLoop, \
381 "mix leaving main loop") \
382 SYS_EVENT_DEF(event_array, ev_sys_sigTerm, \
383 "mix caught SIG_TERM") \
384 SYS_EVENT_DEF(event_array, ev_sys_sigInt, \
385 "mix caught SIG_INT") \
386 SYS_EVENT_DEF(event_array, ev_sys_sigSegV, \
387 "mix caught SIG_SEGV")
390 #define NET_STATE_DEF(state_array, state_type, description, transitions, stateLevel) \
391 STATE_DEF(state_array, stat_networking, state_type, description, transitions, stateLevel)
393 #define NET_EVENT_DEF(event_array, event_type, description) \
394 EVENT_DEF(event_array, stat_networking, event_type, description)
397 #define PAY_STATE_DEF(state_array, state_type, description, transitions, stateLevel) \
398 STATE_DEF(state_array, stat_payment, state_type, description, transitions, stateLevel)
400 #define PAY_EVENT_DEF(event_array, event_type, description) \
401 EVENT_DEF(event_array, stat_payment, event_type, description)
403 #define PAY_STATE_DEF(state_array, state_type, description, transitions, stateLevel)
404 #define PAY_EVENT_DEF(event_array, event_type, description)
407 #define SYS_STATE_DEF(state_array, state_type, description, transitions, stateLevel) \
408 STATE_DEF(state_array, stat_system, state_type, description, transitions, stateLevel)
410 #define SYS_EVENT_DEF(event_array, event_type, description) \
411 EVENT_DEF(event_array, stat_system, event_type, description)
416 #define STATE_DEF(state_array, status_type, state_type, description, transitions, stateLevel) \
417 state_array[status_type][state_type]->st_description = (char *) description; \
418 state_array[status_type][state_type]->st_transitions = transitions; \
419 state_array[status_type][state_type]->st_stateLevel = stateLevel;
421 #define EVENT_DEF(event_array, status_type, event_type, description) \
422 event_array[status_type][event_type]->ev_description = (char *) description;
440 #define TRANS_NET_ENTRY \
441 (defineTransitions(stat_networking, 3, \
442 ev_net_firstMixInited, st_net_firstMixInit, \
443 ev_net_middleMixInited, st_net_middleMixInit, \
444 ev_net_lastMixInited, st_net_lastMixInit))
447 #define TRANS_NET_FIRST_MIX_INIT \
448 (defineTransitions(stat_networking, 1, \
449 ev_net_nextConnected, st_net_firstMixConnectedToNext))
452 #define TRANS_NET_FIRST_MIX_CONNECTED_TO_NEXT \
453 (defineTransitions(stat_networking, 2, \
454 ev_net_keyExchangeNextSuccessful, st_net_firstMixOnline, \
455 ev_net_nextConnectionClosed, st_net_firstMixInit))
458 #define TRANS_NET_FIRST_MIX_ONLINE \
459 (defineTransitions(stat_networking, 1, \
460 ev_net_nextConnectionClosed, st_net_firstMixInit))
463 #define TRANS_NET_MIDDLE_MIX_INIT \
464 (defineTransitions(stat_networking, 1, \
465 ev_net_prevConnected, st_net_middleMixConnectedToPrev))
468 #define TRANS_NET_MIDDLE_MIX_CONNECTED_TO_PREV \
469 (defineTransitions(stat_networking, 2, \
470 ev_net_nextConnected, st_net_middleMixConnectedToNext, \
471 ev_net_prevConnectionClosed, st_net_middleMixInit))
474 #define TRANS_NET_MIDDLE_MIX_CONNECTED_TO_NEXT \
475 (defineTransitions(stat_networking, 4, \
476 ev_net_keyExchangeNextFailed, st_net_middleMixInit, \
477 ev_net_keyExchangePrevFailed, st_net_middleMixInit, \
478 ev_net_keyExchangeNextSuccessful, st_net_middleMixConnectedToNext, \
479 ev_net_keyExchangePrevSuccessful, st_net_middleMixOnline))
482 #define TRANS_NET_MIDDLE_MIX_ONLINE \
483 (defineTransitions(stat_networking, 2, \
484 ev_net_prevConnectionClosed, st_net_middleMixInit, \
485 ev_net_nextConnectionClosed, st_net_middleMixInit))
488 #define TRANS_NET_LAST_MIX_INIT \
489 (defineTransitions(stat_networking, 1, \
490 ev_net_prevConnected, st_net_lastMixConnectedToPrev))
493 #define TRANS_NET_LAST_MIX_CONNECTED_TO_PREV \
494 (defineTransitions(stat_networking, 2, \
495 ev_net_keyExchangePrevFailed, st_net_lastMixInit, \
496 ev_net_keyExchangePrevSuccessful, st_net_lastMixOnline))
500 #define TRANS_NET_LAST_MIX_ONLINE \
501 (defineTransitions(stat_networking, 1, \
502 ev_net_prevConnectionClosed, st_net_lastMixInit))
509 #define TRANS_PAY_ENTRY \
510 (defineTransitions(stat_payment, 1, \
511 ev_pay_aiInited, st_pay_aiInit))
514 #define TRANS_PAY_AI_INIT \
515 (defineTransitions(stat_payment, 4, \
516 ev_pay_aiShutdown, st_pay_aiShutdown, \
517 ev_pay_biConnectionSuccess, st_pay_biAvailable, \
518 ev_pay_biConnectionFailure, st_pay_biUnreachable, \
519 ev_pay_dbConnectionFailure, st_pay_dbError))
522 #define TRANS_PAY_AI_SHUTDOWN \
523 (defineTransitions(stat_payment, 1, \
524 ev_pay_aiInited, st_pay_aiInit))
527 #define TRANS_PAY_BI_AVAILABLE \
528 (defineTransitions(stat_payment, 3, \
529 ev_pay_aiShutdown, st_pay_aiShutdown, \
530 ev_pay_biConnectionFailure, st_pay_biUnreachable, \
531 ev_pay_dbConnectionFailure, st_pay_dbError))
534 #define TRANS_PAY_BI_UNREACHABLE \
535 (defineTransitions(stat_payment, 4, \
536 ev_pay_aiShutdown, st_pay_aiShutdown, \
537 ev_pay_biConnectionSuccess, st_pay_biAvailable, \
538 ev_pay_biConnectionCriticalSubseqFailures, st_pay_biPermanentlyUnreachable, \
539 ev_pay_dbConnectionFailure, st_pay_dbErrorBiUnreachable))
542 #define TRANS_PAY_BI_PERMANENTLY_UNREACHABLE \
543 (defineTransitions(stat_payment, 3, \
544 ev_pay_aiShutdown, st_pay_aiShutdown, \
545 ev_pay_biConnectionSuccess, st_pay_biAvailable, \
546 ev_pay_dbConnectionFailure, st_pay_dbErrorBiPermanentlyUnreachable))
549 #define TRANS_PAY_DB_ERROR \
550 (defineTransitions(stat_payment, 2, \
551 ev_pay_aiShutdown, st_pay_aiShutdown, \
552 ev_pay_dbConnectionSuccess, st_pay_aiInit))
555 #define TRANS_PAY_DB_ERROR_BI_UNREACHABLE \
556 (defineTransitions(stat_payment, 2, \
557 ev_pay_aiShutdown, st_pay_aiShutdown, \
558 ev_pay_dbConnectionSuccess, st_pay_biUnreachable))
561 #define TRANS_PAY_DB_ERROR_BI_PERMANENTLY_UNREACHABLE \
562 (defineTransitions(stat_payment, 2, \
563 ev_pay_aiShutdown, st_pay_aiShutdown, \
564 ev_pay_dbConnectionSuccess, st_pay_biPermanentlyUnreachable))
571 #define TRANS_SYS_ENTRY \
572 (defineTransitions(stat_system, 1, \
573 ev_sys_start, st_sys_initializing))
576 #define TRANS_SYS_INITIALIZING \
577 (defineTransitions(stat_system, 4, \
578 ev_sys_enterMainLoop, st_sys_operating, \
579 ev_sys_sigTerm, st_sys_shuttingDown, \
580 ev_sys_sigInt, st_sys_shuttingDown, \
581 ev_sys_sigSegV, st_sys_ShuttingDownAfterSegFault))
584 #define TRANS_SYS_OPERATING \
585 (defineTransitions(stat_system, 4, \
586 ev_sys_leavingMainLoop, st_sys_restarting, \
587 ev_sys_sigTerm, st_sys_shuttingDown, \
588 ev_sys_sigInt, st_sys_shuttingDown, \
589 ev_sys_sigSegV, st_sys_ShuttingDownAfterSegFault))
592 #define TRANS_SYS_RESTARTING \
593 (defineTransitions(stat_system, 4, \
594 ev_sys_enterMainLoop, st_sys_operating, \
595 ev_sys_sigTerm, st_sys_shuttingDown, \
596 ev_sys_sigInt, st_sys_shuttingDown, \
597 ev_sys_sigSegV, st_sys_ShuttingDownAfterSegFault))
600 #define TRANS_SYS_SHUTTING_DOWN \
601 (defineTransitions(stat_system, 1, \
602 ev_sys_sigSegV, st_sys_ShuttingDownAfterSegFault))
605 #define TRANS_SYS_SHUTTING_DOWN_AFTER_SEG_FAULT \
606 (defineTransitions(stat_system, 0))
transition_t * defineTransitions(status_type_t s_type, int transitionCount,...)
a convenience function for easily defining state transitions
#define NR_NETWORKING_EVENTS
#define SYSTEM_STATUS_NAME
enum state_type transition_t
@ ev_net_nextConnectionClosed
@ ev_net_keyExchangePrevSuccessful
@ ev_net_prevConnectionClosed
@ ev_net_keyExchangeNextSuccessful
@ ev_net_keyExchangePrevFailed
@ ev_net_keyExchangeNextFailed
@ st_net_lastMixConnectedToPrev
@ st_net_middleMixConnectedToPrev
@ st_sys_ShuttingDownAfterSegFault
@ st_net_firstMixConnectedToNext
@ st_net_middleMixConnectedToNext
enum state_level state_level_t
enum state_type state_type_t
#define NR_NETWORKING_STATES
enum event_type event_type_t
enum status_type status_type_t
#define NETWORKING_STATUS_NAME
status_type_t ev_statusType
transition_t * st_transitions
status_type_t st_statusType
state_level_t st_stateLevel