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