2017-05-19 22:22:40 +02:00
/**************************************************************************
*
* AVAIL . C - Nagios Availability CGI
*
*
* License :
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation .
*
* 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 . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "../include/config.h"
# include "../include/common.h"
# include "../include/objects.h"
# include "../include/comments.h"
# include "../include/statusdata.h"
# include "../include/cgiutils.h"
# include "../include/cgiauth.h"
# include "../include/getcgi.h"
extern char main_config_file [ MAX_FILENAME_LENGTH ] ;
extern char url_html_path [ MAX_FILENAME_LENGTH ] ;
extern char url_images_path [ MAX_FILENAME_LENGTH ] ;
extern char url_stylesheets_path [ MAX_FILENAME_LENGTH ] ;
# ifndef max
# define max(a,b) (((a) > (b)) ? (a) : (b))
# endif
# ifndef min
# define min(a,b) (((a) < (b)) ? (a) : (b))
# endif
/* output types */
# define HTML_OUTPUT 0
# define CSV_OUTPUT 1
/* archived state types */
# define AS_CURRENT_STATE -1 /* special case for initial assumed state */
# define AS_NO_DATA 0
# define AS_PROGRAM_END 1
# define AS_PROGRAM_START 2
# define AS_HOST_UP 3
# define AS_HOST_DOWN 4
# define AS_HOST_UNREACHABLE 5
# define AS_SVC_OK 6
# define AS_SVC_UNKNOWN 7
# define AS_SVC_WARNING 8
# define AS_SVC_CRITICAL 9
# define AS_SVC_DOWNTIME_START 10
# define AS_SVC_DOWNTIME_END 11
# define AS_HOST_DOWNTIME_START 12
# define AS_HOST_DOWNTIME_END 13
# define AS_SOFT_STATE 1
# define AS_HARD_STATE 2
/* display types */
# define DISPLAY_NO_AVAIL 0
# define DISPLAY_HOSTGROUP_AVAIL 1
# define DISPLAY_HOST_AVAIL 2
# define DISPLAY_SERVICE_AVAIL 3
# define DISPLAY_SERVICEGROUP_AVAIL 4
/* subject types */
# define HOST_SUBJECT 0
# define SERVICE_SUBJECT 1
/* standard report times */
# define TIMEPERIOD_CUSTOM 0
# define TIMEPERIOD_TODAY 1
# define TIMEPERIOD_YESTERDAY 2
# define TIMEPERIOD_THISWEEK 3
# define TIMEPERIOD_LASTWEEK 4
# define TIMEPERIOD_THISMONTH 5
# define TIMEPERIOD_LASTMONTH 6
# define TIMEPERIOD_THISQUARTER 7
# define TIMEPERIOD_LASTQUARTER 8
# define TIMEPERIOD_THISYEAR 9
# define TIMEPERIOD_LASTYEAR 10
# define TIMEPERIOD_LAST24HOURS 11
# define TIMEPERIOD_LAST7DAYS 12
# define TIMEPERIOD_LAST31DAYS 13
# define MIN_TIMESTAMP_SPACING 10
# define MAX_ARCHIVE_SPREAD 65
# define MAX_ARCHIVE 65
# define MAX_ARCHIVE_BACKTRACKS 60
authdata current_authdata ;
typedef struct archived_state_struct {
time_t time_stamp ;
int entry_type ;
int state_type ;
char * state_info ;
int processed_state ;
struct archived_state_struct * misc_ptr ;
struct archived_state_struct * next ;
} archived_state ;
typedef struct avail_subject_struct {
int type ;
char * host_name ;
char * service_description ;
archived_state * as_list ; /* archived state list */
archived_state * as_list_tail ;
archived_state * sd_list ; /* scheduled downtime list */
int last_known_state ;
time_t earliest_time ;
time_t latest_time ;
int earliest_state ;
int latest_state ;
unsigned long time_up ;
unsigned long time_down ;
unsigned long time_unreachable ;
unsigned long time_ok ;
unsigned long time_warning ;
unsigned long time_unknown ;
unsigned long time_critical ;
unsigned long scheduled_time_up ;
unsigned long scheduled_time_down ;
unsigned long scheduled_time_unreachable ;
unsigned long scheduled_time_ok ;
unsigned long scheduled_time_warning ;
unsigned long scheduled_time_unknown ;
unsigned long scheduled_time_critical ;
unsigned long scheduled_time_indeterminate ;
unsigned long time_indeterminate_nodata ;
unsigned long time_indeterminate_notrunning ;
struct avail_subject_struct * next ;
} avail_subject ;
avail_subject * subject_list = NULL ;
time_t t1 ;
time_t t2 ;
int display_type = DISPLAY_NO_AVAIL ;
int timeperiod_type = TIMEPERIOD_LAST24HOURS ;
int show_log_entries = FALSE ;
int full_log_entries = FALSE ;
int show_scheduled_downtime = TRUE ;
int start_second = 0 ;
int start_minute = 0 ;
int start_hour = 0 ;
int start_day = 1 ;
int start_month = 1 ;
int start_year = 2000 ;
int end_second = 0 ;
int end_minute = 0 ;
int end_hour = 24 ;
int end_day = 1 ;
int end_month = 1 ;
int end_year = 2000 ;
int get_date_parts = FALSE ;
int select_hostgroups = FALSE ;
int select_hosts = FALSE ;
int select_servicegroups = FALSE ;
int select_services = FALSE ;
int select_output_format = FALSE ;
int compute_time_from_parts = FALSE ;
int show_all_hostgroups = FALSE ;
int show_all_hosts = FALSE ;
int show_all_servicegroups = FALSE ;
int show_all_services = FALSE ;
int assume_initial_states = TRUE ;
int assume_state_retention = TRUE ;
int assume_states_during_notrunning = TRUE ;
int initial_assumed_host_state = AS_NO_DATA ;
int initial_assumed_service_state = AS_NO_DATA ;
int include_soft_states = FALSE ;
char * hostgroup_name = " " ;
char * host_name = " " ;
char * servicegroup_name = " " ;
char * svc_description = " " ;
void create_subject_list ( void ) ;
void add_subject ( int , char * , char * ) ;
avail_subject * find_subject ( int , char * , char * ) ;
void compute_availability ( void ) ;
void compute_subject_availability ( avail_subject * , time_t ) ;
void compute_subject_availability_times ( int , int , time_t , time_t , time_t , avail_subject * , archived_state * ) ;
void compute_subject_downtime ( avail_subject * , time_t ) ;
void compute_subject_downtime_times ( time_t , time_t , avail_subject * , archived_state * ) ;
void compute_subject_downtime_part_times ( time_t , time_t , int , avail_subject * ) ;
void display_hostgroup_availability ( void ) ;
void display_specific_hostgroup_availability ( hostgroup * ) ;
void display_servicegroup_availability ( void ) ;
void display_specific_servicegroup_availability ( servicegroup * ) ;
void display_host_availability ( void ) ;
void display_service_availability ( void ) ;
void write_log_entries ( avail_subject * ) ;
void get_running_average ( double * , double , int ) ;
2017-05-19 23:37:19 +02:00
void host_report_url ( const char * , const char * ) ;
void service_report_url ( const char * , const char * , const char * ) ;
2017-05-19 22:22:40 +02:00
void compute_report_times ( void ) ;
int convert_host_state_to_archived_state ( int ) ;
int convert_service_state_to_archived_state ( int ) ;
2017-05-19 23:37:19 +02:00
void add_global_archived_state ( int , int , time_t , const char * ) ;
void add_archived_state ( int , int , time_t , const char * , avail_subject * ) ;
2017-05-19 22:22:40 +02:00
void add_scheduled_downtime ( int , time_t , avail_subject * ) ;
void free_availability_data ( void ) ;
void free_archived_state_list ( archived_state * ) ;
void read_archived_state_data ( void ) ;
void scan_log_file_for_archived_state_data ( char * ) ;
void convert_timeperiod_to_times ( int ) ;
unsigned long calculate_total_time ( time_t , time_t ) ;
void document_header ( int ) ;
void document_footer ( void ) ;
int process_cgivars ( void ) ;
int backtrack_archives = 2 ;
int earliest_archive = 0 ;
int embedded = FALSE ;
int display_header = TRUE ;
timeperiod * current_timeperiod = NULL ;
int output_format = HTML_OUTPUT ;
int main ( int argc , char * * argv ) {
char temp_buffer [ MAX_INPUT_BUFFER ] ;
char start_timestring [ MAX_DATETIME_LENGTH ] ;
char end_timestring [ MAX_DATETIME_LENGTH ] ;
host * temp_host ;
service * temp_service ;
int is_authorized = TRUE ;
time_t report_start_time ;
time_t report_end_time ;
int days , hours , minutes , seconds ;
hostgroup * temp_hostgroup ;
servicegroup * temp_servicegroup ;
timeperiod * temp_timeperiod ;
time_t t3 ;
time_t current_time ;
struct tm * t ;
char * firsthostpointer ;
/* reset internal CGI variables */
reset_cgi_vars ( ) ;
2017-05-19 23:37:19 +02:00
cgi_init ( document_header , document_footer , READ_ALL_OBJECT_DATA , READ_ALL_STATUS_DATA ) ;
2017-05-19 22:22:40 +02:00
/* initialize time period to last 24 hours */
time ( & current_time ) ;
t2 = current_time ;
t1 = ( time_t ) ( current_time - ( 60 * 60 * 24 ) ) ;
/* default number of backtracked archives */
2019-04-18 17:09:18 +02:00
switch ( log_rotation_method ) {
case LOG_ROTATION_MONTHLY :
backtrack_archives = 1 ;
break ;
case LOG_ROTATION_WEEKLY :
backtrack_archives = 2 ;
break ;
case LOG_ROTATION_DAILY :
backtrack_archives = 4 ;
break ;
case LOG_ROTATION_HOURLY :
backtrack_archives = 8 ;
break ;
default :
backtrack_archives = 2 ;
break ;
}
2017-05-19 22:22:40 +02:00
/* get the arguments passed in the URL */
process_cgivars ( ) ;
document_header ( TRUE ) ;
/* get authentication information */
get_authentication_information ( & current_authdata ) ;
2019-04-18 17:09:18 +02:00
if ( compute_time_from_parts = = TRUE )
2017-05-19 22:22:40 +02:00
compute_report_times ( ) ;
/* make sure times are sane, otherwise swap them */
2019-04-18 17:09:18 +02:00
if ( t2 < t1 ) {
2017-05-19 22:22:40 +02:00
t3 = t2 ;
t2 = t1 ;
t1 = t3 ;
}
/* don't let user create reports in the future */
2019-04-18 17:09:18 +02:00
if ( t2 > current_time ) {
2017-05-19 22:22:40 +02:00
t2 = current_time ;
2019-04-18 17:09:18 +02:00
if ( t1 > t2 )
2017-05-19 22:22:40 +02:00
t1 = t2 - ( 60 * 60 * 24 ) ;
}
2019-04-18 17:09:18 +02:00
if ( display_header = = TRUE ) {
2017-05-19 22:22:40 +02:00
/* begin top table */
printf ( " <table border=0 width=100%% cellspacing=0 cellpadding=0> \n " ) ;
printf ( " <tr> \n " ) ;
/* left column of the first row */
printf ( " <td align=left valign=top width=33%%> \n " ) ;
2019-04-18 17:09:18 +02:00
switch ( display_type ) {
case DISPLAY_HOST_AVAIL :
snprintf ( temp_buffer , sizeof ( temp_buffer ) - 1 , " Host Availability Report " ) ;
break ;
case DISPLAY_SERVICE_AVAIL :
snprintf ( temp_buffer , sizeof ( temp_buffer ) - 1 , " Service Availability Report " ) ;
break ;
case DISPLAY_HOSTGROUP_AVAIL :
snprintf ( temp_buffer , sizeof ( temp_buffer ) - 1 , " Hostgroup Availability Report " ) ;
break ;
case DISPLAY_SERVICEGROUP_AVAIL :
snprintf ( temp_buffer , sizeof ( temp_buffer ) - 1 , " Servicegroup Availability Report " ) ;
break ;
default :
snprintf ( temp_buffer , sizeof ( temp_buffer ) - 1 , " Availability Report " ) ;
break ;
}
2017-05-19 22:22:40 +02:00
temp_buffer [ sizeof ( temp_buffer ) - 1 ] = ' \x0 ' ;
display_info_table ( temp_buffer , FALSE , & current_authdata ) ;
2019-04-18 17:09:18 +02:00
if ( ( ( display_type = = DISPLAY_HOST_AVAIL & & show_all_hosts = = FALSE ) | | ( display_type = = DISPLAY_SERVICE_AVAIL & & show_all_services = = FALSE ) ) & & get_date_parts = = FALSE ) {
2017-05-19 22:22:40 +02:00
printf ( " <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'> \n " ) ;
printf ( " <TR><TD CLASS='linkBox'> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL & & show_all_hosts = = FALSE ) {
2017-05-19 22:22:40 +02:00
host_report_url ( " all " , " View Availability Report For All Hosts " ) ;
printf ( " <BR> \n " ) ;
# ifdef USE_TRENDS
printf ( " <a href='%s?host=%s&t1=%lu&t2=%lu&assumestateretention=%s&assumeinitialstates=%s&includesoftstates=%s&assumestatesduringnotrunning=%s&initialassumedhoststate=%d&backtrack=%d'>View Trends For This Host</a><BR> \n " , TRENDS_CGI , url_encode ( host_name ) , t1 , t2 , ( include_soft_states = = TRUE ) ? " yes " : " no " , ( assume_state_retention = = TRUE ) ? " yes " : " no " , ( assume_initial_states = = TRUE ) ? " yes " : " no " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " , initial_assumed_host_state , backtrack_archives ) ;
# endif
# ifdef USE_HISTOGRAM
printf ( " <a href='%s?host=%s&t1=%lu&t2=%lu&assumestateretention=%s'>View Alert Histogram For This Host</a><BR> \n " , HISTOGRAM_CGI , url_encode ( host_name ) , t1 , t2 , ( assume_state_retention = = TRUE ) ? " yes " : " no " ) ;
# endif
printf ( " <a href='%s?host=%s'>View Status Detail For This Host</a><BR> \n " , STATUS_CGI , url_encode ( host_name ) ) ;
printf ( " <a href='%s?host=%s'>View Alert History For This Host</a><BR> \n " , HISTORY_CGI , url_encode ( host_name ) ) ;
printf ( " <a href='%s?host=%s'>View Notifications For This Host</a><BR> \n " , NOTIFICATIONS_CGI , url_encode ( host_name ) ) ;
}
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICE_AVAIL & & show_all_services = = FALSE ) {
2017-05-19 22:22:40 +02:00
host_report_url ( host_name , " View Availability Report For This Host " ) ;
printf ( " <BR> \n " ) ;
service_report_url ( " null " , " all " , " View Availability Report For All Services " ) ;
printf ( " <BR> \n " ) ;
# ifdef USE_TRENDS
printf ( " <a href='%s?host=%s " , TRENDS_CGI , url_encode ( host_name ) ) ;
printf ( " &service=%s&t1=%lu&t2=%lu&assumestateretention=%s&includesoftstates=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d'>View Trends For This Service</a><BR> \n " , url_encode ( svc_description ) , t1 , t2 , ( include_soft_states = = TRUE ) ? " yes " : " no " , ( assume_state_retention = = TRUE ) ? " yes " : " no " , ( assume_initial_states = = TRUE ) ? " yes " : " no " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " , initial_assumed_service_state , backtrack_archives ) ;
# endif
# ifdef USE_HISTOGRAM
printf ( " <a href='%s?host=%s " , HISTOGRAM_CGI , url_encode ( host_name ) ) ;
printf ( " &service=%s&t1=%lu&t2=%lu&assumestateretention=%s'>View Alert Histogram For This Service</a><BR> \n " , url_encode ( svc_description ) , t1 , t2 , ( assume_state_retention = = TRUE ) ? " yes " : " no " ) ;
# endif
printf ( " <A HREF='%s?host=%s& " , HISTORY_CGI , url_encode ( host_name ) ) ;
printf ( " service=%s'>View Alert History For This Service</A><BR> \n " , url_encode ( svc_description ) ) ;
printf ( " <A HREF='%s?host=%s& " , NOTIFICATIONS_CGI , url_encode ( host_name ) ) ;
printf ( " service=%s'>View Notifications For This Service</A><BR> \n " , url_encode ( svc_description ) ) ;
}
printf ( " </TD></TR> \n " ) ;
printf ( " </TABLE> \n " ) ;
}
printf ( " </td> \n " ) ;
/* center column of top row */
printf ( " <td align=center valign=top width=33%%> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type ! = DISPLAY_NO_AVAIL & & get_date_parts = = FALSE ) {
2017-05-19 22:22:40 +02:00
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL ) {
if ( show_all_hosts = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " All Hosts " ) ;
else
printf ( " Host '%s' " , host_name ) ;
}
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICE_AVAIL ) {
if ( show_all_services = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " All Services " ) ;
else
printf ( " Service '%s' On Host '%s' " , svc_description , host_name ) ;
}
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_HOSTGROUP_AVAIL ) {
if ( show_all_hostgroups = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " All Hostgroups " ) ;
else
printf ( " Hostgroup '%s' " , hostgroup_name ) ;
}
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICEGROUP_AVAIL ) {
if ( show_all_servicegroups = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " All Servicegroups " ) ;
else
printf ( " Servicegroup '%s' " , servicegroup_name ) ;
}
printf ( " </DIV> \n " ) ;
printf ( " <BR> \n " ) ;
printf ( " <IMG SRC='%s%s' BORDER=0 ALT='Availability Report' TITLE='Availability Report'> \n " , url_images_path , TRENDS_ICON ) ;
printf ( " <BR CLEAR=ALL> \n " ) ;
get_time_string ( & t1 , start_timestring , sizeof ( start_timestring ) - 1 , SHORT_DATE_TIME ) ;
get_time_string ( & t2 , end_timestring , sizeof ( end_timestring ) - 1 , SHORT_DATE_TIME ) ;
printf ( " <div align=center class='reportRange'>%s to %s</div> \n " , start_timestring , end_timestring ) ;
get_time_breakdown ( ( time_t ) ( t2 - t1 ) , & days , & hours , & minutes , & seconds ) ;
2017-05-19 23:37:19 +02:00
printf ( " <div align=center class='reportDuration'>Duration: %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
if ( current_timeperiod )
printf ( " <br>(using timeperiod %s) " , current_timeperiod - > name ) ;
printf ( " </div> \n " ) ;
2017-05-19 22:22:40 +02:00
}
printf ( " </td> \n " ) ;
/* right hand column of top row */
printf ( " <td align=right valign=bottom width=33%%> \n " ) ;
printf ( " <form method= \" GET \" action= \" %s \" > \n " , AVAIL_CGI ) ;
printf ( " <table border=0 CLASS='optBox'> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type ! = DISPLAY_NO_AVAIL & & get_date_parts = = FALSE ) {
2017-05-19 22:22:40 +02:00
printf ( " <tr><td valign=top align=left class='optBoxItem'>First assumed %s state:</td><td valign=top align=left class='optBoxItem'>%s</td></tr> \n " , ( display_type = = DISPLAY_SERVICE_AVAIL ) ? " service " : " host " , ( display_type = = DISPLAY_HOST_AVAIL | | display_type = = DISPLAY_HOSTGROUP_AVAIL | | display_type = = DISPLAY_SERVICEGROUP_AVAIL ) ? " First assumed service state " : " " ) ;
printf ( " <tr> \n " ) ;
printf ( " <td valign=top align=left class='optBoxItem'> \n " ) ;
printf ( " <input type='hidden' name='t1' value='%lu'> \n " , ( unsigned long ) t1 ) ;
printf ( " <input type='hidden' name='t2' value='%lu'> \n " , ( unsigned long ) t2 ) ;
2019-04-18 17:09:18 +02:00
if ( show_log_entries = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='show_log_entries' value=''> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( full_log_entries = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='full_log_entries' value=''> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOSTGROUP_AVAIL )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='hostgroup' value='%s'> \n " , escape_string ( hostgroup_name ) ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL | | display_type = = DISPLAY_SERVICE_AVAIL )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='host' value='%s'> \n " , escape_string ( host_name ) ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_SERVICE_AVAIL )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='service' value='%s'> \n " , escape_string ( svc_description ) ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_SERVICEGROUP_AVAIL )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='servicegroup' value='%s'> \n " , escape_string ( servicegroup_name ) ) ;
printf ( " <input type='hidden' name='assumeinitialstates' value='%s'> \n " , ( assume_initial_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " <input type='hidden' name='assumestateretention' value='%s'> \n " , ( assume_state_retention = = TRUE ) ? " yes " : " no " ) ;
printf ( " <input type='hidden' name='assumestatesduringnotrunning' value='%s'> \n " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " ) ;
printf ( " <input type='hidden' name='includesoftstates' value='%s'> \n " , ( include_soft_states = = TRUE ) ? " yes " : " no " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL | | display_type = = DISPLAY_HOSTGROUP_AVAIL | | display_type = = DISPLAY_SERVICEGROUP_AVAIL ) {
2017-05-19 22:22:40 +02:00
printf ( " <select name='initialassumedhoststate'> \n " ) ;
printf ( " <option value=%d %s>Unspecified \n " , AS_NO_DATA , ( initial_assumed_host_state = = AS_NO_DATA ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Current State \n " , AS_CURRENT_STATE , ( initial_assumed_host_state = = AS_CURRENT_STATE ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Host Up \n " , AS_HOST_UP , ( initial_assumed_host_state = = AS_HOST_UP ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Host Down \n " , AS_HOST_DOWN , ( initial_assumed_host_state = = AS_HOST_DOWN ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Host Unreachable \n " , AS_HOST_UNREACHABLE , ( initial_assumed_host_state = = AS_HOST_UNREACHABLE ) ? " SELECTED " : " " ) ;
printf ( " </select> \n " ) ;
}
else {
printf ( " <input type='hidden' name='initialassumedhoststate' value='%d'> " , initial_assumed_host_state ) ;
printf ( " <select name='initialassumedservicestate'> \n " ) ;
printf ( " <option value=%d %s>Unspecified \n " , AS_NO_DATA , ( initial_assumed_service_state = = AS_NO_DATA ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Current State \n " , AS_CURRENT_STATE , ( initial_assumed_service_state = = AS_CURRENT_STATE ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Service Ok \n " , AS_SVC_OK , ( initial_assumed_service_state = = AS_SVC_OK ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Service Warning \n " , AS_SVC_WARNING , ( initial_assumed_service_state = = AS_SVC_WARNING ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Service Unknown \n " , AS_SVC_UNKNOWN , ( initial_assumed_service_state = = AS_SVC_UNKNOWN ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Service Critical \n " , AS_SVC_CRITICAL , ( initial_assumed_service_state = = AS_SVC_CRITICAL ) ? " SELECTED " : " " ) ;
printf ( " </select> \n " ) ;
}
printf ( " </td> \n " ) ;
printf ( " <td CLASS='optBoxItem'> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL | | display_type = = DISPLAY_HOSTGROUP_AVAIL | | display_type = = DISPLAY_SERVICEGROUP_AVAIL ) {
2017-05-19 22:22:40 +02:00
printf ( " <select name='initialassumedservicestate'> \n " ) ;
printf ( " <option value=%d %s>Unspecified \n " , AS_NO_DATA , ( initial_assumed_service_state = = AS_NO_DATA ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Current State \n " , AS_CURRENT_STATE , ( initial_assumed_service_state = = AS_CURRENT_STATE ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Service Ok \n " , AS_SVC_OK , ( initial_assumed_service_state = = AS_SVC_OK ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Service Warning \n " , AS_SVC_WARNING , ( initial_assumed_service_state = = AS_SVC_WARNING ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Service Unknown \n " , AS_SVC_UNKNOWN , ( initial_assumed_service_state = = AS_SVC_UNKNOWN ) ? " SELECTED " : " " ) ;
printf ( " <option value=%d %s>Service Critical \n " , AS_SVC_CRITICAL , ( initial_assumed_service_state = = AS_SVC_CRITICAL ) ? " SELECTED " : " " ) ;
printf ( " </select> \n " ) ;
}
printf ( " </td> \n " ) ;
printf ( " </tr> \n " ) ;
printf ( " <tr><td valign=top align=left class='optBoxItem'>Report period:</td><td valign=top align=left class='optBoxItem'>Backtracked archives:</td></tr> \n " ) ;
printf ( " <tr> \n " ) ;
printf ( " <td valign=top align=left class='optBoxItem'> \n " ) ;
printf ( " <select name='timeperiod'> \n " ) ;
printf ( " <option SELECTED>[ Current time range ] \n " ) ;
printf ( " <option value=today %s>Today \n " , ( timeperiod_type = = TIMEPERIOD_TODAY ) ? " SELECTED " : " " ) ;
printf ( " <option value=last24hours %s>Last 24 Hours \n " , ( timeperiod_type = = TIMEPERIOD_LAST24HOURS ) ? " SELECTED " : " " ) ;
printf ( " <option value=yesterday %s>Yesterday \n " , ( timeperiod_type = = TIMEPERIOD_YESTERDAY ) ? " SELECTED " : " " ) ;
printf ( " <option value=thisweek %s>This Week \n " , ( timeperiod_type = = TIMEPERIOD_THISWEEK ) ? " SELECTED " : " " ) ;
printf ( " <option value=last7days %s>Last 7 Days \n " , ( timeperiod_type = = TIMEPERIOD_LAST7DAYS ) ? " SELECTED " : " " ) ;
printf ( " <option value=lastweek %s>Last Week \n " , ( timeperiod_type = = TIMEPERIOD_LASTWEEK ) ? " SELECTED " : " " ) ;
printf ( " <option value=thismonth %s>This Month \n " , ( timeperiod_type = = TIMEPERIOD_THISMONTH ) ? " SELECTED " : " " ) ;
printf ( " <option value=last31days %s>Last 31 Days \n " , ( timeperiod_type = = TIMEPERIOD_LAST31DAYS ) ? " SELECTED " : " " ) ;
printf ( " <option value=lastmonth %s>Last Month \n " , ( timeperiod_type = = TIMEPERIOD_LASTMONTH ) ? " SELECTED " : " " ) ;
printf ( " <option value=thisyear %s>This Year \n " , ( timeperiod_type = = TIMEPERIOD_THISYEAR ) ? " SELECTED " : " " ) ;
printf ( " <option value=lastyear %s>Last Year \n " , ( timeperiod_type = = TIMEPERIOD_LASTYEAR ) ? " SELECTED " : " " ) ;
printf ( " </select> \n " ) ;
printf ( " </td> \n " ) ;
printf ( " <td valign=top align=left CLASS='optBoxItem'> \n " ) ;
printf ( " <input type='text' size='2' maxlength='2' name='backtrack' value='%d'> \n " , backtrack_archives ) ;
printf ( " </td> \n " ) ;
printf ( " </tr> \n " ) ;
printf ( " <tr><td valign=top align=left></td> \n " ) ;
printf ( " <td valign=top align=left CLASS='optBoxItem'> \n " ) ;
printf ( " <input type='submit' value='Update'> \n " ) ;
printf ( " </td> \n " ) ;
printf ( " </tr> \n " ) ;
}
/* display context-sensitive help */
printf ( " <tr><td></td><td align=right valign=bottom> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( get_date_parts = = TRUE )
2017-05-19 22:22:40 +02:00
display_context_help ( CONTEXTHELP_AVAIL_MENU5 ) ;
2019-04-18 17:09:18 +02:00
else if ( select_hostgroups = = TRUE )
2017-05-19 22:22:40 +02:00
display_context_help ( CONTEXTHELP_AVAIL_MENU2 ) ;
2019-04-18 17:09:18 +02:00
else if ( select_hosts = = TRUE )
2017-05-19 22:22:40 +02:00
display_context_help ( CONTEXTHELP_AVAIL_MENU3 ) ;
2019-04-18 17:09:18 +02:00
else if ( select_services = = TRUE )
2017-05-19 22:22:40 +02:00
display_context_help ( CONTEXTHELP_AVAIL_MENU4 ) ;
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_HOSTGROUP_AVAIL )
2017-05-19 22:22:40 +02:00
display_context_help ( CONTEXTHELP_AVAIL_HOSTGROUP ) ;
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_HOST_AVAIL )
2017-05-19 22:22:40 +02:00
display_context_help ( CONTEXTHELP_AVAIL_HOST ) ;
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICE_AVAIL )
2017-05-19 22:22:40 +02:00
display_context_help ( CONTEXTHELP_AVAIL_SERVICE ) ;
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICEGROUP_AVAIL )
2017-05-19 22:22:40 +02:00
display_context_help ( CONTEXTHELP_AVAIL_SERVICEGROUP ) ;
else
display_context_help ( CONTEXTHELP_AVAIL_MENU1 ) ;
printf ( " </td></tr> \n " ) ;
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
printf ( " </td> \n " ) ;
/* end of top table */
printf ( " </tr> \n " ) ;
printf ( " </table> \n " ) ;
}
/* step 3 - ask user for report date range */
2019-04-18 17:09:18 +02:00
if ( get_date_parts = = TRUE ) {
2017-05-19 22:22:40 +02:00
time ( & current_time ) ;
t = localtime ( & current_time ) ;
start_day = 1 ;
start_year = t - > tm_year + 1900 ;
end_day = t - > tm_mday ;
end_year = t - > tm_year + 1900 ;
printf ( " <P><DIV ALIGN=CENTER CLASS='dateSelectTitle'>Step 3: Select Report Options</DIV></p> \n " ) ;
printf ( " <P><DIV ALIGN=CENTER> \n " ) ;
printf ( " <form method= \" get \" action= \" %s \" > \n " , AVAIL_CGI ) ;
printf ( " <input type='hidden' name='show_log_entries' value=''> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOSTGROUP_AVAIL )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='hostgroup' value='%s'> \n " , escape_string ( hostgroup_name ) ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL | | display_type = = DISPLAY_SERVICE_AVAIL )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='host' value='%s'> \n " , escape_string ( host_name ) ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_SERVICE_AVAIL )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='service' value='%s'> \n " , escape_string ( svc_description ) ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_SERVICEGROUP_AVAIL )
2017-05-19 22:22:40 +02:00
printf ( " <input type='hidden' name='servicegroup' value='%s'> \n " , escape_string ( servicegroup_name ) ) ;
printf ( " <table border=0 cellpadding=5> \n " ) ;
printf ( " <tr> " ) ;
printf ( " <td valign=top class='reportSelectSubTitle'>Report Period:</td> \n " ) ;
printf ( " <td valign=top align=left class='optBoxItem'> \n " ) ;
printf ( " <select name='timeperiod'> \n " ) ;
printf ( " <option value=today>Today \n " ) ;
printf ( " <option value=last24hours>Last 24 Hours \n " ) ;
printf ( " <option value=yesterday>Yesterday \n " ) ;
printf ( " <option value=thisweek>This Week \n " ) ;
printf ( " <option value=last7days SELECTED>Last 7 Days \n " ) ;
printf ( " <option value=lastweek>Last Week \n " ) ;
printf ( " <option value=thismonth>This Month \n " ) ;
printf ( " <option value=last31days>Last 31 Days \n " ) ;
printf ( " <option value=lastmonth>Last Month \n " ) ;
printf ( " <option value=thisyear>This Year \n " ) ;
printf ( " <option value=lastyear>Last Year \n " ) ;
printf ( " <option value=custom>* CUSTOM REPORT PERIOD * \n " ) ;
printf ( " </select> \n " ) ;
printf ( " </td> \n " ) ;
printf ( " </tr> \n " ) ;
printf ( " <tr><td valign=top class='reportSelectSubTitle'>If Custom Report Period...</td></tr> \n " ) ;
printf ( " <tr> " ) ;
printf ( " <td valign=top class='reportSelectSubTitle'>Start Date (Inclusive):</td> \n " ) ;
printf ( " <td align=left valign=top class='reportSelectItem'> " ) ;
printf ( " <select name='smon'> \n " ) ;
printf ( " <option value='1' %s>January \n " , ( t - > tm_mon = = 0 ) ? " SELECTED " : " " ) ;
printf ( " <option value='2' %s>February \n " , ( t - > tm_mon = = 1 ) ? " SELECTED " : " " ) ;
printf ( " <option value='3' %s>March \n " , ( t - > tm_mon = = 2 ) ? " SELECTED " : " " ) ;
printf ( " <option value='4' %s>April \n " , ( t - > tm_mon = = 3 ) ? " SELECTED " : " " ) ;
printf ( " <option value='5' %s>May \n " , ( t - > tm_mon = = 4 ) ? " SELECTED " : " " ) ;
printf ( " <option value='6' %s>June \n " , ( t - > tm_mon = = 5 ) ? " SELECTED " : " " ) ;
printf ( " <option value='7' %s>July \n " , ( t - > tm_mon = = 6 ) ? " SELECTED " : " " ) ;
printf ( " <option value='8' %s>August \n " , ( t - > tm_mon = = 7 ) ? " SELECTED " : " " ) ;
printf ( " <option value='9' %s>September \n " , ( t - > tm_mon = = 8 ) ? " SELECTED " : " " ) ;
printf ( " <option value='10' %s>October \n " , ( t - > tm_mon = = 9 ) ? " SELECTED " : " " ) ;
printf ( " <option value='11' %s>November \n " , ( t - > tm_mon = = 10 ) ? " SELECTED " : " " ) ;
printf ( " <option value='12' %s>December \n " , ( t - > tm_mon = = 11 ) ? " SELECTED " : " " ) ;
printf ( " </select> \n " ) ;
printf ( " <input type='text' size='2' maxlength='2' name='sday' value='%d'> " , start_day ) ;
printf ( " <input type='text' size='4' maxlength='4' name='syear' value='%d'> " , start_year ) ;
printf ( " <input type='hidden' name='shour' value='0'> \n " ) ;
printf ( " <input type='hidden' name='smin' value='0'> \n " ) ;
printf ( " <input type='hidden' name='ssec' value='0'> \n " ) ;
printf ( " </td> \n " ) ;
printf ( " </tr> \n " ) ;
printf ( " <tr> " ) ;
printf ( " <td valign=top class='reportSelectSubTitle'>End Date (Inclusive):</td> \n " ) ;
printf ( " <td align=left valign=top class='reportSelectItem'> " ) ;
printf ( " <select name='emon'> \n " ) ;
printf ( " <option value='1' %s>January \n " , ( t - > tm_mon = = 0 ) ? " SELECTED " : " " ) ;
printf ( " <option value='2' %s>February \n " , ( t - > tm_mon = = 1 ) ? " SELECTED " : " " ) ;
printf ( " <option value='3' %s>March \n " , ( t - > tm_mon = = 2 ) ? " SELECTED " : " " ) ;
printf ( " <option value='4' %s>April \n " , ( t - > tm_mon = = 3 ) ? " SELECTED " : " " ) ;
printf ( " <option value='5' %s>May \n " , ( t - > tm_mon = = 4 ) ? " SELECTED " : " " ) ;
printf ( " <option value='6' %s>June \n " , ( t - > tm_mon = = 5 ) ? " SELECTED " : " " ) ;
printf ( " <option value='7' %s>July \n " , ( t - > tm_mon = = 6 ) ? " SELECTED " : " " ) ;
printf ( " <option value='8' %s>August \n " , ( t - > tm_mon = = 7 ) ? " SELECTED " : " " ) ;
printf ( " <option value='9' %s>September \n " , ( t - > tm_mon = = 8 ) ? " SELECTED " : " " ) ;
printf ( " <option value='10' %s>October \n " , ( t - > tm_mon = = 9 ) ? " SELECTED " : " " ) ;
printf ( " <option value='11' %s>November \n " , ( t - > tm_mon = = 10 ) ? " SELECTED " : " " ) ;
printf ( " <option value='12' %s>December \n " , ( t - > tm_mon = = 11 ) ? " SELECTED " : " " ) ;
printf ( " </select> \n " ) ;
printf ( " <input type='text' size='2' maxlength='2' name='eday' value='%d'> " , end_day ) ;
printf ( " <input type='text' size='4' maxlength='4' name='eyear' value='%d'> " , end_year ) ;
printf ( " <input type='hidden' name='ehour' value='24'> \n " ) ;
printf ( " <input type='hidden' name='emin' value='0'> \n " ) ;
printf ( " <input type='hidden' name='esec' value='0'> \n " ) ;
printf ( " </td> \n " ) ;
printf ( " </tr> \n " ) ;
printf ( " <tr><td colspan=2><br></td></tr> \n " ) ;
printf ( " <tr> " ) ;
printf ( " <td valign=top class='reportSelectSubTitle'>Report time Period:</td> \n " ) ;
printf ( " <td valign=top align=left class='optBoxItem'> \n " ) ;
printf ( " <select name='rpttimeperiod'> \n " ) ;
printf ( " <option value= \" \" >None \n " ) ;
/* check all the time periods... */
2019-04-18 17:09:18 +02:00
for ( temp_timeperiod = timeperiod_list ; temp_timeperiod ! = NULL ; temp_timeperiod = temp_timeperiod - > next )
2017-05-19 22:22:40 +02:00
printf ( " <option value=%s>%s \n " , escape_string ( temp_timeperiod - > name ) , temp_timeperiod - > name ) ;
printf ( " </select> \n " ) ;
printf ( " </td> \n " ) ;
printf ( " </tr> \n " ) ;
printf ( " <tr><td colspan=2><br></td></tr> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' align=right>Assume Initial States:</td> \n " ) ;
printf ( " <td class='reportSelectItem'> \n " ) ;
printf ( " <select name='assumeinitialstates'> \n " ) ;
printf ( " <option value=yes>Yes \n " ) ;
printf ( " <option value=no>No \n " ) ;
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' align=right>Assume State Retention:</td> \n " ) ;
printf ( " <td class='reportSelectItem'> \n " ) ;
printf ( " <select name='assumestateretention'> \n " ) ;
printf ( " <option value=yes>Yes \n " ) ;
printf ( " <option value=no>No \n " ) ;
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' align=right>Assume States During Program Downtime:</td> \n " ) ;
printf ( " <td class='reportSelectItem'> \n " ) ;
printf ( " <select name='assumestatesduringnotrunning'> \n " ) ;
printf ( " <option value=yes>Yes \n " ) ;
printf ( " <option value=no>No \n " ) ;
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' align=right>Include Soft States:</td> \n " ) ;
printf ( " <td class='reportSelectItem'> \n " ) ;
printf ( " <select name='includesoftstates'> \n " ) ;
printf ( " <option value=yes>Yes \n " ) ;
printf ( " <option value=no SELECTED>No \n " ) ;
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type ! = DISPLAY_SERVICE_AVAIL ) {
2017-05-19 22:22:40 +02:00
printf ( " <tr><td class='reportSelectSubTitle' align=right>First Assumed Host State:</td> \n " ) ;
printf ( " <td class='reportSelectItem'> \n " ) ;
printf ( " <select name='initialassumedhoststate'> \n " ) ;
printf ( " <option value=%d>Unspecified \n " , AS_NO_DATA ) ;
printf ( " <option value=%d>Current State \n " , AS_CURRENT_STATE ) ;
printf ( " <option value=%d>Host Up \n " , AS_HOST_UP ) ;
printf ( " <option value=%d>Host Down \n " , AS_HOST_DOWN ) ;
printf ( " <option value=%d>Host Unreachable \n " , AS_HOST_UNREACHABLE ) ;
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
}
printf ( " <tr><td class='reportSelectSubTitle' align=right>First Assumed Service State:</td> \n " ) ;
printf ( " <td class='reportSelectItem'> \n " ) ;
printf ( " <select name='initialassumedservicestate'> \n " ) ;
printf ( " <option value=%d>Unspecified \n " , AS_NO_DATA ) ;
printf ( " <option value=%d>Current State \n " , AS_CURRENT_STATE ) ;
printf ( " <option value=%d>Service Ok \n " , AS_SVC_OK ) ;
printf ( " <option value=%d>Service Warning \n " , AS_SVC_WARNING ) ;
printf ( " <option value=%d>Service Unknown \n " , AS_SVC_UNKNOWN ) ;
printf ( " <option value=%d>Service Critical \n " , AS_SVC_CRITICAL ) ;
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' align=right>Backtracked Archives (To Scan For Initial States):</td> \n " ) ;
printf ( " <td class='reportSelectItem'> \n " ) ;
printf ( " <input type='text' name='backtrack' size='2' maxlength='2' value='%d'> \n " , backtrack_archives ) ;
printf ( " </td></tr> \n " ) ;
2019-04-18 17:09:18 +02:00
printf ( " <tr> " ) ;
printf ( " <td valign=top class='reportSelectSubTitle'>Output in CSV Format:</td> \n " ) ;
printf ( " <td valign=top class='reportSelectItem'> " ) ;
printf ( " <input type='checkbox' name='csvoutput' value=''> \n " ) ;
printf ( " </td> \n " ) ;
printf ( " </tr> \n " ) ;
2017-05-19 22:22:40 +02:00
printf ( " <tr><td></td><td align=left class='dateSelectItem'><input type='submit' value='Create Availability Report!'></td></tr> \n " ) ;
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
printf ( " </DIV></P> \n " ) ;
}
/* step 2 - the user wants to select a hostgroup */
2019-04-18 17:09:18 +02:00
else if ( select_hostgroups = = TRUE ) {
2017-05-19 22:22:40 +02:00
printf ( " <p><div align=center class='reportSelectTitle'>Step 2: Select Hostgroup</div></p> \n " ) ;
printf ( " <p><div align=center> \n " ) ;
printf ( " <form method= \" get \" action= \" %s \" > \n " , AVAIL_CGI ) ;
printf ( " <input type='hidden' name='get_date_parts'> \n " ) ;
printf ( " <table border=0 cellpadding=5> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' valign=center>Hostgroup(s):</td><td align=left valign=center class='reportSelectItem'> \n " ) ;
printf ( " <select name='hostgroup'> \n " ) ;
printf ( " <option value='all'>** ALL HOSTGROUPS ** \n " ) ;
2019-04-18 17:09:18 +02:00
for ( temp_hostgroup = hostgroup_list ; temp_hostgroup ! = NULL ; temp_hostgroup = temp_hostgroup - > next ) {
if ( is_authorized_for_hostgroup ( temp_hostgroup , & current_authdata ) = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " <option value='%s'>%s \n " , escape_string ( temp_hostgroup - > group_name ) , temp_hostgroup - > group_name ) ;
}
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td></td><td align=left class='dateSelectItem'><input type='submit' value='Continue to Step 3'></td></tr> \n " ) ;
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
printf ( " </div></p> \n " ) ;
}
/* step 2 - the user wants to select a host */
2019-04-18 17:09:18 +02:00
else if ( select_hosts = = TRUE ) {
2017-05-19 22:22:40 +02:00
printf ( " <p><div align=center class='reportSelectTitle'>Step 2: Select Host</div></p> \n " ) ;
printf ( " <p><div align=center> \n " ) ;
printf ( " <form method= \" get \" action= \" %s \" > \n " , AVAIL_CGI ) ;
printf ( " <input type='hidden' name='get_date_parts'> \n " ) ;
printf ( " <table border=0 cellpadding=5> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' valign=center>Host(s):</td><td align=left valign=center class='reportSelectItem'> \n " ) ;
printf ( " <select name='host'> \n " ) ;
printf ( " <option value='all'>** ALL HOSTS ** \n " ) ;
2019-04-18 17:09:18 +02:00
for ( temp_host = host_list ; temp_host ! = NULL ; temp_host = temp_host - > next ) {
if ( is_authorized_for_host ( temp_host , & current_authdata ) = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " <option value='%s'>%s \n " , escape_string ( temp_host - > name ) , temp_host - > name ) ;
}
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td></td><td align=left class='dateSelectItem'><input type='submit' value='Continue to Step 3'></td></tr> \n " ) ;
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
printf ( " </div></p> \n " ) ;
printf ( " <div align=center class='helpfulHint'>Tip: If you want to have the option of getting the availability data in CSV format, select '<b>** ALL HOSTS **</b>' from the pull-down menu. \n " ) ;
}
/* step 2 - the user wants to select a servicegroup */
2019-04-18 17:09:18 +02:00
else if ( select_servicegroups = = TRUE ) {
2017-05-19 22:22:40 +02:00
printf ( " <p><div align=center class='reportSelectTitle'>Step 2: Select Servicegroup</div></p> \n " ) ;
printf ( " <p><div align=center> \n " ) ;
printf ( " <form method= \" get \" action= \" %s \" > \n " , AVAIL_CGI ) ;
printf ( " <input type='hidden' name='get_date_parts'> \n " ) ;
printf ( " <table border=0 cellpadding=5> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' valign=center>Servicegroup(s):</td><td align=left valign=center class='reportSelectItem'> \n " ) ;
printf ( " <select name='servicegroup'> \n " ) ;
printf ( " <option value='all'>** ALL SERVICEGROUPS ** \n " ) ;
2019-04-18 17:09:18 +02:00
for ( temp_servicegroup = servicegroup_list ; temp_servicegroup ! = NULL ; temp_servicegroup = temp_servicegroup - > next ) {
if ( is_authorized_for_servicegroup ( temp_servicegroup , & current_authdata ) = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " <option value='%s'>%s \n " , escape_string ( temp_servicegroup - > group_name ) , temp_servicegroup - > group_name ) ;
}
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td></td><td align=left class='dateSelectItem'><input type='submit' value='Continue to Step 3'></td></tr> \n " ) ;
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
printf ( " </div></p> \n " ) ;
}
/* step 2 - the user wants to select a service */
2019-04-18 17:09:18 +02:00
else if ( select_services = = TRUE ) {
2017-05-19 22:22:40 +02:00
printf ( " <SCRIPT LANGUAGE='JavaScript'> \n " ) ;
printf ( " function gethostname(hostindex){ \n " ) ;
printf ( " hostnames=[ \" all \" " ) ;
firsthostpointer = NULL ;
2019-04-18 17:09:18 +02:00
for ( temp_service = service_list ; temp_service ! = NULL ; temp_service = temp_service - > next ) {
if ( is_authorized_for_service ( temp_service , & current_authdata ) = = TRUE ) {
if ( ! firsthostpointer )
2017-05-19 22:22:40 +02:00
firsthostpointer = temp_service - > host_name ;
printf ( " , \" %s \" " , temp_service - > host_name ) ;
}
}
printf ( " ] \n " ) ;
printf ( " return hostnames[hostindex]; \n " ) ;
printf ( " } \n " ) ;
printf ( " </SCRIPT> \n " ) ;
printf ( " <p><div align=center class='reportSelectTitle'>Step 2: Select Service</div></p> \n " ) ;
printf ( " <p><div align=center> \n " ) ;
printf ( " <form method= \" get \" action= \" %s \" name='serviceform'> \n " , AVAIL_CGI ) ;
printf ( " <input type='hidden' name='get_date_parts'> \n " ) ;
printf ( " <input type='hidden' name='host' value='%s'> \n " , ( firsthostpointer = = NULL ) ? " unknown " : ( char * ) escape_string ( firsthostpointer ) ) ;
printf ( " <table border=0 cellpadding=5> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' valign=center>Service(s):</td><td align=left valign=center class='reportSelectItem'> \n " ) ;
printf ( " <select name='service' onFocus='document.serviceform.host.value=gethostname(this.selectedIndex);' onChange='document.serviceform.host.value=gethostname(this.selectedIndex);'> \n " ) ;
printf ( " <option value='all'>** ALL SERVICES ** \n " ) ;
2019-04-18 17:09:18 +02:00
for ( temp_service = service_list ; temp_service ! = NULL ; temp_service = temp_service - > next ) {
if ( is_authorized_for_service ( temp_service , & current_authdata ) = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " <option value='%s'>%s;%s \n " , escape_string ( temp_service - > description ) , temp_service - > host_name , temp_service - > description ) ;
}
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td></td><td align=left class='dateSelectItem'><input type='submit' value='Continue to Step 3'></td></tr> \n " ) ;
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
printf ( " </div></p> \n " ) ;
printf ( " <div align=center class='helpfulHint'>Tip: If you want to have the option of getting the availability data in CSV format, select '<b>** ALL SERVICES **</b>' from the pull-down menu. \n " ) ;
}
/* generate availability report */
2019-04-18 17:09:18 +02:00
else if ( display_type ! = DISPLAY_NO_AVAIL ) {
2017-05-19 22:22:40 +02:00
/* check authorization */
is_authorized = TRUE ;
2019-04-18 17:09:18 +02:00
if ( ( display_type = = DISPLAY_HOST_AVAIL & & show_all_hosts = = FALSE ) | | ( display_type = = DISPLAY_SERVICE_AVAIL & & show_all_services = = FALSE ) ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL & & show_all_hosts = = FALSE )
2017-05-19 22:22:40 +02:00
is_authorized = is_authorized_for_host ( find_host ( host_name ) , & current_authdata ) ;
else
is_authorized = is_authorized_for_service ( find_service ( host_name , svc_description ) , & current_authdata ) ;
}
2019-04-18 17:09:18 +02:00
if ( is_authorized = = FALSE )
2017-05-19 22:22:40 +02:00
printf ( " <P><DIV ALIGN=CENTER CLASS='errorMessage'>It appears as though you are not authorized to view information for the specified %s...</DIV></P> \n " , ( display_type = = DISPLAY_HOST_AVAIL ) ? " host " : " service " ) ;
else {
time ( & report_start_time ) ;
/* create list of subjects to collect availability data for */
create_subject_list ( ) ;
/* read in all necessary archived state data */
read_archived_state_data ( ) ;
/* compute availability data */
compute_availability ( ) ;
time ( & report_end_time ) ;
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
get_time_breakdown ( ( time_t ) ( report_end_time - report_start_time ) , & days , & hours , & minutes , & seconds ) ;
printf ( " <div align=center class='reportTime'>[ Availability report completed in %d min %d sec ]</div> \n " , minutes , seconds ) ;
printf ( " <BR><BR> \n " ) ;
}
/* display availability data */
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL )
2017-05-19 22:22:40 +02:00
display_host_availability ( ) ;
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICE_AVAIL )
2017-05-19 22:22:40 +02:00
display_service_availability ( ) ;
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_HOSTGROUP_AVAIL )
2017-05-19 22:22:40 +02:00
display_hostgroup_availability ( ) ;
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICEGROUP_AVAIL )
2017-05-19 22:22:40 +02:00
display_servicegroup_availability ( ) ;
/* free memory allocated to availability data */
free_availability_data ( ) ;
}
}
/* step 1 - ask the user what kind of report they want */
else {
printf ( " <p><div align=center class='reportSelectTitle'>Step 1: Select Report Type</div></p> \n " ) ;
printf ( " <p><div align=center> \n " ) ;
printf ( " <form method= \" get \" action= \" %s \" > \n " , AVAIL_CGI ) ;
printf ( " <table border=0 cellpadding=5> \n " ) ;
printf ( " <tr><td class='reportSelectSubTitle' align=right>Type:</td> \n " ) ;
printf ( " <td class='reportSelectItem'> \n " ) ;
printf ( " <select name='report_type'> \n " ) ;
printf ( " <option value=hostgroups>Hostgroup(s) \n " ) ;
printf ( " <option value=hosts>Host(s) \n " ) ;
printf ( " <option value=servicegroups>Servicegroup(s) \n " ) ;
printf ( " <option value=services>Service(s) \n " ) ;
printf ( " </select> \n " ) ;
printf ( " </td></tr> \n " ) ;
printf ( " <tr><td></td><td align=left class='dateSelectItem'><input type='submit' value='Continue to Step 2'></td></tr> \n " ) ;
printf ( " </table> \n " ) ;
printf ( " </form> \n " ) ;
printf ( " </div></p> \n " ) ;
}
document_footer ( ) ;
/* free all other allocated memory */
free_memory ( ) ;
return OK ;
}
void document_header ( int use_stylesheet ) {
char date_time [ MAX_DATETIME_LENGTH ] ;
time_t current_time ;
time_t expire_time ;
printf ( " Cache-Control: no-store \r \n " ) ;
printf ( " Pragma: no-cache \r \n " ) ;
time ( & current_time ) ;
get_time_string ( & current_time , date_time , sizeof ( date_time ) , HTTP_DATE_TIME ) ;
printf ( " Last-Modified: %s \r \n " , date_time ) ;
expire_time = ( time_t ) 0 ;
get_time_string ( & expire_time , date_time , sizeof ( date_time ) , HTTP_DATE_TIME ) ;
printf ( " Expires: %s \r \n " , date_time ) ;
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT )
2017-05-19 23:37:19 +02:00
printf ( " Content-type: text/html; charset=utf-8 \r \n \r \n " ) ;
2017-05-19 22:22:40 +02:00
else {
2019-04-18 17:09:18 +02:00
printf ( " Content-type: text/csv \r \n " ) ;
printf ( " Content-Disposition: attachment; filename= \" avail.csv \" \r \n \r \n " ) ;
2017-05-19 22:22:40 +02:00
return ;
}
2019-04-18 17:09:18 +02:00
if ( embedded = = TRUE | | output_format = = CSV_OUTPUT )
2017-05-19 22:22:40 +02:00
return ;
printf ( " <html> \n " ) ;
printf ( " <head> \n " ) ;
printf ( " <link rel= \" shortcut icon \" href= \" %sfavicon.ico \" type= \" image/ico \" > \n " , url_images_path ) ;
printf ( " <title> \n " ) ;
printf ( " Nagios Availability \n " ) ;
printf ( " </title> \n " ) ;
2019-04-18 17:09:18 +02:00
if ( use_stylesheet = = TRUE ) {
2017-05-19 22:22:40 +02:00
printf ( " <LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'> \n " , url_stylesheets_path , COMMON_CSS ) ;
printf ( " <LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'> \n " , url_stylesheets_path , AVAIL_CSS ) ;
}
printf ( " </head> \n " ) ;
printf ( " <BODY CLASS='avail'> \n " ) ;
/* include user SSI header */
include_ssi_files ( AVAIL_CGI , SSI_HEADER ) ;
return ;
}
void document_footer ( void ) {
2019-04-18 17:09:18 +02:00
if ( output_format ! = HTML_OUTPUT )
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
if ( embedded = = TRUE )
2017-05-19 22:22:40 +02:00
return ;
/* include user SSI footer */
include_ssi_files ( AVAIL_CGI , SSI_FOOTER ) ;
printf ( " </body> \n " ) ;
printf ( " </html> \n " ) ;
return ;
}
int process_cgivars ( void ) {
char * * variables ;
int error = FALSE ;
int x ;
variables = getcgivars ( ) ;
2019-04-18 17:09:18 +02:00
for ( x = 0 ; variables [ x ] ; x + + ) {
2017-05-19 22:22:40 +02:00
/* do some basic length checking on the variable identifier to prevent buffer overflows */
2019-04-18 17:09:18 +02:00
if ( strlen ( variables [ x ] ) > = MAX_INPUT_BUFFER - 1 ) {
2017-05-19 22:22:40 +02:00
continue ;
}
/* we found the hostgroup argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " hostgroup " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ( hostgroup_name = ( char * ) strdup ( variables [ x ] ) ) = = NULL )
2017-05-19 22:22:40 +02:00
hostgroup_name = " " ;
strip_html_brackets ( hostgroup_name ) ;
display_type = DISPLAY_HOSTGROUP_AVAIL ;
show_all_hostgroups = ( strcmp ( hostgroup_name , " all " ) ) ? FALSE : TRUE ;
}
/* we found the servicegroup argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " servicegroup " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ( servicegroup_name = ( char * ) strdup ( variables [ x ] ) ) = = NULL )
2017-05-19 22:22:40 +02:00
servicegroup_name = " " ;
strip_html_brackets ( servicegroup_name ) ;
display_type = DISPLAY_SERVICEGROUP_AVAIL ;
show_all_servicegroups = ( strcmp ( servicegroup_name , " all " ) ) ? FALSE : TRUE ;
}
/* we found the host argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " host " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ( host_name = ( char * ) strdup ( variables [ x ] ) ) = = NULL )
2017-05-19 22:22:40 +02:00
host_name = " " ;
strip_html_brackets ( host_name ) ;
display_type = DISPLAY_HOST_AVAIL ;
show_all_hosts = ( strcmp ( host_name , " all " ) ) ? FALSE : TRUE ;
}
/* we found the service description argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " service " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ( svc_description = ( char * ) strdup ( variables [ x ] ) ) = = NULL )
2017-05-19 22:22:40 +02:00
svc_description = " " ;
strip_html_brackets ( svc_description ) ;
display_type = DISPLAY_SERVICE_AVAIL ;
show_all_services = ( strcmp ( svc_description , " all " ) ) ? FALSE : TRUE ;
}
/* we found first time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " t1 " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
t1 = ( time_t ) strtoul ( variables [ x ] , NULL , 10 ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = FALSE ;
}
/* we found first time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " t2 " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
t2 = ( time_t ) strtoul ( variables [ x ] , NULL , 10 ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = FALSE ;
}
/* we found the assume initial states option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " assumeinitialstates " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ! strcmp ( variables [ x ] , " yes " ) )
2017-05-19 22:22:40 +02:00
assume_initial_states = TRUE ;
else
assume_initial_states = FALSE ;
}
/* we found the assume state during program not running option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " assumestatesduringnotrunning " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ! strcmp ( variables [ x ] , " yes " ) )
2017-05-19 22:22:40 +02:00
assume_states_during_notrunning = TRUE ;
else
assume_states_during_notrunning = FALSE ;
}
/* we found the initial assumed host state option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " initialassumedhoststate " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
initial_assumed_host_state = atoi ( variables [ x ] ) ;
}
/* we found the initial assumed service state option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " initialassumedservicestate " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
initial_assumed_service_state = atoi ( variables [ x ] ) ;
}
/* we found the assume state retention option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " assumestateretention " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ! strcmp ( variables [ x ] , " yes " ) )
2017-05-19 22:22:40 +02:00
assume_state_retention = TRUE ;
else
assume_state_retention = FALSE ;
}
/* we found the include soft states option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " includesoftstates " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ! strcmp ( variables [ x ] , " yes " ) )
2017-05-19 22:22:40 +02:00
include_soft_states = TRUE ;
else
include_soft_states = FALSE ;
}
/* we found the backtrack archives argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " backtrack " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
backtrack_archives = atoi ( variables [ x ] ) ;
2019-04-18 17:09:18 +02:00
if ( backtrack_archives < 0 )
2017-05-19 22:22:40 +02:00
backtrack_archives = 0 ;
2019-04-18 17:09:18 +02:00
if ( backtrack_archives > MAX_ARCHIVE_BACKTRACKS )
2017-05-19 22:22:40 +02:00
backtrack_archives = MAX_ARCHIVE_BACKTRACKS ;
# ifdef DEBUG
printf ( " BACKTRACK ARCHIVES: %d \n " , backtrack_archives ) ;
# endif
}
/* we found the standard timeperiod argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " timeperiod " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ! strcmp ( variables [ x ] , " today " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_TODAY ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " yesterday " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_YESTERDAY ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " thisweek " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_THISWEEK ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " lastweek " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_LASTWEEK ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " thismonth " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_THISMONTH ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " lastmonth " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_LASTMONTH ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " thisquarter " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_THISQUARTER ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " lastquarter " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_LASTQUARTER ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " thisyear " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_THISYEAR ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " lastyear " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_LASTYEAR ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " last24hours " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_LAST24HOURS ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " last7days " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_LAST7DAYS ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " last31days " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_LAST31DAYS ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " custom " ) )
2017-05-19 22:22:40 +02:00
timeperiod_type = TIMEPERIOD_CUSTOM ;
else
continue ;
convert_timeperiod_to_times ( timeperiod_type ) ;
compute_time_from_parts = FALSE ;
}
/* we found the embed option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " embedded " ) )
2017-05-19 22:22:40 +02:00
embedded = TRUE ;
/* we found the noheader option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " noheader " ) )
2017-05-19 22:22:40 +02:00
display_header = FALSE ;
/* we found the CSV output option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " csvoutput " ) ) {
2017-05-19 22:22:40 +02:00
display_header = FALSE ;
output_format = CSV_OUTPUT ;
}
/* we found the log entries option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " show_log_entries " ) )
2017-05-19 22:22:40 +02:00
show_log_entries = TRUE ;
/* we found the full log entries option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " full_log_entries " ) )
2017-05-19 22:22:40 +02:00
full_log_entries = TRUE ;
/* we found the get date parts option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " get_date_parts " ) )
2017-05-19 22:22:40 +02:00
get_date_parts = TRUE ;
/* we found the report type selection option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " report_type " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ! strcmp ( variables [ x ] , " hostgroups " ) )
2017-05-19 22:22:40 +02:00
select_hostgroups = TRUE ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " servicegroups " ) )
2017-05-19 22:22:40 +02:00
select_servicegroups = TRUE ;
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " hosts " ) )
2017-05-19 22:22:40 +02:00
select_hosts = TRUE ;
else
select_services = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " smon " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
start_month = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " sday " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
start_day = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " syear " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
start_year = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " smin " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
start_minute = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " ssec " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
start_second = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " shour " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
start_hour = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " emon " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
end_month = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " eday " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
end_day = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " eyear " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
end_year = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " emin " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
end_minute = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " esec " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
end_second = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found time argument */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " ehour " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( timeperiod_type ! = TIMEPERIOD_CUSTOM )
2017-05-19 22:22:40 +02:00
continue ;
end_hour = atoi ( variables [ x ] ) ;
timeperiod_type = TIMEPERIOD_CUSTOM ;
compute_time_from_parts = TRUE ;
}
/* we found the show scheduled downtime option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " showscheduleddowntime " ) ) {
2017-05-19 22:22:40 +02:00
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
if ( ! strcmp ( variables [ x ] , " yes " ) )
2017-05-19 22:22:40 +02:00
show_scheduled_downtime = TRUE ;
else
show_scheduled_downtime = FALSE ;
}
/* we found the report timeperiod option */
2019-04-18 17:09:18 +02:00
else if ( ! strcmp ( variables [ x ] , " rpttimeperiod " ) ) {
2017-05-19 22:22:40 +02:00
timeperiod * temp_timeperiod ;
x + + ;
2019-04-18 17:09:18 +02:00
if ( variables [ x ] = = NULL ) {
2017-05-19 22:22:40 +02:00
error = TRUE ;
break ;
}
2019-04-18 17:09:18 +02:00
for ( temp_timeperiod = timeperiod_list ; temp_timeperiod ! = NULL ; temp_timeperiod = temp_timeperiod - > next ) {
if ( ! strcmp ( temp_timeperiod - > name , variables [ x ] ) ) {
2017-05-19 22:22:40 +02:00
current_timeperiod = temp_timeperiod ;
break ;
}
}
}
}
/* free memory allocated to the CGI variables */
free_cgivars ( variables ) ;
return error ;
}
/* computes availability data for all subjects */
void compute_availability ( void ) {
avail_subject * temp_subject ;
time_t current_time ;
time ( & current_time ) ;
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
compute_subject_availability ( temp_subject , current_time ) ;
compute_subject_downtime ( temp_subject , current_time ) ;
}
return ;
}
/* computes availability data for a given subject */
void compute_subject_availability ( avail_subject * subject , time_t current_time ) {
archived_state * temp_as ;
archived_state * last_as ;
time_t a ;
time_t b ;
int current_state = AS_NO_DATA ;
int have_some_real_data = FALSE ;
hoststatus * hststatus = NULL ;
servicestatus * svcstatus = NULL ;
time_t initial_assumed_time ;
int initial_assumed_state = AS_NO_DATA ;
int error ;
/* if left hand of graph is after current time, we can't do anything at all.... */
2019-04-18 17:09:18 +02:00
if ( t1 > current_time )
2017-05-19 22:22:40 +02:00
return ;
/* get current state of host or service if possible */
2019-04-18 17:09:18 +02:00
if ( subject - > type = = HOST_SUBJECT )
2017-05-19 22:22:40 +02:00
hststatus = find_hoststatus ( subject - > host_name ) ;
else
svcstatus = find_servicestatus ( subject - > host_name , subject - > service_description ) ;
/************************************/
/* INSERT CURRENT STATE (IF WE CAN) */
/************************************/
/* if current time DOES NOT fall within graph bounds, so we can't do anything as far as assuming current state */
/* if we don't have any data, assume current state (if possible) */
2019-04-18 17:09:18 +02:00
if ( subject - > as_list = = NULL & & current_time > t1 & & current_time < = t2 ) {
2017-05-19 22:22:40 +02:00
/* we don't have any historical information, but the current time falls within the reporting period, so use */
/* the current status of the host/service as the starting data */
2019-04-18 17:09:18 +02:00
if ( subject - > type = = HOST_SUBJECT ) {
if ( hststatus ! = NULL ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( hststatus - > status = = SD_HOST_DOWN )
2017-05-19 22:22:40 +02:00
subject - > last_known_state = AS_HOST_DOWN ;
2019-04-18 17:09:18 +02:00
else if ( hststatus - > status = = SD_HOST_UNREACHABLE )
2017-05-19 22:22:40 +02:00
subject - > last_known_state = AS_HOST_UNREACHABLE ;
2019-04-18 17:09:18 +02:00
else if ( hststatus - > status = = SD_HOST_UP )
2017-05-19 22:22:40 +02:00
subject - > last_known_state = AS_HOST_UP ;
else
subject - > last_known_state = AS_NO_DATA ;
2019-04-18 17:09:18 +02:00
if ( subject - > last_known_state ! = AS_NO_DATA ) {
2017-05-19 22:22:40 +02:00
/* add a dummy archived state item, so something can get graphed */
add_archived_state ( subject - > last_known_state , AS_HARD_STATE , t1 , " Current Host State Assumed (Faked Log Entry) " , subject ) ;
}
}
}
else {
2019-04-18 17:09:18 +02:00
if ( svcstatus ! = NULL ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( svcstatus - > status = = SERVICE_OK )
2017-05-19 22:22:40 +02:00
subject - > last_known_state = AS_SVC_OK ;
2019-04-18 17:09:18 +02:00
else if ( svcstatus - > status = = SERVICE_WARNING )
2017-05-19 22:22:40 +02:00
subject - > last_known_state = AS_SVC_WARNING ;
2019-04-18 17:09:18 +02:00
else if ( svcstatus - > status = = SERVICE_CRITICAL )
2017-05-19 22:22:40 +02:00
subject - > last_known_state = AS_SVC_CRITICAL ;
2019-04-18 17:09:18 +02:00
else if ( svcstatus - > status = = SERVICE_UNKNOWN )
2017-05-19 22:22:40 +02:00
subject - > last_known_state = AS_SVC_UNKNOWN ;
else
subject - > last_known_state = AS_NO_DATA ;
2019-04-18 17:09:18 +02:00
if ( subject - > last_known_state ! = AS_NO_DATA ) {
2017-05-19 22:22:40 +02:00
/* add a dummy archived state item, so something can get graphed */
add_archived_state ( subject - > last_known_state , AS_HARD_STATE , t1 , " Current Service State Assumed (Faked Log Entry) " , subject ) ;
}
}
}
}
/******************************************/
/* INSERT FIRST ASSUMED STATE (IF WE CAN) */
/******************************************/
2019-04-18 17:09:18 +02:00
if ( ( subject - > type = = HOST_SUBJECT & & initial_assumed_host_state ! = AS_NO_DATA ) | | ( subject - > type = = SERVICE_SUBJECT & & initial_assumed_service_state ! = AS_NO_DATA ) ) {
2017-05-19 22:22:40 +02:00
/* see if its okay to assume initial state for this subject */
error = FALSE ;
2019-04-18 17:09:18 +02:00
if ( subject - > type = = SERVICE_SUBJECT ) {
if ( initial_assumed_service_state ! = AS_SVC_OK & & initial_assumed_service_state ! = AS_SVC_WARNING & & initial_assumed_service_state ! = AS_SVC_UNKNOWN & & initial_assumed_service_state ! = AS_SVC_CRITICAL & & initial_assumed_service_state ! = AS_CURRENT_STATE )
2017-05-19 22:22:40 +02:00
error = TRUE ;
else
initial_assumed_state = initial_assumed_service_state ;
2019-04-18 17:09:18 +02:00
if ( initial_assumed_service_state = = AS_CURRENT_STATE & & svcstatus = = NULL )
2017-05-19 22:22:40 +02:00
error = TRUE ;
}
else {
2019-04-18 17:09:18 +02:00
if ( initial_assumed_host_state ! = AS_HOST_UP & & initial_assumed_host_state ! = AS_HOST_DOWN & & initial_assumed_host_state ! = AS_HOST_UNREACHABLE & & initial_assumed_host_state ! = AS_CURRENT_STATE )
2017-05-19 22:22:40 +02:00
error = TRUE ;
else
initial_assumed_state = initial_assumed_host_state ;
2019-04-18 17:09:18 +02:00
if ( initial_assumed_host_state = = AS_CURRENT_STATE & & hststatus = = NULL )
2017-05-19 22:22:40 +02:00
error = TRUE ;
}
/* get the current state if applicable */
2019-04-18 17:09:18 +02:00
if ( ( ( subject - > type = = HOST_SUBJECT & & initial_assumed_host_state = = AS_CURRENT_STATE ) | | ( subject - > type = = SERVICE_SUBJECT & & initial_assumed_service_state = = AS_CURRENT_STATE ) ) & & error = = FALSE ) {
if ( subject - > type = = SERVICE_SUBJECT ) {
switch ( svcstatus - > status ) {
case SERVICE_OK :
initial_assumed_state = AS_SVC_OK ;
break ;
case SERVICE_WARNING :
initial_assumed_state = AS_SVC_WARNING ;
break ;
case SERVICE_UNKNOWN :
initial_assumed_state = AS_SVC_UNKNOWN ;
break ;
case SERVICE_CRITICAL :
initial_assumed_state = AS_SVC_CRITICAL ;
break ;
default :
error = TRUE ;
break ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
2019-04-18 17:09:18 +02:00
switch ( hststatus - > status ) {
case SD_HOST_DOWN :
initial_assumed_state = AS_HOST_DOWN ;
break ;
case SD_HOST_UNREACHABLE :
initial_assumed_state = AS_HOST_UNREACHABLE ;
break ;
case SD_HOST_UP :
initial_assumed_state = AS_HOST_UP ;
break ;
default :
error = TRUE ;
break ;
2017-05-19 22:22:40 +02:00
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( error = = FALSE ) {
2017-05-19 22:22:40 +02:00
/* add this assumed state entry before any entries in the list and <= t1 */
2019-04-18 17:09:18 +02:00
if ( subject - > as_list = = NULL )
2017-05-19 22:22:40 +02:00
initial_assumed_time = t1 ;
2019-04-18 17:09:18 +02:00
else if ( subject - > as_list - > time_stamp > t1 )
2017-05-19 22:22:40 +02:00
initial_assumed_time = t1 ;
else
initial_assumed_time = subject - > as_list - > time_stamp - 1 ;
2019-04-18 17:09:18 +02:00
if ( subject - > type = = HOST_SUBJECT )
2017-05-19 22:22:40 +02:00
add_archived_state ( initial_assumed_state , AS_HARD_STATE , initial_assumed_time , " First Host State Assumed (Faked Log Entry) " , subject ) ;
else
add_archived_state ( initial_assumed_state , AS_HARD_STATE , initial_assumed_time , " First Service State Assumed (Faked Log Entry) " , subject ) ;
}
}
/**************************************/
/* BAIL OUT IF WE DON'T HAVE ANYTHING */
/**************************************/
have_some_real_data = FALSE ;
2019-04-18 17:09:18 +02:00
for ( temp_as = subject - > as_list ; temp_as ! = NULL ; temp_as = temp_as - > next ) {
if ( temp_as - > entry_type ! = AS_NO_DATA & & temp_as - > entry_type ! = AS_PROGRAM_START & & temp_as - > entry_type ! = AS_PROGRAM_END ) {
2017-05-19 22:22:40 +02:00
have_some_real_data = TRUE ;
break ;
}
}
2019-04-18 17:09:18 +02:00
if ( have_some_real_data = = FALSE )
2017-05-19 22:22:40 +02:00
return ;
last_as = NULL ;
subject - > earliest_time = t2 ;
subject - > latest_time = t1 ;
# ifdef DEBUG
printf ( " --- BEGINNING/MIDDLE SECTION ---<BR> \n " ) ;
# endif
2019-08-03 18:28:19 +02:00
# ifdef DEBUG2
printf ( " <pre> " ) ;
# endif
2017-05-19 22:22:40 +02:00
/**********************************/
/* BEGINNING/MIDDLE SECTION */
/**********************************/
2019-04-18 17:09:18 +02:00
for ( temp_as = subject - > as_list ; temp_as ! = NULL ; temp_as = temp_as - > next ) {
2017-05-19 22:22:40 +02:00
/* keep this as last known state if this is the first entry or if it occurs before the starting point of the graph */
2019-04-18 17:09:18 +02:00
if ( ( temp_as - > time_stamp < = t1 | | temp_as = = subject - > as_list ) & & ( temp_as - > entry_type ! = AS_NO_DATA & & temp_as - > entry_type ! = AS_PROGRAM_END & & temp_as - > entry_type ! = AS_PROGRAM_START ) ) {
2017-05-19 22:22:40 +02:00
subject - > last_known_state = temp_as - > entry_type ;
# ifdef DEBUG
printf ( " SETTING LAST KNOWN STATE=%d<br> \n " , subject - > last_known_state ) ;
# endif
}
/* skip this entry if it occurs before the starting point of the graph */
2019-04-18 17:09:18 +02:00
if ( temp_as - > time_stamp < = t1 ) {
2017-05-19 22:22:40 +02:00
# ifdef DEBUG
printf ( " SKIPPING PRE-EVENT: %d @ %lu<br> \n " , temp_as - > entry_type , temp_as - > time_stamp ) ;
# endif
last_as = temp_as ;
continue ;
}
/* graph this span if we're not on the first item */
2019-04-18 17:09:18 +02:00
if ( last_as ! = NULL ) {
2017-05-19 22:22:40 +02:00
a = last_as - > time_stamp ;
b = temp_as - > time_stamp ;
/* we've already passed the last time displayed in the graph */
2019-04-18 17:09:18 +02:00
if ( a > t2 )
2017-05-19 22:22:40 +02:00
break ;
/* only graph this data if its on the graph */
2019-04-18 17:09:18 +02:00
else if ( b > t1 ) {
2017-05-19 22:22:40 +02:00
/* clip last time if it exceeds graph limits */
2019-04-18 17:09:18 +02:00
if ( b > t2 )
2017-05-19 22:22:40 +02:00
b = t2 ;
/* clip first time if it precedes graph limits */
2019-04-18 17:09:18 +02:00
if ( a < t1 )
2017-05-19 22:22:40 +02:00
a = t1 ;
/* save this time if its the earliest we've graphed */
2019-04-18 17:09:18 +02:00
if ( a < subject - > earliest_time ) {
2017-05-19 22:22:40 +02:00
subject - > earliest_time = a ;
subject - > earliest_state = last_as - > entry_type ;
}
/* save this time if its the latest we've graphed */
2019-04-18 17:09:18 +02:00
if ( b > subject - > latest_time ) {
2017-05-19 22:22:40 +02:00
subject - > latest_time = b ;
subject - > latest_state = last_as - > entry_type ;
}
/* compute availability times for this chunk */
compute_subject_availability_times ( last_as - > entry_type , temp_as - > entry_type , last_as - > time_stamp , a , b , subject , temp_as ) ;
/* return if we've reached the end of the graph limits */
2019-04-18 17:09:18 +02:00
if ( b > = t2 ) {
2017-05-19 22:22:40 +02:00
last_as = temp_as ;
break ;
}
}
}
/* keep track of the last item */
last_as = temp_as ;
}
# ifdef DEBUG
printf ( " --- END SECTION ---<BR> \n " ) ;
# endif
/**********************************/
/* END SECTION */
/**********************************/
2019-04-18 17:09:18 +02:00
if ( last_as ! = NULL ) {
2017-05-19 22:22:40 +02:00
/* don't process an entry that is beyond the limits of the graph */
2019-04-18 17:09:18 +02:00
if ( last_as - > time_stamp < t2 ) {
2017-05-19 22:22:40 +02:00
time ( & current_time ) ;
b = current_time ;
2019-04-18 17:09:18 +02:00
if ( b > t2 )
2017-05-19 22:22:40 +02:00
b = t2 ;
a = last_as - > time_stamp ;
2019-04-18 17:09:18 +02:00
if ( a < t1 )
2017-05-19 22:22:40 +02:00
a = t1 ;
/* fake the current state (it doesn't really matter for graphing) */
2019-04-18 17:09:18 +02:00
if ( subject - > type = = HOST_SUBJECT )
2017-05-19 22:22:40 +02:00
current_state = AS_HOST_UP ;
else
current_state = AS_SVC_OK ;
/* compute availability times for last state */
compute_subject_availability_times ( last_as - > entry_type , current_state , last_as - > time_stamp , a , b , subject , last_as ) ;
}
}
2019-08-03 18:28:19 +02:00
# ifdef DEBUG2
printf ( " </pre> " ) ;
# endif
2017-05-19 22:22:40 +02:00
return ;
}
/* computes availability times */
2019-04-18 17:09:18 +02:00
void compute_subject_availability_times ( int first_state , int last_state , time_t real_start_time , time_t start_time , time_t end_time , avail_subject * subject , archived_state * as )
{
int start_state = 0 ;
unsigned long state_duration = 0L ;
struct tm * t = NULL ;
time_t midnight_today = 0L ;
int weekday = 0 ;
timerange * temp_timerange = NULL ;
unsigned long temp_duration = 0L ;
unsigned long temp_end = 0L ;
unsigned long temp_start = 0L ;
unsigned long start = 0L ;
unsigned long end = 0L ;
2017-05-19 22:22:40 +02:00
2019-08-03 18:28:19 +02:00
# ifdef DEBUG2
2019-04-18 17:09:18 +02:00
if ( subject - > type = = HOST_SUBJECT ) {
2019-08-03 18:28:19 +02:00
printf ( " \n HOST '%s'... \n " , subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
}
else {
2019-08-03 18:28:19 +02:00
printf ( " \n SERVICE '%s' ON HOST '%s'... \n " , subject - > service_description , subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-08-03 18:28:19 +02:00
printf ( " COMPUTING %d->%d FROM %lu to %lu (%lu seconds) FOR %s \n " , first_state , last_state , start_time , end_time , ( end_time - start_time ) , ( subject - > type = = HOST_SUBJECT ) ? " HOST " : " SERVICE " ) ;
2017-05-19 22:22:40 +02:00
# endif
/* clip times if necessary */
2019-04-18 17:09:18 +02:00
if ( start_time < t1 ) {
2017-05-19 22:22:40 +02:00
start_time = t1 ;
2019-04-18 17:09:18 +02:00
}
if ( end_time > t2 ) {
2017-05-19 22:22:40 +02:00
end_time = t2 ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* make sure this is a valid time */
2019-04-18 17:09:18 +02:00
if ( start_time > t2 ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
if ( end_time < t1 ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* MickeM - attempt to handle the current time_period (if any) */
2019-04-18 17:09:18 +02:00
if ( current_timeperiod ! = NULL ) {
2017-05-19 22:22:40 +02:00
t = localtime ( ( time_t * ) & start_time ) ;
state_duration = 0 ;
/* calculate the start of the day (midnight, 00:00 hours) */
2019-04-18 17:09:18 +02:00
t - > tm_sec = 0 ;
t - > tm_min = 0 ;
t - > tm_hour = 0 ;
t - > tm_isdst = - 1 ;
2017-05-19 22:22:40 +02:00
midnight_today = ( unsigned long ) mktime ( t ) ;
2019-04-18 17:09:18 +02:00
weekday = t - > tm_wday ;
while ( midnight_today < end_time ) {
2017-05-19 22:22:40 +02:00
temp_duration = 0 ;
temp_end = min ( 86400 , end_time - midnight_today ) ;
temp_start = 0 ;
2019-04-18 17:09:18 +02:00
if ( start_time > midnight_today ) {
2017-05-19 22:22:40 +02:00
temp_start = start_time - midnight_today ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
# ifdef DEBUG
printf ( " <b>Matching: %ld -> %ld. (%ld -> %ld)</b><br> \n " , temp_start , temp_end , midnight_today + temp_start , midnight_today + temp_end ) ;
# endif
/* check all time ranges for this day of the week */
2019-04-18 17:09:18 +02:00
for ( temp_timerange = current_timeperiod - > days [ weekday ] ; temp_timerange ! = NULL ; temp_timerange = temp_timerange - > next ) {
2017-05-19 22:22:40 +02:00
# ifdef DEBUG
printf ( " <li>Matching in timerange[%d]: %d -> %d (%ld -> %ld)<br> \n " , weekday , temp_timerange - > range_start , temp_timerange - > range_end , temp_start , temp_end ) ;
# endif
start = max ( temp_timerange - > range_start , temp_start ) ;
end = min ( temp_timerange - > range_end , temp_end ) ;
2019-04-18 17:09:18 +02:00
if ( start < end ) {
2017-05-19 22:22:40 +02:00
temp_duration + = end - start ;
# ifdef DEBUG
printf ( " <li>Matched time: %ld -> %ld = %d<br> \n " , start , end , temp_duration ) ;
# endif
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
# ifdef DEBUG
2019-04-18 17:09:18 +02:00
else {
2017-05-19 22:22:40 +02:00
printf ( " <li>Ignored time: %ld -> %ld<br> \n " , start , end ) ;
}
2019-04-18 17:09:18 +02:00
# endif
}
2017-05-19 22:22:40 +02:00
state_duration + = temp_duration ;
temp_start = 0 ;
midnight_today + = 86400 ;
2019-04-18 17:09:18 +02:00
if ( + + weekday > 6 ) {
2017-05-19 22:22:40 +02:00
weekday = 0 ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* no report timeperiod was selected (assume 24x7) */
else {
/* calculate time in this state */
state_duration = ( unsigned long ) ( end_time - start_time ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* can't graph if we don't have data... */
2019-04-18 17:09:18 +02:00
if ( first_state = = AS_NO_DATA | | last_state = = AS_NO_DATA ) {
2017-05-19 22:22:40 +02:00
subject - > time_indeterminate_nodata + = state_duration ;
return ;
2019-04-18 17:09:18 +02:00
}
if ( first_state = = AS_PROGRAM_START & & ( last_state = = AS_PROGRAM_END | | last_state = = AS_PROGRAM_START ) ) {
if ( assume_initial_states = = FALSE ) {
2017-05-19 22:22:40 +02:00
subject - > time_indeterminate_nodata + = state_duration ;
return ;
}
2019-04-18 17:09:18 +02:00
}
if ( first_state = = AS_PROGRAM_END ) {
if ( assume_states_during_notrunning = = TRUE ) {
2017-05-19 22:22:40 +02:00
first_state = subject - > last_known_state ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
subject - > time_indeterminate_notrunning + = state_duration ;
return ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* special case if first entry was program start */
2019-04-18 17:09:18 +02:00
if ( first_state = = AS_PROGRAM_START ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( assume_initial_states = = TRUE ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( assume_state_retention = = TRUE ) {
2017-05-19 22:22:40 +02:00
start_state = subject - > last_known_state ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
2019-04-18 17:09:18 +02:00
if ( subject - > type = = HOST_SUBJECT ) {
2017-05-19 22:22:40 +02:00
start_state = AS_HOST_UP ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
start_state = AS_SVC_OK ;
}
}
2019-04-18 17:09:18 +02:00
}
else {
2019-08-03 18:28:19 +02:00
as - > processed_state = AS_NO_DATA ;
2017-05-19 22:22:40 +02:00
return ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
start_state = first_state ;
subject - > last_known_state = first_state ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* save "processed state" info */
as - > processed_state = start_state ;
2019-08-03 18:28:19 +02:00
# ifdef DEBUG2
printf ( " PROCESSED_STATE: %d \n " , start_state ) ;
# endif
2017-05-19 22:22:40 +02:00
# ifdef DEBUG
printf ( " PASSED TIME CHECKS, CLIPPED VALUES: START=%lu, END=%lu \n " , start_time , end_time ) ;
# endif
/* add time in this state to running totals */
2019-04-18 17:09:18 +02:00
switch ( start_state ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
case AS_HOST_UP :
subject - > time_up + = state_duration ;
break ;
case AS_HOST_DOWN :
subject - > time_down + = state_duration ;
break ;
case AS_HOST_UNREACHABLE :
subject - > time_unreachable + = state_duration ;
break ;
case AS_SVC_OK :
subject - > time_ok + = state_duration ;
break ;
case AS_SVC_WARNING :
subject - > time_warning + = state_duration ;
break ;
case AS_SVC_UNKNOWN :
subject - > time_unknown + = state_duration ;
break ;
case AS_SVC_CRITICAL :
subject - > time_critical + = state_duration ;
break ;
default :
break ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* computes downtime data for a given subject */
2019-04-18 17:09:18 +02:00
void compute_subject_downtime ( avail_subject * subject , time_t current_time )
{
archived_state * temp_sd = NULL ;
time_t start_time = 0L ;
time_t end_time = 0L ;
int host_downtime_state = 0 ;
2017-05-19 23:37:19 +02:00
int service_downtime_state = 0 ;
2019-04-18 17:09:18 +02:00
int process_chunk = FALSE ;
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " <pre> " ) ;
2017-05-19 22:22:40 +02:00
printf ( " COMPUTE_SUBJECT_DOWNTIME \n " ) ;
# endif
/* if left hand of graph is after current time, we can't do anything at all.... */
2019-04-18 17:09:18 +02:00
if ( t1 > current_time ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* no scheduled downtime data for subject... */
2019-04-18 17:09:18 +02:00
if ( subject - > sd_list = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* all data we have occurs after last time on graph... */
2019-04-18 17:09:18 +02:00
if ( subject - > sd_list - > time_stamp > = t2 ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* initialize pointer */
temp_sd = subject - > sd_list ;
/* special case if first entry is the end of scheduled downtime */
2019-04-18 17:09:18 +02:00
if ( ( temp_sd - > entry_type = = AS_HOST_DOWNTIME_END | | temp_sd - > entry_type = = AS_SVC_DOWNTIME_END ) & & temp_sd - > time_stamp > t1 ) {
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
printf ( " \t SPECIAL DOWNTIME CASE \n " ) ;
# endif
start_time = t1 ;
end_time = ( temp_sd - > time_stamp > t2 ) ? t2 : temp_sd - > time_stamp ;
compute_subject_downtime_times ( start_time , end_time , subject , NULL ) ;
temp_sd = temp_sd - > next ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* process all periods of scheduled downtime */
2019-04-18 17:09:18 +02:00
for ( ; temp_sd ! = NULL ; temp_sd = temp_sd - > next ) {
2017-05-19 22:22:40 +02:00
/* we've passed graph bounds... */
2019-04-18 17:09:18 +02:00
if ( temp_sd - > time_stamp > = t2 ) {
2017-05-19 22:22:40 +02:00
break ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_sd - > entry_type = = AS_HOST_DOWNTIME_START ) {
2017-05-19 23:37:19 +02:00
host_downtime_state = 1 ;
2019-04-18 17:09:18 +02:00
}
else if ( temp_sd - > entry_type = = AS_HOST_DOWNTIME_END ) {
2017-05-19 23:37:19 +02:00
host_downtime_state = 0 ;
2019-04-18 17:09:18 +02:00
}
else if ( temp_sd - > entry_type = = AS_SVC_DOWNTIME_START ) {
2017-05-19 23:37:19 +02:00
service_downtime_state = 1 ;
2019-04-18 17:09:18 +02:00
}
else if ( temp_sd - > entry_type = = AS_SVC_DOWNTIME_END ) {
2017-05-19 23:37:19 +02:00
service_downtime_state = 0 ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
process_chunk = FALSE ;
2019-04-18 17:09:18 +02:00
if ( temp_sd - > entry_type = = AS_HOST_DOWNTIME_START | | temp_sd - > entry_type = = AS_SVC_DOWNTIME_START ) {
2017-05-19 22:22:40 +02:00
process_chunk = TRUE ;
2019-04-18 17:09:18 +02:00
}
else if ( subject - > type = = SERVICE_SUBJECT & & ( host_downtime_state = = 1 | | service_downtime_state = = 1 ) ) {
2017-05-19 22:22:40 +02:00
process_chunk = TRUE ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* process this specific "chunk" of scheduled downtime */
2019-04-18 17:09:18 +02:00
if ( process_chunk = = TRUE ) {
2017-05-19 22:22:40 +02:00
start_time = temp_sd - > time_stamp ;
end_time = ( temp_sd - > next = = NULL ) ? current_time : temp_sd - > next - > time_stamp ;
/* check time sanity */
2019-04-18 17:09:18 +02:00
if ( end_time < = t1 ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
if ( start_time > = t2 ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
if ( start_time > = end_time ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* clip time values */
2019-04-18 17:09:18 +02:00
if ( start_time < t1 ) {
2017-05-19 22:22:40 +02:00
start_time = t1 ;
2019-04-18 17:09:18 +02:00
}
if ( end_time > t2 ) {
2017-05-19 22:22:40 +02:00
end_time = t2 ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
compute_subject_downtime_times ( start_time , end_time , subject , temp_sd ) ;
}
}
2019-08-03 18:28:19 +02:00
# ifdef DEBUG2
printf ( " </pre> " ) ;
# endif
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* computes downtime times */
2019-04-18 17:09:18 +02:00
void compute_subject_downtime_times ( time_t start_time , time_t end_time , avail_subject * subject , archived_state * sd )
{
archived_state * temp_as = NULL ;
time_t part_subject_state = 0L ;
int saved_status = 0 ;
time_t saved_stamp = 0 ;
int count = 0 ;
2017-05-19 22:22:40 +02:00
archived_state * temp_before = NULL ;
2019-04-18 17:09:18 +02:00
archived_state * last = NULL ;
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " \n <b>ENTERING COMPUTE_SUBJECT_DOWNTIME_TIMES: start=%lu, end=%lu, t1=%lu, t2=%lu </b> \n \n " , start_time , end_time , t1 , t2 ) ;
2017-05-19 22:22:40 +02:00
# endif
/* times are weird, so bail out... */
2019-04-18 17:09:18 +02:00
if ( start_time > end_time ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
if ( start_time < t1 | | end_time > t2 ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* find starting point in archived state list */
2019-04-18 17:09:18 +02:00
if ( sd = = NULL ) {
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " TEMP_AS=SUBJECT->AS_LIST \n " ) ;
2017-05-19 22:22:40 +02:00
# endif
temp_as = subject - > as_list ;
2019-04-18 17:09:18 +02:00
}
else if ( sd - > misc_ptr = = NULL ) {
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " TEMP_AS=SUBJECT->AS_LIST \n " ) ;
2017-05-19 22:22:40 +02:00
# endif
temp_as = subject - > as_list ;
2019-04-18 17:09:18 +02:00
}
else if ( sd - > misc_ptr - > next = = NULL ) {
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " TEMP_AS=SD->MISC_PTR \n " ) ;
2017-05-19 22:22:40 +02:00
# endif
temp_as = sd - > misc_ptr ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " TEMP_AS=SD->MISC_PTR->NEXT \n " ) ;
2017-05-19 22:22:40 +02:00
# endif
temp_as = sd - > misc_ptr - > next ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* initialize values */
2019-04-18 17:09:18 +02:00
if ( temp_as = = NULL ) {
2017-05-19 22:22:40 +02:00
part_subject_state = AS_NO_DATA ;
2019-04-18 17:09:18 +02:00
}
else if ( temp_as - > processed_state = = AS_PROGRAM_START | | temp_as - > processed_state = = AS_PROGRAM_END | | temp_as - > processed_state = = AS_NO_DATA ) {
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " ENTRY TYPE #1: %d \n " , temp_as - > entry_type ) ;
2017-05-19 22:22:40 +02:00
# endif
part_subject_state = AS_NO_DATA ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " ENTRY TYPE #2: %d \n " , temp_as - > entry_type ) ;
printf ( " STATE: %d \n " , temp_as - > processed_state ) ;
2017-05-19 22:22:40 +02:00
# endif
part_subject_state = temp_as - > processed_state ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
2019-08-03 18:28:19 +02:00
printf ( " TEMP_AS=%s \n " , ( temp_as = = NULL ) ? " NULL " : " Not NULL " ) ;
printf ( " SD=%s \n \n " , ( sd = = NULL ) ? " NULL " : " Not NULL " ) ;
2017-05-19 22:22:40 +02:00
# endif
/* temp_as now points to first event to possibly "break" this chunk */
2019-04-18 17:09:18 +02:00
for ( ; temp_as ! = NULL ; temp_as = temp_as - > next ) {
2017-05-19 22:22:40 +02:00
count + + ;
last = temp_as ;
2019-04-18 17:09:18 +02:00
if ( temp_before = = NULL ) {
if ( last - > time_stamp > start_time ) {
if ( last - > time_stamp > end_time ) {
2017-05-19 22:22:40 +02:00
compute_subject_downtime_part_times ( start_time , end_time , part_subject_state , subject ) ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
compute_subject_downtime_part_times ( start_time , last - > time_stamp , part_subject_state , subject ) ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
temp_before = temp_as ;
saved_status = temp_as - > entry_type ;
saved_stamp = temp_as - > time_stamp ;
/* check if first time is before schedule downtime */
2019-04-18 17:09:18 +02:00
if ( saved_stamp < start_time ) {
2017-05-19 22:22:40 +02:00
saved_stamp = start_time ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* if status changed, we have to calculate */
2019-04-18 17:09:18 +02:00
if ( saved_status ! = temp_as - > entry_type ) {
2017-05-19 22:22:40 +02:00
2019-08-03 18:28:19 +02:00
/* accommodate status for program start/end */
if ( saved_status = = AS_PROGRAM_START | | saved_status = = AS_PROGRAM_END ) {
saved_status = temp_as - > processed_state ;
}
2017-05-19 22:22:40 +02:00
/* is outside schedule time, use end schdule downtime */
2019-04-18 17:09:18 +02:00
if ( temp_as - > time_stamp > end_time ) {
if ( saved_stamp < start_time ) {
2017-05-19 22:22:40 +02:00
compute_subject_downtime_part_times ( start_time , end_time , saved_status , subject ) ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
compute_subject_downtime_part_times ( saved_stamp , end_time , saved_status , subject ) ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
2019-04-18 17:09:18 +02:00
if ( saved_stamp < start_time ) {
2017-05-19 22:22:40 +02:00
compute_subject_downtime_part_times ( start_time , temp_as - > time_stamp , saved_status , subject ) ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
compute_subject_downtime_part_times ( saved_stamp , temp_as - > time_stamp , saved_status , subject ) ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
saved_status = temp_as - > entry_type ;
saved_stamp = temp_as - > time_stamp ;
2017-05-19 23:37:19 +02:00
/* check if first time is before schedule downtime */
2019-04-18 17:09:18 +02:00
if ( saved_stamp < start_time ) {
2017-05-19 23:37:19 +02:00
saved_stamp = start_time ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* just one entry inside the scheduled downtime */
2019-04-18 17:09:18 +02:00
if ( count = = 0 ) {
2017-05-19 22:22:40 +02:00
compute_subject_downtime_part_times ( start_time , end_time , part_subject_state , subject ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
2019-08-03 18:28:19 +02:00
/* is outside scheduled time, or at the end of the log, so fake the end of scheduled downtime */
# ifdef DEBUG2
printf ( " <b>LAST ENTRY TYPE: %d</b> \n " , last - > entry_type ) ;
# endif
if ( last - > entry_type = = AS_PROGRAM_START | | last - > entry_type = = AS_PROGRAM_END ) {
/* if we are NOT assuming initial states, then we do not want to add this data into the downtime */
if ( last - > entry_type = = AS_PROGRAM_START & & assume_initial_states = = FALSE ) {
return ;
}
compute_subject_downtime_part_times ( saved_stamp , end_time , part_subject_state , subject ) ;
} else {
2017-05-19 22:22:40 +02:00
compute_subject_downtime_part_times ( saved_stamp , end_time , saved_status , subject ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* computes downtime times */
2019-04-18 17:09:18 +02:00
void compute_subject_downtime_part_times ( time_t start_time , time_t end_time , int subject_state , avail_subject * subject )
{
unsigned long state_duration = 0L ;
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
printf ( " ENTERING COMPUTE_SUBJECT_DOWNTIME_PART_TIMES \n " ) ;
# endif
/* times are weird */
2019-04-18 17:09:18 +02:00
if ( start_time > end_time ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
state_duration = ( unsigned long ) ( end_time - start_time ) ;
2019-04-18 17:09:18 +02:00
switch ( subject_state ) {
case AS_HOST_UP :
subject - > scheduled_time_up + = state_duration ;
break ;
case AS_HOST_DOWN :
subject - > scheduled_time_down + = state_duration ;
break ;
case AS_HOST_UNREACHABLE :
subject - > scheduled_time_unreachable + = state_duration ;
break ;
case AS_SVC_OK :
subject - > scheduled_time_ok + = state_duration ;
break ;
case AS_SVC_WARNING :
subject - > scheduled_time_warning + = state_duration ;
break ;
case AS_SVC_UNKNOWN :
subject - > scheduled_time_unknown + = state_duration ;
break ;
case AS_SVC_CRITICAL :
subject - > scheduled_time_critical + = state_duration ;
break ;
default :
subject - > scheduled_time_indeterminate + = state_duration ;
break ;
}
2017-05-19 22:22:40 +02:00
# ifdef DEBUG2
printf ( " \t SUBJECT DOWNTIME: Host '%s', Service '%s', State=%d, Duration=%lu, Start=%lu \n " , subject - > host_name , ( subject - > service_description = = NULL ) ? " NULL " : subject - > service_description , subject_state , state_duration , start_time ) ;
# endif
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* convert current host state to archived state value */
2019-04-18 17:09:18 +02:00
int convert_host_state_to_archived_state ( int current_status )
{
if ( current_status = = SD_HOST_UP ) {
2017-05-19 22:22:40 +02:00
return AS_HOST_UP ;
2019-04-18 17:09:18 +02:00
}
if ( current_status = = SD_HOST_DOWN ) {
2017-05-19 22:22:40 +02:00
return AS_HOST_DOWN ;
2019-04-18 17:09:18 +02:00
}
if ( current_status = = SD_HOST_UNREACHABLE ) {
2017-05-19 22:22:40 +02:00
return AS_HOST_UNREACHABLE ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
return AS_NO_DATA ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* convert current service state to archived state value */
2019-04-18 17:09:18 +02:00
int convert_service_state_to_archived_state ( int current_status )
{
if ( current_status = = SERVICE_OK ) {
2017-05-19 22:22:40 +02:00
return AS_SVC_OK ;
2019-04-18 17:09:18 +02:00
}
if ( current_status = = SERVICE_UNKNOWN ) {
2017-05-19 22:22:40 +02:00
return AS_SVC_UNKNOWN ;
2019-04-18 17:09:18 +02:00
}
if ( current_status = = SERVICE_WARNING ) {
2017-05-19 22:22:40 +02:00
return AS_SVC_WARNING ;
2019-04-18 17:09:18 +02:00
}
if ( current_status = = SERVICE_CRITICAL ) {
2017-05-19 22:22:40 +02:00
return AS_SVC_CRITICAL ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
return AS_NO_DATA ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* create list of subjects to collect availability data for */
2019-04-18 17:09:18 +02:00
void create_subject_list ( void )
{
hostgroup * temp_hostgroup = NULL ;
hostsmember * temp_hgmember = NULL ;
servicegroup * temp_servicegroup = NULL ;
servicesmember * temp_sgmember = NULL ;
host * temp_host = NULL ;
service * temp_service = NULL ;
const char * last_host_name = " " ;
2017-05-19 22:22:40 +02:00
/* we're displaying one or more hosts */
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL & & host_name & & strcmp ( host_name , " " ) ) {
2017-05-19 22:22:40 +02:00
/* we're only displaying a specific host (and summaries for all services associated with it) */
2019-04-18 17:09:18 +02:00
if ( show_all_hosts = = FALSE ) {
2017-05-19 22:22:40 +02:00
add_subject ( HOST_SUBJECT , host_name , NULL ) ;
2019-04-18 17:09:18 +02:00
for ( temp_service = service_list ; temp_service ! = NULL ; temp_service = temp_service - > next ) {
if ( ! strcmp ( temp_service - > host_name , host_name ) ) {
2017-05-19 22:22:40 +02:00
add_subject ( SERVICE_SUBJECT , host_name , temp_service - > description ) ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* we're displaying all hosts */
else {
2019-04-18 17:09:18 +02:00
for ( temp_host = host_list ; temp_host ! = NULL ; temp_host = temp_host - > next ) {
2017-05-19 22:22:40 +02:00
add_subject ( HOST_SUBJECT , temp_host - > name , NULL ) ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* we're displaying a specific service */
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICE_AVAIL & & svc_description & & strcmp ( svc_description , " " ) ) {
2017-05-19 22:22:40 +02:00
/* we're only displaying a specific service */
2019-04-18 17:09:18 +02:00
if ( show_all_services = = FALSE ) {
2017-05-19 22:22:40 +02:00
add_subject ( SERVICE_SUBJECT , host_name , svc_description ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* we're displaying all services */
else {
2019-04-18 17:09:18 +02:00
for ( temp_service = service_list ; temp_service ! = NULL ; temp_service = temp_service - > next ) {
2017-05-19 22:22:40 +02:00
add_subject ( SERVICE_SUBJECT , temp_service - > host_name , temp_service - > description ) ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* we're displaying one or more hostgroups (the host members of the groups) */
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_HOSTGROUP_AVAIL & & hostgroup_name & & strcmp ( hostgroup_name , " " ) ) {
2017-05-19 22:22:40 +02:00
/* we're displaying all hostgroups */
2019-04-18 17:09:18 +02:00
if ( show_all_hostgroups = = TRUE ) {
for ( temp_hostgroup = hostgroup_list ; temp_hostgroup ! = NULL ; temp_hostgroup = temp_hostgroup - > next ) {
for ( temp_hgmember = temp_hostgroup - > members ; temp_hgmember ! = NULL ; temp_hgmember = temp_hgmember - > next ) {
2017-05-19 22:22:40 +02:00
add_subject ( HOST_SUBJECT , temp_hgmember - > host_name , NULL ) ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* we're only displaying a specific hostgroup */
else {
2019-04-18 17:09:18 +02:00
2017-05-19 22:22:40 +02:00
temp_hostgroup = find_hostgroup ( hostgroup_name ) ;
2019-04-18 17:09:18 +02:00
if ( temp_hostgroup ! = NULL ) {
for ( temp_hgmember = temp_hostgroup - > members ; temp_hgmember ! = NULL ; temp_hgmember = temp_hgmember - > next ) {
2017-05-19 22:22:40 +02:00
add_subject ( HOST_SUBJECT , temp_hgmember - > host_name , NULL ) ;
}
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* we're displaying one or more servicegroups (the host and service members of the groups) */
2019-04-18 17:09:18 +02:00
else if ( display_type = = DISPLAY_SERVICEGROUP_AVAIL & & servicegroup_name & & strcmp ( servicegroup_name , " " ) ) {
2017-05-19 22:22:40 +02:00
/* we're displaying all servicegroups */
2019-04-18 17:09:18 +02:00
if ( show_all_servicegroups = = TRUE ) {
for ( temp_servicegroup = servicegroup_list ; temp_servicegroup ! = NULL ; temp_servicegroup = temp_servicegroup - > next ) {
for ( temp_sgmember = temp_servicegroup - > members ; temp_sgmember ! = NULL ; temp_sgmember = temp_sgmember - > next ) {
2017-05-19 22:22:40 +02:00
add_subject ( SERVICE_SUBJECT , temp_sgmember - > host_name , temp_sgmember - > service_description ) ;
2019-04-18 17:09:18 +02:00
if ( strcmp ( last_host_name , temp_sgmember - > host_name ) ) {
2017-05-19 22:22:40 +02:00
add_subject ( HOST_SUBJECT , temp_sgmember - > host_name , NULL ) ;
}
2019-04-18 17:09:18 +02:00
last_host_name = temp_sgmember - > host_name ;
2017-05-19 22:22:40 +02:00
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* we're only displaying a specific servicegroup */
else {
temp_servicegroup = find_servicegroup ( servicegroup_name ) ;
2019-04-18 17:09:18 +02:00
if ( temp_servicegroup ! = NULL ) {
for ( temp_sgmember = temp_servicegroup - > members ; temp_sgmember ! = NULL ; temp_sgmember = temp_sgmember - > next ) {
2017-05-19 22:22:40 +02:00
add_subject ( SERVICE_SUBJECT , temp_sgmember - > host_name , temp_sgmember - > service_description ) ;
2019-04-18 17:09:18 +02:00
if ( strcmp ( last_host_name , temp_sgmember - > host_name ) ) {
2017-05-19 22:22:40 +02:00
add_subject ( HOST_SUBJECT , temp_sgmember - > host_name , NULL ) ;
}
2019-04-18 17:09:18 +02:00
last_host_name = temp_sgmember - > host_name ;
2017-05-19 22:22:40 +02:00
}
}
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* adds a subject */
2019-04-18 17:09:18 +02:00
void add_subject ( int subject_type , char * hn , char * sd )
{
2017-05-19 22:22:40 +02:00
avail_subject * last_subject = NULL ;
avail_subject * temp_subject = NULL ;
2019-04-18 17:09:18 +02:00
avail_subject * new_subject = NULL ;
int is_authorized = FALSE ;
2017-05-19 22:22:40 +02:00
/* bail if we've already added the subject */
2019-04-18 17:09:18 +02:00
if ( find_subject ( subject_type , hn , sd ) ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* see if the user is authorized to see data for this host or service */
2019-04-18 17:09:18 +02:00
if ( subject_type = = HOST_SUBJECT ) {
2017-05-19 22:22:40 +02:00
is_authorized = is_authorized_for_host ( find_host ( hn ) , & current_authdata ) ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
is_authorized = is_authorized_for_service ( find_service ( hn , sd ) , & current_authdata ) ;
2019-04-18 17:09:18 +02:00
}
if ( is_authorized = = FALSE ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* allocate memory for the new entry */
new_subject = ( avail_subject * ) malloc ( sizeof ( avail_subject ) ) ;
2019-04-18 17:09:18 +02:00
if ( new_subject = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* allocate memory for the host name */
2019-04-18 17:09:18 +02:00
if ( hn ! = NULL ) {
2017-05-19 22:22:40 +02:00
new_subject - > host_name = ( char * ) malloc ( strlen ( hn ) + 1 ) ;
2019-04-18 17:09:18 +02:00
if ( new_subject - > host_name ! = NULL ) {
2017-05-19 22:22:40 +02:00
strcpy ( new_subject - > host_name , hn ) ;
}
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
new_subject - > host_name = NULL ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* allocate memory for the service description */
2019-04-18 17:09:18 +02:00
if ( sd ! = NULL ) {
2017-05-19 22:22:40 +02:00
new_subject - > service_description = ( char * ) malloc ( strlen ( sd ) + 1 ) ;
2019-04-18 17:09:18 +02:00
if ( new_subject - > service_description ! = NULL ) {
2017-05-19 22:22:40 +02:00
strcpy ( new_subject - > service_description , sd ) ;
}
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
new_subject - > service_description = NULL ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
new_subject - > type = subject_type ;
new_subject - > earliest_state = AS_NO_DATA ;
new_subject - > latest_state = AS_NO_DATA ;
new_subject - > time_up = 0L ;
new_subject - > time_down = 0L ;
new_subject - > time_unreachable = 0L ;
new_subject - > time_ok = 0L ;
new_subject - > time_warning = 0L ;
new_subject - > time_unknown = 0L ;
new_subject - > time_critical = 0L ;
new_subject - > scheduled_time_up = 0L ;
new_subject - > scheduled_time_down = 0L ;
new_subject - > scheduled_time_unreachable = 0L ;
new_subject - > scheduled_time_ok = 0L ;
new_subject - > scheduled_time_warning = 0L ;
new_subject - > scheduled_time_unknown = 0L ;
new_subject - > scheduled_time_critical = 0L ;
new_subject - > scheduled_time_indeterminate = 0L ;
new_subject - > time_indeterminate_nodata = 0L ;
2017-05-19 22:22:40 +02:00
new_subject - > time_indeterminate_notrunning = 0L ;
2019-04-18 17:09:18 +02:00
new_subject - > as_list = NULL ;
new_subject - > as_list_tail = NULL ;
new_subject - > sd_list = NULL ;
new_subject - > last_known_state = AS_NO_DATA ;
2017-05-19 22:22:40 +02:00
/* add the new entry to the list in memory, sorted by host name */
last_subject = subject_list ;
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
if ( strcmp ( new_subject - > host_name , temp_subject - > host_name ) < 0 ) {
2017-05-19 22:22:40 +02:00
new_subject - > next = temp_subject ;
2019-04-18 17:09:18 +02:00
if ( temp_subject = = subject_list ) {
2017-05-19 22:22:40 +02:00
subject_list = new_subject ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
last_subject - > next = new_subject ;
}
2019-04-18 17:09:18 +02:00
break ;
}
else {
2017-05-19 22:22:40 +02:00
last_subject = temp_subject ;
}
2019-04-18 17:09:18 +02:00
}
if ( subject_list = = NULL ) {
2017-05-19 22:22:40 +02:00
new_subject - > next = NULL ;
subject_list = new_subject ;
2019-04-18 17:09:18 +02:00
}
else if ( temp_subject = = NULL ) {
2017-05-19 22:22:40 +02:00
new_subject - > next = NULL ;
last_subject - > next = new_subject ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* finds a specific subject */
2019-04-18 17:09:18 +02:00
avail_subject * find_subject ( int type , char * hn , char * sd )
{
avail_subject * temp_subject = NULL ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( hn = = NULL ) {
2017-05-19 22:22:40 +02:00
return NULL ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( type = = SERVICE_SUBJECT & & sd = = NULL ) {
2017-05-19 22:22:40 +02:00
return NULL ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
if ( temp_subject - > type ! = type ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
if ( strcmp ( hn , temp_subject - > host_name ) ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
if ( type = = SERVICE_SUBJECT & & strcmp ( sd , temp_subject - > service_description ) ) {
2017-05-19 22:22:40 +02:00
continue ;
}
2019-04-18 17:09:18 +02:00
return temp_subject ;
}
2017-05-19 22:22:40 +02:00
return NULL ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* adds an archived state entry to all subjects */
2019-04-18 17:09:18 +02:00
void add_global_archived_state ( int entry_type , int state_type , time_t time_stamp , const char * state_info )
{
avail_subject * temp_subject = NULL ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
add_archived_state ( entry_type , state_type , time_stamp , state_info , temp_subject ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* adds an archived state entry to a specific subject */
2017-05-19 23:37:19 +02:00
void add_archived_state ( int entry_type , int state_type , time_t time_stamp , const char * state_info , avail_subject * subject ) {
2017-05-19 22:22:40 +02:00
archived_state * last_as = NULL ;
archived_state * temp_as = NULL ;
archived_state * new_as = NULL ;
/* allocate memory for the new entry */
new_as = ( archived_state * ) malloc ( sizeof ( archived_state ) ) ;
2019-04-18 17:09:18 +02:00
if ( new_as = = NULL )
2017-05-19 22:22:40 +02:00
return ;
/* allocate memory for the state info */
2019-04-18 17:09:18 +02:00
if ( state_info ! = NULL ) {
2017-05-19 22:22:40 +02:00
new_as - > state_info = ( char * ) malloc ( strlen ( state_info ) + 1 ) ;
2019-04-18 17:09:18 +02:00
if ( new_as - > state_info ! = NULL )
2017-05-19 22:22:40 +02:00
strcpy ( new_as - > state_info , state_info ) ;
}
else new_as - > state_info = NULL ;
/* initialize the "processed state" value - this gets modified later for most entries */
2019-04-18 17:09:18 +02:00
if ( entry_type ! = AS_PROGRAM_START & & entry_type ! = AS_PROGRAM_END & & entry_type ! = AS_NO_DATA )
2017-05-19 22:22:40 +02:00
new_as - > processed_state = entry_type ;
else
new_as - > processed_state = AS_NO_DATA ;
new_as - > entry_type = entry_type ;
new_as - > state_type = state_type ;
new_as - > time_stamp = time_stamp ;
new_as - > misc_ptr = NULL ;
/* add the new entry to the list in memory, sorted by time (more recent entries should appear towards end of list) */
last_as = subject - > as_list ;
2019-04-18 17:09:18 +02:00
for ( temp_as = subject - > as_list ; temp_as ! = NULL ; temp_as = temp_as - > next ) {
if ( new_as - > time_stamp < temp_as - > time_stamp ) {
2017-05-19 22:22:40 +02:00
new_as - > next = temp_as ;
2019-04-18 17:09:18 +02:00
if ( temp_as = = subject - > as_list )
2017-05-19 22:22:40 +02:00
subject - > as_list = new_as ;
else
last_as - > next = new_as ;
break ;
}
else
last_as = temp_as ;
}
2019-04-18 17:09:18 +02:00
if ( subject - > as_list = = NULL ) {
2017-05-19 22:22:40 +02:00
new_as - > next = NULL ;
subject - > as_list = new_as ;
}
2019-04-18 17:09:18 +02:00
else if ( temp_as = = NULL ) {
2017-05-19 22:22:40 +02:00
new_as - > next = NULL ;
last_as - > next = new_as ;
}
/* update "tail" of the list - not really the tail, just last item added */
subject - > as_list_tail = new_as ;
return ;
}
/* adds a scheduled downtime entry to a specific subject */
void add_scheduled_downtime ( int state_type , time_t time_stamp , avail_subject * subject ) {
archived_state * last_sd = NULL ;
archived_state * temp_sd = NULL ;
archived_state * new_sd = NULL ;
/* allocate memory for the new entry */
new_sd = ( archived_state * ) malloc ( sizeof ( archived_state ) ) ;
2019-04-18 17:09:18 +02:00
if ( new_sd = = NULL )
2017-05-19 22:22:40 +02:00
return ;
new_sd - > state_info = NULL ;
new_sd - > processed_state = state_type ;
new_sd - > entry_type = state_type ;
new_sd - > time_stamp = time_stamp ;
new_sd - > misc_ptr = subject - > as_list_tail ;
/* add the new entry to the list in memory, sorted by time (more recent entries should appear towards end of list) */
last_sd = subject - > sd_list ;
2019-04-18 17:09:18 +02:00
for ( temp_sd = subject - > sd_list ; temp_sd ! = NULL ; temp_sd = temp_sd - > next ) {
if ( new_sd - > time_stamp < = temp_sd - > time_stamp ) {
2017-05-19 22:22:40 +02:00
new_sd - > next = temp_sd ;
2019-04-18 17:09:18 +02:00
if ( temp_sd = = subject - > sd_list )
2017-05-19 22:22:40 +02:00
subject - > sd_list = new_sd ;
else
last_sd - > next = new_sd ;
break ;
}
else
last_sd = temp_sd ;
}
2019-04-18 17:09:18 +02:00
if ( subject - > sd_list = = NULL ) {
2017-05-19 22:22:40 +02:00
new_sd - > next = NULL ;
subject - > sd_list = new_sd ;
}
2019-04-18 17:09:18 +02:00
else if ( temp_sd = = NULL ) {
2017-05-19 22:22:40 +02:00
new_sd - > next = NULL ;
last_sd - > next = new_sd ;
}
return ;
}
/* frees memory allocated to all availability data */
void free_availability_data ( void ) {
avail_subject * this_subject ;
avail_subject * next_subject ;
2019-04-18 17:09:18 +02:00
for ( this_subject = subject_list ; this_subject ! = NULL ; ) {
2017-05-19 22:22:40 +02:00
next_subject = this_subject - > next ;
2019-04-18 17:09:18 +02:00
if ( this_subject - > host_name ! = NULL )
2017-05-19 22:22:40 +02:00
free ( this_subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
if ( this_subject - > service_description ! = NULL )
2017-05-19 22:22:40 +02:00
free ( this_subject - > service_description ) ;
free_archived_state_list ( this_subject - > as_list ) ;
free_archived_state_list ( this_subject - > sd_list ) ;
free ( this_subject ) ;
this_subject = next_subject ;
}
return ;
}
/* frees memory allocated to the archived state list */
void free_archived_state_list ( archived_state * as_list ) {
archived_state * this_as = NULL ;
archived_state * next_as = NULL ;
2019-04-18 17:09:18 +02:00
for ( this_as = as_list ; this_as ! = NULL ; ) {
2017-05-19 22:22:40 +02:00
next_as = this_as - > next ;
2019-04-18 17:09:18 +02:00
if ( this_as - > state_info ! = NULL )
2017-05-19 22:22:40 +02:00
free ( this_as - > state_info ) ;
free ( this_as ) ;
this_as = next_as ;
}
as_list = NULL ;
return ;
}
/* reads log files for archived state data */
void read_archived_state_data ( void ) {
char filename [ MAX_FILENAME_LENGTH ] ;
int oldest_archive = 0 ;
int newest_archive = 0 ;
int current_archive = 0 ;
/* determine oldest archive to use when scanning for data (include backtracked archives as well) */
oldest_archive = determine_archive_to_use_from_time ( t1 ) ;
2019-04-18 17:09:18 +02:00
if ( log_rotation_method ! = LOG_ROTATION_NONE )
2017-05-19 22:22:40 +02:00
oldest_archive + = backtrack_archives ;
/* determine most recent archive to use when scanning for data */
newest_archive = determine_archive_to_use_from_time ( t2 ) ;
2019-04-18 17:09:18 +02:00
if ( oldest_archive < newest_archive )
2017-05-19 22:22:40 +02:00
oldest_archive = newest_archive ;
/* read in all the necessary archived logs (from most recent to earliest) */
2019-04-18 17:09:18 +02:00
for ( current_archive = newest_archive ; current_archive < = oldest_archive ; current_archive + + ) {
2017-05-19 22:22:40 +02:00
# ifdef DEBUG
printf ( " Reading archive #%d \n " , current_archive ) ;
# endif
/* get the name of the log file that contains this archive */
get_log_archive_to_use ( current_archive , filename , sizeof ( filename ) - 1 ) ;
# ifdef DEBUG
printf ( " Archive name: '%s' \n " , filename ) ;
# endif
/* scan the log file for archived state data */
scan_log_file_for_archived_state_data ( filename ) ;
}
return ;
}
/* grabs archives state data from a log file */
void scan_log_file_for_archived_state_data ( char * filename ) {
char * input = NULL ;
char * input2 = NULL ;
char entry_host_name [ MAX_INPUT_BUFFER ] ;
char entry_svc_description [ MAX_INPUT_BUFFER ] ;
char * plugin_output = NULL ;
char * temp_buffer = NULL ;
time_t time_stamp ;
mmapfile * thefile = NULL ;
avail_subject * temp_subject = NULL ;
int state_type = 0 ;
2019-04-18 17:09:18 +02:00
if ( ( thefile = mmap_fopen ( filename ) ) = = NULL )
2017-05-19 22:22:40 +02:00
return ;
while ( 1 ) {
/* free memory */
free ( input ) ;
free ( input2 ) ;
input = NULL ;
input2 = NULL ;
/* read the next line */
2019-04-18 17:09:18 +02:00
if ( ( input = mmap_fgets ( thefile ) ) = = NULL )
2017-05-19 22:22:40 +02:00
break ;
strip ( input ) ;
2019-04-18 17:09:18 +02:00
if ( ( input2 = strdup ( input ) ) = = NULL )
2017-05-19 22:22:40 +02:00
continue ;
temp_buffer = my_strtok ( input2 , " ] " ) ;
time_stamp = ( temp_buffer = = NULL ) ? ( time_t ) 0 : ( time_t ) strtoul ( temp_buffer + 1 , NULL , 10 ) ;
/* program starts/restarts */
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " starting... " ) )
2017-05-19 22:22:40 +02:00
add_global_archived_state ( AS_PROGRAM_START , AS_NO_DATA , time_stamp , " Program start " ) ;
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " restarting... " ) )
2017-05-19 22:22:40 +02:00
add_global_archived_state ( AS_PROGRAM_START , AS_NO_DATA , time_stamp , " Program restart " ) ;
/* program stops */
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " shutting down... " ) )
2017-05-19 22:22:40 +02:00
add_global_archived_state ( AS_PROGRAM_END , AS_NO_DATA , time_stamp , " Normal program termination " ) ;
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " Bailing out " ) )
2017-05-19 22:22:40 +02:00
add_global_archived_state ( AS_PROGRAM_END , AS_NO_DATA , time_stamp , " Abnormal program termination " ) ;
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_HOST_AVAIL | | display_type = = DISPLAY_HOSTGROUP_AVAIL | | display_type = = DISPLAY_SERVICEGROUP_AVAIL ) {
2017-05-19 22:22:40 +02:00
/* normal host alerts and initial/current states */
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " HOST ALERT: " ) | | strstr ( input , " INITIAL HOST STATE: " ) | | strstr ( input , " CURRENT HOST STATE: " ) ) {
2017-05-19 22:22:40 +02:00
/* get host name */
temp_buffer = my_strtok ( NULL , " : " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
strncpy ( entry_host_name , ( temp_buffer = = NULL ) ? " " : temp_buffer + 1 , sizeof ( entry_host_name ) ) ;
entry_host_name [ sizeof ( entry_host_name ) - 1 ] = ' \x0 ' ;
/* see if there is a corresponding subject for this host */
temp_subject = find_subject ( HOST_SUBJECT , entry_host_name , NULL ) ;
2019-04-18 17:09:18 +02:00
if ( temp_subject = = NULL )
2017-05-19 22:22:40 +02:00
continue ;
/* state types */
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;SOFT; " ) ) {
if ( include_soft_states = = FALSE )
2017-05-19 22:22:40 +02:00
continue ;
state_type = AS_SOFT_STATE ;
}
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;HARD; " ) )
2017-05-19 22:22:40 +02:00
state_type = AS_HARD_STATE ;
/* get the plugin output */
temp_buffer = my_strtok ( NULL , " ; " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
plugin_output = my_strtok ( NULL , " \n " ) ;
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;DOWN; " ) )
2017-05-19 22:22:40 +02:00
add_archived_state ( AS_HOST_DOWN , state_type , time_stamp , plugin_output , temp_subject ) ;
2019-04-18 17:09:18 +02:00
else if ( strstr ( input , " ;UNREACHABLE; " ) )
2017-05-19 22:22:40 +02:00
add_archived_state ( AS_HOST_UNREACHABLE , state_type , time_stamp , plugin_output , temp_subject ) ;
2019-04-18 17:09:18 +02:00
else if ( strstr ( input , " ;RECOVERY " ) | | strstr ( input , " ;UP; " ) )
2017-05-19 22:22:40 +02:00
add_archived_state ( AS_HOST_UP , state_type , time_stamp , plugin_output , temp_subject ) ;
else
add_archived_state ( AS_NO_DATA , AS_NO_DATA , time_stamp , plugin_output , temp_subject ) ;
}
/* scheduled downtime notices */
2019-04-18 17:09:18 +02:00
else if ( strstr ( input , " HOST DOWNTIME ALERT: " ) ) {
2017-05-19 22:22:40 +02:00
/* get host name */
temp_buffer = my_strtok ( NULL , " : " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
strncpy ( entry_host_name , ( temp_buffer = = NULL ) ? " " : temp_buffer + 1 , sizeof ( entry_host_name ) ) ;
entry_host_name [ sizeof ( entry_host_name ) - 1 ] = ' \x0 ' ;
/* see if there is a corresponding subject for this host */
temp_subject = find_subject ( HOST_SUBJECT , entry_host_name , NULL ) ;
2019-04-18 17:09:18 +02:00
if ( temp_subject = = NULL )
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
if ( show_scheduled_downtime = = FALSE )
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;STARTED; " ) )
2017-05-19 22:22:40 +02:00
add_scheduled_downtime ( AS_HOST_DOWNTIME_START , time_stamp , temp_subject ) ;
else
add_scheduled_downtime ( AS_HOST_DOWNTIME_END , time_stamp , temp_subject ) ;
}
}
2019-04-18 17:09:18 +02:00
if ( display_type = = DISPLAY_SERVICE_AVAIL | | display_type = = DISPLAY_HOST_AVAIL | | display_type = = DISPLAY_SERVICEGROUP_AVAIL ) {
2017-05-19 22:22:40 +02:00
/* normal service alerts and initial/current states */
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " SERVICE ALERT: " ) | | strstr ( input , " INITIAL SERVICE STATE: " ) | | strstr ( input , " CURRENT SERVICE STATE: " ) ) {
2017-05-19 22:22:40 +02:00
/* get host name */
temp_buffer = my_strtok ( NULL , " : " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
strncpy ( entry_host_name , ( temp_buffer = = NULL ) ? " " : temp_buffer + 1 , sizeof ( entry_host_name ) ) ;
entry_host_name [ sizeof ( entry_host_name ) - 1 ] = ' \x0 ' ;
/* get service description */
temp_buffer = my_strtok ( NULL , " ; " ) ;
strncpy ( entry_svc_description , ( temp_buffer = = NULL ) ? " " : temp_buffer , sizeof ( entry_svc_description ) ) ;
entry_svc_description [ sizeof ( entry_svc_description ) - 1 ] = ' \x0 ' ;
/* see if there is a corresponding subject for this service */
temp_subject = find_subject ( SERVICE_SUBJECT , entry_host_name , entry_svc_description ) ;
2019-04-18 17:09:18 +02:00
if ( temp_subject = = NULL )
2017-05-19 22:22:40 +02:00
continue ;
/* state types */
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;SOFT; " ) ) {
if ( include_soft_states = = FALSE )
2017-05-19 22:22:40 +02:00
continue ;
state_type = AS_SOFT_STATE ;
}
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;HARD; " ) )
2017-05-19 22:22:40 +02:00
state_type = AS_HARD_STATE ;
/* get the plugin output */
temp_buffer = my_strtok ( NULL , " ; " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
plugin_output = my_strtok ( NULL , " \n " ) ;
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;CRITICAL; " ) )
2017-05-19 22:22:40 +02:00
add_archived_state ( AS_SVC_CRITICAL , state_type , time_stamp , plugin_output , temp_subject ) ;
2019-04-18 17:09:18 +02:00
else if ( strstr ( input , " ;WARNING; " ) )
2017-05-19 22:22:40 +02:00
add_archived_state ( AS_SVC_WARNING , state_type , time_stamp , plugin_output , temp_subject ) ;
2019-04-18 17:09:18 +02:00
else if ( strstr ( input , " ;UNKNOWN; " ) )
2017-05-19 22:22:40 +02:00
add_archived_state ( AS_SVC_UNKNOWN , state_type , time_stamp , plugin_output , temp_subject ) ;
2019-04-18 17:09:18 +02:00
else if ( strstr ( input , " ;RECOVERY; " ) | | strstr ( input , " ;OK; " ) )
2017-05-19 22:22:40 +02:00
add_archived_state ( AS_SVC_OK , state_type , time_stamp , plugin_output , temp_subject ) ;
else
add_archived_state ( AS_NO_DATA , AS_NO_DATA , time_stamp , plugin_output , temp_subject ) ;
}
/* scheduled service downtime notices */
2019-04-18 17:09:18 +02:00
else if ( strstr ( input , " SERVICE DOWNTIME ALERT: " ) ) {
2017-05-19 22:22:40 +02:00
/* get host name */
temp_buffer = my_strtok ( NULL , " : " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
strncpy ( entry_host_name , ( temp_buffer = = NULL ) ? " " : temp_buffer + 1 , sizeof ( entry_host_name ) ) ;
entry_host_name [ sizeof ( entry_host_name ) - 1 ] = ' \x0 ' ;
/* get service description */
temp_buffer = my_strtok ( NULL , " ; " ) ;
strncpy ( entry_svc_description , ( temp_buffer = = NULL ) ? " " : temp_buffer , sizeof ( entry_svc_description ) ) ;
entry_svc_description [ sizeof ( entry_svc_description ) - 1 ] = ' \x0 ' ;
/* see if there is a corresponding subject for this service */
temp_subject = find_subject ( SERVICE_SUBJECT , entry_host_name , entry_svc_description ) ;
2019-04-18 17:09:18 +02:00
if ( temp_subject = = NULL )
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
if ( show_scheduled_downtime = = FALSE )
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;STARTED; " ) )
2017-05-19 22:22:40 +02:00
add_scheduled_downtime ( AS_SVC_DOWNTIME_START , time_stamp , temp_subject ) ;
else
add_scheduled_downtime ( AS_SVC_DOWNTIME_END , time_stamp , temp_subject ) ;
}
/* scheduled host downtime notices */
2019-04-18 17:09:18 +02:00
else if ( strstr ( input , " HOST DOWNTIME ALERT: " ) ) {
2017-05-19 22:22:40 +02:00
/* get host name */
temp_buffer = my_strtok ( NULL , " : " ) ;
temp_buffer = my_strtok ( NULL , " ; " ) ;
strncpy ( entry_host_name , ( temp_buffer = = NULL ) ? " " : temp_buffer + 1 , sizeof ( entry_host_name ) ) ;
entry_host_name [ sizeof ( entry_host_name ) - 1 ] = ' \x0 ' ;
/* this host downtime entry must be added to all service subjects associated with the host! */
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_subject - > type ! = SERVICE_SUBJECT )
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
if ( strcmp ( temp_subject - > host_name , entry_host_name ) )
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
if ( show_scheduled_downtime = = FALSE )
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
if ( strstr ( input , " ;STARTED; " ) )
2017-05-19 22:22:40 +02:00
add_scheduled_downtime ( AS_HOST_DOWNTIME_START , time_stamp , temp_subject ) ;
else
add_scheduled_downtime ( AS_HOST_DOWNTIME_END , time_stamp , temp_subject ) ;
}
}
}
}
/* free memory and close the file */
free ( input ) ;
free ( input2 ) ;
mmap_fclose ( thefile ) ;
return ;
}
void convert_timeperiod_to_times ( int type ) {
time_t current_time ;
struct tm * t ;
/* get the current time */
time ( & current_time ) ;
t = localtime ( & current_time ) ;
t - > tm_sec = 0 ;
t - > tm_min = 0 ;
t - > tm_hour = 0 ;
t - > tm_isdst = - 1 ;
2019-04-18 17:09:18 +02:00
switch ( type ) {
case TIMEPERIOD_LAST24HOURS :
t1 = current_time - ( 60 * 60 * 24 ) ;
t2 = current_time ;
break ;
case TIMEPERIOD_TODAY :
t1 = mktime ( t ) ;
t2 = current_time ;
break ;
case TIMEPERIOD_YESTERDAY :
t1 = ( time_t ) ( mktime ( t ) - ( 60 * 60 * 24 ) ) ;
t2 = ( time_t ) mktime ( t ) ;
break ;
case TIMEPERIOD_THISWEEK :
t1 = ( time_t ) ( mktime ( t ) - ( 60 * 60 * 24 * t - > tm_wday ) ) ;
t2 = current_time ;
break ;
case TIMEPERIOD_LASTWEEK :
t1 = ( time_t ) ( mktime ( t ) - ( 60 * 60 * 24 * t - > tm_wday ) - ( 60 * 60 * 24 * 7 ) ) ;
t2 = ( time_t ) ( mktime ( t ) - ( 60 * 60 * 24 * t - > tm_wday ) ) ;
break ;
case TIMEPERIOD_THISMONTH :
t - > tm_mday = 1 ;
t1 = mktime ( t ) ;
t2 = current_time ;
break ;
case TIMEPERIOD_LASTMONTH :
t - > tm_mday = 1 ;
t2 = mktime ( t ) ;
if ( t - > tm_mon = = 0 ) {
t - > tm_mon = 11 ;
2017-05-19 22:22:40 +02:00
t - > tm_year - - ;
2019-04-18 17:09:18 +02:00
}
else
t - > tm_mon - - ;
t1 = mktime ( t ) ;
break ;
case TIMEPERIOD_THISQUARTER :
/* not implemented */
break ;
case TIMEPERIOD_LASTQUARTER :
/* not implemented */
break ;
case TIMEPERIOD_THISYEAR :
t - > tm_mon = 0 ;
t - > tm_mday = 1 ;
t1 = mktime ( t ) ;
t2 = current_time ;
break ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
case TIMEPERIOD_LASTYEAR :
t - > tm_mon = 0 ;
t - > tm_mday = 1 ;
t2 = mktime ( t ) ;
t - > tm_year - - ;
t1 = mktime ( t ) ;
break ;
case TIMEPERIOD_LAST7DAYS :
t2 = current_time ;
t1 = current_time - ( 7 * 24 * 60 * 60 ) ;
break ;
case TIMEPERIOD_LAST31DAYS :
t2 = current_time ;
t1 = current_time - ( 31 * 24 * 60 * 60 ) ;
break ;
default :
break ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
void compute_report_times ( void )
{
time_t current_time = 0L ;
struct tm * st = NULL ;
struct tm * et = NULL ;
2017-05-19 22:22:40 +02:00
/* get the current time */
time ( & current_time ) ;
st = localtime ( & current_time ) ;
2019-04-18 17:09:18 +02:00
st - > tm_sec = start_second ;
st - > tm_min = start_minute ;
st - > tm_hour = start_hour ;
st - > tm_mday = start_day ;
st - > tm_mon = start_month - 1 ;
st - > tm_year = start_year - 1900 ;
2017-05-19 22:22:40 +02:00
st - > tm_isdst = - 1 ;
t1 = mktime ( st ) ;
et = localtime ( & current_time ) ;
2019-04-18 17:09:18 +02:00
et - > tm_sec = end_second ;
et - > tm_min = end_minute ;
et - > tm_hour = end_hour ;
et - > tm_mday = end_day ;
et - > tm_mon = end_month - 1 ;
et - > tm_year = end_year - 1900 ;
2017-05-19 22:22:40 +02:00
et - > tm_isdst = - 1 ;
t2 = mktime ( et ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* writes log entries to screen */
2019-04-18 17:09:18 +02:00
void write_log_entries ( avail_subject * subject )
{
archived_state * temp_as = NULL ;
archived_state * temp_sd = NULL ;
time_t current_time = 0L ;
char start_date_time [ MAX_DATETIME_LENGTH ] = { 0 } ;
char end_date_time [ MAX_DATETIME_LENGTH ] = { 0 } ;
char duration [ 20 ] = { 0 } ;
const char * bgclass = " " ;
const char * ebgclass = " " ;
const char * entry_type = " " ;
const char * state_type = " " ;
int days = 0 ;
int hours = 0 ;
int minutes = 0 ;
int seconds = 0 ;
int odd = 0 ;
if ( output_format ! = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( show_log_entries = = FALSE ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( subject = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
time ( & current_time ) ;
/* inject all scheduled downtime entries into the main list for display purposes */
2019-04-18 17:09:18 +02:00
for ( temp_sd = subject - > sd_list ; temp_sd ! = NULL ; temp_sd = temp_sd - > next ) {
switch ( temp_sd - > entry_type ) {
case AS_SVC_DOWNTIME_START :
case AS_HOST_DOWNTIME_START :
entry_type = " Start of scheduled downtime " ;
break ;
case AS_SVC_DOWNTIME_END :
case AS_HOST_DOWNTIME_END :
entry_type = " End of scheduled downtime " ;
break ;
default :
entry_type = " ? " ;
break ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
add_archived_state ( temp_sd - > entry_type , AS_NO_DATA , temp_sd - > time_stamp , entry_type , subject ) ;
}
2017-05-19 22:22:40 +02:00
printf ( " <BR><BR> \n " ) ;
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>%s Log Entries:</DIV> \n " , ( subject - > type = = HOST_SUBJECT ) ? " Host " : " Service " ) ;
printf ( " <DIV ALIGN=CENTER CLASS='infoMessage'> " ) ;
2019-04-18 17:09:18 +02:00
if ( full_log_entries = = TRUE ) {
2017-05-19 22:22:40 +02:00
full_log_entries = FALSE ;
2019-04-18 17:09:18 +02:00
if ( subject - > type = = HOST_SUBJECT ) {
2017-05-19 22:22:40 +02:00
host_report_url ( subject - > host_name , " [ View condensed log entries ] " ) ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
service_report_url ( subject - > host_name , subject - > service_description , " [ View condensed log entries ] " ) ;
}
2019-04-18 17:09:18 +02:00
full_log_entries = TRUE ;
}
2017-05-19 22:22:40 +02:00
else {
2019-04-18 17:09:18 +02:00
2017-05-19 22:22:40 +02:00
full_log_entries = TRUE ;
2019-04-18 17:09:18 +02:00
if ( subject - > type = = HOST_SUBJECT ) {
2017-05-19 22:22:40 +02:00
host_report_url ( subject - > host_name , " [ View full log entries ] " ) ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
service_report_url ( subject - > host_name , subject - > service_description , " [ View full log entries ] " ) ;
}
2019-04-18 17:09:18 +02:00
full_log_entries = FALSE ;
}
2017-05-19 22:22:40 +02:00
printf ( " </DIV> \n " ) ;
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <table border=1 cellspacing=0 cellpadding=3 class='logEntries'> \n " ) ;
2019-04-18 17:09:18 +02:00
printf ( " <tr><th class='logEntries'>Event Start Time</th> " ) ;
printf ( " <th class='logEntries'>Event End Time</th> " ) ;
printf ( " <th class='logEntries'>Event Duration</th> " ) ;
printf ( " <th class='logEntries'>Event/State Type</th> " ) ;
printf ( " <th class='logEntries'>Event/State Information</th></tr> \n " ) ;
2017-05-19 22:22:40 +02:00
/* write all archived state entries */
2019-04-18 17:09:18 +02:00
for ( temp_as = subject - > as_list ; temp_as ! = NULL ; temp_as = temp_as - > next ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_as - > state_type = = AS_HARD_STATE ) {
2017-05-19 22:22:40 +02:00
state_type = " (HARD) " ;
2019-04-18 17:09:18 +02:00
}
else if ( temp_as - > state_type = = AS_SOFT_STATE ) {
2017-05-19 22:22:40 +02:00
state_type = " (SOFT) " ;
2019-04-18 17:09:18 +02:00
}
else {
2017-05-19 22:22:40 +02:00
state_type = " " ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
switch ( temp_as - > entry_type ) {
case AS_NO_DATA :
if ( full_log_entries = = FALSE ) {
continue ;
}
entry_type = " NO DATA " ;
ebgclass = " INDETERMINATE " ;
break ;
case AS_PROGRAM_END :
if ( full_log_entries = = FALSE ) {
continue ;
}
entry_type = " PROGRAM END " ;
ebgclass = " INDETERMINATE " ;
break ;
case AS_PROGRAM_START :
if ( full_log_entries = = FALSE ) {
continue ;
}
entry_type = " PROGRAM (RE)START " ;
ebgclass = " INDETERMINATE " ;
break ;
case AS_HOST_UP :
entry_type = " HOST UP " ;
ebgclass = " UP " ;
break ;
case AS_HOST_DOWN :
entry_type = " HOST DOWN " ;
ebgclass = " DOWN " ;
break ;
case AS_HOST_UNREACHABLE :
entry_type = " HOST UNREACHABLE " ;
ebgclass = " UNREACHABLE " ;
break ;
case AS_SVC_OK :
entry_type = " SERVICE OK " ;
ebgclass = " OK " ;
break ;
case AS_SVC_UNKNOWN :
entry_type = " SERVICE UNKNOWN " ;
ebgclass = " UNKNOWN " ;
break ;
case AS_SVC_WARNING :
entry_type = " SERVICE WARNING " ;
ebgclass = " WARNING " ;
break ;
case AS_SVC_CRITICAL :
entry_type = " SERVICE CRITICAL " ;
ebgclass = " CRITICAL " ;
break ;
case AS_SVC_DOWNTIME_START :
entry_type = " SERVICE DOWNTIME START " ;
ebgclass = " INDETERMINATE " ;
break ;
case AS_SVC_DOWNTIME_END :
entry_type = " SERVICE DOWNTIME END " ;
ebgclass = " INDETERMINATE " ;
break ;
case AS_HOST_DOWNTIME_START :
entry_type = " HOST DOWNTIME START " ;
ebgclass = " INDETERMINATE " ;
break ;
case AS_HOST_DOWNTIME_END :
entry_type = " HOST DOWNTIME END " ;
ebgclass = " INDETERMINATE " ;
break ;
default :
if ( full_log_entries = = FALSE ) {
continue ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
entry_type = " ? " ;
ebgclass = " INDETERMINATE " ;
}
2017-05-19 22:22:40 +02:00
get_time_string ( & ( temp_as - > time_stamp ) , start_date_time , sizeof ( start_date_time ) - 1 , SHORT_DATE_TIME ) ;
2019-04-18 17:09:18 +02:00
if ( temp_as - > next = = NULL ) {
2017-05-19 22:22:40 +02:00
get_time_string ( & t2 , end_date_time , sizeof ( end_date_time ) - 1 , SHORT_DATE_TIME ) ;
get_time_breakdown ( ( time_t ) ( t2 - temp_as - > time_stamp ) , & days , & hours , & minutes , & seconds ) ;
2019-08-03 18:28:19 +02:00
/* show blank event duration if the end time is past the start time */
if ( ( t2 - temp_as - > time_stamp ) > end_date_time ) {
snprintf ( duration , sizeof ( duration ) , " " ) ;
} else {
snprintf ( duration , sizeof ( duration ) - 1 , " %dd %dh %dm %ds+ " , days , hours , minutes , seconds ) ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
get_time_string ( & ( temp_as - > next - > time_stamp ) , end_date_time , sizeof ( end_date_time ) - 1 , SHORT_DATE_TIME ) ;
get_time_breakdown ( ( time_t ) ( temp_as - > next - > time_stamp - temp_as - > time_stamp ) , & days , & hours , & minutes , & seconds ) ;
snprintf ( duration , sizeof ( duration ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( odd ) {
2017-05-19 22:22:40 +02:00
bgclass = " Odd " ;
odd = 0 ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
bgclass = " Even " ;
odd = 1 ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
printf ( " <tr class='logEntries%s'> " , bgclass ) ;
printf ( " <td class='logEntries%s'>%s</td> " , bgclass , start_date_time ) ;
printf ( " <td class='logEntries%s'>%s</td> " , bgclass , end_date_time ) ;
printf ( " <td class='logEntries%s'>%s</td> " , bgclass , duration ) ;
printf ( " <td class='logEntries%s'>%s%s</td> " , ebgclass , entry_type , state_type ) ;
printf ( " <td class='logEntries%s'>%s</td> " , bgclass , ( temp_as - > state_info = = NULL ) ? " " : html_encode ( temp_as - > state_info , FALSE ) ) ;
printf ( " </tr> \n " ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* display hostgroup availability */
2019-04-18 17:09:18 +02:00
void display_hostgroup_availability ( void )
{
hostgroup * temp_hostgroup = NULL ;
if ( output_format = = CSV_OUTPUT ) {
printf ( " HOSTGROUP_NAME, HOST_NAME, " ) ;
printf ( " TIME_UP, PERCENT_TIME_UP, PERCENT_KNOWN_TIME_UP, " ) ;
printf ( " TIME_DOWN, PERCENT_TIME_DOWN, PERCENT_KNOWN_TIME_DOWN, " ) ;
printf ( " TIME_UNREACHABLE, PERCENT_TIME_UNREACHABLE, PERCENT_KNOWN_TIME_UNREACHABLE, " ) ;
printf ( " TIME_UNDETERMINED, PERCENT_TIME_UNDETERMINED \n " ) ;
}
2017-05-19 22:22:40 +02:00
/* display data for a specific hostgroup */
2019-04-18 17:09:18 +02:00
if ( show_all_hostgroups = = FALSE ) {
2017-05-19 22:22:40 +02:00
temp_hostgroup = find_hostgroup ( hostgroup_name ) ;
display_specific_hostgroup_availability ( temp_hostgroup ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* display data for all hostgroups */
else {
2019-04-18 17:09:18 +02:00
for ( temp_hostgroup = hostgroup_list ; temp_hostgroup ! = NULL ; temp_hostgroup = temp_hostgroup - > next ) {
2017-05-19 22:22:40 +02:00
display_specific_hostgroup_availability ( temp_hostgroup ) ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* display availability for a specific hostgroup */
2019-04-18 17:09:18 +02:00
void display_specific_hostgroup_availability ( hostgroup * hg )
{
unsigned long total_time = 0L ;
unsigned long time_determinate = 0L ;
unsigned long time_indeterminate = 0L ;
avail_subject * temp_subject = NULL ;
double percent_time_up = 0.0 ;
double percent_time_down = 0.0 ;
double percent_time_unreachable = 0.0 ;
double percent_time_up_known = 0.0 ;
double percent_time_down_known = 0.0 ;
double percent_time_unreachable_known = 0.0 ;
double percent_time_indeterminate = 0.0 ;
double average_percent_time_up = 0.0 ;
double average_percent_time_up_known = 0.0 ;
double average_percent_time_down = 0.0 ;
double average_percent_time_down_known = 0.0 ;
double average_percent_time_unreachable = 0.0 ;
2017-05-19 22:22:40 +02:00
double average_percent_time_unreachable_known = 0.0 ;
2019-04-18 17:09:18 +02:00
double average_percent_time_indeterminate = 0.0 ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
int current_subject = 0 ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
const char * bgclass = " " ;
int odd = 1 ;
host * temp_host = NULL ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( hg = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* the user isn't authorized to view this hostgroup */
2019-04-18 17:09:18 +02:00
if ( is_authorized_for_hostgroup ( hg , & current_authdata ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* calculate total time during period based on timeperiod used for reporting */
total_time = calculate_total_time ( t1 , t2 ) ;
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <BR><BR> \n " ) ;
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>Hostgroup '%s' Host State Breakdowns:</DIV> \n " , hg - > group_name ) ;
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <TABLE BORDER=0 CLASS='data'> \n " ) ;
printf ( " <TR><TH CLASS='data'>Host</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Up</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Down</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Unreachable</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Undetermined</TH></TR> \n " ) ;
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_subject - > type ! = HOST_SUBJECT ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
temp_host = find_host ( temp_subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
if ( temp_host = = NULL ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( is_host_member_of_hostgroup ( hg , temp_host ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
current_subject + + ;
/* reset variables */
2019-04-18 17:09:18 +02:00
percent_time_up = 0.0 ;
percent_time_down = 0.0 ;
percent_time_unreachable = 0.0 ;
percent_time_indeterminate = 0.0 ;
percent_time_up_known = 0.0 ;
percent_time_down_known = 0.0 ;
2017-05-19 22:22:40 +02:00
percent_time_unreachable_known = 0.0 ;
time_determinate = temp_subject - > time_up + temp_subject - > time_down + temp_subject - > time_unreachable ;
time_indeterminate = total_time - time_determinate ;
2019-04-18 17:09:18 +02:00
if ( total_time > 0 ) {
percent_time_up = ( double ) ( ( ( double ) temp_subject - > time_up * 100.0 ) / ( double ) total_time ) ;
percent_time_down = ( double ) ( ( ( double ) temp_subject - > time_down * 100.0 ) / ( double ) total_time ) ;
percent_time_unreachable = ( double ) ( ( ( double ) temp_subject - > time_unreachable * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate = ( double ) ( ( ( double ) time_indeterminate * 100.0 ) / ( double ) total_time ) ;
if ( time_determinate > 0 ) {
percent_time_up_known = ( double ) ( ( ( double ) temp_subject - > time_up * 100.0 ) / ( double ) time_determinate ) ;
percent_time_down_known = ( double ) ( ( ( double ) temp_subject - > time_down * 100.0 ) / ( double ) time_determinate ) ;
percent_time_unreachable_known = ( double ) ( ( ( double ) temp_subject - > time_unreachable * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( odd ) {
2017-05-19 22:22:40 +02:00
odd = 0 ;
bgclass = " Odd " ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
}
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <tr CLASS='data%s'><td CLASS='data%s'> " , bgclass , bgclass ) ;
host_report_url ( temp_subject - > host_name , temp_subject - > host_name ) ;
printf ( " </td><td CLASS='hostUP'>%2.3f%% (%2.3f%%)</td> " , percent_time_up , percent_time_up_known ) ;
printf ( " <td CLASS='hostDOWN'>%2.3f%% (%2.3f%%)</td> " , percent_time_down , percent_time_down_known ) ;
printf ( " <td CLASS='hostUNREACHABLE'>%2.3f%% (%2.3f%%)</td> " , percent_time_unreachable , percent_time_unreachable_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
get_running_average ( & average_percent_time_up , percent_time_up , current_subject ) ;
get_running_average ( & average_percent_time_up_known , percent_time_up_known , current_subject ) ;
get_running_average ( & average_percent_time_down , percent_time_down , current_subject ) ;
get_running_average ( & average_percent_time_down_known , percent_time_down_known , current_subject ) ;
get_running_average ( & average_percent_time_unreachable , percent_time_unreachable , current_subject ) ;
get_running_average ( & average_percent_time_unreachable_known , percent_time_unreachable_known , current_subject ) ;
get_running_average ( & average_percent_time_indeterminate , percent_time_indeterminate , current_subject ) ;
}
else if ( output_format = = CSV_OUTPUT ) {
/* hostgroup/host name */
printf ( " \" %s \" , \" %s \" , " , hg - > group_name , temp_subject - > host_name ) ;
/* time up */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_up , percent_time_up , percent_time_up_known ) ;
/* time down */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_down , percent_time_down , percent_time_down_known ) ;
/* time unreachable */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_unreachable , percent_time_unreachable , percent_time_unreachable_known ) ;
/* time undetermined */
printf ( " %lu, %2.3f%% \n " , time_indeterminate , percent_time_indeterminate ) ;
}
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
/* average statistics */
if ( output_format = = HTML_OUTPUT ) {
if ( odd ) {
odd = 0 ;
bgclass = " Odd " ;
}
else {
odd = 1 ;
bgclass = " Even " ;
}
printf ( " <tr CLASS='data%s'><td CLASS='data%s'>Average</td> " , bgclass , bgclass ) ;
printf ( " <td CLASS='hostUP'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_up , average_percent_time_up_known ) ;
printf ( " <td CLASS='hostDOWN'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_down , average_percent_time_down_known ) ;
printf ( " <td CLASS='hostUNREACHABLE'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_unreachable , average_percent_time_unreachable_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> " , bgclass , average_percent_time_indeterminate ) ;
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
}
}
2017-05-19 22:22:40 +02:00
/* display servicegroup availability */
2019-04-18 17:09:18 +02:00
void display_servicegroup_availability ( void )
{
servicegroup * temp_servicegroup = NULL ;
if ( output_format = = CSV_OUTPUT ) {
printf ( " SERVICEGROUP_NAME, HOST_NAME, SERVICE_DESCRIPTION, " ) ;
/*
it would be nice to include all of the host information as well
but this would require re - writing the way the loops work in display_specific_servicegroup_availability ( )
and i don ' t think that ' s appropriate for a bug - fix issue ( TODO )
*/
/*
printf ( " HOST_TIME_UP, HOST_PERCENT_TIME_UP, HOST_PERCENT_KNOWN_TIME_UP, " ) ;
printf ( " HOST_TIME_DOWN, HOST_PERCENT_TIME_DOWN, HOST_PERCENT_KNOWN_TIME_DOWN, " ) ;
printf ( " HOST_TIME_UNREACHABLE, HOST_PERCENT_TIME_UNREACHABLE, HOST_PERCENT_KNOWN_TIME_UNREACHABLE, " ) ;
printf ( " HOST_TIME_UNDETERMINED, HOST_PERCENT_TIME_UNDETERMINED, " ) ;
*/
printf ( " SERVICE_TIME_OK, SERVICE_PERCENT_TIME_OK, SERVICE_PERCENT_KNOWN_TIME_OK, " ) ;
printf ( " SERVICE_TIME_WARNING, SERVICE_PERCENT_TIME_WARNING, SERVICE_PERCENT_KNOWN_TIME_WARNING, " ) ;
printf ( " SERVICE_TIME_CRITICAL, SERVICE_PERCENT_TIME_CRITICAL, SERVICE_PERCENT_KNOWN_TIME_CRITICAL, " ) ;
printf ( " SERVICE_TIME_UNKNOWN, SERVICE_PERCENT_TIME_UNKNOWN, SERVICE_PERCENT_KNOWN_TIME_UNKNOWN, " ) ;
printf ( " SERVICE_TIME_UNDETERMINED, SERVICE_PERCENT_TIME_UNDETERMINED \n " ) ;
}
2017-05-19 22:22:40 +02:00
/* display data for a specific servicegroup */
2019-04-18 17:09:18 +02:00
if ( show_all_servicegroups = = FALSE ) {
2017-05-19 22:22:40 +02:00
temp_servicegroup = find_servicegroup ( servicegroup_name ) ;
display_specific_servicegroup_availability ( temp_servicegroup ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* display data for all servicegroups */
else {
2019-04-18 17:09:18 +02:00
for ( temp_servicegroup = servicegroup_list ; temp_servicegroup ! = NULL ; temp_servicegroup = temp_servicegroup - > next ) {
2017-05-19 22:22:40 +02:00
display_specific_servicegroup_availability ( temp_servicegroup ) ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* display availability for a specific servicegroup */
2019-04-18 17:09:18 +02:00
void display_specific_servicegroup_availability ( servicegroup * sg )
{
unsigned long total_time = 0L ;
unsigned long time_determinate = 0L ;
unsigned long time_indeterminate = 0L ;
avail_subject * temp_subject = NULL ;
double percent_time_up = 0.0 ;
double percent_time_down = 0.0 ;
double percent_time_unreachable = 0.0 ;
double percent_time_up_known = 0.0 ;
double percent_time_down_known = 0.0 ;
double percent_time_unreachable_known = 0.0 ;
double percent_time_indeterminate = 0.0 ;
double percent_time_ok = 0.0 ;
double percent_time_warning = 0.0 ;
double percent_time_unknown = 0.0 ;
double percent_time_critical = 0.0 ;
double percent_time_ok_known = 0.0 ;
double percent_time_warning_known = 0.0 ;
double percent_time_unknown_known = 0.0 ;
double percent_time_critical_known = 0.0 ;
double average_percent_time_up = 0.0 ;
double average_percent_time_up_known = 0.0 ;
double average_percent_time_down = 0.0 ;
double average_percent_time_down_known = 0.0 ;
double average_percent_time_unreachable = 0.0 ;
2017-05-19 22:22:40 +02:00
double average_percent_time_unreachable_known = 0.0 ;
2019-04-18 17:09:18 +02:00
double average_percent_time_ok = 0.0 ;
double average_percent_time_ok_known = 0.0 ;
double average_percent_time_unknown = 0.0 ;
double average_percent_time_unknown_known = 0.0 ;
double average_percent_time_warning = 0.0 ;
double average_percent_time_warning_known = 0.0 ;
double average_percent_time_critical = 0.0 ;
double average_percent_time_critical_known = 0.0 ;
double average_percent_time_indeterminate = 0.0 ;
const char * bgclass = " " ;
int current_subject = 0 ;
int odd = 1 ;
host * temp_host = NULL ;
service * temp_service = NULL ;
/* Initialize to empty string for initial strcmp() below */
char last_host [ MAX_INPUT_BUFFER ] = { 0 } ;
if ( sg = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* the user isn't authorized to view this servicegroup */
2019-04-18 17:09:18 +02:00
if ( is_authorized_for_servicegroup ( sg , & current_authdata ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* calculate total time during period based on timeperiod used for reporting */
total_time = calculate_total_time ( t1 , t2 ) ;
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
printf ( " <BR><BR> \n " ) ;
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>Servicegroup '%s' Host State Breakdowns:</DIV> \n " , sg - > group_name ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <TABLE BORDER=0 CLASS='data'> \n " ) ;
printf ( " <TR><TH CLASS='data'>Host</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Up</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Down</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Unreachable</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Undetermined</TH></TR> \n " ) ;
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_subject - > type ! = HOST_SUBJECT ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
temp_host = find_host ( temp_subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
if ( temp_host = = NULL ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( is_host_member_of_servicegroup ( sg , temp_host ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
current_subject + + ;
/* reset variables */
2019-04-18 17:09:18 +02:00
percent_time_up = 0.0 ;
percent_time_down = 0.0 ;
percent_time_unreachable = 0.0 ;
percent_time_indeterminate = 0.0 ;
percent_time_up_known = 0.0 ;
percent_time_down_known = 0.0 ;
2017-05-19 22:22:40 +02:00
percent_time_unreachable_known = 0.0 ;
time_determinate = temp_subject - > time_up + temp_subject - > time_down + temp_subject - > time_unreachable ;
time_indeterminate = total_time - time_determinate ;
2019-04-18 17:09:18 +02:00
if ( total_time > 0 ) {
percent_time_up = ( double ) ( ( ( double ) temp_subject - > time_up * 100.0 ) / ( double ) total_time ) ;
percent_time_down = ( double ) ( ( ( double ) temp_subject - > time_down * 100.0 ) / ( double ) total_time ) ;
percent_time_unreachable = ( double ) ( ( ( double ) temp_subject - > time_unreachable * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate = ( double ) ( ( ( double ) time_indeterminate * 100.0 ) / ( double ) total_time ) ;
if ( time_determinate > 0 ) {
percent_time_up_known = ( double ) ( ( ( double ) temp_subject - > time_up * 100.0 ) / ( double ) time_determinate ) ;
percent_time_down_known = ( double ) ( ( ( double ) temp_subject - > time_down * 100.0 ) / ( double ) time_determinate ) ;
percent_time_unreachable_known = ( double ) ( ( ( double ) temp_subject - > time_unreachable * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
if ( odd ) {
odd = 0 ;
bgclass = " Odd " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
printf ( " <tr CLASS='data%s'><td CLASS='data%s'> " , bgclass , bgclass ) ;
host_report_url ( temp_subject - > host_name , temp_subject - > host_name ) ;
printf ( " </td><td CLASS='hostUP'>%2.3f%% (%2.3f%%)</td> " , percent_time_up , percent_time_up_known ) ;
printf ( " <td CLASS='hostDOWN'>%2.3f%% (%2.3f%%)</td> " , percent_time_down , percent_time_down_known ) ;
printf ( " <td CLASS='hostUNREACHABLE'>%2.3f%% (%2.3f%%)</td> " , percent_time_unreachable , percent_time_unreachable_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , percent_time_indeterminate ) ;
get_running_average ( & average_percent_time_up , percent_time_up , current_subject ) ;
get_running_average ( & average_percent_time_up_known , percent_time_up_known , current_subject ) ;
get_running_average ( & average_percent_time_down , percent_time_down , current_subject ) ;
get_running_average ( & average_percent_time_down_known , percent_time_down_known , current_subject ) ;
get_running_average ( & average_percent_time_unreachable , percent_time_unreachable , current_subject ) ;
get_running_average ( & average_percent_time_unreachable_known , percent_time_unreachable_known , current_subject ) ;
get_running_average ( & average_percent_time_indeterminate , percent_time_indeterminate , current_subject ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* average statistics */
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
if ( odd ) {
odd = 0 ;
bgclass = " Odd " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
printf ( " <tr CLASS='data%s'><td CLASS='data%s'>Average</td> " , bgclass , bgclass ) ;
printf ( " <td CLASS='hostUP'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_up , average_percent_time_up_known ) ;
printf ( " <td CLASS='hostDOWN'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_down , average_percent_time_down_known ) ;
printf ( " <td CLASS='hostUNREACHABLE'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_unreachable , average_percent_time_unreachable_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> " , bgclass , average_percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <BR> \n " ) ;
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>Servicegroup '%s' Service State Breakdowns:</DIV> \n " , sg - > group_name ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <TABLE BORDER=0 CLASS='data'> \n " ) ;
printf ( " <TR><TH CLASS='data'>Host</TH> " ) ;
printf ( " <TH CLASS='data'>Service</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time OK</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Warning</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Unknown</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Critical</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Undetermined</TH></TR> \n " ) ;
}
2017-05-19 22:22:40 +02:00
current_subject = 0 ;
average_percent_time_indeterminate = 0.0 ;
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_subject - > type ! = SERVICE_SUBJECT ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
temp_service = find_service ( temp_subject - > host_name , temp_subject - > service_description ) ;
2019-04-18 17:09:18 +02:00
if ( temp_service = = NULL ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( is_service_member_of_servicegroup ( sg , temp_service ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
current_subject + + ;
time_determinate = temp_subject - > time_ok + temp_subject - > time_warning + temp_subject - > time_unknown + temp_subject - > time_critical ;
time_indeterminate = total_time - time_determinate ;
/* adjust indeterminate time due to insufficient data (not all was caught) */
temp_subject - > time_indeterminate_nodata = time_indeterminate - temp_subject - > time_indeterminate_notrunning ;
/* initialize values */
2019-04-18 17:09:18 +02:00
percent_time_ok = 0.0 ;
percent_time_warning = 0.0 ;
percent_time_unknown = 0.0 ;
percent_time_critical = 0.0 ;
percent_time_indeterminate = 0.0 ;
percent_time_ok_known = 0.0 ;
percent_time_warning_known = 0.0 ;
percent_time_unknown_known = 0.0 ;
2017-05-19 22:22:40 +02:00
percent_time_critical_known = 0.0 ;
2019-04-18 17:09:18 +02:00
if ( total_time > 0 ) {
percent_time_ok = ( double ) ( ( ( double ) temp_subject - > time_ok * 100.0 ) / ( double ) total_time ) ;
percent_time_warning = ( double ) ( ( ( double ) temp_subject - > time_warning * 100.0 ) / ( double ) total_time ) ;
percent_time_unknown = ( double ) ( ( ( double ) temp_subject - > time_unknown * 100.0 ) / ( double ) total_time ) ;
percent_time_critical = ( double ) ( ( ( double ) temp_subject - > time_critical * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate = ( double ) ( ( ( double ) time_indeterminate * 100.0 ) / ( double ) total_time ) ;
if ( time_determinate > 0 ) {
percent_time_ok_known = ( double ) ( ( ( double ) temp_subject - > time_ok * 100.0 ) / ( double ) time_determinate ) ;
percent_time_warning_known = ( double ) ( ( ( double ) temp_subject - > time_warning * 100.0 ) / ( double ) time_determinate ) ;
percent_time_unknown_known = ( double ) ( ( ( double ) temp_subject - > time_unknown * 100.0 ) / ( double ) time_determinate ) ;
percent_time_critical_known = ( double ) ( ( ( double ) temp_subject - > time_critical * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
if ( odd ) {
odd = 0 ;
bgclass = " Odd " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
printf ( " <tr CLASS='data%s'><td CLASS='data%s'> " , bgclass , bgclass ) ;
if ( strcmp ( temp_subject - > host_name , last_host ) ) {
host_report_url ( temp_subject - > host_name , temp_subject - > host_name ) ;
}
printf ( " </td><td CLASS='data%s'> " , bgclass ) ;
service_report_url ( temp_subject - > host_name , temp_subject - > service_description , temp_subject - > service_description ) ;
printf ( " </td><td CLASS='serviceOK'>%2.3f%% (%2.3f%%)</td> " , percent_time_ok , percent_time_ok_known ) ;
printf ( " <td CLASS='serviceWARNING'>%2.3f%% (%2.3f%%)</td> " , percent_time_warning , percent_time_warning_known ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%2.3f%% (%2.3f%%)</td> " , percent_time_unknown , percent_time_unknown_known ) ;
printf ( " <td class='serviceCRITICAL'>%2.3f%% (%2.3f%%)</td> " , percent_time_critical , percent_time_critical_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , percent_time_indeterminate ) ;
strncpy ( last_host , temp_subject - > host_name , sizeof ( last_host ) - 1 ) ;
last_host [ sizeof ( last_host ) - 1 ] = ' \x0 ' ;
get_running_average ( & average_percent_time_ok , percent_time_ok , current_subject ) ;
get_running_average ( & average_percent_time_ok_known , percent_time_ok_known , current_subject ) ;
get_running_average ( & average_percent_time_unknown , percent_time_unknown , current_subject ) ;
get_running_average ( & average_percent_time_unknown_known , percent_time_unknown_known , current_subject ) ;
get_running_average ( & average_percent_time_warning , percent_time_warning , current_subject ) ;
get_running_average ( & average_percent_time_warning_known , percent_time_warning_known , current_subject ) ;
get_running_average ( & average_percent_time_critical , percent_time_critical , current_subject ) ;
get_running_average ( & average_percent_time_critical_known , percent_time_critical_known , current_subject ) ;
get_running_average ( & average_percent_time_indeterminate , percent_time_indeterminate , current_subject ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
else if ( output_format = = CSV_OUTPUT ) {
/* servicegroup name, host name, service description */
printf ( " \" %s \" , \" %s \" , \" %s \" , " , sg - > group_name , temp_subject - > host_name , temp_subject - > service_description ) ;
/* time ok */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_ok , percent_time_ok , percent_time_ok_known ) ;
/* time warning */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_warning , percent_time_warning , percent_time_warning_known ) ;
/* time critical */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_critical , percent_time_critical , percent_time_critical_known ) ;
/* time unknown */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_unknown , percent_time_unknown , percent_time_unknown_known ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
/* time undetermined */
printf ( " %lu, %2.3f%% \n " , time_indeterminate , percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
if ( output_format = = HTML_OUTPUT ) {
/* display average stats */
if ( odd ) {
odd = 0 ;
bgclass = " Odd " ;
}
else {
odd = 1 ;
bgclass = " Even " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
printf ( " <tr CLASS='data%s'><td CLASS='data%s' colspan='2'>Average</td> " , bgclass , bgclass ) ;
printf ( " <td CLASS='serviceOK'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_ok , average_percent_time_ok_known ) ;
printf ( " <td CLASS='serviceWARNING'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_warning , average_percent_time_warning_known ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_unknown , average_percent_time_unknown_known ) ;
printf ( " <td class='serviceCRITICAL'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_critical , average_percent_time_critical_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , average_percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* display host availability */
2019-04-18 17:09:18 +02:00
void display_host_availability ( void )
{
unsigned long total_time = 0L ;
unsigned long time_determinate = 0L ;
unsigned long time_indeterminate = 0L ;
avail_subject * temp_subject = NULL ;
host * temp_host = NULL ;
service * temp_service = NULL ;
int days = 0 ;
int hours = 0 ;
int minutes = 0 ;
int seconds = 0 ;
char time_indeterminate_string [ 48 ] = { 0 } ;
char time_determinate_string [ 48 ] = { 0 } ;
char total_time_string [ 48 ] = { 0 } ;
double percent_time_ok = 0.0 ;
double percent_time_warning = 0.0 ;
double percent_time_unknown = 0.0 ;
double percent_time_critical = 0.0 ;
double percent_time_indeterminate = 0.0 ;
double percent_time_ok_known = 0.0 ;
double percent_time_warning_known = 0.0 ;
double percent_time_unknown_known = 0.0 ;
double percent_time_critical_known = 0.0 ;
char time_up_string [ 48 ] = { 0 } ;
char time_down_string [ 48 ] = { 0 } ;
char time_unreachable_string [ 48 ] = { 0 } ;
double percent_time_up = 0.0 ;
double percent_time_down = 0.0 ;
double percent_time_unreachable = 0.0 ;
double percent_time_up_known = 0.0 ;
double percent_time_down_known = 0.0 ;
double percent_time_unreachable_known = 0.0 ;
double percent_time_up_scheduled = 0.0 ;
double percent_time_up_unscheduled = 0.0 ;
double percent_time_down_scheduled = 0.0 ;
double percent_time_down_unscheduled = 0.0 ;
double percent_time_unreachable_scheduled = 0.0 ;
double percent_time_unreachable_unscheduled = 0.0 ;
double percent_time_up_scheduled_known = 0.0 ;
double percent_time_up_unscheduled_known = 0.0 ;
double percent_time_down_scheduled_known = 0.0 ;
double percent_time_down_unscheduled_known = 0.0 ;
double percent_time_unreachable_scheduled_known = 0.0 ;
2017-05-19 22:22:40 +02:00
double percent_time_unreachable_unscheduled_known = 0.0 ;
2019-04-18 17:09:18 +02:00
char time_up_scheduled_string [ 48 ] = { 0 } ;
char time_up_unscheduled_string [ 48 ] = { 0 } ;
char time_down_scheduled_string [ 48 ] = { 0 } ;
char time_down_unscheduled_string [ 48 ] = { 0 } ;
char time_unreachable_scheduled_string [ 48 ] = { 0 } ;
char time_unreachable_unscheduled_string [ 48 ] = { 0 } ;
char time_indeterminate_scheduled_string [ 48 ] = { 0 } ;
char time_indeterminate_unscheduled_string [ 48 ] = { 0 } ;
char time_indeterminate_notrunning_string [ 48 ] = { 0 } ;
char time_indeterminate_nodata_string [ 48 ] = { 0 } ;
double percent_time_indeterminate_notrunning = 0.0 ;
double percent_time_indeterminate_nodata = 0.0 ;
double average_percent_time_up = 0.0 ;
double average_percent_time_up_known = 0.0 ;
double average_percent_time_down = 0.0 ;
double average_percent_time_down_known = 0.0 ;
double average_percent_time_unreachable = 0.0 ;
double average_percent_time_unreachable_known = 0.0 ;
double average_percent_time_indeterminate = 0.0 ;
double average_percent_time_ok = 0.0 ;
double average_percent_time_ok_known = 0.0 ;
double average_percent_time_unknown = 0.0 ;
double average_percent_time_unknown_known = 0.0 ;
double average_percent_time_warning = 0.0 ;
double average_percent_time_warning_known = 0.0 ;
double average_percent_time_critical = 0.0 ;
double average_percent_time_critical_known = 0.0 ;
const char * bgclass = " " ;
int current_subject = 0 ;
int odd = 1 ;
2017-05-19 22:22:40 +02:00
/* calculate total time during period based on timeperiod used for reporting */
total_time = calculate_total_time ( t1 , t2 ) ;
# ifdef DEBUG
printf ( " Total time: '%ld' seconds<br> \n " , total_time ) ;
# endif
2019-04-18 17:09:18 +02:00
/* its the same header for all CSV outputs */
if ( output_format = = CSV_OUTPUT ) {
printf ( " HOST_NAME, " ) ;
printf ( " TIME_UP_SCHEDULED, PERCENT_TIME_UP_SCHEDULED, PERCENT_KNOWN_TIME_UP_SCHEDULED, " ) ;
printf ( " TIME_UP_UNSCHEDULED, PERCENT_TIME_UP_UNSCHEDULED, PERCENT_KNOWN_TIME_UP_UNSCHEDULED, " ) ;
printf ( " TOTAL_TIME_UP, PERCENT_TOTAL_TIME_UP, PERCENT_KNOWN_TIME_UP, " ) ;
printf ( " TIME_DOWN_SCHEDULED, PERCENT_TIME_DOWN_SCHEDULED, PERCENT_KNOWN_TIME_DOWN_SCHEDULED, " ) ;
printf ( " TIME_DOWN_UNSCHEDULED, PERCENT_TIME_DOWN_UNSCHEDULED, PERCENT_KNOWN_TIME_DOWN_UNSCHEDULED, " ) ;
printf ( " TOTAL_TIME_DOWN, PERCENT_TOTAL_TIME_DOWN, PERCENT_KNOWN_TIME_DOWN, " ) ;
printf ( " TIME_UNREACHABLE_SCHEDULED, PERCENT_TIME_UNREACHABLE_SCHEDULED, " ) ;
printf ( " PERCENT_KNOWN_TIME_UNREACHABLE_SCHEDULED, TIME_UNREACHABLE_UNSCHEDULED, " ) ;
printf ( " PERCENT_TIME_UNREACHABLE_UNSCHEDULED, PERCENT_KNOWN_TIME_UNREACHABLE_UNSCHEDULED, " ) ;
printf ( " TOTAL_TIME_UNREACHABLE, PERCENT_TOTAL_TIME_UNREACHABLE, PERCENT_KNOWN_TIME_UNREACHABLE, " ) ;
printf ( " TIME_UNDETERMINED_NOT_RUNNING, PERCENT_TIME_UNDETERMINED_NOT_RUNNING, " ) ;
printf ( " TIME_UNDETERMINED_NO_DATA, PERCENT_TIME_UNDETERMINED_NO_DATA, " ) ;
printf ( " TOTAL_TIME_UNDETERMINED, PERCENT_TOTAL_TIME_UNDETERMINED \n " ) ;
}
2017-05-19 22:22:40 +02:00
/* show data for a specific host */
2019-04-18 17:09:18 +02:00
if ( show_all_hosts = = FALSE ) {
2017-05-19 22:22:40 +02:00
temp_subject = find_subject ( HOST_SUBJECT , host_name , NULL ) ;
2019-04-18 17:09:18 +02:00
if ( temp_subject = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
temp_host = find_host ( temp_subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
if ( temp_host = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* the user isn't authorized to view this host */
2019-04-18 17:09:18 +02:00
if ( is_authorized_for_host ( temp_host , & current_authdata ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
time_determinate = temp_subject - > time_up + temp_subject - > time_down + temp_subject - > time_unreachable ;
time_indeterminate = total_time - time_determinate ;
/* adjust indeterminate time due to insufficient data (not all was caught) */
temp_subject - > time_indeterminate_nodata = time_indeterminate - temp_subject - > time_indeterminate_notrunning ;
/* up times */
get_time_breakdown ( temp_subject - > time_up , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_up_string , sizeof ( time_up_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_up , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_up_scheduled_string , sizeof ( time_up_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_up - temp_subject - > scheduled_time_up , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_up_unscheduled_string , sizeof ( time_up_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
/* down times */
get_time_breakdown ( temp_subject - > time_down , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_down_string , sizeof ( time_down_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_down , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_down_scheduled_string , sizeof ( time_down_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_down - temp_subject - > scheduled_time_down , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_down_unscheduled_string , sizeof ( time_down_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
/* unreachable times */
get_time_breakdown ( temp_subject - > time_unreachable , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_unreachable_string , sizeof ( time_unreachable_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_unreachable , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_unreachable_scheduled_string , sizeof ( time_unreachable_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_unreachable - temp_subject - > scheduled_time_unreachable , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_unreachable_unscheduled_string , sizeof ( time_unreachable_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
/* indeterminate times */
get_time_breakdown ( time_indeterminate , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_string , sizeof ( time_indeterminate_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_indeterminate , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_scheduled_string , sizeof ( time_indeterminate_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( time_indeterminate - temp_subject - > scheduled_time_indeterminate , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_unscheduled_string , sizeof ( time_indeterminate_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_indeterminate_notrunning , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_notrunning_string , sizeof ( time_indeterminate_notrunning_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_indeterminate_nodata , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_nodata_string , sizeof ( time_indeterminate_nodata_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( time_determinate , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_determinate_string , sizeof ( time_determinate_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( total_time , & days , & hours , & minutes , & seconds ) ;
snprintf ( total_time_string , sizeof ( total_time_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
2019-04-18 17:09:18 +02:00
if ( total_time > 0 ) {
percent_time_up = ( double ) ( ( ( double ) temp_subject - > time_up * 100.0 ) / ( double ) total_time ) ;
percent_time_up_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_up * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_up_unscheduled = percent_time_up - percent_time_up_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_down = ( double ) ( ( ( double ) temp_subject - > time_down * 100.0 ) / ( double ) total_time ) ;
percent_time_down_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_down * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_down_unscheduled = percent_time_down - percent_time_down_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_unreachable = ( double ) ( ( ( double ) temp_subject - > time_unreachable * 100.0 ) / ( double ) total_time ) ;
percent_time_unreachable_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_unreachable * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_unreachable_unscheduled = percent_time_unreachable - percent_time_unreachable_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_indeterminate = ( double ) ( ( ( double ) time_indeterminate * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate_notrunning = ( double ) ( ( ( double ) temp_subject - > time_indeterminate_notrunning * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate_nodata = ( double ) ( ( ( double ) temp_subject - > time_indeterminate_nodata * 100.0 ) / ( double ) total_time ) ;
if ( time_determinate > 0 ) {
percent_time_up_known = ( double ) ( ( ( double ) temp_subject - > time_up * 100.0 ) / ( double ) time_determinate ) ;
percent_time_up_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_up * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_up_unscheduled_known = percent_time_up_known - percent_time_up_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_down_known = ( double ) ( ( ( double ) temp_subject - > time_down * 100.0 ) / ( double ) time_determinate ) ;
percent_time_down_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_down * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_down_unscheduled_known = percent_time_down_known - percent_time_down_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_unreachable_known = ( double ) ( ( ( double ) temp_subject - > time_unreachable * 100.0 ) / ( double ) time_determinate ) ;
percent_time_unreachable_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_unreachable * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_unreachable_unscheduled_known = percent_time_unreachable_known - percent_time_unreachable_scheduled_known ;
}
2019-04-18 17:09:18 +02:00
}
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>Host State Breakdowns:</DIV> \n " ) ;
2017-05-19 22:22:40 +02:00
# ifdef USE_TRENDS
2019-04-18 17:09:18 +02:00
printf ( " <p align='center'> \n " ) ;
printf ( " <a href='%s?host=%s " , TRENDS_CGI , url_encode ( host_name ) ) ;
printf ( " &t1=%lu&t2=%lu&includesoftstates=%s " , t1 , t2 , ( include_soft_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumestateretention=%s&assumeinitialstates=%s " , ( assume_state_retention = = TRUE ) ? " yes " : " no " , ( assume_initial_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumestatesduringnotrunning=%s&initialassumedhoststate=%d " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " , initial_assumed_host_state ) ;
printf ( " &backtrack=%d'> " , backtrack_archives ) ;
2017-05-19 23:37:19 +02:00
# ifdef LEGACY_GRAPHICAL_CGIS
2019-04-18 17:09:18 +02:00
printf ( " <img src='%s?createimage&smallimage&host=%s " , TRENDS_CGI , url_encode ( host_name ) ) ;
2017-05-19 23:37:19 +02:00
# else
2019-04-18 17:09:18 +02:00
printf ( " <img src='%s?createimage&smallimage&host=%s " , LEGACY_TRENDS_CGI , url_encode ( host_name ) ) ;
2017-05-19 23:37:19 +02:00
# endif
2019-04-18 17:09:18 +02:00
printf ( " &t1=%lu&t2=%lu&includesoftstates=%s " , t1 , t2 , ( include_soft_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumestateretention=%s&assumeinitialstates=%s " , ( assume_state_retention = = TRUE ) ? " yes " : " no " , ( assume_initial_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumestatesduringnotrunning=%s&initialassumedhoststate=%d " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " , initial_assumed_host_state ) ;
printf ( " &backtrack=%d' " , backtrack_archives ) ;
printf ( " border=1 alt='Host State Trends' title='Host State Trends' width='500' height='20'> " ) ;
printf ( " </a><br> \n " ) ;
printf ( " </p> \n " ) ;
2017-05-19 22:22:40 +02:00
# endif
2019-04-18 17:09:18 +02:00
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <TABLE BORDER=0 CLASS='data'> \n " ) ;
printf ( " <TR><TH CLASS='data'>State</TH> " ) ;
printf ( " <TH CLASS='data'>Type / Reason</TH> " ) ;
printf ( " <TH CLASS='data'>Time</TH> " ) ;
printf ( " <TH CLASS='data'>%% Total Time</TH> " ) ;
printf ( " <TH CLASS='data'>%% Known Time</TH></TR> \n " ) ;
/* up times */
printf ( " <tr CLASS='dataEven'> " ) ;
printf ( " <td CLASS='hostUP' rowspan=3>UP</td> " ) ;
printf ( " <td CLASS='dataEven'>Unscheduled</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_up_unscheduled_string ) ;
2019-08-03 18:28:19 +02:00
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_up_unscheduled ) ;
printf ( " <td class='dataEven'>%2.3f%%</td></tr> \n " , percent_time_up_unscheduled_known ) ;
2019-04-18 17:09:18 +02:00
printf ( " <tr CLASS='dataEven'> " ) ;
printf ( " <td CLASS='dataEven'>Scheduled</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_up_scheduled_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_up_scheduled ) ;
printf ( " <td class='dataEven'>%2.3f%%</td></tr> \n " , percent_time_up_scheduled_known ) ;
printf ( " <tr CLASS='hostUP'> " ) ;
printf ( " <td CLASS='hostUP'>Total</td> " ) ;
printf ( " <td CLASS='hostUP'>%s</td> " , time_up_string ) ;
printf ( " <td CLASS='hostUP'>%2.3f%%</td> " , percent_time_up ) ;
printf ( " <td class='hostUP'>%2.3f%%</td></tr> \n " , percent_time_up_known ) ;
/* down times */
printf ( " <tr CLASS='dataOdd'> " ) ;
printf ( " <td CLASS='hostDOWN' rowspan=3>DOWN</td> " ) ;
printf ( " <td CLASS='dataOdd'>Unscheduled</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_down_unscheduled_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_down_unscheduled ) ;
printf ( " <td class='dataOdd'>%2.3f%%</td></tr> \n " , percent_time_down_unscheduled_known ) ;
printf ( " <tr CLASS='dataOdd'> " ) ;
printf ( " <td CLASS='dataOdd'>Scheduled</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_down_scheduled_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_down_scheduled ) ;
printf ( " <td class='dataOdd'>%2.3f%%</td></tr> \n " , percent_time_down_scheduled_known ) ;
printf ( " <tr CLASS='hostDOWN'> " ) ;
printf ( " <td CLASS='hostDOWN'>Total</td> " ) ;
printf ( " <td CLASS='hostDOWN'>%s</td> " , time_down_string ) ;
printf ( " <td CLASS='hostDOWN'>%2.3f%%</td> " , percent_time_down ) ;
printf ( " <td class='hostDOWN'>%2.3f%%</td></tr> \n " , percent_time_down_known ) ;
/* unreachable times */
printf ( " <tr CLASS='dataEven'> " ) ;
printf ( " <td CLASS='hostUNREACHABLE' rowspan=3>UNREACHABLE</td> " ) ;
printf ( " <td CLASS='dataEven'>Unscheduled</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_unreachable_unscheduled_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_unreachable ) ;
printf ( " <td class='dataEven'>%2.3f%%</td></tr> \n " , percent_time_unreachable_known ) ;
printf ( " <tr CLASS='dataEven'> " ) ;
printf ( " <td CLASS='dataEven'>Scheduled</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_unreachable_scheduled_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_unreachable_scheduled ) ;
printf ( " <td class='dataEven'>%2.3f%%</td></tr> \n " , percent_time_unreachable_scheduled_known ) ;
printf ( " <tr CLASS='hostUNREACHABLE'> " ) ;
printf ( " <td CLASS='hostUNREACHABLE'>Total</td> " ) ;
printf ( " <td CLASS='hostUNREACHABLE'>%s</td> " , time_unreachable_string ) ;
printf ( " <td CLASS='hostUNREACHABLE'>%2.3f%%</td> " , percent_time_unreachable ) ;
printf ( " <td class='hostUNREACHABLE'>%2.3f%%</td></tr> \n " , percent_time_unreachable_known ) ;
/* indeterminate times */
printf ( " <tr CLASS='dataOdd'> " ) ;
printf ( " <td CLASS='dataOdd' rowspan=3>Undetermined</td> " ) ;
printf ( " <td CLASS='dataOdd'>Nagios Not Running</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_indeterminate_notrunning_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_indeterminate_notrunning ) ;
printf ( " <td CLASS='dataOdd'></td></tr> \n " ) ;
printf ( " <tr CLASS='dataOdd'> " ) ;
printf ( " <td CLASS='dataOdd'>Insufficient Data</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_indeterminate_nodata_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_indeterminate_nodata ) ;
printf ( " <td CLASS='dataOdd'></td></tr> \n " ) ;
printf ( " <tr CLASS='dataOdd'> " ) ;
printf ( " <td CLASS='dataOdd'>Total</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_indeterminate_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_indeterminate ) ;
printf ( " <td CLASS='dataOdd'></td></tr> \n " ) ;
printf ( " <tr><td colspan=3></td></tr> \n " ) ;
printf ( " <tr CLASS='dataEven'><td CLASS='dataEven'>All</td><td class='dataEven'>Total</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>100.000%%</td><td CLASS='dataEven'>100.000%%</td></tr> \n " , total_time_string ) ;
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
/* display state breakdowns for all services on this host (only HTML output) */
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <BR><BR> \n " ) ;
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>State Breakdowns For Host Services:</DIV> \n " ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <TABLE BORDER=0 CLASS='data'> \n " ) ;
printf ( " <TR><TH CLASS='data'>Service</TH><TH CLASS='data'>%% Time OK</TH><TH CLASS='data'>%% Time Warning</TH><TH CLASS='data'>%% Time Unknown</TH><TH CLASS='data'>%% Time Critical</TH><TH CLASS='data'>%% Time Undetermined</TH></TR> \n " ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_subject - > type ! = SERVICE_SUBJECT ) {
continue ;
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
temp_service = find_service ( temp_subject - > host_name , temp_subject - > service_description ) ;
if ( temp_service = = NULL ) {
continue ;
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
/* the user isn't authorized to view this service */
if ( is_authorized_for_service ( temp_service , & current_authdata ) = = FALSE ) {
continue ;
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
current_subject + + ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( odd ) {
odd = 0 ;
bgclass = " Odd " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
/* reset variables */
percent_time_ok = 0.0 ;
percent_time_warning = 0.0 ;
percent_time_unknown = 0.0 ;
percent_time_critical = 0.0 ;
percent_time_indeterminate = 0.0 ;
percent_time_ok_known = 0.0 ;
percent_time_warning_known = 0.0 ;
percent_time_unknown_known = 0.0 ;
percent_time_critical_known = 0.0 ;
time_determinate = temp_subject - > time_ok + temp_subject - > time_warning + temp_subject - > time_unknown + temp_subject - > time_critical ;
time_indeterminate = total_time - time_determinate ;
if ( total_time > 0 ) {
percent_time_ok = ( double ) ( ( ( double ) temp_subject - > time_ok * 100.0 ) / ( double ) total_time ) ;
percent_time_warning = ( double ) ( ( ( double ) temp_subject - > time_warning * 100.0 ) / ( double ) total_time ) ;
percent_time_unknown = ( double ) ( ( ( double ) temp_subject - > time_unknown * 100.0 ) / ( double ) total_time ) ;
percent_time_critical = ( double ) ( ( ( double ) temp_subject - > time_critical * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate = ( double ) ( ( ( double ) time_indeterminate * 100.0 ) / ( double ) total_time ) ;
if ( time_determinate > 0 ) {
percent_time_ok_known = ( double ) ( ( ( double ) temp_subject - > time_ok * 100.0 ) / ( double ) time_determinate ) ;
percent_time_warning_known = ( double ) ( ( ( double ) temp_subject - > time_warning * 100.0 ) / ( double ) time_determinate ) ;
percent_time_unknown_known = ( double ) ( ( ( double ) temp_subject - > time_unknown * 100.0 ) / ( double ) time_determinate ) ;
percent_time_critical_known = ( double ) ( ( ( double ) temp_subject - > time_critical * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
}
}
2019-04-18 17:09:18 +02:00
printf ( " <tr CLASS='data%s'><td CLASS='data%s'> " , bgclass , bgclass ) ;
service_report_url ( temp_subject - > host_name , temp_subject - > service_description , temp_subject - > service_description ) ;
printf ( " </td><td CLASS='serviceOK'>%2.3f%% (%2.3f%%)</td> " , percent_time_ok , percent_time_ok_known ) ;
printf ( " <td CLASS='serviceWARNING'>%2.3f%% (%2.3f%%)</td> " , percent_time_warning , percent_time_warning_known ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%2.3f%% (%2.3f%%)</td> " , percent_time_unknown , percent_time_unknown_known ) ;
printf ( " <td class='serviceCRITICAL'>%2.3f%% (%2.3f%%)</td> " , percent_time_critical , percent_time_critical_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , percent_time_indeterminate ) ;
get_running_average ( & average_percent_time_ok , percent_time_ok , current_subject ) ;
get_running_average ( & average_percent_time_ok_known , percent_time_ok_known , current_subject ) ;
get_running_average ( & average_percent_time_unknown , percent_time_unknown , current_subject ) ;
get_running_average ( & average_percent_time_unknown_known , percent_time_unknown_known , current_subject ) ;
get_running_average ( & average_percent_time_warning , percent_time_warning , current_subject ) ;
get_running_average ( & average_percent_time_warning_known , percent_time_warning_known , current_subject ) ;
get_running_average ( & average_percent_time_critical , percent_time_critical , current_subject ) ;
get_running_average ( & average_percent_time_critical_known , percent_time_critical_known , current_subject ) ;
get_running_average ( & average_percent_time_indeterminate , percent_time_indeterminate , current_subject ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
/* display average stats */
if ( odd ) {
odd = 0 ;
bgclass = " Odd " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
printf ( " <tr CLASS='data%s'><td CLASS='data%s'>Average</td> " , bgclass , bgclass ) ;
printf ( " <td CLASS='serviceOK'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_ok , average_percent_time_ok_known ) ;
printf ( " <td CLASS='serviceWARNING'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_warning , average_percent_time_warning_known ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_unknown , average_percent_time_unknown_known ) ;
printf ( " <td class='serviceCRITICAL'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_critical , average_percent_time_critical_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , average_percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
/* write log entries for the host */
temp_subject = find_subject ( HOST_SUBJECT , host_name , NULL ) ;
write_log_entries ( temp_subject ) ;
}
else if ( output_format = = CSV_OUTPUT ) {
/* host name */
printf ( " \" %s \" , " , temp_subject - > host_name ) ;
/* up times */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_up , percent_time_up_scheduled , percent_time_up_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_up - temp_subject - > scheduled_time_up , percent_time_up_unscheduled , percent_time_up_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_up , percent_time_up , percent_time_up_known ) ;
/* down times */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_down , percent_time_down_scheduled , percent_time_down_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_down - temp_subject - > scheduled_time_down , percent_time_down_unscheduled , percent_time_down_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_down , percent_time_down , percent_time_down_known ) ;
/* unreachable times */
printf ( " %lu, %2.3f%%, " , temp_subject - > scheduled_time_unreachable , percent_time_unreachable_scheduled ) ;
printf ( " %2.3f%%, %lu, " , percent_time_unreachable_scheduled_known , temp_subject - > time_unreachable - temp_subject - > scheduled_time_unreachable ) ;
printf ( " %2.3f%%, %2.3f%%, " , percent_time_unreachable_unscheduled , percent_time_unreachable_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_unreachable , percent_time_unreachable , percent_time_unreachable_known ) ;
/* indeterminate times */
printf ( " %lu, %2.3f%%, " , temp_subject - > time_indeterminate_notrunning , percent_time_indeterminate_notrunning ) ;
printf ( " %lu, %2.3f%%, " , temp_subject - > time_indeterminate_nodata , percent_time_indeterminate_nodata ) ;
printf ( " %lu, %2.3f%% \n " , time_indeterminate , percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* display data for all hosts */
else {
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
printf ( " <BR><BR> \n " ) ;
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>Host State Breakdowns:</DIV> \n " ) ;
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <TABLE BORDER=0 CLASS='data'> \n " ) ;
2019-04-18 17:09:18 +02:00
printf ( " <TR><TH CLASS='data'>Host</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Up</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Down</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Unreachable</TH> " ) ;
printf ( " <TH CLASS='data'>%% Time Undetermined</TH></TR> \n " ) ;
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_subject - > type ! = HOST_SUBJECT ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
temp_host = find_host ( temp_subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
if ( temp_host = = NULL ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* the user isn't authorized to view this host */
2019-04-18 17:09:18 +02:00
if ( is_authorized_for_host ( temp_host , & current_authdata ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
current_subject + + ;
time_determinate = temp_subject - > time_up + temp_subject - > time_down + temp_subject - > time_unreachable ;
time_indeterminate = total_time - time_determinate ;
/* adjust indeterminate time due to insufficient data (not all was caught) */
temp_subject - > time_indeterminate_nodata = time_indeterminate - temp_subject - > time_indeterminate_notrunning ;
/* initialize values */
2019-04-18 17:09:18 +02:00
percent_time_up = 0.0 ;
percent_time_up_scheduled = 0.0 ;
percent_time_up_unscheduled = 0.0 ;
percent_time_down = 0.0 ;
percent_time_down_scheduled = 0.0 ;
percent_time_down_unscheduled = 0.0 ;
percent_time_unreachable = 0.0 ;
percent_time_unreachable_scheduled = 0.0 ;
percent_time_unreachable_unscheduled = 0.0 ;
percent_time_indeterminate = 0.0 ;
percent_time_indeterminate_notrunning = 0.0 ;
percent_time_indeterminate_nodata = 0.0 ;
percent_time_up_known = 0.0 ;
percent_time_up_scheduled_known = 0.0 ;
percent_time_up_unscheduled_known = 0.0 ;
percent_time_down_known = 0.0 ;
percent_time_down_scheduled_known = 0.0 ;
percent_time_down_unscheduled_known = 0.0 ;
percent_time_unreachable_known = 0.0 ;
percent_time_unreachable_scheduled_known = 0.0 ;
2017-05-19 22:22:40 +02:00
percent_time_unreachable_unscheduled_known = 0.0 ;
2019-04-18 17:09:18 +02:00
if ( total_time > 0 ) {
percent_time_up = ( double ) ( ( ( double ) temp_subject - > time_up * 100.0 ) / ( double ) total_time ) ;
percent_time_up_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_up * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_up_unscheduled = percent_time_up - percent_time_up_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_down = ( double ) ( ( ( double ) temp_subject - > time_down * 100.0 ) / ( double ) total_time ) ;
percent_time_down_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_down * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_down_unscheduled = percent_time_down - percent_time_down_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_unreachable = ( double ) ( ( ( double ) temp_subject - > time_unreachable * 100.0 ) / ( double ) total_time ) ;
percent_time_unreachable_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_unreachable * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_unreachable_unscheduled = percent_time_unreachable - percent_time_unreachable_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_indeterminate = ( double ) ( ( ( double ) time_indeterminate * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate_notrunning = ( double ) ( ( ( double ) temp_subject - > time_indeterminate_notrunning * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate_nodata = ( double ) ( ( ( double ) temp_subject - > time_indeterminate_nodata * 100.0 ) / ( double ) total_time ) ;
if ( time_determinate > 0 ) {
percent_time_up_known = ( double ) ( ( ( double ) temp_subject - > time_up * 100.0 ) / ( double ) time_determinate ) ;
percent_time_up_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_up * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_up_unscheduled_known = percent_time_up_known - percent_time_up_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_down_known = ( double ) ( ( ( double ) temp_subject - > time_down * 100.0 ) / ( double ) time_determinate ) ;
percent_time_down_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_down * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_down_unscheduled_known = percent_time_down_known - percent_time_down_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_unreachable_known = ( double ) ( ( ( double ) temp_subject - > time_unreachable * 100.0 ) / ( double ) time_determinate ) ;
percent_time_unreachable_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_unreachable * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_unreachable_unscheduled_known = percent_time_unreachable_known - percent_time_unreachable_scheduled_known ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( odd ) {
2017-05-19 22:22:40 +02:00
odd = 0 ;
bgclass = " Odd " ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
printf ( " <tr CLASS='data%s'><td CLASS='data%s'> " , bgclass , bgclass ) ;
host_report_url ( temp_subject - > host_name , temp_subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
printf ( " </td><td CLASS='hostUP'>%2.3f%% (%2.3f%%)</td> " , percent_time_up , percent_time_up_known ) ;
printf ( " <td CLASS='hostDOWN'>%2.3f%% (%2.3f%%)</td> " , percent_time_down , percent_time_down_known ) ;
printf ( " <td CLASS='hostUNREACHABLE'>%2.3f%% (%2.3f%%)</td> " , percent_time_unreachable , percent_time_unreachable_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , percent_time_indeterminate ) ;
/* we only print the averages for html output */
get_running_average ( & average_percent_time_up , percent_time_up , current_subject ) ;
get_running_average ( & average_percent_time_up_known , percent_time_up_known , current_subject ) ;
get_running_average ( & average_percent_time_down , percent_time_down , current_subject ) ;
get_running_average ( & average_percent_time_down_known , percent_time_down_known , current_subject ) ;
get_running_average ( & average_percent_time_unreachable , percent_time_unreachable , current_subject ) ;
get_running_average ( & average_percent_time_unreachable_known , percent_time_unreachable_known , current_subject ) ;
get_running_average ( & average_percent_time_indeterminate , percent_time_indeterminate , current_subject ) ;
}
else if ( output_format = = CSV_OUTPUT ) {
2017-05-19 22:22:40 +02:00
/* host name */
2019-04-18 17:09:18 +02:00
printf ( " \" %s \" , " , temp_subject - > host_name ) ;
2017-05-19 22:22:40 +02:00
/* up times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_up , percent_time_up_scheduled , percent_time_up_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_up - temp_subject - > scheduled_time_up , percent_time_up_unscheduled , percent_time_up_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_up , percent_time_up , percent_time_up_known ) ;
2017-05-19 22:22:40 +02:00
/* down times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_down , percent_time_down_scheduled , percent_time_down_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_down - temp_subject - > scheduled_time_down , percent_time_down_unscheduled , percent_time_down_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_down , percent_time_down , percent_time_down_known ) ;
2017-05-19 22:22:40 +02:00
/* unreachable times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, " , temp_subject - > scheduled_time_unreachable , percent_time_unreachable_scheduled ) ;
printf ( " %2.3f%%, %lu, " , percent_time_unreachable_scheduled_known , temp_subject - > time_unreachable - temp_subject - > scheduled_time_unreachable ) ;
printf ( " %2.3f%%, %2.3f%%, " , percent_time_unreachable_unscheduled , percent_time_unreachable_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_unreachable , percent_time_unreachable , percent_time_unreachable_known ) ;
2017-05-19 22:22:40 +02:00
/* indeterminate times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, " , temp_subject - > time_indeterminate_notrunning , percent_time_indeterminate_notrunning ) ;
printf ( " %lu, %2.3f%%, " , temp_subject - > time_indeterminate_nodata , percent_time_indeterminate_nodata ) ;
printf ( " %lu, %2.3f%% \n " , time_indeterminate , percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
/* average statistics */
2019-04-18 17:09:18 +02:00
if ( odd ) {
2017-05-19 22:22:40 +02:00
odd = 0 ;
bgclass = " Odd " ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
2019-04-18 17:09:18 +02:00
}
printf ( " <tr CLASS='data%s'><td CLASS='data%s'>Average</td> " , bgclass , bgclass ) ;
printf ( " <td CLASS='hostUP'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_up , average_percent_time_up_known ) ;
printf ( " <td CLASS='hostDOWN'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_down , average_percent_time_down_known ) ;
printf ( " <td CLASS='hostUNREACHABLE'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_unreachable , average_percent_time_unreachable_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> " , bgclass , average_percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* display service availability */
2019-04-18 17:09:18 +02:00
void display_service_availability ( void )
{
unsigned long total_time = 0L ;
unsigned long time_determinate = 0L ;
unsigned long time_indeterminate = 0L ;
avail_subject * temp_subject = NULL ;
service * temp_service = NULL ;
int days = 0 ;
int hours = 0 ;
int minutes = 0 ;
int seconds = 0 ;
char time_ok_string [ 48 ] = { 0 } ;
char time_warning_string [ 48 ] = { 0 } ;
char time_unknown_string [ 48 ] = { 0 } ;
char time_critical_string [ 48 ] = { 0 } ;
char time_indeterminate_string [ 48 ] = { 0 } ;
char time_determinate_string [ 48 ] = { 0 } ;
char total_time_string [ 48 ] = { 0 } ;
double percent_time_ok = 0.0 ;
double percent_time_warning = 0.0 ;
double percent_time_unknown = 0.0 ;
double percent_time_critical = 0.0 ;
double percent_time_indeterminate = 0.0 ;
double percent_time_ok_known = 0.0 ;
double percent_time_warning_known = 0.0 ;
double percent_time_unknown_known = 0.0 ;
double percent_time_critical_known = 0.0 ;
char time_critical_scheduled_string [ 48 ] = { 0 } ;
char time_critical_unscheduled_string [ 48 ] = { 0 } ;
double percent_time_critical_scheduled = 0.0 ;
double percent_time_critical_unscheduled = 0.0 ;
double percent_time_critical_scheduled_known = 0.0 ;
double percent_time_critical_unscheduled_known = 0.0 ;
char time_unknown_scheduled_string [ 48 ] = { 0 } ;
char time_unknown_unscheduled_string [ 48 ] = { 0 } ;
double percent_time_unknown_scheduled = 0.0 ;
double percent_time_unknown_unscheduled = 0.0 ;
double percent_time_unknown_scheduled_known = 0.0 ;
double percent_time_unknown_unscheduled_known = 0.0 ;
char time_warning_scheduled_string [ 48 ] = { 0 } ;
char time_warning_unscheduled_string [ 48 ] = { 0 } ;
double percent_time_warning_scheduled = 0.0 ;
double percent_time_warning_unscheduled = 0.0 ;
double percent_time_warning_scheduled_known = 0.0 ;
double percent_time_warning_unscheduled_known = 0.0 ;
char time_ok_scheduled_string [ 48 ] = { 0 } ;
char time_ok_unscheduled_string [ 48 ] = { 0 } ;
double percent_time_ok_scheduled = 0.0 ;
double percent_time_ok_unscheduled = 0.0 ;
double percent_time_ok_scheduled_known = 0.0 ;
double percent_time_ok_unscheduled_known = 0.0 ;
double average_percent_time_ok = 0.0 ;
double average_percent_time_ok_known = 0.0 ;
double average_percent_time_unknown = 0.0 ;
double average_percent_time_unknown_known = 0.0 ;
double average_percent_time_warning = 0.0 ;
double average_percent_time_warning_known = 0.0 ;
double average_percent_time_critical = 0.0 ;
double average_percent_time_critical_known = 0.0 ;
double average_percent_time_indeterminate = 0.0 ;
int current_subject = 0 ;
char time_indeterminate_scheduled_string [ 48 ] = { 0 } ;
char time_indeterminate_unscheduled_string [ 48 ] = { 0 } ;
char time_indeterminate_notrunning_string [ 48 ] = { 0 } ;
char time_indeterminate_nodata_string [ 48 ] = { 0 } ;
double percent_time_indeterminate_notrunning = 0.0 ;
double percent_time_indeterminate_nodata = 0.0 ;
int odd = 1 ;
const char * bgclass = " " ;
char last_host [ 128 ] = " " ;
2017-05-19 22:22:40 +02:00
/* calculate total time during period based on timeperiod used for reporting */
total_time = calculate_total_time ( t1 , t2 ) ;
2019-04-18 17:09:18 +02:00
# ifdef DEBUG
printf ( " Total time: '%ld' seconds<br> \n " , total_time ) ;
# endif
/* its the same header for all CSV outputs */
if ( output_format = = CSV_OUTPUT ) {
printf ( " HOST_NAME, SERVICE_DESCRIPTION, " ) ;
printf ( " TIME_OK_SCHEDULED, PERCENT_TIME_OK_SCHEDULED, PERCENT_KNOWN_TIME_OK_SCHEDULED, " ) ;
printf ( " TIME_OK_UNSCHEDULED, PERCENT_TIME_OK_UNSCHEDULED, PERCENT_KNOWN_TIME_OK_UNSCHEDULED, " ) ;
printf ( " TOTAL_TIME_OK, PERCENT_TOTAL_TIME_OK, PERCENT_KNOWN_TIME_OK, " ) ;
printf ( " TIME_WARNING_SCHEDULED, PERCENT_TIME_WARNING_SCHEDULED, PERCENT_KNOWN_TIME_WARNING_SCHEDULED, " ) ;
printf ( " TIME_WARNING_UNSCHEDULED, PERCENT_TIME_WARNING_UNSCHEDULED, PERCENT_KNOWN_TIME_WARNING_UNSCHEDULED, " ) ;
printf ( " TOTAL_TIME_WARNING, PERCENT_TOTAL_TIME_WARNING, PERCENT_KNOWN_TIME_WARNING, " ) ;
printf ( " TIME_UNKNOWN_SCHEDULED, PERCENT_TIME_UNKNOWN_SCHEDULED, PERCENT_KNOWN_TIME_UNKNOWN_SCHEDULED, " ) ;
printf ( " TIME_UNKNOWN_UNSCHEDULED, PERCENT_TIME_UNKNOWN_UNSCHEDULED, PERCENT_KNOWN_TIME_UNKNOWN_UNSCHEDULED, " ) ;
printf ( " TOTAL_TIME_UNKNOWN, PERCENT_TOTAL_TIME_UNKNOWN, PERCENT_KNOWN_TIME_UNKNOWN, " ) ;
printf ( " TIME_CRITICAL_SCHEDULED, PERCENT_TIME_CRITICAL_SCHEDULED, PERCENT_KNOWN_TIME_CRITICAL_SCHEDULED, " ) ;
printf ( " TIME_CRITICAL_UNSCHEDULED, PERCENT_TIME_CRITICAL_UNSCHEDULED, PERCENT_KNOWN_TIME_CRITICAL_UNSCHEDULED, " ) ;
printf ( " TOTAL_TIME_CRITICAL, PERCENT_TOTAL_TIME_CRITICAL, PERCENT_KNOWN_TIME_CRITICAL, " ) ;
printf ( " TIME_UNDETERMINED_NOT_RUNNING, PERCENT_TIME_UNDETERMINED_NOT_RUNNING, TIME_UNDETERMINED_NO_DATA, " ) ;
printf ( " PERCENT_TIME_UNDETERMINED_NO_DATA, TOTAL_TIME_UNDETERMINED, PERCENT_TOTAL_TIME_UNDETERMINED \n " ) ;
}
2017-05-19 22:22:40 +02:00
/* we're only getting data for one service */
2019-04-18 17:09:18 +02:00
if ( show_all_services = = FALSE ) {
2017-05-19 22:22:40 +02:00
temp_subject = find_subject ( SERVICE_SUBJECT , host_name , svc_description ) ;
2019-04-18 17:09:18 +02:00
if ( temp_subject = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
temp_service = find_service ( temp_subject - > host_name , temp_subject - > service_description ) ;
2019-04-18 17:09:18 +02:00
if ( temp_service = = NULL ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* the user isn't authorized to view this service */
2019-04-18 17:09:18 +02:00
if ( is_authorized_for_service ( temp_service , & current_authdata ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
return ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
time_determinate = temp_subject - > time_ok + temp_subject - > time_warning + temp_subject - > time_unknown + temp_subject - > time_critical ;
time_indeterminate = total_time - time_determinate ;
/* adjust indeterminate time due to insufficient data (not all was caught) */
temp_subject - > time_indeterminate_nodata = time_indeterminate - temp_subject - > time_indeterminate_notrunning ;
/* ok states */
get_time_breakdown ( temp_subject - > time_ok , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_ok_string , sizeof ( time_ok_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_ok , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_ok_scheduled_string , sizeof ( time_ok_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_ok - temp_subject - > scheduled_time_ok , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_ok_unscheduled_string , sizeof ( time_ok_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
/* warning states */
get_time_breakdown ( temp_subject - > time_warning , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_warning_string , sizeof ( time_warning_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_warning , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_warning_scheduled_string , sizeof ( time_warning_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_warning - temp_subject - > scheduled_time_warning , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_warning_unscheduled_string , sizeof ( time_warning_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
/* unknown states */
get_time_breakdown ( temp_subject - > time_unknown , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_unknown_string , sizeof ( time_unknown_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_unknown , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_unknown_scheduled_string , sizeof ( time_unknown_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_unknown - temp_subject - > scheduled_time_unknown , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_unknown_unscheduled_string , sizeof ( time_unknown_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
/* critical states */
get_time_breakdown ( temp_subject - > time_critical , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_critical_string , sizeof ( time_critical_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_critical , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_critical_scheduled_string , sizeof ( time_critical_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_critical - temp_subject - > scheduled_time_critical , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_critical_unscheduled_string , sizeof ( time_critical_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
/* indeterminate time */
get_time_breakdown ( time_indeterminate , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_string , sizeof ( time_indeterminate_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > scheduled_time_indeterminate , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_scheduled_string , sizeof ( time_indeterminate_scheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( time_indeterminate - temp_subject - > scheduled_time_indeterminate , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_unscheduled_string , sizeof ( time_indeterminate_unscheduled_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_indeterminate_notrunning , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_notrunning_string , sizeof ( time_indeterminate_notrunning_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( temp_subject - > time_indeterminate_nodata , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_indeterminate_nodata_string , sizeof ( time_indeterminate_nodata_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( time_determinate , & days , & hours , & minutes , & seconds ) ;
snprintf ( time_determinate_string , sizeof ( time_determinate_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
get_time_breakdown ( total_time , & days , & hours , & minutes , & seconds ) ;
snprintf ( total_time_string , sizeof ( total_time_string ) - 1 , " %dd %dh %dm %ds " , days , hours , minutes , seconds ) ;
2019-04-18 17:09:18 +02:00
if ( total_time > 0 ) {
percent_time_ok = ( double ) ( ( ( double ) temp_subject - > time_ok * 100.0 ) / ( double ) total_time ) ;
percent_time_ok_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_ok * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_ok_unscheduled = percent_time_ok - percent_time_ok_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_warning = ( double ) ( ( ( double ) temp_subject - > time_warning * 100.0 ) / ( double ) total_time ) ;
percent_time_warning_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_warning * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_warning_unscheduled = percent_time_warning - percent_time_warning_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_unknown = ( double ) ( ( ( double ) temp_subject - > time_unknown * 100.0 ) / ( double ) total_time ) ;
percent_time_unknown_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_unknown * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_unknown_unscheduled = percent_time_unknown - percent_time_unknown_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_critical = ( double ) ( ( ( double ) temp_subject - > time_critical * 100.0 ) / ( double ) total_time ) ;
percent_time_critical_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_critical * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_critical_unscheduled = percent_time_critical - percent_time_critical_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_indeterminate = ( double ) ( ( ( double ) time_indeterminate * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate_notrunning = ( double ) ( ( ( double ) temp_subject - > time_indeterminate_notrunning * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate_nodata = ( double ) ( ( ( double ) temp_subject - > time_indeterminate_nodata * 100.0 ) / ( double ) total_time ) ;
if ( time_determinate > 0 ) {
percent_time_ok_known = ( double ) ( ( ( double ) temp_subject - > time_ok * 100.0 ) / ( double ) time_determinate ) ;
percent_time_ok_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_ok * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_ok_unscheduled_known = percent_time_ok_known - percent_time_ok_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_warning_known = ( double ) ( ( ( double ) temp_subject - > time_warning * 100.0 ) / ( double ) time_determinate ) ;
percent_time_warning_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_warning * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_warning_unscheduled_known = percent_time_warning_known - percent_time_warning_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_unknown_known = ( double ) ( ( ( double ) temp_subject - > time_unknown * 100.0 ) / ( double ) time_determinate ) ;
percent_time_unknown_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_unknown * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_unknown_unscheduled_known = percent_time_unknown_known - percent_time_unknown_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_critical_known = ( double ) ( ( ( double ) temp_subject - > time_critical * 100.0 ) / ( double ) time_determinate ) ;
percent_time_critical_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_critical * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_critical_unscheduled_known = percent_time_critical_known - percent_time_critical_scheduled_known ;
}
2019-04-18 17:09:18 +02:00
}
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>Service State Breakdowns:</DIV> \n " ) ;
2017-05-19 22:22:40 +02:00
# ifdef USE_TRENDS
2019-04-18 17:09:18 +02:00
printf ( " <p align='center'> \n " ) ;
printf ( " <a href='%s?host=%s " , TRENDS_CGI , url_encode ( host_name ) ) ;
printf ( " &service=%s&t1=%lu&t2=%lu&includesoftstates=%s " , url_encode ( svc_description ) , t1 , t2 , ( include_soft_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumestateretention=%s&assumeinitialstates=%s " , ( assume_state_retention = = TRUE ) ? " yes " : " no " , ( assume_initial_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumestatesduringnotrunning=%s&initialassumedservicestate=%d " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " , initial_assumed_service_state ) ;
printf ( " &backtrack=%d'> " , backtrack_archives ) ;
2017-05-19 23:37:19 +02:00
# ifdef LEGACY_GRAPHICAL_CGIS
2019-04-18 17:09:18 +02:00
printf ( " <img src='%s?createimage&smallimage&host=%s " , TRENDS_CGI , url_encode ( host_name ) ) ;
2017-05-19 23:37:19 +02:00
# else
2019-04-18 17:09:18 +02:00
printf ( " <img src='%s?createimage&smallimage&host=%s " , LEGACY_TRENDS_CGI , url_encode ( host_name ) ) ;
2017-05-19 23:37:19 +02:00
# endif
2019-04-18 17:09:18 +02:00
printf ( " &service=%s&t1=%lu&t2=%lu " , url_encode ( svc_description ) , t1 , t2 ) ;
printf ( " &includesoftstates=%s&assumestateretention=%s " , ( include_soft_states = = TRUE ) ? " yes " : " no " , ( assume_state_retention = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumeinitialstates=%s&assumestatesduringnotrunning=%s " , ( assume_initial_states = = TRUE ) ? " yes " : " no " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " ) ;
printf ( " &initialassumedservicestate=%d&backtrack=%d' " , initial_assumed_service_state , backtrack_archives ) ;
printf ( " border=1 alt='Service State Trends' title='Service State Trends' width='500' height='20'> " ) ;
printf ( " </a><br> \n " ) ;
printf ( " </p> \n " ) ;
2017-05-19 22:22:40 +02:00
# endif
2019-04-18 17:09:18 +02:00
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <TABLE BORDER=0 CLASS='data'> \n " ) ;
printf ( " <TR><TH CLASS='data'>State</TH> " ) ;
printf ( " <TH CLASS='data'>Type / Reason</TH> " ) ;
printf ( " <TH CLASS='data'>Time</TH> " ) ;
printf ( " <TH CLASS='data'>%% Total Time</TH> " ) ;
printf ( " <TH CLASS='data'>%% Known Time</TH></TR> \n " ) ;
/* ok states */
printf ( " <tr CLASS='dataEven'><td CLASS='serviceOK' rowspan=3>OK</td> " ) ;
printf ( " <td CLASS='dataEven'>Unscheduled</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_ok_unscheduled_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_ok_unscheduled ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td></tr> \n " , percent_time_ok_unscheduled_known ) ;
printf ( " <tr CLASS='dataEven'><td CLASS='dataEven'>Scheduled</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_ok_scheduled_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_ok_scheduled ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td></tr> \n " , percent_time_ok_scheduled_known ) ;
printf ( " <tr CLASS='serviceOK'><td CLASS='serviceOK'>Total</td> " ) ;
printf ( " <td CLASS='serviceOK'>%s</td> " , time_ok_string ) ;
printf ( " <td CLASS='serviceOK'>%2.3f%%</td> " , percent_time_ok ) ;
printf ( " <td CLASS='serviceOK'>%2.3f%%</td></tr> \n " , percent_time_ok_known ) ;
/* warning states */
printf ( " <tr CLASS='dataOdd'><td CLASS='serviceWARNING' rowspan=3>WARNING</td> " ) ;
printf ( " <td CLASS='dataOdd'>Unscheduled</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_warning_unscheduled_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_warning_unscheduled ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td></tr> \n " , percent_time_warning_unscheduled_known ) ;
printf ( " <tr CLASS='dataOdd'><td CLASS='dataOdd'>Scheduled</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_warning_scheduled_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_warning_scheduled ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td></tr> \n " , percent_time_warning_scheduled_known ) ;
printf ( " <tr CLASS='serviceWARNING'><td CLASS='serviceWARNING'>Total</td> " ) ;
printf ( " <td CLASS='serviceWARNING'>%s</td> " , time_warning_string ) ;
printf ( " <td CLASS='serviceWARNING'>%2.3f%%</td> " , percent_time_warning ) ;
printf ( " <td CLASS='serviceWARNING'>%2.3f%%</td></tr> \n " , percent_time_warning_known ) ;
/* unknown states */
printf ( " <tr CLASS='dataEven'><td CLASS='serviceUNKNOWN' rowspan=3>UNKNOWN</td> " ) ;
printf ( " <td CLASS='dataEven'>Unscheduled</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_unknown_unscheduled_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_unknown_unscheduled ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td></tr> \n " , percent_time_unknown_unscheduled_known ) ;
printf ( " <tr CLASS='dataEven'><td CLASS='dataEven'>Scheduled</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_unknown_scheduled_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_unknown_scheduled ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td></tr> \n " , percent_time_unknown_scheduled_known ) ;
printf ( " <tr CLASS='serviceUNKNOWN'><td CLASS='serviceUNKNOWN'>Total</td> " ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%s</td> " , time_unknown_string ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%2.3f%%</td> " , percent_time_unknown ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%2.3f%%</td></tr> \n " , percent_time_unknown_known ) ;
/* critical states */
printf ( " <tr CLASS='dataOdd'><td CLASS='serviceCRITICAL' rowspan=3>CRITICAL</td> " ) ;
printf ( " <td CLASS='dataOdd'>Unscheduled</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_critical_unscheduled_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_critical_unscheduled ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td></tr> \n " , percent_time_critical_unscheduled_known ) ;
printf ( " <tr CLASS='dataOdd'><td CLASS='dataOdd'>Scheduled</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , time_critical_scheduled_string ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td> " , percent_time_critical_scheduled ) ;
printf ( " <td CLASS='dataOdd'>%2.3f%%</td></tr> \n " , percent_time_critical_scheduled_known ) ;
printf ( " <tr CLASS='serviceCRITICAL'><td CLASS='serviceCRITICAL'>Total</td> " ) ;
printf ( " <td CLASS='serviceCRITICAL'>%s</td> " , time_critical_string ) ;
printf ( " <td CLASS='serviceCRITICAL'>%2.3f%%</td> " , percent_time_critical ) ;
printf ( " <td CLASS='serviceCRITICAL'>%2.3f%%</td></tr> \n " , percent_time_critical_known ) ;
printf ( " <tr CLASS='dataEven'><td CLASS='dataEven' rowspan=3>Undetermined</td> " ) ;
printf ( " <td CLASS='dataEven'>Nagios Not Running</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_indeterminate_notrunning_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_indeterminate_notrunning ) ;
printf ( " <td CLASS='dataEven'></td></tr> \n " ) ;
printf ( " <tr CLASS='dataEven'><td CLASS='dataEven'>Insufficient Data</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_indeterminate_nodata_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_indeterminate_nodata ) ;
printf ( " <td CLASS='dataEven'></td></tr> \n " ) ;
printf ( " <tr CLASS='dataEven'><td CLASS='dataEven'>Total</td> " ) ;
printf ( " <td CLASS='dataEven'>%s</td> " , time_indeterminate_string ) ;
printf ( " <td CLASS='dataEven'>%2.3f%%</td> " , percent_time_indeterminate ) ;
printf ( " <td CLASS='dataEven'></td></tr> \n " ) ;
printf ( " <tr><td colspan=3></td></tr> \n " ) ;
printf ( " <tr CLASS='dataOdd'><td CLASS='dataOdd'>All</td> " ) ;
printf ( " <td CLASS='dataOdd'>Total</td> " ) ;
printf ( " <td CLASS='dataOdd'>%s</td> " , total_time_string ) ;
printf ( " <td CLASS='dataOdd'>100.000%%</td> " ) ;
printf ( " <td CLASS='dataOdd'>100.000%%</td></tr> \n " ) ;
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
write_log_entries ( temp_subject ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
else if ( output_format = = CSV_OUTPUT ) {
/* host name and service description */
printf ( " \" %s \" , \" %s \" , " , temp_subject - > host_name , temp_subject - > service_description ) ;
/* ok times */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_ok , percent_time_ok_scheduled , percent_time_ok_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_ok - temp_subject - > scheduled_time_ok , percent_time_ok_unscheduled , percent_time_ok_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_ok , percent_time_ok , percent_time_ok_known ) ;
/* warning times */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_warning , percent_time_warning_scheduled , percent_time_warning_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_warning - temp_subject - > scheduled_time_warning , percent_time_warning_unscheduled , percent_time_warning_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_warning , percent_time_warning , percent_time_warning_known ) ;
/* unknown times */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_unknown , percent_time_unknown_scheduled , percent_time_unknown_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_unknown - temp_subject - > scheduled_time_unknown , percent_time_unknown_unscheduled , percent_time_unknown_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_unknown , percent_time_unknown , percent_time_unknown_known ) ;
/* critical times */
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_critical , percent_time_critical_scheduled , percent_time_critical_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_critical - temp_subject - > scheduled_time_critical , percent_time_critical_unscheduled , percent_time_critical_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_critical , percent_time_critical , percent_time_critical_known ) ;
/* indeterminate times */
printf ( " %lu, %2.3f%%, " , temp_subject - > time_indeterminate_notrunning , percent_time_indeterminate_notrunning ) ;
printf ( " %lu, %2.3f%%, " , temp_subject - > time_indeterminate_nodata , percent_time_indeterminate_nodata ) ;
printf ( " %lu, %2.3f%% \n " , time_indeterminate , percent_time_indeterminate ) ;
}
}
2017-05-19 22:22:40 +02:00
/* display data for all services */
else {
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
printf ( " <DIV ALIGN=CENTER CLASS='dataTitle'>Service State Breakdowns:</DIV> \n " ) ;
printf ( " <DIV ALIGN=CENTER> \n " ) ;
printf ( " <TABLE BORDER=0 CLASS='data'> \n " ) ;
printf ( " <TR><TH CLASS='data'>Host</TH><TH CLASS='data'>Service</TH><TH CLASS='data'>%% Time OK</TH><TH CLASS='data'>%% Time Warning</TH><TH CLASS='data'>%% Time Unknown</TH><TH CLASS='data'>%% Time Critical</TH><TH CLASS='data'>%% Time Undetermined</TH></TR> \n " ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
for ( temp_subject = subject_list ; temp_subject ! = NULL ; temp_subject = temp_subject - > next ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( temp_subject - > type ! = SERVICE_SUBJECT ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
temp_service = find_service ( temp_subject - > host_name , temp_subject - > service_description ) ;
2019-04-18 17:09:18 +02:00
if ( temp_service = = NULL ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
/* the user isn't authorized to view this service */
2019-04-18 17:09:18 +02:00
if ( is_authorized_for_service ( temp_service , & current_authdata ) = = FALSE ) {
2017-05-19 22:22:40 +02:00
continue ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
current_subject + + ;
time_determinate = temp_subject - > time_ok + temp_subject - > time_warning + temp_subject - > time_unknown + temp_subject - > time_critical ;
time_indeterminate = total_time - time_determinate ;
/* adjust indeterminate time due to insufficient data (not all was caught) */
temp_subject - > time_indeterminate_nodata = time_indeterminate - temp_subject - > time_indeterminate_notrunning ;
/* initialize values */
2019-04-18 17:09:18 +02:00
percent_time_ok = 0.0 ;
percent_time_ok_scheduled = 0.0 ;
percent_time_ok_unscheduled = 0.0 ;
percent_time_warning = 0.0 ;
percent_time_warning_scheduled = 0.0 ;
percent_time_warning_unscheduled = 0.0 ;
percent_time_unknown = 0.0 ;
percent_time_unknown_scheduled = 0.0 ;
percent_time_unknown_unscheduled = 0.0 ;
percent_time_critical = 0.0 ;
percent_time_critical_scheduled = 0.0 ;
percent_time_critical_unscheduled = 0.0 ;
percent_time_indeterminate = 0.0 ;
percent_time_indeterminate_notrunning = 0.0 ;
percent_time_indeterminate_nodata = 0.0 ;
percent_time_ok_known = 0.0 ;
percent_time_ok_scheduled_known = 0.0 ;
percent_time_ok_unscheduled_known = 0.0 ;
percent_time_warning_known = 0.0 ;
percent_time_warning_scheduled_known = 0.0 ;
percent_time_warning_unscheduled_known = 0.0 ;
percent_time_unknown_known = 0.0 ;
percent_time_unknown_scheduled_known = 0.0 ;
percent_time_unknown_unscheduled_known = 0.0 ;
percent_time_critical_known = 0.0 ;
percent_time_critical_scheduled_known = 0.0 ;
2017-05-19 22:22:40 +02:00
percent_time_critical_unscheduled_known = 0.0 ;
2019-04-18 17:09:18 +02:00
if ( total_time > 0 ) {
percent_time_ok = ( double ) ( ( ( double ) temp_subject - > time_ok * 100.0 ) / ( double ) total_time ) ;
percent_time_ok_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_ok * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_ok_unscheduled = percent_time_ok - percent_time_ok_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_warning = ( double ) ( ( ( double ) temp_subject - > time_warning * 100.0 ) / ( double ) total_time ) ;
percent_time_warning_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_warning * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_warning_unscheduled = percent_time_warning - percent_time_warning_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_unknown = ( double ) ( ( ( double ) temp_subject - > time_unknown * 100.0 ) / ( double ) total_time ) ;
percent_time_unknown_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_unknown * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_unknown_unscheduled = percent_time_unknown - percent_time_unknown_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_critical = ( double ) ( ( ( double ) temp_subject - > time_critical * 100.0 ) / ( double ) total_time ) ;
percent_time_critical_scheduled = ( double ) ( ( ( double ) temp_subject - > scheduled_time_critical * 100.0 ) / ( double ) total_time ) ;
2017-05-19 22:22:40 +02:00
percent_time_critical_unscheduled = percent_time_critical - percent_time_critical_scheduled ;
2019-04-18 17:09:18 +02:00
percent_time_indeterminate = ( double ) ( ( ( double ) time_indeterminate * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate_notrunning = ( double ) ( ( ( double ) temp_subject - > time_indeterminate_notrunning * 100.0 ) / ( double ) total_time ) ;
percent_time_indeterminate_nodata = ( double ) ( ( ( double ) temp_subject - > time_indeterminate_nodata * 100.0 ) / ( double ) total_time ) ;
if ( time_determinate > 0 ) {
percent_time_ok_known = ( double ) ( ( ( double ) temp_subject - > time_ok * 100.0 ) / ( double ) time_determinate ) ;
percent_time_ok_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_ok * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_ok_unscheduled_known = percent_time_ok_known - percent_time_ok_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_warning_known = ( double ) ( ( ( double ) temp_subject - > time_warning * 100.0 ) / ( double ) time_determinate ) ;
percent_time_warning_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_warning * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_warning_unscheduled_known = percent_time_warning_known - percent_time_warning_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_unknown_known = ( double ) ( ( ( double ) temp_subject - > time_unknown * 100.0 ) / ( double ) time_determinate ) ;
percent_time_unknown_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_unknown * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_unknown_unscheduled_known = percent_time_unknown_known - percent_time_unknown_scheduled_known ;
2019-04-18 17:09:18 +02:00
percent_time_critical_known = ( double ) ( ( ( double ) temp_subject - > time_critical * 100.0 ) / ( double ) time_determinate ) ;
percent_time_critical_scheduled_known = ( double ) ( ( ( double ) temp_subject - > scheduled_time_critical * 100.0 ) / ( double ) time_determinate ) ;
2017-05-19 22:22:40 +02:00
percent_time_critical_unscheduled_known = percent_time_critical_known - percent_time_critical_scheduled_known ;
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( odd ) {
2017-05-19 22:22:40 +02:00
odd = 0 ;
bgclass = " Odd " ;
}
else {
odd = 1 ;
bgclass = " Even " ;
}
printf ( " <tr CLASS='data%s'><td CLASS='data%s'> " , bgclass , bgclass ) ;
2019-04-18 17:09:18 +02:00
if ( strcmp ( temp_subject - > host_name , last_host ) ) {
2017-05-19 22:22:40 +02:00
host_report_url ( temp_subject - > host_name , temp_subject - > host_name ) ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
printf ( " </td><td CLASS='data%s'> " , bgclass ) ;
service_report_url ( temp_subject - > host_name , temp_subject - > service_description , temp_subject - > service_description ) ;
2019-04-18 17:09:18 +02:00
printf ( " </td><td CLASS='serviceOK'>%2.3f%% (%2.3f%%)</td> " , percent_time_ok , percent_time_ok_known ) ;
printf ( " <td CLASS='serviceWARNING'>%2.3f%% (%2.3f%%)</td> " , percent_time_warning , percent_time_warning_known ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%2.3f%% (%2.3f%%)</td> " , percent_time_unknown , percent_time_unknown_known ) ;
printf ( " <td class='serviceCRITICAL'>%2.3f%% (%2.3f%%)</td> " , percent_time_critical , percent_time_critical_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , percent_time_indeterminate ) ;
/* we only print the averages for html output */
get_running_average ( & average_percent_time_ok , percent_time_ok , current_subject ) ;
get_running_average ( & average_percent_time_ok_known , percent_time_ok_known , current_subject ) ;
get_running_average ( & average_percent_time_unknown , percent_time_unknown , current_subject ) ;
get_running_average ( & average_percent_time_unknown_known , percent_time_unknown_known , current_subject ) ;
get_running_average ( & average_percent_time_warning , percent_time_warning , current_subject ) ;
get_running_average ( & average_percent_time_warning_known , percent_time_warning_known , current_subject ) ;
get_running_average ( & average_percent_time_critical , percent_time_critical , current_subject ) ;
get_running_average ( & average_percent_time_critical_known , percent_time_critical_known , current_subject ) ;
get_running_average ( & average_percent_time_indeterminate , percent_time_indeterminate , current_subject ) ;
strncpy ( last_host , temp_subject - > host_name , sizeof ( last_host ) - 1 ) ;
last_host [ sizeof ( last_host ) - 1 ] = ' \x0 ' ;
}
else if ( output_format = = CSV_OUTPUT ) {
2017-05-19 22:22:40 +02:00
/* host name and service description */
2019-04-18 17:09:18 +02:00
printf ( " \" %s \" , \" %s \" , " , temp_subject - > host_name , temp_subject - > service_description ) ;
2017-05-19 22:22:40 +02:00
/* ok times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_ok , percent_time_ok_scheduled , percent_time_ok_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_ok - temp_subject - > scheduled_time_ok , percent_time_ok_unscheduled , percent_time_ok_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_ok , percent_time_ok , percent_time_ok_known ) ;
2017-05-19 22:22:40 +02:00
/* warning times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_warning , percent_time_warning_scheduled , percent_time_warning_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_warning - temp_subject - > scheduled_time_warning , percent_time_warning_unscheduled , percent_time_warning_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_warning , percent_time_warning , percent_time_warning_known ) ;
2017-05-19 22:22:40 +02:00
/* unknown times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_unknown , percent_time_unknown_scheduled , percent_time_unknown_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_unknown - temp_subject - > scheduled_time_unknown , percent_time_unknown_unscheduled , percent_time_unknown_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_unknown , percent_time_unknown , percent_time_unknown_known ) ;
2017-05-19 22:22:40 +02:00
/* critical times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > scheduled_time_critical , percent_time_critical_scheduled , percent_time_critical_scheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_critical - temp_subject - > scheduled_time_critical , percent_time_critical_unscheduled , percent_time_critical_unscheduled_known ) ;
printf ( " %lu, %2.3f%%, %2.3f%%, " , temp_subject - > time_critical , percent_time_critical , percent_time_critical_known ) ;
2017-05-19 22:22:40 +02:00
/* indeterminate times */
2019-04-18 17:09:18 +02:00
printf ( " %lu, %2.3f%%, " , temp_subject - > time_indeterminate_notrunning , percent_time_indeterminate_notrunning ) ;
printf ( " %lu, %2.3f%%, " , temp_subject - > time_indeterminate_nodata , percent_time_indeterminate_nodata ) ;
printf ( " %lu, %2.3f%% \n " , time_indeterminate , percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2019-04-18 17:09:18 +02:00
if ( output_format = = HTML_OUTPUT ) {
2017-05-19 22:22:40 +02:00
/* average statistics */
2019-04-18 17:09:18 +02:00
if ( odd ) {
2017-05-19 22:22:40 +02:00
odd = 0 ;
bgclass = " Odd " ;
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
else {
odd = 1 ;
bgclass = " Even " ;
2019-04-18 17:09:18 +02:00
}
printf ( " <tr CLASS='data%s'><td CLASS='data%s' colspan='2'>Average</td> " , bgclass , bgclass ) ;
printf ( " <td CLASS='serviceOK'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_ok , average_percent_time_ok_known ) ;
printf ( " <td CLASS='serviceWARNING'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_warning , average_percent_time_warning_known ) ;
printf ( " <td CLASS='serviceUNKNOWN'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_unknown , average_percent_time_unknown_known ) ;
printf ( " <td class='serviceCRITICAL'>%2.3f%% (%2.3f%%)</td> " , average_percent_time_critical , average_percent_time_critical_known ) ;
printf ( " <td class='data%s'>%2.3f%%</td></tr> \n " , bgclass , average_percent_time_indeterminate ) ;
2017-05-19 22:22:40 +02:00
printf ( " </table> \n " ) ;
printf ( " </DIV> \n " ) ;
}
}
2019-04-18 17:09:18 +02:00
}
2017-05-19 22:22:40 +02:00
2017-05-19 23:37:19 +02:00
void host_report_url ( const char * hn , const char * label ) {
2017-05-19 22:22:40 +02:00
printf ( " <a href='%s?host=%s " , AVAIL_CGI , url_encode ( hn ) ) ;
printf ( " &show_log_entries " ) ;
printf ( " &t1=%lu&t2=%lu " , t1 , t2 ) ;
printf ( " &backtrack=%d " , backtrack_archives ) ;
printf ( " &assumestateretention=%s " , ( assume_state_retention = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumeinitialstates=%s " , ( assume_initial_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumestatesduringnotrunning=%s " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " ) ;
printf ( " &initialassumedhoststate=%d " , initial_assumed_host_state ) ;
printf ( " &initialassumedservicestate=%d " , initial_assumed_service_state ) ;
2019-04-18 17:09:18 +02:00
if ( show_log_entries = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " &show_log_entries " ) ;
2019-04-18 17:09:18 +02:00
if ( full_log_entries = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " &full_log_entries " ) ;
printf ( " &showscheduleddowntime=%s " , ( show_scheduled_downtime = = TRUE ) ? " yes " : " no " ) ;
2019-04-18 17:09:18 +02:00
if ( current_timeperiod ! = NULL )
2017-05-19 22:22:40 +02:00
printf ( " &rpttimeperiod=%s " , url_encode ( current_timeperiod - > name ) ) ;
printf ( " '>%s</a> " , label ) ;
return ;
}
2017-05-19 23:37:19 +02:00
void service_report_url ( const char * hn , const char * sd , const char * label ) {
2017-05-19 22:22:40 +02:00
printf ( " <a href='%s?host=%s " , AVAIL_CGI , url_encode ( hn ) ) ;
printf ( " &service=%s " , url_encode ( sd ) ) ;
printf ( " &t1=%lu&t2=%lu " , t1 , t2 ) ;
printf ( " &backtrack=%d " , backtrack_archives ) ;
printf ( " &assumestateretention=%s " , ( assume_state_retention = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumeinitialstates=%s " , ( assume_initial_states = = TRUE ) ? " yes " : " no " ) ;
printf ( " &assumestatesduringnotrunning=%s " , ( assume_states_during_notrunning = = TRUE ) ? " yes " : " no " ) ;
printf ( " &initialassumedhoststate=%d " , initial_assumed_host_state ) ;
printf ( " &initialassumedservicestate=%d " , initial_assumed_service_state ) ;
2019-04-18 17:09:18 +02:00
if ( show_log_entries = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " &show_log_entries " ) ;
2019-04-18 17:09:18 +02:00
if ( full_log_entries = = TRUE )
2017-05-19 22:22:40 +02:00
printf ( " &full_log_entries " ) ;
printf ( " &showscheduleddowntime=%s " , ( show_scheduled_downtime = = TRUE ) ? " yes " : " no " ) ;
2019-04-18 17:09:18 +02:00
if ( current_timeperiod ! = NULL )
2017-05-19 22:22:40 +02:00
printf ( " &rpttimeperiod=%s " , url_encode ( current_timeperiod - > name ) ) ;
2019-04-18 17:09:18 +02:00
if ( include_soft_states = = TRUE )
2017-05-19 23:37:19 +02:00
printf ( " &includesoftstates=%s " , ( include_soft_states = = TRUE ) ? " yes " : " no " ) ;
2017-05-19 22:22:40 +02:00
printf ( " '>%s</a> " , label ) ;
return ;
}
/* calculates running average */
void get_running_average ( double * running_average , double new_value , int current_item ) {
* running_average = ( ( ( * running_average * ( ( double ) current_item - 1.0 ) ) + new_value ) / ( double ) current_item ) ;
return ;
}
/* used in reports where a timeperiod is selected */
unsigned long calculate_total_time ( time_t start_time , time_t end_time ) {
struct tm * t ;
2017-05-19 23:37:19 +02:00
time_t midnight_today ;
2017-05-19 22:22:40 +02:00
int weekday ;
unsigned long total_time ;
timerange * temp_timerange ;
unsigned long temp_duration ;
unsigned long temp_end ;
unsigned long temp_start ;
unsigned long start ;
unsigned long end ;
/* attempt to handle the current time_period */
2019-04-18 17:09:18 +02:00
if ( current_timeperiod ! = NULL ) {
2017-05-19 22:22:40 +02:00
/* "A day" is 86400 seconds */
t = localtime ( & start_time ) ;
/* calculate the start of the day (midnight, 00:00 hours) */
t - > tm_sec = 0 ;
t - > tm_min = 0 ;
t - > tm_hour = 0 ;
t - > tm_isdst = - 1 ;
2017-05-19 23:37:19 +02:00
midnight_today = mktime ( t ) ;
2017-05-19 22:22:40 +02:00
weekday = t - > tm_wday ;
total_time = 0 ;
while ( midnight_today < end_time ) {
temp_duration = 0 ;
temp_end = min ( 86400 , t2 - midnight_today ) ;
temp_start = 0 ;
2019-04-18 17:09:18 +02:00
if ( t1 > midnight_today )
2017-05-19 22:22:40 +02:00
temp_start = t1 - midnight_today ;
/* check all time ranges for this day of the week */
2019-04-18 17:09:18 +02:00
for ( temp_timerange = current_timeperiod - > days [ weekday ] ; temp_timerange ! = NULL ; temp_timerange = temp_timerange - > next ) {
2017-05-19 22:22:40 +02:00
start = max ( temp_timerange - > range_start , temp_start ) ;
end = min ( temp_timerange - > range_end , temp_end ) ;
# ifdef DEBUG
printf ( " <li>Matching in timerange[%d]: %d -> %d (%ld -> %ld) %d -> %d = %ld<br> \n " , weekday , temp_timerange - > range_start , temp_timerange - > range_end , temp_start , temp_end , start , end , end - start ) ;
# endif
2019-04-18 17:09:18 +02:00
if ( end > start )
2017-05-19 22:22:40 +02:00
temp_duration + = end - start ;
}
total_time + = temp_duration ;
temp_start = 0 ;
midnight_today + = 86400 ;
2019-04-18 17:09:18 +02:00
if ( + + weekday > 6 )
2017-05-19 22:22:40 +02:00
weekday = 0 ;
}
return total_time ;
}
/* no timeperiod was selected */
return end_time - start_time ;
}