Date format in Cacti log

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

Post Reply
phoenix
Posts: 27
Joined: Thu Aug 19, 2004 3:18 pm

Date format in Cacti log

Post by phoenix »

Hi

Is there any chance we could have an option to change the date format in the cacti logfile? Not a major priority but it would be nice for us Europeans. :D
Regards


Bill
Lux
Cacti User
Posts: 195
Joined: Tue Nov 11, 2003 10:57 am
Location: Luxembourg

Post by Lux »

I second that. As far as I know the U.S. is the only country to use that particular format. Every other country that I've been to uses day month year. Actually, even the U.S. Military uses the day month year format, though they like to string it all together into one big number.


Mike
Hiney
Cacti User
Posts: 56
Joined: Mon Oct 16, 2006 11:50 pm

here here

Post by Hiney »

I'll third this request. I was actually looking to see if someone had requested it already, and they had !!!

this is not a great fix, but it will do until i can find out the command to get the date environment from the o/s, or setup a proper config entry in the database where you can specify you own format.

functions.php

Code: Select all

	/* fill in the current date for printing in the log */
	$date = date("m/d/Y h:i:s A");
becomes

Code: Select all

$date = date("d/m/Y h:i:s A");
H
Hiney
Cacti User
Posts: 56
Joined: Mon Oct 16, 2006 11:50 pm

OK, this is a start ...

Post by Hiney »

http://au2.php.net/date for date format options

in functions.php change

Code: Select all

$date = date("m/d/Y h:i:s A");
to

Code: Select all

$date = date(read_config_option("date_format") . " " . read_config_option("time_format"));
in utilites.php change

Code: Select all

$timestamp = date("m/d/Y h:i:s A");
to

Code: Select all

$timestamp = date(read_config_option("date_format") . " " . read_config_option("time_format"));
in config_settings.php change

Code: Select all

		"remove_verification" => array(
			"friendly_name" => "Remove Verification",
			"description" => "Prompt user before item deletion.",
			"default" => "on",
			"method" => "checkbox"
			)
to (watch the comma at the end of the remove_verification section)

Code: Select all

		"remove_verification" => array(
			"friendly_name" => "Remove Verification",
			"description" => "Prompt user before item deletion.",
			"default" => "on",
			"method" => "checkbox"
			),
		"date_format" => array(
			"friendly_name" => "Date Format",
			"description" => "Default format for some things, like the log.",
			"method" => "textbox",
			"default" => "m/d/Y",
			"max_length" => "100",
			),
		"time_format" => array(
			"friendly_name" => "Time Format",
			"description" => "Default format for some things, like the log.",
			"method" => "textbox",
			"default" => "h:i:s A",
			"max_length" => "100",
			)

this is not all of them, but it is a start.

I set my date to `Ymd` (international format) and time to `H:i:s` (24 hour time)

H
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

We are moving logging to the database and syslog in 0.9.0. So this issue is going away.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
Hiney
Cacti User
Posts: 56
Joined: Mon Oct 16, 2006 11:50 pm

cactid

Post by Hiney »

Tony, thanks. I've spent the last few hours learning C, so i'll post what i've done anyway.

Cactid use's a different date and time format string (to php's) so putting it in the .conf file is more logical than putting another entry in the main system. I didn't twig to this obvious bit of info at first, so i wrote it to use the DB's format entries first. surprising it didn't work.

anyway here it is. this was done on cactid 0.8.6, put it should work on most of the other versions (it's why i didn't supply a diff/patch file).


cactid.h. Add formats to configure structure.
change

Code: Select all

	int php_current_server;
} config_t;
to

Code: Select all

	int php_current_server;
	char date_format[100]; //matches the definition in config_settings.php
	char time_format[100]; //matches the definition in config_settings.php
} config_t;
util.c. Set the default format in case there are no entries in the .conf file.
change

Code: Select all

