Skip to content

Latest commit

 

History

History
164 lines (134 loc) · 6.7 KB

Plugin-Development.md

File metadata and controls

164 lines (134 loc) · 6.7 KB

Plugin Development

Overview

Cacti plugins extend the web interface and the polling process. The plugin architecture grew out of Jimmy Conner's work on the SquirrelMail project.

  • Thold checks data source values against thresholds.
  • Syslog collects log messages and matches them against rules that can trigger alerts.
  • Monitor shows device status on a dashboard.
  • Intropage displays Cacti metrics on a single page.
  • Weathermap displays live data on network diagrams.

Read the plugin's installation and removal instructions before enabling it. To start a new plugin, see Creating Plugins.

Legacy Plugins Notice

Plugins written for Cacti 0.8.x need changes to run on Cacti 1.x. Cacti 1.x uses the Plugin Architecture (PIA) 2.x installation and setup conventions.

Plugin Migration

For an example of how a maintained plugin registers its hooks, see Graph Export. For a core page with list filters, pagination, and bulk actions, see vdef.php on the development branch. Use the corresponding file on the branch you support.

Migration Steps

Required Steps

  • Create an INFO file in the plugin directory and update the installation and setup functions in setup.php. See Creating Plugins.
  • Replace direct header includes with the function for the page. Use top_header() for a console page, top_graph_header() for a graph page, or general_header() for the general header. End the page with bottom_footer().
  • Use the link classes from the corresponding core page so Cacti can attach its navigation callbacks. When an AJAX request needs only the page content, include header=false in the destination URL.
  • Keep form controls inside their form and use valid HTML table markup. For paginated tables, render the navigation bar above and below the table.
  • Validate named request fields with get_filter_request_var(). Its default filter checks integers. Choose a filter appropriate to the field. After validation, use get_request_var() to read the value. Use isset_request_var() and isempty_request_var() to check presence or emptiness, and set_request_var() to set a request value.
  • For bulk actions with dynamically named checkboxes, inspect the submitted field names. For example, vdef.php matches chk_ followed by digits and validates the extracted ID. Check the user's permission for each selected object before applying the action.
  • Remove hooks that load jQuery or jQuery UI into the page header. Cacti already supplies both libraries.

Optional Steps

  • Use Cacti's CSS classes for colors and alternating table rows. Remove inline styles and references to the legacy $colors array.
  • Use AJAX callbacks to refresh filtered results. For list pages that keep filters between requests, validate_store_request_vars() validates the fields and stores their values in the session when given a session prefix.
  • Use the table helpers for sortable headings, checkbox columns, tooltips, and alignment. Use html_nav_bar() to generate pagination links.

INFO File Structure

The INFO file uses INI syntax. Put the following keys in its [info] section.

  • name is the plugin's directory name.
  • version is the plugin's version number.
  • longname is the plugin's display name.
  • author, email, and homepage identify the maintainer and provide contact information.
  • compat specifies the Cacti versions the plugin supports. A bare version sets the minimum. Use this form for plugins that support Cacti 1.2.x.
  • requires lists plugin dependencies. Separate entries with a single space. Each entry gives the directory name and can include a colon followed by a minimum version. For example, thold:1.2.1 monitor:2.0 requires Thold 1.2.1 or later and Monitor 2.0 or later.
  • capabilities is a comma-separated list of flags that describe which operations the plugin supports on a remote data collector.
  • nosync is a comma-separated list of files or directories to skip at the top level of the plugin directory. An entry such as *.csv skips files with that extension at the top level. Throughout the directory tree, Cacti skips files ending in tar, gz, zip, tgz, ttf, z, exe, pack, swp, and swo.

Example INFO Files

Monitor 3.0 declares Thold as a dependency. Cacti checks the installed version of Thold before it installs Monitor.

[info]
name = monitor
version = 3.0
longname = Device Monitoring
author = The Cacti Group
email =
homepage = http://www.cacti.net
compat = 1.2.29
requires = thold:1.2.1
capabilities = online_view:1, online_mgmt:1, offline_view:0, offline_mgmt:0, remote_collect:0

Syslog 5.0 excludes its local configuration file from synchronization and declares which hooks it uses on a remote collector.

[info]
name = syslog
version = 5.0
longname = Syslog Monitoring
author = The Cacti Group
email =
homepage = http://www.cacti.net
compat = 1.2.23
nosync = config.php
capabilities = online_view:1, online_mgmt:1, offline_view:1, offline_mgmt:1, remote_collect:0, remote_poller:1

With nosync = config.php, each collector can keep its own Syslog configuration. The remote_poller:1 flag allows Cacti to run the plugin's registered poller_bottom hook on a remote collector. Collection hooks such as poller_top and poller_output use remote_collect, which Syslog sets to 0. See the plugin hook reference for hook descriptions.

Changes in Cacti 1.3+

The 1.3 development branch accepts a range in compat. Quote the value, attach each operator to its version, and separate comparisons with a space. The following example includes 1.3.0 and excludes 1.4.0. In requires, each space starts a new dependency, so keep each plugin and its version together.

[info]
compat = ">=1.3.0 <1.4.0"
requires = thold:1.2.1 monitor:2.0

Charting Functionality

For browser charts, Cacti includes billboard.js, D3, and Chart.js. Cacti 1.2.x also ships dygraphs and jQuery Sparklines. Check the JavaScript files on each branch your plugin supports before choosing a library.

Logging

On the development branch, open Configuration > Settings in the console. On the Logging tab, select the plugin under Selective Plugin Debug. Use Selective File Debug for individual files or Selective Device Debug to trace polling for specific device IDs. See Log Settings.


Copyright (c) 2004-2026 The Cacti Group