While we use a number of monitoring tools CACTI is still a faithful option to just keep the basic graphing in place.
The ops team obviously have to keep this page running in the background – even when on standby remotely etc. A common pain with Cacti is it’s default meta refresh approach which redirects you to a broken page if you’re offline 😉
A quick fix (likely made totally over complicated by me with the inclusion of jQuery – but hey something shiny to play with …)
Inside: /usr/share/cacti/site/includes/top_graph_header.php (or where every you decided to install it)
<?php if (isset($_SESSION["custom"])) { print “<meta http-equiv=refresh content=’300′>\r\n”; }else{ print “<meta http-equiv=refresh content=’” . htmlspecialchars(read_graph_config_option(“page_refresh”),ENT_QUOTES) . “‘>\r\n”; } ?>
DELETE THOSE BITS!
Then, go to the end of the head section near
<script type="text/javascript" src="include/jscalendar/calendar-setup.js"></script> </head> <body>
And replace it with:
<script type="text/javascript" src="include/jscalendar/calendar-setup.js"></script> <script type="text/javascript" src="include/jquery-1.6.4.min.js"></script> <script type="text/javascript"> var tTime; function startRefreshTimer() { <?php if (isset($_SESSION["custom"]) && $_SESSION["custom"] == true) { print "\ttTime=setTimeout('refreshTimer()',99999000);\r\n"; }else{ print "\ttTime=setTimeout('refreshTimer()'," . htmlspecialchars(read_graph_config_option("page_refresh"),ENT_QUOTES)*1000 . ");\r\n"; } ?> } function refreshTimer() { $.get(location.href,function() { window.location = location.href; }).error(function() { startRefreshTimer();}) } </script> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="startRefreshTimer()" >
So, what’s going on here:
- First we delete the META refresh stuff so that we can apply some intelligence!
- Then we add jQuery to the mix – the request is so simple you could alternatively use other libs or code native but I’m just using the quickest option here
- Then we create a simple bit of javascript that actually checks to make sure the page we’re trying to refresh is alive. If it is great, otherwise just back off and try again in the normal fresh timeout.
The code could be tweaked to rather check more aggresively if the page is down but this approach is simpler and JustWorks ™
Hope this helps someone out there 😉