Re: [Nagios-devel] Date in Log File

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

Re: [Nagios-devel] Date in Log File

Post by Guest »

This is a multi-part message in MIME format.
--------------010701000504060608010700
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Steve Pribyl wrote:
>> Epoch time is 500000 times easier to parse from programs.
>>
> I am not going to disagree with you there. Is there a way to get both in
> there. I will happily write the patch it there is some agreement.
>

There is no agreement, since you'd have to support the current format and
whatever new format you concoct, and you need to support them by trial and
error. Since there are (for large installs), several million lines of logdata
to parse when creating fe an availability-report, slowing down logparsing
while at the same time making it more complicated is a bad idea.

> Epoch is hard to read by people.
>

People can use perl, or naglog.c (attached) to get the date in a sort-of
human-readable format. As soon as you start fiddling with such things
though, you'll find that "human-readable" means different things in
different parts of the world.

--
Andreas Ericsson [email protected]
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231

--------------010701000504060608010700
Content-Type: text/x-csrc;
name="naglog.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="naglog.c"

/*
* naglog.c
*
* This program was written to display Nagios logs with the timestamp
* translated to human-readable (European, Americans are only barely human)
* format. Don't whine if it doesn't work for you, and don't ask me to add
* support for other date-formats.
*
* Author: Andreas Ericsson
*
* Copyright: None. This program is in the public domain.
*
* Compile as such:
* gcc -O2 -pipe -Wall naglog.c -o naglog
*
*/

#define _XOPEN_SOURCE

#include
#include
#include

int main(int argc, char **argv)
{
struct tm tm;
FILE *fp;
char buf[8192], *str, date[20];
int i = 1;

if(argc < 2) fp = stdin;
else {
parse_next:
printf("opening %s\n", argv);
fp = fopen(argv[i++], "r");
}

if(!fp) {
perror("fopen():");
return -1;
}

while((fgets(buf, sizeof(buf), fp))) {
memset(&tm, 0, sizeof(struct tm));
str = strptime(buf, "[%s] ", &tm);
strftime(date, sizeof(date), "%Y-%m-%d %T", &tm);
printf("%s: %s", date, str);
}

fclose(fp);

if(i < argc)
goto parse_next;

return 0;
}

--------------010701000504060608010700--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked