1 /***************************************************************************** 2 * 3 * STATUSDATA.H - Header for external status data routines 4 * 5 * 6 * License: 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * 21 *****************************************************************************/ 22 23 #ifndef NAGIOS_STATUSDATA_H_INCLUDED 24 #define NAGIOS_STATUSDATA_H_INCLUDED 25 26 #include "common.h" 27 #include "objects.h" 28 29 #ifdef NSCGI 30 #define READ_PROGRAM_STATUS 1 31 #define READ_HOST_STATUS 2 32 #define READ_SERVICE_STATUS 4 33 #define READ_CONTACT_STATUS 8 34 35 #define READ_ALL_STATUS_DATA READ_PROGRAM_STATUS | READ_HOST_STATUS | READ_SERVICE_STATUS | READ_CONTACT_STATUS 36 37 38 39 /*************************** CHAINED HASH LIMITS ***************************/ 40 41 #define SERVICESTATUS_HASHSLOTS 1024 42 #define HOSTSTATUS_HASHSLOTS 1024 43 44 45 /**************************** DATA STRUCTURES ******************************/ 46 47 NAGIOS_BEGIN_DECL 48 49 /* HOST STATUS structure */ 50 typedef struct hoststatus_struct { 51 char *host_name; 52 char *plugin_output; 53 char *long_plugin_output; 54 char *perf_data; 55 int status; 56 time_t last_update; 57 int has_been_checked; 58 int should_be_scheduled; 59 int current_attempt; 60 int max_attempts; 61 time_t last_check; 62 time_t next_check; 63 int check_options; 64 int check_type; 65 time_t last_state_change; 66 time_t last_hard_state_change; 67 int last_hard_state; 68 time_t last_time_up; 69 time_t last_time_down; 70 time_t last_time_unreachable; 71 int state_type; 72 time_t last_notification; 73 time_t next_notification; 74 int no_more_notifications; 75 int notifications_enabled; 76 int problem_has_been_acknowledged; 77 int acknowledgement_type; 78 int current_notification_number; 79 int accept_passive_checks; 80 int event_handler_enabled; 81 int checks_enabled; 82 int flap_detection_enabled; 83 int is_flapping; 84 double percent_state_change; 85 double latency; 86 double execution_time; 87 int scheduled_downtime_depth; 88 int process_performance_data; 89 int obsess; 90 struct hoststatus_struct *next; 91 struct hoststatus_struct *nexthash; 92 } hoststatus; 93 94 95 /* SERVICE STATUS structure */ 96 typedef struct servicestatus_struct { 97 char *host_name; 98 char *description; 99 char *plugin_output; 100 char *long_plugin_output; 101 char *perf_data; 102 int max_attempts; 103 int current_attempt; 104 int status; 105 time_t last_update; 106 int has_been_checked; 107 int should_be_scheduled; 108 time_t last_check; 109 time_t next_check; 110 int check_options; 111 int check_type; 112 int checks_enabled; 113 time_t last_state_change; 114 time_t last_hard_state_change; 115 int last_hard_state; 116 time_t last_time_ok; 117 time_t last_time_warning; 118 time_t last_time_unknown; 119 time_t last_time_critical; 120 int state_type; 121 time_t last_notification; 122 time_t next_notification; 123 int no_more_notifications; 124 int notifications_enabled; 125 int problem_has_been_acknowledged; 126 int acknowledgement_type; 127 int current_notification_number; 128 int accept_passive_checks; 129 int event_handler_enabled; 130 int flap_detection_enabled; 131 int is_flapping; 132 double percent_state_change; 133 double latency; 134 double execution_time; 135 int scheduled_downtime_depth; 136 int process_performance_data; 137 int obsess; 138 struct servicestatus_struct *next; 139 struct servicestatus_struct *nexthash; 140 } servicestatus; 141 142 143 /*************************** SERVICE STATES ***************************/ 144 145 #define SERVICE_PENDING 1 146 #define SERVICE_OK 2 147 #define SERVICE_WARNING 4 148 #define SERVICE_UNKNOWN 8 149 #define SERVICE_CRITICAL 16 150 151 152 153 /**************************** HOST STATES ****************************/ 154 155 #define HOST_PENDING 1 156 #define SD_HOST_UP 2 157 #define SD_HOST_DOWN 4 158 #define SD_HOST_UNREACHABLE 8 159 160 /* Convert the (historically ordered) host states into a notion of "urgency". 161 This is defined as, in ascending order: 162 SD_HOST_UP (business as usual) 163 HOST_PENDING (waiting for - supposedly first - check result) 164 SD_HOST_UNREACHABLE (a problem, but likely not its cause) 165 SD_HOST_DOWN (look here!!) 166 The exact values are irrelevant, so I try to make the conversion as 167 CPU-efficient as possible: */ 168 #define HOST_URGENCY(hs) ((hs)|(((hs)&0x5)<<1)) 169 170 171 172 /**************************** FUNCTIONS ******************************/ 173 174 int read_status_data(const char *, int); /* reads all status data */ 175 int add_host_status(hoststatus *); /* adds a host status entry to the list in memory */ 176 int add_service_status(servicestatus *); /* adds a service status entry to the list in memory */ 177 178 int add_hoststatus_to_hashlist(hoststatus *); 179 int add_servicestatus_to_hashlist(servicestatus *); 180 181 servicestatus *find_servicestatus(char *, char *); /* finds status information for a specific service */ 182 hoststatus *find_hoststatus(char *); /* finds status information for a specific host */ 183 int get_servicestatus_count(char *, int); /* gets total number of services of a certain type for a specific host */ 184 185 void free_status_data(void); /* free all memory allocated to status data */ 186 #endif 187 188 #ifndef NSCGI 189 int initialize_status_data(const char *); /* initializes status data at program start */ 190 int update_all_status_data(void); /* updates all status data */ 191 int cleanup_status_data(int); /* cleans up status data at program termination */ 192 int update_program_status(int); /* updates program status data */ 193 int update_host_status(host *, int); /* updates host status data */ 194 int update_service_status(service *, int); /* updates service status data */ 195 int update_contact_status(contact *, int); /* updates contact status data */ 196 #endif 197 198 NAGIOS_END_DECL 199 #endif 200