if ((fp = fopen(file, "rb")) == NULL) {
to

Code: Select all

  //set time defaults. Can't use any printf function here as it contains at least one '%'
	strncpy(set.date_format, "%m/%d/%Y", sizeof(set.date_format)-1);
	strncpy(set.time_format, "%I:%M:%S %p", sizeof(set.time_format)-1);

	if ((fp = fopen(file, "rb")) == NULL) {
util.c. Read the variables from the config file.
change

Code: Select all

				else if (STRIMATCH(p1, "DB_Port")) set.dbport = atoi(p2);
				else {
					printf("WARNING: Unrecongized directive: %s=%s in %s\n", p1, p2, file);
to

Code: Select all

				else if (STRIMATCH(p1, "DB_Port")) set.dbport = atoi(p2);
				  //can't use any printf function here as it contains at least one '%'
				else if (STRIMATCH(p1, "date_format")) strncpy(set.date_format, p2, sizeof(set.date_format)-1);
				  //can't use any printf function here as it contains at least one '%'
				else if (STRIMATCH(p1, "time_format")) strncpy(set.time_format, p2, sizeof(set.time_format)-1);
				else {
					printf("WARNING: Unrecognized directive: %s=%s in %s\n", p1, p2, file);
util.c. Change hard coded entry to use the new format variables.
change

Code: Select all

	if (strftime(flogmessage, 50, "%m/%d/%Y %I:%M:%S %p - ", now_ptr) == (size_t) 0) { */
		fprintf(stderr, "ERROR: Could not get string from strftime()\n");
	}
to

Code: Select all

	  //can't use any printf function here as it contains at least one '%'
	strncpy(datetime_format, set.date_format, sizeof(datetime_format)-1);
	strncat(datetime_format, " ", 1);
	strncat(datetime_format, set.time_format, strlen(set.time_format));
	strncat(datetime_format, " - ", 3);

	CACTID_LOG_DEBUG(("DEBUG: The datetime_format is %s\n", datetime_format));

	if (strftime(flogmessage, 50, datetime_format, now_ptr) == (size_t) 0) {
		fprintf(stderr, "ERROR: Could not get string from strftime()\n");
	}
cactid.conf
add your format to the file
date_format %Y%m%d
time_format %H:%M:%S
Last edited by Hiney on Thu Oct 19, 2006 11:53 pm, edited 2 times in total.
Hiney
Cacti User
Posts: 56
Joined: Mon Oct 16, 2006 11:50 pm

monitor.php

Post by Hiney »

change

Code: Select all

print "<center>Last Refresh : " . date("g:i:s a", time()) . '</center><br>';
to

Code: Select all

print "<center>Last Refresh : " . date(read_config_option("time_format"), time()) . '</center><br>';
User avatar
TheWitness
Developer
Posts: 17004
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

looks good enough.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
lbm
Posts: 29
Joined: Tue Nov 22, 2011 11:04 am

Re: Date format in Cacti log

Post by lbm »

Is this still the way to do it, or is there a better way ?
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Date format in Cacti log

Post by gandalf »

You've hit a quite old thread. To be honest, I don't know the current status. To get things moving, please (again) phrase what you really need and what stilll is missing
R.
saik0
Posts: 9
Joined: Fri Aug 31, 2012 5:36 pm

Re: Date format in Cacti log

Post by saik0 »

And still no movement...
So currently it's impossible to configure the date format and on top of that it's US style.
Option for date format in the console setting would be much appreciated...
Eol
Posts: 44
Joined: Mon Apr 13, 2015 5:53 pm

Re: Date format in Cacti log

Post by Eol »

Really old post as 0.9 was talked about in 2006 and while we did move to a database, syslog never happened (yet). Anyways since a couple other folk have commented over the years looking for a solution and I just stumbled across this myself wondering the same thing (as I wanted 24 hour clock) the answer is:

1: Open lib/functions.php
2: Find the $date line, copy it, and comment out the old one.
3: Modify the new uncommented $date line to suit your taste using appropriate PHP date() parameters (https://php.net/manual/en/function.date.php)
4: Win?

Example:

me@a.b.c.d:/usr/local/share/cacti/lib # diff -ruN functions.php.orig functions.php
--- functions.php.orig 2015-05-20 18:55:42.126062957 -1000
+++ functions.php 2015-05-20 18:49:13.880731397 -1000
@@ -479,7 +479,8 @@
global $config;

/* fill in the current date for printing in the log */
- $date = date("m/d/Y h:i:s A");
+/* $date = date("m/d/Y h:i:s A"); */
+ $date = date("dMy H:i:s");


Yes that is the exact same thing Hiney said but follow up commentors seemed to have missed it; it's a one line three second fix once you know where to look.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest