[SOLVED] System Time in Header

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

noflies
Cacti User
Posts: 83
Joined: Sun Dec 18, 2005 9:30 am

[SOLVED] System Time in Header

Post by noflies »

Not sure my Virtual Machines and non-VM servers were keeping adequate time and whereas most of my users will not have anything but http access to our cacti servers; I added one line to each of:
(in 0-8-6i)

/include/top_graph_header.php (line 149)
/include/top_header.php (line 72)

Code: Select all

System Time: <strong><?php echo date(DATE_RFC822);?></strong>&nbsp;&nbsp;&nbsp;
Attachments
Cacti System Time.png
Cacti System Time.png (9.34 KiB) Viewed 14030 times
noflies
Cacti User
Posts: 83
Joined: Sun Dec 18, 2005 9:30 am

Post by noflies »

UPDATE!! Please note, apparently this is only supported beginning with PHP version 5.1.1
The below should work with just about any version of PHP. (Same results as the image above.)

Code: Select all

System Time: <strong><?php echo date("D, d M Y H:i:s T");?></strong>&nbsp;&nbsp;&nbsp;
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

I've acknowledged this request, but payed respect to user specific time formats.
Reinhard
noflies
Cacti User
Posts: 83
Joined: Sun Dec 18, 2005 9:30 am

Post by noflies »

Doh! Internationalization!!! :)

I tried to circumvent by implementing a (my) variant of the ISO-8601 !!
Seriously, thats great...respecting user formats is always good, after all we're not B. Gates.

I've actually tweaked that header since my original post to include the following:

Code: Select all

<strong><?php print $config["cacti_server_os"];?></strong>&nbsp;
Cacti Version: <strong><?php print $config["cacti_version"];?></strong>&nbsp;
System Time: <strong><?php echo date(DATE_RFC822);?></strong>&nbsp;
That helps me remember which version on what platform.

Thanks Gandalf!!
Attachments
with platform and version too.
with platform and version too.
Updated System Time.png (4.85 KiB) Viewed 13662 times
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

Seconded. I added this mod back in October/November to one of our servers and it's surprisingly useful - I miss it on the other installs.

Mainly it's useful to me to know that the reason why the web interface has just gone completely dead is that the poller is running. I'll add a separate post about that though...
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
User avatar
fmangeant
Cacti Guru User
Posts: 2345
Joined: Fri Sep 19, 2003 8:36 am
Location: Sophia-Antipolis, France
Contact:

Post by fmangeant »

Hi

Reinhard's commit for next major release (0.8.8) is IMO very nice :

