"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/availability.c" between
xymon-4.3.28.tar.gz and xymon-4.3.29.tar.gz

About: Xymon is a system for monitoring servers, applications and networks (like Big Brother; former name "hobbit").

availability.c  (xymon-4.3.28):availability.c  (xymon-4.3.29)
skipping to change at line 14 skipping to change at line 14
/* This file contains code to calculate availability percentages and do */ /* This file contains code to calculate availability percentages and do */
/* SLA calculations. */ /* SLA calculations. */
/* */ /* */
/* Copyright (C) 2002-2011 Henrik Storner <henrik@storner.dk> */ /* Copyright (C) 2002-2011 Henrik Storner <henrik@storner.dk> */
/* */ /* */
/* This program is released under the GNU General Public License (GPL), */ /* This program is released under the GNU General Public License (GPL), */
/* version 2. See the file "COPYING" for details. */ /* version 2. See the file "COPYING" for details. */
/* */ /* */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
static char rcsid[] = "$Id: availability.c 7678 2015-10-01 14:42:42Z jccleaver $ "; static char rcsid[] = "$Id: availability.c 7678M 2019-07-23 14:46:51Z (local) $" ;
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include "libxymon.h" #include "libxymon.h"
skipping to change at line 40 skipping to change at line 40
static int reptimecnt = 0; static int reptimecnt = 0;
replog_t *reploghead = NULL; replog_t *reploghead = NULL;
char *durationstr(time_t duration) char *durationstr(time_t duration)
{ {
static char dur[100]; static char dur[100];
char dhelp[100]; char dhelp[100];
if (duration <= 0) { if (duration <= 0) {
strcpy(dur, "none"); strncpy(dur, "none", sizeof(dur));
} }
else { else {
dur[0] = '\0'; dur[0] = '\0';
if (duration > 86400) { if (duration > 86400) {
sprintf(dhelp, "%u days ", (unsigned int)(duration / 8640 0)); snprintf(dhelp, sizeof(dhelp), "%u days ", (unsigned int) (duration / 86400));
duration %= 86400; duration %= 86400;
strcpy(dur, dhelp); strncpy(dur, dhelp, sizeof(dur));
} }
sprintf(dhelp, "%u:%02u:%02u", (unsigned int)(duration / 3600), snprintf(dhelp, sizeof(dhelp), "%u:%02u:%02u", (unsigned int)(dur ation / 3600),
(unsigned int)((duration % 3600) / 60), (unsigned int)(du ration % 60)); (unsigned int)((duration % 3600) / 60), (unsigned int)(du ration % 60));
strcat(dur, dhelp); strncat(dur, dhelp, (sizeof(dur) - strlen(dur)));
} }
return dur; return dur;
} }
static time_t secs(int hour, int minute, int sec) static time_t secs(int hour, int minute, int sec)
{ {
return (hour*3600 + minute*60 + sec); return (hour*3600 + minute*60 + sec);
} }
skipping to change at line 164 skipping to change at line 164
{ {
char cause[MAX_LINE_LEN]; char cause[MAX_LINE_LEN];
char fn[PATH_MAX]; char fn[PATH_MAX];
char *p; char *p;
FILE *fd; FILE *fd;
char l[MAX_LINE_LEN]; char l[MAX_LINE_LEN];
int causefull = 0; int causefull = 0;
cause[0] = '\0'; cause[0] = '\0';
sprintf(fn, "%s/%s", xgetenv("XYMONHISTLOGS"), commafy(hostname)); snprintf(fn, sizeof(fn), "%s/%s", xgetenv("XYMONHISTLOGS"), commafy(hostn ame));
for (p = strrchr(fn, '/'); (*p); p++) if (*p == ',') *p = '_'; for (p = strrchr(fn, '/'); (*p); p++) if (*p == ',') *p = '_';
sprintf(p, "/%s/%s", servicename, timespec); snprintf(p, (sizeof(fn) - (p - fn)), "/%s/%s", servicename, timespec);
dbgprintf("Looking at history logfile %s\n", fn); dbgprintf("Looking at history logfile %s\n", fn);
fd = fopen(fn, "r"); fd = fopen(fn, "r");
if (fd != NULL) { if (fd != NULL) {
while (!causefull && fgets(l, sizeof(l), fd)) { while (!causefull && fgets(l, sizeof(l), fd)) {
p = strchr(l, '\n'); if (p) *p = '\0'; p = strchr(l, '\n'); if (p) *p = '\0';
if ((l[0] == '&') && (strncmp(l, "&green", 6) != 0)) { if ((l[0] == '&') && (strncmp(l, "&green", 6) != 0)) {
p = skipwhitespace(skipword(l)); p = skipwhitespace(skipword(l));
if ((strlen(cause) + strlen(p) + strlen("<BR>\n") + 1) < sizeof(cause)) { if ((strlen(cause) + strlen(p) + strlen("<BR>\n") + 1) < sizeof(cause)) {
strcat(cause, p); strncat(cause, p, (sizeof(cause) - strlen
strcat(cause, "<BR>\n"); (cause)));
strncat(cause, "<BR>\n", (sizeof(cause) -
strlen(cause)));
} }
else causefull = 1; else causefull = 1;
} }
} }
#if 1 #if 1
if (strlen(cause) == 0) { if (strlen(cause) == 0) {
strcpy(cause, "See detailed log"); strncpy(cause, "See detailed log", sizeof(cause));
} }
#else #else
/* What is this code supposed to do ? The sscanf seemingly never succeeds */ /* What is this code supposed to do ? The sscanf seemingly never succeeds */
/* storner, 2006-06-02 */ /* storner, 2006-06-02 */
if (strlen(cause) == 0) { if (strlen(cause) == 0) {
int offset; int offset;
rewind(fd); rewind(fd);
if (fgets(l, sizeof(l), fd)) { if (fgets(l, sizeof(l), fd)) {
p = strchr(l, '\n'); if (p) *p = '\0'; p = strchr(l, '\n'); if (p) *p = '\0';
if (sscanf(l, "%*s %*s %*s %*s %*s %*s %*s %n", & offset) == 1) { if (sscanf(l, "%*s %*s %*s %*s %*s %*s %*s %n", & offset) == 1) {
skipping to change at line 209 skipping to change at line 209
else { else {
errprintf("Scan of file %s failed, l='%s' \n", fn, l); errprintf("Scan of file %s failed, l='%s' \n", fn, l);
} }
cause[sizeof(cause)-1] = '\0'; cause[sizeof(cause)-1] = '\0';
} }
} }
#endif #endif
if (causefull) { if (causefull) {
cause[sizeof(cause) - strlen(" [Truncated]") - 1] = '\0'; cause[sizeof(cause) - strlen(" [Truncated]") - 1] = '\0';
strcat(cause, " [Truncated]"); strncat(cause, " [Truncated]", (sizeof(cause) - strlen(ca use)));
} }
fclose(fd); fclose(fd);
} }
else { else {
strcpy(cause, "No historical status available"); strncpy(cause, "No historical status available", sizeof(cause));
} }
return strdup(cause); return strdup(cause);
} }
static char *get_historyline(char *buf, int bufsize, FILE *fd, int *err, static char *get_historyline(char *buf, int bufsize, FILE *fd, int *err,
char *colstr, unsigned int *start, unsigned int *dur ation, int *scanres) char *colstr, unsigned int *start, unsigned int *dur ation, int *scanres)
{ {
int ok; int ok;
skipping to change at line 261 skipping to change at line 261
dbgprintf("Bad history line (bad color string): %s\n", bu f); dbgprintf("Bad history line (bad color string): %s\n", bu f);
continue; continue;
} }
} while (!ok); } while (!ok);
return buf; return buf;
} }
static int scan_historyfile(FILE *fd, time_t fromtime, time_t totime, static int scan_historyfile(FILE *fd, time_t fromtime, time_t totime,
char *buf, size_t bufsize, char *buf, size_t bufsize,
time_t *starttime, time_t *duration, char *colstr) time_t *starttime, time_t *duration, char *colstr, unsigned int c olstr_buflen)
{ {
time_t start, dur; time_t start, dur;
unsigned int uistart, uidur; unsigned int uistart, uidur;
int scanres; int scanres;
int err = 0; int err = 0;
/* /*
* Format of history entries: * Format of history entries:
* asctime-stamp newcolor starttime [duration] * asctime-stamp newcolor starttime [duration]
*/ */
/* Is start of history after our report-end time ? */ /* Is start of history after our report-end time ? */
rewind(fd); rewind(fd);
if (!get_historyline(buf, bufsize, fd, &err, colstr, &uistart, &uidur, &s canres)) { if (!get_historyline(buf, bufsize, fd, &err, colstr, &uistart, &uidur, &s canres)) {
*starttime = getcurrenttime(NULL); *starttime = getcurrenttime(NULL);
*duration = 0; *duration = 0;
strcpy(colstr, "clear"); strncpy(colstr, "clear", colstr_buflen);
return err; return err;
} }
if (scanres == 2) uidur = getcurrenttime(NULL)-uistart; if (scanres == 2) uidur = getcurrenttime(NULL)-uistart;
start = uistart; dur = uidur; start = uistart; dur = uidur;
if (start > totime) { if (start > totime) {
*starttime = start; *starttime = start;
*duration = dur; *duration = dur;
strcpy(colstr, "clear"); strncpy(colstr, "clear", colstr_buflen);
return 0; return 0;
} }
/* First, do a quick scan through the file to find the approximate positi on where we should start */ /* First, do a quick scan through the file to find the approximate positi on where we should start */
while ((start+dur) < fromtime) { while ((start+dur) < fromtime) {
if (get_historyline(buf, bufsize, fd, &err, colstr, &uistart, &ui dur, &scanres)) { if (get_historyline(buf, bufsize, fd, &err, colstr, &uistart, &ui dur, &scanres)) {
start = uistart; dur = uidur; start = uistart; dur = uidur;
if (scanres == 2) dur = getcurrenttime(NULL) - start; if (scanres == 2) dur = getcurrenttime(NULL) - start;
if (scanres >= 2) { if (scanres >= 2) {
skipping to change at line 404 skipping to change at line 404
repinfo->reportstops = 0; repinfo->reportstops = 0;
if (reporttime) build_reportspecs(reporttime); if (reporttime) build_reportspecs(reporttime);
/* Sanity check */ /* Sanity check */
if (totime > getcurrenttime(NULL)) totime = getcurrenttime(NULL); if (totime > getcurrenttime(NULL)) totime = getcurrenttime(NULL);
/* If for_history and fromtime is 0, don't do any seeking */ /* If for_history and fromtime is 0, don't do any seeking */
if (!for_history || (fromtime > 0)) { if (!for_history || (fromtime > 0)) {
fileerrors = scan_historyfile(fd, fromtime, totime, fileerrors = scan_historyfile(fd, fromtime, totime,
l, sizeof(l), &starttime, &duration, colstr ); l, sizeof(l), &starttime, &duration, colstr , sizeof(colstr));
} }
else { else {
/* Already positioned (probably in a pipe) */ /* Already positioned (probably in a pipe) */
if (get_historyline(l, sizeof(l), fd, &fileerrors, colstr, &uista rt, &uidur, &scanres)) { if (get_historyline(l, sizeof(l), fd, &fileerrors, colstr, &uista rt, &uidur, &scanres)) {
starttime = uistart; duration = uidur; starttime = uistart; duration = uidur;
if (scanres == 2) duration = getcurrenttime(NULL) - start time; if (scanres == 2) duration = getcurrenttime(NULL) - start time;
} }
else { else {
starttime = getcurrenttime(NULL); duration = 0; starttime = getcurrenttime(NULL); duration = 0;
strcpy(colstr, "clear"); strncpy(colstr, "clear", sizeof(colstr));
fileerrors = 1; fileerrors = 1;
} }
} }
if (starttime > totime) { if (starttime > totime) {
repinfo->fullavailability = repinfo->reportavailability = 100.0; repinfo->fullavailability = repinfo->reportavailability = 100.0;
repinfo->fullpct[COL_CLEAR] = repinfo->reportpct[COL_CLEAR] = 100 .0; repinfo->fullpct[COL_CLEAR] = repinfo->reportpct[COL_CLEAR] = 100 .0;
repinfo->count[COL_CLEAR] = 1; repinfo->count[COL_CLEAR] = 1;
return COL_CLEAR; return COL_CLEAR;
} }
skipping to change at line 437 skipping to change at line 437
if (starttime < fromtime) { if (starttime < fromtime) {
duration -= (fromtime - starttime); duration -= (fromtime - starttime);
starttime = fromtime; starttime = fromtime;
} }
repinfo->reportstart = starttime; repinfo->reportstart = starttime;
done = 0; done = 0;
do { do {
/* If event ends after our reportend, adjust duration */ /* If event ends after our reportend, adjust duration */
if ((starttime + duration) > totime) duration = (totime - startti me); if ((starttime + duration) > totime) duration = (totime - startti me);
strcat(colstr, " "); color = parse_color(colstr); strncat(colstr, " ", (sizeof(colstr) - strlen(colstr))); color = parse_color(colstr);
if (color != -1) { if (color != -1) {
unsigned long sladuration = 0; unsigned long sladuration = 0;
dbgprintf("In-range entry starting %lu lasting %lu color %d: %s", starttime, duration, color, l); dbgprintf("In-range entry starting %lu lasting %lu color %d: %s", starttime, duration, color, l);
repinfo->count[color]++; repinfo->count[color]++;
repinfo->fullduration[color] += duration; repinfo->fullduration[color] += duration;
if (color > COL_YELLOW) repinfo->fullstops++; if (color > COL_YELLOW) repinfo->fullstops++;
if (reporttime) { if (reporttime) {
sladuration = reportingduration(starttime, durati on); sladuration = reportingduration(starttime, durati on);
skipping to change at line 558 skipping to change at line 558
int history_color(FILE *fd, time_t snapshot, time_t *starttime, char **histlogna me) int history_color(FILE *fd, time_t snapshot, time_t *starttime, char **histlogna me)
{ {
char l[MAX_LINE_LEN]; char l[MAX_LINE_LEN];
time_t duration; time_t duration;
char colstr[MAX_LINE_LEN]; char colstr[MAX_LINE_LEN];
int color; int color;
char *p; char *p;
*histlogname = NULL; *histlogname = NULL;
scan_historyfile(fd, snapshot, snapshot, l, sizeof(l), starttime, &durati on, colstr); scan_historyfile(fd, snapshot, snapshot, l, sizeof(l), starttime, &durati on, colstr, sizeof(colstr));
strcat(colstr, " "); strncat(colstr, " ", (sizeof(colstr) - strlen(colstr)));
color = parse_color(colstr); color = parse_color(colstr);
if ((color == COL_PURPLE) || (color == -1)) { if ((color == COL_PURPLE) || (color == -1)) {
color = -2; color = -2;
} }
p = timename(l); p = timename(l);
if (p) *histlogname = strdup(p); if (p) *histlogname = strdup(p);
return color; return color;
} }
skipping to change at line 631 skipping to change at line 631
time_t endtime; time_t endtime;
time_t duration; time_t duration;
strftime(start, sizeof(start), "%a %b %d %H:%M:%S %Y", localtime( &rwalk->starttime)); strftime(start, sizeof(start), "%a %b %d %H:%M:%S %Y", localtime( &rwalk->starttime));
endtime = rwalk->starttime + rwalk->duration; endtime = rwalk->starttime + rwalk->duration;
strftime(end, sizeof(end), "%a %b %d %H:%M:%S %Y", localtime(&end time)); strftime(end, sizeof(end), "%a %b %d %H:%M:%S %Y", localtime(&end time));
duration = rwalk->duration; duration = rwalk->duration;
dur[0] = '\0'; dur[0] = '\0';
if (duration > 86400) { if (duration > 86400) {
sprintf(dhelp, "%lu days ", (duration / 86400)); snprintf(dhelp, sizeof(dhelp), "%lu days ", (duration / 8 6400));
duration %= 86400; duration %= 86400;
strcpy(dur, dhelp); strncpy(dur, dhelp, sizeof(dur));
} }
sprintf(dhelp, "%lu:%02lu:%02lu", duration / 3600, ((duration % 3 snprintf(dhelp, sizeof(dhelp), "%lu:%02lu:%02lu", duration / 3600
600) / 60), (duration % 60)); , ((duration % 3600) / 60), (duration % 60));
strcat(dur, dhelp); strncat(dur, dhelp, (sizeof(dur) - strlen(dur)));
dbgprintf("Start: %s, End: %s, Color: %s, Duration: %s, Cause: %s \n", dbgprintf("Start: %s, End: %s, Color: %s, Duration: %s, Cause: %s \n",
start, end, colorname(rwalk->color), dur, rwalk->cause); start, end, colorname(rwalk->color), dur, rwalk->cause);
} }
return 0; return 0;
} }
#endif #endif
 End of changes. 23 change blocks. 
26 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)