Change TimeZone for a specific suer

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
alexmartin
Posts: 1
Joined: Mon Sep 12, 2011 9:05 am

Change TimeZone for a specific suer

Post by alexmartin »

Hi,

I have a central cacti server and have configured 20servers to monitor for my customers. But the customers are live in different locations and they need to change the timezone to view graph in their timezone. So I am not sure how to change the timezone for a particular user cacti account.

Can anyone let me know how to change this?

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

Re: Change TimeZone for a specific suer

Post by rony »

Not currently supported... :(
[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]
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Change TimeZone for a specific suer

Post by gandalf »

But will be supported starting with 1.0.0
R.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Change TimeZone for a specific suer

Post by noname »

From interests, I've tried implementing user specific timezone when viewing graphs.

Graph settings (per user)
Image

Image


When selected another timezone
Image

Image


Patch file for Cacti 0.8.7g +official patch +PIA2.9
user_timezone.patch.zip
(5.36 KiB) Downloaded 119 times
- To apply:
% patch -p1 -N < /tmp/user_timezone.patch
patching file include/global_settings.php
patching file include/global_arrays.php
patching file lib/time.php
patching file lib/rrd.php

- To revert:
% patch -p1 -N --reverse < /tmp/user_timezone.patch


Modification summary
- Borrowed basic idea from here: http://www.vandenbogaerdt.nl/rrdtool/timezone.php

- Timezone lists are created from PECL's timezonedb.h

- Define new function to change TZ environment in lib/time.php

Code: Select all

/* set_user_timezone    - set user specific timezone for displaying graphs
 * @arg $timezone       - timezone string
 */
function set_user_timezone($timezone = '') {
        global $config;
        include($config["include_path"] . "/global_arrays.php");

        if (empty($timezone)) {
                $tz_id = read_graph_config_option("default_user_timezone");
                if (!isset($tz_id) || $tz_id == '0') {
                        return '';
                }
                $timezone = $graph_usertimezones[$tz_id];
        }
        putenv("TZ=" . $timezone);

        return $timezone;
}
NOTE: date_default_timezone_set() doesn't take effect because (maybe) that is only available in PHP session (not in HTML part)..

- Change timezone in functions referring to date/time in lib/time.php

Code: Select all

function get_timespan(&$span, $curr_time, $timespan_given, $first_weekdayid) {
        set_user_timezone();
        ...
}
function check_month_boundaries(&$span) {
        set_user_timezone();
        ...
}
function shift_right_boundary(&$span, $direction, $shift_size) {
        set_user_timezone();
        ...
}
function shift_time(&$span, $direction, $shift_size) {
        set_user_timezone();
        ...
}
- Also in lib/rrd.php

Code: Select all

function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array, &$rrdtool_pipe) {
        ...
        /* set timezone */
        include_once($config["library_path"] . "/time.php");
        $tz_serv = getenv("TZ");
        $tz_user = set_user_timezone();

        /* setup date format */
        ...
        ...
        /* show timezone if needed */
        if (read_graph_config_option("display_timezone_in_graph") == "on") {
                $txt_graph_items .= RRD_NL . "COMMENT:\" \\n\"";
                $txt_graph_items .= RRD_NL . "COMMENT:\"Timezone for displaying = " . ($tz_user == '' ? "default(" . $tz_serv . ")" : $tz_user) . "\"";
        }

        $graph_array = api_plugin_hook_function('rrd_graph_graph_options', ...
Known issue
Server's timezone is changed temporarily only when displaying graphs, so any logs (PHP error log, Cacti's web events, etc.) are recorded with timestamps of selected timezone at that moment.

// Sorry my English
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests