1 /*
2  * Copyright (C) 2006 Folkert van Heusden <folkert@vanheusden.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  *
17  */
18 
19 #define TYPE_IGNORE	0
20 #define TYPE_HOST	1
21 #define TYPE_SERVICE	2
22 
23 #define V1_0_MAX_ELEMENTS	32
24 
25 #define VARTYPE_PCHAR	0
26 #define VARTYPE_INT	1
27 #define VARTYPE_TIMET	2
28 #define VARTYPE_DOUBLE	3
29 
30 #define STATS_OFFSET(x)	(int)(offsetof(struct stats, x))
31 
32 #define ST_HARD			1
33 #define ST_SOFT			0
34 
35 struct v2_0_config
36 {
37 	char *str;
38 	int offset;
39 	int type;
40 };
41 
42 struct stats
43 {
44 	int type;
45 
46 	char *host_name;
47 	int current_state;
48 	char *service_description;
49 	char *plugin_output;
50 	time_t last_state_change;
51 	int active_checks_enabled;
52 	int passive_checks_enabled;
53 	int notifications_enabled;
54 	int problem_has_been_acknowledged;
55 	double scheduled_downtime_depth;
56 	int state_type;
57 	int last_hard_state;
58         double percent_state_change;
59         double check_execution_time;
60         double check_latency;
61 	int modified_attributes;
62 	int event_handler;
63 	int has_been_checked;
64 	int should_be_scheduled;
65 	int current_attempt;
66 	int max_attempts;
67 	int last_hard_state_change;
68 	int last_time_ok;
69 	int last_time_warning;
70 	int last_time_unknown;
71 	int last_time_critical;
72 	time_t last_check;
73 	time_t next_check;
74 	int check_type;
75 	double current_notification_number;
76 	int last_notification;
77 	int next_notification;
78 	int no_more_notifications;
79 	int event_handler_enabled;
80 	int acknowledgement_type;
81 	int flap_detection_enabled;
82 	int failure_prediction_enabled;
83 	int process_performance_data;
84 	int obsess_over_service;
85 	int obsess_over_host;
86 	time_t last_update;
87 	int is_flapping;
88 	char * performance_data;
89 	char * check_command;
90 	int last_time_up;
91 	int last_time_down;
92 	int last_time_unreachable;
93 	/* newly added in 3.0 */
94 	char *author;
95 	double check_interval;
96 	int check_options;
97 	char *check_period;
98 	char *comment_data;
99 	int comment_id;
100 	int current_event_id;
101 	int current_notification_id;
102 	int current_problem_id;
103 	time_t entry_time;
104 	int entry_type;
105 	int expires;
106 	time_t expire_time;
107 	char *host_notification_period;
108 	int last_event_id;
109 	int last_problem_id;
110 	char *long_plugin_output;
111 	int next_comment_id;
112 	char *notification_period;
113 	int persistent;
114 	double retry_interval;
115 	char *service_notification_period;
116 	int source;
117 	int downtime_id;
118 	time_t start_time, end_time;
119 	int triggered_by;
120 	int fixed;
121 	int duration;
122 	char *comment;
123 };
124 
125 void parse_1_0_statuslog(int fd, struct stats **pstats, int *n_stats);
126 void parse_2_0_statuslog(int fd, struct stats **pstats, int *n_stats);
127 void free_stats_array(struct stats *pstats, int n_stats);
128 void sort_stats_array(struct stats *pstats, int n_stats);
129 int host_is_down(struct stats *pstats, int n_stats, char *host_name);
130 int should_i_show_entry(struct stats *pstats, int n_stats, int cur_index, char list_all_problems, char always_notify, char also_acknowledged, char hide_ok);
131 int find_index_by_host_and_service(struct stats *pstats, int n_stats, char *host_name, char *service_description);
132 int check_max_age_last_check(struct stats *pstats, int n_stats, int max_time_last_host_update, int max_time_oldest_host_update, int max_time_last_host_check, int max_time_oldest_host_check, int max_time_last_service_check, int max_time_oldest_service_check, int max_time_oldest_next_service_check, char **message);
133 void calc_stats_stats(struct stats *pstats, int n_stats, char list_all_problems, char always_notify, char also_acknowledged, char hide_ok, int *n_critical, int *n_warning, int *n_ok, int *n_up, int *n_down, int *n_unreachable, int *n_pending);
134