/* * Copyright (C) 2008 Groundwork Open Source * Written by Daniel Emmanuel Feinsmith * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301, USA. * * File: bronx.h * Author: dfeinsmith * * Created on July 11, 2007, 1:31 PM */ #ifndef _BRONX_H #define _BRONX_H // Set DEBUG to 1 if you want a profusion of output in your [nagios.log] and console, // otherwise, set it to 0, and it will complain only when there is something wrong. #define DEBUG 1 // Define off64_t for non-64-bit platforms, for use with apr 1.0 or higher #ifndef off64_t #define off64_t long #endif /* Include SQLite3 Engine */ #include "sqlite3.h" /* include some other NAGIOS stuff as well */ #define NSCORE #include "config.h" #include "common.h" #include "nagios.h" #include "objects.h" #include "statusdata.h" /* Generic includes */ #include // Include our types #include // Include support for our FIFO Special Files #include // Include support for our sockets #include #include #include #include /* Include required APR libraries */ #include #include #include #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif // VARIOUS #define BRONX_STALE_TIMEOUT (unsigned long)300 // OUR TYPES #define MSG_TYPE_HOST_STATUS 1 #define MSG_TYPE_SERVICE_STATUS 2 #define MSG_TYPE_SYSTEM_CONFIG 3 #define MSG_TYPE_NAGIOS_LOG 4 #define MSG_TYPE_ACKNOWLEDGEMENT 5 #define MSG_TYPE_NOTIFICATION 6 // OUR ERRORS #define BRONX_EINVALIDTYPE 1 // What are the columns in our message table #define BRONXDB_ID_COL 0 #define BRONXDB_MESSAGE_COL 1 #define BRONXDB_TIMESTAMP_COL 2 typedef struct last_object_state_struc { int last_state; int last_state_type; } last_object_state; /* Our message structure declaration */ struct message_struc { apr_pool_t *pool; int type; // Type of Message. apr_hash_t *properties; // Hash Table. }; typedef struct message_struc message; /* A structure to hold a result id. populated when executing a sql select statement and iterating through the results. */ struct resultid_struc { char *id; apr_pool_t *pool; }; typedef struct resultid_struc resultid; struct bronx_metric_struc { apr_pool_t *pool; char host_name[MAX_HOSTNAME_LENGTH+1]; char svc_description[MAX_SERVICEDESC_LENGTH+1]; char plugin_output[MAX_PLUGINOUTPUT_LENGTH+1]; time_t check_time; int return_code; }; typedef struct bronx_metric_struc bronx_metric; /* * Includes. */ #include "bronx_route.h" #include "bronx_config.h" #include "bronx_log.h" // Global Data. extern int _bronx_terminating; extern time_t _bronx_start_time; extern int _bronx_paused; extern int _bronx_manually_paused; // Pool and Queue Data. extern apr_thread_mutex_t *_queue_mutex; extern apr_queue_t *_queue; // Routing Data. extern apr_thread_cond_t *_route_thread_cond_signal; extern int _msg_sequence; /* Two thread handlers to our threads */ extern apr_thread_t *_thread_router; extern apr_thread_t *_thread_listener; /* Configuration Data */ extern configuration_criteria *_configuration; // CALLBACKS extern int processStatus(int, void *); extern int processHostCheck(int, void *); extern int processServiceCheck(int, void *); extern int processAcknowledgement(int cmd, void *data); extern int processCommand(int cmd, void *data); extern int processExternalCommand(int cmd, void *data); extern int processDowntime(int cmd, void *data); extern int processProcessData(int cmd, void *data); extern int processContactNotification(int cmd, void *data); extern int processProgramStatus(int cmd, void *data); // SYSTEM extern int is_bronx_paused(); extern int is_bronx_in_startup_pause(); extern void set_bronx_paused(int); extern void set_bronx_manually_paused(int); // MESSAGE HANDLING extern apr_status_t routes_init(); extern int route_message_from_database(void *param, int colCount, char **values, char **names); extern apr_status_t route_file_init(route_definition *route); extern void route_manage_inbound(); extern apr_status_t assert_routes_initialized(configuration_criteria *config); extern void generate_host_properties(host *hst, apr_pool_t *pool, apr_hash_t *properties, int); extern void generate_service_properties(service *svc, apr_pool_t *pool, apr_hash_t *properties); extern void generate_log_message_properties(host *hst, apr_pool_t *pool, apr_hash_t *properties); extern apr_status_t assert_route_connect(route_definition *route); extern apr_status_t assert_tcp_connect(route_definition *route); extern apr_status_t assert_file_connect(route_definition *route); extern int routes_initialized(); // THREAD HANDLING extern apr_status_t threads_init(); extern void assert_threads_running(configuration_criteria *); extern int threads_running(); // UTILITY FUNCTIONS (found in bronx_utils.c) extern char *pstrreplace(apr_pool_t* mp, const char* str, const char* needle1, const char* needle2 ); extern char *strcleanup(apr_pool_t *tempmp, char *str); extern char *datetostring(apr_pool_t*, time_t time); // Helper function to convert time_t to string in iso format extern void normalize_plugin_output(char *plugin_output, char *source); extern void filter_message(route_definition *route, message *msg); extern void admin_execute_nagios_command(char *buffer); extern int nagios_level(int); extern int parse_bool(char *varvalue, int *result, int line); // QUEUE FUNCTIONS extern apr_status_t queue_init(); extern void queue_uninit(); extern apr_status_t queue_push_message(int type, apr_pool_t *pool, apr_hash_t* properties, char *source); extern apr_pool_t *queue_pool(); // PROCESSOR FUNCTIONS extern apr_status_t processors_init(); extern void processors_uninit(); // DATABASE FUNCTIONALITY extern apr_status_t database_initialize(configuration_criteria *config, route_definition *route); extern int process_backup_data(); extern int process_all_databases(), route_message_from_database(void *, int colCount, char **, char **); extern void database_purge(route_definition *route); extern void database_purge_and_shutoff_backups(route_definition *route, char *error_msg); int database_set_dirty_callback(void *, int, char **, char **); extern int database_get_any_routes_dirty(); extern int add_message_to_route_databases(message *msg); // MARSHALLING FUNCTIONALITY extern char *marshall_properties(route_definition *route, message *msg), *marshall_properties_to_xml(message *msg); // LISTENER extern void listener_thread_exit(char *cause_string, int return_code); extern apr_status_t submit_check_result_to_nagios(char *host_name, char *svc_description, int return_code, char *plugin_output, time_t check_time); extern apr_status_t _submit_check_result_to_nagios(char *host_name, char *svc_description, int return_code, char *plugin_output, time_t check_time); extern int submit_command_to_nagios(char *cmd); extern void manage_connections(); extern void accept_connection(int sock, void *unused); extern void handle_connection(int sock, void *data); extern void handle_connection_read(int sock, void *data); extern int post_check_result(char *, char *, int , char *, time_t); extern apr_status_t admin_execute_command(configuration_criteria *, char *cmd); extern int is_bronx_paused(); extern int is_bronx_in_startup_pause(); // NAGIOS extern host *auto_add_nagios_host(service *mirror_svc, char *host_name); extern service * auto_add_nagios_service(service *mirror_svc, host *hst, char *svc_description); extern int auto_add(char *host_name, char *svc_description); extern service * find_service_only(char *svc_description); extern void auto_add_harvest_queue(); #ifdef __cplusplus } #endif #endif /* _BRONX_H */