Thursday, March 15, 2012

Cacti: http to https

Though may not be required for most users to use Secured HTTP for their Cacti System, some may be required as a basic policy requirements especially for financial institutions. The simple PHP code below will redirect all http request to https, this is also the simplest method that will do the job compared to other methods that you may find on the web.

<?php
if ($_SERVER['SERVER_PORT']!=443)
{
$url = "https://". $_SERVER['SERVER_NAME'] . ":443".$_SERVER['REQUEST_URI'];
header("Location: $url");
}
?>

The code came from this blog, and is made for IIS Web Server, but after giving it a try on Centos 5, my Cacti System, it works like a charm and is very easy to deploy.

So here is the tip on how to deploy in your Linux-Cacti Machine:

1.  Edit the index.php located on cacti's root folder

#cd /var/www/cacti
#vi index.php

    copy the PHP code above and insert it on the first line of index.php

2. Exit from vi saving the changes and restart httpd service

#service httpd restart

Open your cacti using http://your-server-ip/cacti, this will redirect you to https://your-server-ip/cacti and ask you to verify and confirm web certificate on the first use. Just proceed and complete the process and you are good to go.


The only one problem is, upon login on your cacti and pointing the browser directly to the webpage content like:  http://your-server-ip/cacti/plugins/devices/device.php, it will NOT redirect you to https://your-server-ip/cacti/plugins/devices/device.php, instead, the page will just open as a regular http.

A simple fix would be ......insert the PHP code on "device.php". Do this on your other pages as well.





Wednesday, March 14, 2012

Cacti: Ping is "up" but Device status is "down"

This a simple solution to a problem on ping availability detection in Cacti. Commonly, you notice that when you use the ICMP ping for downed detection, cacti can ping the host but still, it displays "down" under the Devices. You may have tried already changing other parameter such as UDP or ICMP Ping to no avail, but the simple solution is pertaining to file permissions on spine.

Change the spine permission as follows

#cd /usr/local/spine/bin
#chmod a+s spine

You may run poller.php manually from your cacti root folder if you can't wait your cron cycle to run poller.php. You may see your device status as "Recovering" after running the poller.php.

Friday, February 17, 2012

Auto Login in Cacti

After finishing a second Cacti project, I need to place a link for the second cacti from the main Cacti System. It was just easy to make it using the 'superlinks' plugin in cacti, but the problem is, I have to do another login using my credentials for the second cacti system. And not only that, the header of the second cacti also appears below the header of the main Cacti.

I want my other users to view the "read-only" Devices (plugin), with only the device name and device status (up  or down. I modified the "Devices" plugin to suit my requirements and remove the headers from the script leaving only hosts status and filter options.

First, is to create an autologin.php in your cacti folder using the code below:

<?php

$_REQUEST["action"]="login";
$_POST["login_username"]='username';
$_POST["login_password"]='password';
$_SERVER["HTTP_REFERER"]='/plugins/devices/devices.php';

include "index.php";

?>

Call the script from your browser, and it will direct you to your http://your-server-ip/cacti/plugins/devices.php. The problem here is when you click again the 'superlinks tab', you will get an 'Access Denied'. To fix this, insert a code on your devices.php to call the autologin.php when opening the devices.php.

include_once("./autologin.php");

Then load the "http://your-server-ip/cacti/plugins/devices/devices.php" on the main Cacti's 'superlinks', you can now re-click the superlinks without getting an "Access Denied" error.


Thursday, February 16, 2012

Auto Refresh in PHP Script

Using the simple code below, you can auto refresh the output of your php script in a browser. Place the code on the first line of your php script.

<?php header('Refresh: 10'); ?>

**where 10 is the value in seconds, in the code above, your php page will refresh every 10sec regardless if there are changes in the data or none.



Tuesday, February 14, 2012

Scheduling Poller using Cron

Poller scheduling is not quite common to most of Cacti users. But when I setup a new Cacti system utilizing Ping for availability, there is a need to schedule a poller.php to run at a specified time only or when it's needed. ICMP is a heavy and resource-intensive type of monitoring, it can cause a high CPU utilization to the core routers creating high latency problems within the network. So it is very important to manage the resources wisely. Since my company is operating only on office hours, I scheduled poller.php to run only within the time frame only.

Here's is my cron settings for that particular requirements.

*/10 7-18 * * 1-5 root php /var/www/cacti/poller.php > /dev/null 2>&1

The cron settings above means that poller.php will run every 10mins, from 7:00am to 6:50pm, and from Monday to Friday only. This will coincide with the business operating hours only, and saving precious CPU power for other task such as system backup every night and every weekend.

Output graph of eth0 as a result of cron settings above


Related Posts:
- Cacti 1 minute cron settings
- 1 minute Spine polling

Saturday, January 28, 2012

Motorcycle Pricelist

Motorcycle transportation is booming in the Philippines, with all the daily traffic experience all over Metro Manila, many opted to utilize motorcycle as their alternate mode of transportation. Despite of danger, many still wants to have a motorcycle, simply because of its versatility, low gas consumption, and can inch their way in every traffic jams in the metro. In addition, more and more people can now afford to own a motorcycle especially those below average earners. In-house financing are readily available from most motorcycle dealers.