Image
[size=84]
[color=green]HOWTOs[/color] :
[list][*][url=http://forums.cacti.net/viewtopic.php?t=15353]Install and configure the Net-SNMP agent for Unix[/url]
[*][url=http://forums.cacti.net/viewtopic.php?t=26151]Install and configure the Net-SNMP agent for Windows[/url]
[*][url=http://forums.cacti.net/viewtopic.php?t=28175]Graph multiple servers using an SNMP proxy[/url][/list]
[color=green]Templates[/color] :
[list][*][url=http://forums.cacti.net/viewtopic.php?t=15412]Multiple CPU usage for Linux[/url]
[*][url=http://forums.cacti.net/viewtopic.php?p=125152]Memory & swap usage for Unix[/url][/list][/size]
dave99
Posts: 26
Joined: Fri Mar 17, 2006 11:12 pm

Post by dave99 »

If someone wanted to take it a step further, and put some poller info in the header like this:
Image
it's pretty easy. I just show the last poller endtime, or if the poller is running at the time. I put it in an external file to keep the cacti pages cleaner, called mystuff.php

Code: Select all

<?
$query="select end_time from poller_time where id=1";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num == 0) {
$pinfo="The poller is running.."; }
else {
$pinfo="Last poller end time: <strong>".mysql_result($result,"end_time")."</strong>"; }
?>
just add an include statement in the top php statement in top_header.php and top_graph_header.php

Code: Select all

include('mystuff.php');
and then print the variable right next to the time:

Code: Select all

<? echo $pinfo."&nbsp;&nbsp;&nbsp;"; ?>System Time: <strong><?php echo date("D, d M Y H:i:s T");?></strong>&nbsp;&nbsp;&nbsp;
mcutting
Cacti Guru User
Posts: 1884
Joined: Mon Oct 16, 2006 5:57 am
Location: United Kingdom
Contact:

Post by mcutting »

Nice mod - have just included this in my installation. Very useful.
Cacti Version 0.8.8b
Cacti OS Ubuntu LTS
RRDTool Version RRDTool 1.4.7
Poller Information
Type SPINE 0.8.8b
airwalk
Cacti User
Posts: 103
Joined: Fri Aug 18, 2006 11:22 am
Location: MSK, RU

Post by airwalk »

Thanks, nice mod!
ejensen
Cacti User
Posts: 55
Joined: Mon Jul 12, 2004 11:39 am

Post by ejensen »

very nice. thanks for sharing!
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

How about a little more building upon this idea.

Call this file "liveclock.js" and place it inside your /include directory

Code: Select all

<span id="clock">
<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
<!-- Begin
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
{
 d = new Date();
 Time24H = new Date();
 Time24H.setTime(d.getTime() + (d.getTimezoneOffset()*60000) + 3600000);
 InternetTime = Math.round((Time24H.getHours()*60+Time24H.getMinutes()) / 1.44);
 if (InternetTime < 10) InternetTime = '00'+InternetTime;
 else if (InternetTime < 100) InternetTime = '0'+InternetTime;
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate=dayarray[day]+" "+montharray[month]+" "+daym+" "+year+" "+hours+":"+minutes+":"+seconds+" "+dn+""
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}
window.onload=goforit
//  End -->
</script></span>
Call this file "systime.php" and put it inside your include directory.

Code: Select all

<?php
print "<b>OS:</b >" . $config["cacti_server_os"] ." ";
print "<b>Version:</b> " . $config["cacti_version"] ." ";
$query="select end_time from poller_time where id=1";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num == 0) {
$pinfo="<font color=red> The poller is running.. </font>";
}else{
$pinfo=" <b>Last poller end time:</b> ".mysql_result($result,"end_time");
}
print "<b>Current Time:</b> ";
include_once("liveclock.js");
print $pinfo;
?>
Then put this:

Code: Select all

<?php include_once("systime.php"); ?>
After line 161 in top_header_graph.php and after line 80 in top_header.php

You'll now have a live clock display instead of a static clock as well as the last poller run.
[b]Cacti Version[/b] - 0.8.7d
[b]Plugin Architecture[/b] - 2.4
[b]Poller Type[/b] - Cactid v
[b]Server Info[/b] - Linux 2.6.18-128.1.6.el5
[b]Web Server[/b] - Apache/2.2.3 (CentOS)
[b]PHP[/b] - 5.2.9
[b]MySQL[/b] - 5.0.45-log
[b]RRDTool[/b] - 1.3.0
[b]SNMP[/b] - 5.3.2.2
[b]Plugins[/b]PHP Network Managing v0.6.1, Global Plugin Settings v0.6,thold v0.4.1,XMLPort v0.3.5,CactiCam v0.1.5,NetTools v0.1.5,pollperf v0.32,RRD Cleaner v1.1,sqlqueries v0.2,superlinks v0.8,syslog v0.5.2,update v0.4,discovery v0.9,zond v0.34a,hostinfo v0.2,Bloom v0.6.5,mactrack v1.1,weathermap v0.96a,mobile v0.1
zivley
Cacti User
Posts: 69
Joined: Tue Nov 13, 2007 6:22 am

Post by zivley »

Hey streaker, your trick sounds nice, but somehow it doesn't work on my server. Perhaps I didn't place the lines on the right place in the top_ files, anyway, here's a correction and a suggestion
1. When you say "After line 161 in top_header_graph.php and after line 80 in top_header.php" the first file name is "top_graph_header.php"
2. You should point us more specifically to where exactly to insert the line

Code: Select all

<?php include_once("systime.php"); ?>
because I've seen some cases that the "howto" tell you to change a certain line number in a certain file and in your case the line number is different.
In this case, both files places you said are around similar code, this is my "top_graph_header.php" line 161 and below.

Code: Select all

                                        <td align="right">
                                                <?php if ((isset($_SESSION["sess_user_id"])) && ($using_guest_account == false)) { ?>
                                                Logged in as <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="<?php echo $config['url_path']; ?>logout.php">Logout</a>)&nbsp;
                                                <?php } ?>
                                        </td>
In this case, after line 161 means after '<td align="right">'
This is "top_header.php" line 78 and below.

Code: Select all

<td align="right">
                                                <?php if (read_config_option("auth_method") != 0) { ?>
                                                Logged in as <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="<?php echo $config['url_path']; ?>logout.php">Logout</a>)&nbsp;
                                                <?php } ?>
                                        </td>
In this case, "after line 80" means after "Logged in as<strong>..."

Do you understand my confusion?
I added the line in both cases after the '<td align="right">' and it all displayed right except the current time which was "//" and also the IE gave a "Done with errors" symbol at the left bottom...
Can you help please?
Thanks,
Ziv
zivley
Cacti User
Posts: 69
Joined: Tue Nov 13, 2007 6:22 am

Post by zivley »

Now I tried putting the line on both files after the "logged in as"
This is what I see in the cacti:

Code: Select all

Logged in as ziv (Logout)  OS:unix Version: 0.8.7b Current Time: // The poller is running..
or

Code: Select all

Logged in as ziv (Logout)  OS:unix Version: 0.8.7b Current Time: // Last poller end time: 2008-08-06 10:21:03
And now I don't get the "Done with errors" but when I did get it, the first time, this is what it said:

Code: Select all

Problems with this Web page may prevent it from being displayed, blah blah blah... (And in the "Show details" box)

Line: 94
Char: 3
Error: Expected '}'
Code: 0
URL: http://mycacti.net/cacti/index.php
Anyway, where's the current time??
Thanks,
Ziv
User avatar
streaker69
Cacti Pro User
Posts: 712
Joined: Mon Mar 27, 2006 10:35 am
Location: Psychic Amish Network Administrator

Post by streaker69 »

Can you post a screencap of exactly where you put the include?
[b]Cacti Version[/b] - 0.8.7d
[b]Plugin Architecture[/b] - 2.4
[b]Poller Type[/b] - Cactid v
[b]Server Info[/b] - Linux 2.6.18-128.1.6.el5
[b]Web Server[/b] - Apache/2.2.3 (CentOS)
[b]PHP[/b] - 5.2.9
[b]MySQL[/b] - 5.0.45-log
[b]RRDTool[/b] - 1.3.0
[b]SNMP[/b] - 5.3.2.2
[b]Plugins[/b]PHP Network Managing v0.6.1, Global Plugin Settings v0.6,thold v0.4.1,XMLPort v0.3.5,CactiCam v0.1.5,NetTools v0.1.5,pollperf v0.32,RRD Cleaner v1.1,sqlqueries v0.2,superlinks v0.8,syslog v0.5.2,update v0.4,discovery v0.9,zond v0.34a,hostinfo v0.2,Bloom v0.6.5,mactrack v1.1,weathermap v0.96a,mobile v0.1
zivley
Cacti User
Posts: 69
Joined: Tue Nov 13, 2007 6:22 am

Post by zivley »

Of course I can, here we go:
Attachments
&amp;lt;path_cacti&amp;gt;/include/top_graph_header.php
&lt;path_cacti&gt;/include/top_graph_header.php
top_graph_header.php.png (58.45 KiB) Viewed 11383 times
&amp;lt;path_cacti&amp;gt;/include/top_header.php
&lt;path_cacti&gt;/include/top_header.php
top_header.php.png (41.23 KiB) Viewed 11383 times
Cacti Graphs Header
Cacti Graphs Header
cacti_header.png (17.02 KiB) Viewed 11383 times
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests