mirror of
https://github.com/Cacti/documentation.git
synced 2026-12-06 15:13:53 +09:00
docs: update the 1.2.x plugin developer manual (#300)
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
This commit is contained in:
1 parent
008b36f19d
commit
6b6de65172
11 files changed
+1467
-669
No files matched your search
@@ -0,0 +1,49 @@
|
||||
# Development and Testing
|
||||
|
||||
## Choose the Source and Version
|
||||
|
||||
Use the branch you intend to change in the application, plugin, and manual
|
||||
repositories. This chapter describes Cacti's 1.2.x branch.
|
||||
Read its [Composer requirements][composer] before setting up PHP. For a
|
||||
plugin, check the supported Cacti versions and dependencies in its `INFO`.
|
||||
|
||||
## Theme and Plugin Checks
|
||||
|
||||
The **Cacti 1.2 theme style regressions** workflow uses PHP 8.2, Node 22,
|
||||
and Chromium. From a checkout of the Cacti `1.2.x` branch, run:
|
||||
|
||||
```console
|
||||
cd tests/e2e
|
||||
npm ci --ignore-scripts
|
||||
node node_modules/@playwright/test/cli.js install chromium
|
||||
node node_modules/@playwright/test/cli.js test --config=playwright.config.js \
|
||||
theme-style-regressions.spec.js theme-css.spec.js --workers=1
|
||||
```
|
||||
|
||||
These tests check theme styles in a browser. For changes to plugin behavior,
|
||||
also install the plugin on a disposable 1.2.x system, enable it, visit its
|
||||
pages with the relevant user permissions, and exercise the affected action.
|
||||
|
||||
## Read Actions Results
|
||||
|
||||
Open **Actions > Cacti 1.2 theme style regressions** and select **Theme CSS
|
||||
browser contracts**. The workflow runs on relevant changes to `1.2.x` and
|
||||
supports a manual run. Inspect the failing test and browser assertion to
|
||||
identify the theme, selector, and expected value.
|
||||
|
||||
The [workflow definition][workflow] lists its triggers, dependencies, and
|
||||
exact commands.
|
||||
|
||||
## Documentation Checks
|
||||
|
||||
Run the spelling, Markdown, and navigation checks from the documentation
|
||||
checkout. Render the manual before submitting changes to examples, links, or
|
||||
screenshots. See [Documentation Standards](Standards-Documentation.md).
|
||||
|
||||
[composer]: https://github.com/Cacti/cacti/blob/1.2.x/composer.json
|
||||
[workflow]:
|
||||
<https://github.com/Cacti/cacti/blob/1.2.x/.github/workflows/theme-style-regressions.yml>
|
||||
|
||||
---
|
||||
|
||||
Copyright (c) 2004-2026 The Cacti Group
|
||||
+73
-174
@@ -1,210 +1,109 @@
|
||||
# Creating a plugin
|
||||
|
||||
Your plugin will require a few things to be properly detected by Cacti.
|
||||
Build and test your plugin in a disposable Cacti installation. The
|
||||
[reference plugin](Plugin-Reference.md) shows the smallest installable
|
||||
example. The [downloadable example](Plugin-Guidelines.md#plugin-namespaces)
|
||||
also registers a tab, a page, and a permission realm.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
Your plugin will reside in its own directory in Cacti's plugin directory. You
|
||||
will need to create a new directory, with a unique name. It is recommended that
|
||||
you use all lowercase alpha letters, and try to keep it short (you will be
|
||||
typing it a lot). All plugin names must contain only upper or lowercase letters
|
||||
a-z and digits 0-9.
|
||||
|
||||
So to begin, create your directory in the plugins directory like this.
|
||||
|
||||
```console
|
||||
/plugins/PLUGINNAME/
|
||||
```
|
||||
Choose a short lowercase directory name, such as `example`. Place the
|
||||
directory directly under Cacti's `plugins/` directory. The result should
|
||||
contain `plugins/example/setup.php` and `plugins/example/INFO`. Use the same
|
||||
name for the `INFO` entry and the prefix of the setup functions.
|
||||
|
||||
## Setup File
|
||||
|
||||
Cacti detects plugins by looking for a 'setup.php' file located inside your
|
||||
plugin's directory. It must be all lowercase. Inside this file should only be
|
||||
functions, no code that runs automatically.
|
||||
Define the plugin's lifecycle functions in `setup.php`. Cacti loads this file
|
||||
when it discovers or manages the plugin. Keep page output and database changes
|
||||
inside the callbacks that need them.
|
||||
|
||||
## INFO File
|
||||
|
||||
Every Cacti plugin must have an INFO file. Any legacy plugins that do not have
|
||||
an INFO file will not work with Cacti 1.x. This was done intentionally so that
|
||||
plugin users could know ahead of time that their plugin was not designed for
|
||||
Cacti 1.x. The info file includes several lines, including:
|
||||
|
||||
setting | description
|
||||
:--- | :---
|
||||
*name* | The short name for the plugin. Must be alpha with no spaces and match the directory name.
|
||||
*version* | The version of the plugin. Use two to three decimal places.
|
||||
*longname* | A user readable short description for the plugin.
|
||||
*author* | The author of the plugin.
|
||||
*email* | The author's email address for obtaining support.
|
||||
*homepage* | If the author maintains a homepage, the address for that page.
|
||||
*compat* | The minimum version of Cacti that is required to use this plugin.
|
||||
*requires* | A space delimited list of plugins:version that are required to use this plugin.
|
||||
*capabilities* | A comma delimited list of capabilities to define what capabilities the plugin has primarily remotely.
|
||||
*nosync* | A comma delimited list of relative paths that should not be synchronized with the remote data collectors, for example transient folders that may contain quite a bit of data that changes often.
|
||||
Put the plugin metadata under `[info]`. Supply the directory name, display
|
||||
name, version, author, homepage, and Cacti compatibility. Add `requires` for
|
||||
plugin dependencies, `capabilities` for remote collector behavior, and
|
||||
`nosync` for synchronization exclusions when applicable. See the field
|
||||
definitions and examples in [Plugin Development](Plugin-Development.md).
|
||||
|
||||
## Mandatory functions
|
||||
|
||||
Inside the setup file, there are several functions that are mandatory in order
|
||||
for your plugin to properly be detected, and to properly function.
|
||||
|
||||
### plugin_PLUGINNAME_install
|
||||
|
||||
This first function is the installation function that is run when a request is
|
||||
received to install your plugin. There are no arguments passed to this
|
||||
function.
|
||||
|
||||
You will need to replace PLUGINNAME with the exact folder name (including case
|
||||
sensitivity). Below is an example of this function. We will discuss the
|
||||
register_hook function later in this document.
|
||||
|
||||
```php
|
||||
function plugin_PLUGINNAME_install () {
|
||||
api_plugin_register_hook('PLUGINNAME', 'top_graph_header_tabs', 'PLUGINNAME_show_tab', 'setup.php');
|
||||
}
|
||||
```
|
||||
|
||||
### plugin_PLUGINNAME_uninstall
|
||||
|
||||
The next function is the uninstall function. This is a function that is called
|
||||
when someone requests to uninstall your plugin. You can use this to clean up
|
||||
any extra data that is left by your plugin. If you used the API function to
|
||||
install any tables, they will be cleaned up automatically. Cacti only calls
|
||||
this function if the plugin defines it.
|
||||
Cacti calls the version and installation functions by name. Replace
|
||||
`PLUGINNAME` in the headings below with the plugin's directory name.
|
||||
|
||||
### plugin_PLUGINNAME_version
|
||||
|
||||
The next function is used for checking the version of your plugin, plus
|
||||
providing a little bit more information.
|
||||
|
||||
Below is an example of this function. The few extra things to return are the
|
||||
longname (aka Pretty Name that will be displayed), the author, website, etc.
|
||||
The `url` is a special URL used to check for updates of your plugin to be
|
||||
compatible with the 'update' plugin.
|
||||
Return the metadata array from the `[info]` section. The installer reads
|
||||
`longname`, `author`, and `version` from this array.
|
||||
|
||||
```php
|
||||
function plugin_PLUGINNAME_version () {
|
||||
global $config;
|
||||
$info = parse_ini_file($config['base_path'] . '/plugins/PLUGINNAME/INFO', true);
|
||||
function plugin_example_version() {
|
||||
$info = parse_ini_file(__DIR__ . '/INFO', true, INI_SCANNER_RAW);
|
||||
|
||||
return $info['info'];
|
||||
return $info['info'];
|
||||
}
|
||||
```
|
||||
|
||||
### plugin_PLUGINNAME_install
|
||||
|
||||
Register hooks and realms here. If the plugin needs database tables, create
|
||||
them with Cacti's plugin database helpers. Make installation safe to retry.
|
||||
A successful install callback can return without a value. On the current
|
||||
branch, returning `false` or throwing an exception signals installation
|
||||
failure.
|
||||
|
||||
```php
|
||||
function plugin_example_install() {
|
||||
api_plugin_register_hook('example', 'top_graph_header_tabs', 'example_show_tab', 'setup.php');
|
||||
api_plugin_register_realm('example', 'example.php', 'View Example', true);
|
||||
}
|
||||
```
|
||||
|
||||
The downloadable example supplies `example_show_tab()` and the authenticated
|
||||
page `example.php`. Install and enable the plugin to make its tab available to
|
||||
users with the **View Example** realm.
|
||||
|
||||
On Cacti 1.2.x, the enabled plugin shows **Active**.
|
||||
|
||||

|
||||
|
||||
## Optional functions
|
||||
|
||||
### plugin_PLUGINNAME_check_config
|
||||
|
||||
The last mandatory function is used for determining whether your plugin is
|
||||
ready to be enabled after being installed.
|
||||
Define this callback if the plugin needs settings before it can run. Return
|
||||
`true` when it is ready and `false` when an administrator still needs to
|
||||
configure it. Cacti treats an absent callback as ready. An empty callback
|
||||
returns `null` and prevents the plugin from passing the check.
|
||||
|
||||
When a plugin is installed, it starts in a disabled state. Only a few of the
|
||||
necessary hooks for the plugin are enabled. These are the config_settings,
|
||||
config_arrays and config_form hooks. Anything that uses those hooks will still
|
||||
be available while the plugin is disabled. This allows a user to modify any
|
||||
necessary settings for the plugin before the plugin is actually enabled and goes
|
||||
live. You can then use this check_config function to determine whether
|
||||
everything is correctly set up, before you allow the plugin to be enabled. From
|
||||
this function, you will simply need to return TRUE if everything checks out, or
|
||||
return FALSE if something else needs to be set up. If the plugin does not
|
||||
define this function, Cacti treats the plugin as ready to be enabled.
|
||||
### plugin_PLUGINNAME_uninstall
|
||||
|
||||
```php
|
||||
function plugin_PLUGINNAME_check_config () {
|
||||
if (read_config_option('PLUGINNAME_SETTING') != '') {
|
||||
return true;
|
||||
}
|
||||
Use this callback for plugin-specific cleanup. Cacti also processes the schema
|
||||
changes it recorded through its plugin database API. Tell administrators which
|
||||
data uninstalling will remove and how to back it up.
|
||||
|
||||
return false;
|
||||
}
|
||||
```
|
||||
### Registering Hooks
|
||||
|
||||
## Optional functions
|
||||
Some plugins delete all your data and settings when you uninstall them.
|
||||
However, some plugins preserve the data and can be used again in the future.
|
||||
The following 2 functions allow you to delete all data and settings without
|
||||
uninstalling the plugin or manually deleting them.
|
||||
If the plugin does not contain the function, the delete icon will not appear
|
||||
in the settings (console -> configuration -> plugins).
|
||||
These functions are used in version 1.3 and higher.
|
||||
The arguments to `api_plugin_register_hook()` identify the plugin, hook,
|
||||
callback, and callback file relative to the plugin directory. Cacti loads
|
||||
that file when it invokes the callback. Use the hook name and argument list
|
||||
from the [Hook API Reference](Plugin-Hook-API-Ref.md) and its core call site.
|
||||
|
||||
```php
|
||||
function plugin_PLUGINNAME_has_data() {
|
||||
return true;
|
||||
}
|
||||
Cacti registers `config_arrays`, `config_form`, and `config_settings` as
|
||||
enabled by default so administrators can configure a newly installed plugin.
|
||||
An optional fifth argument enables a hook at registration.
|
||||
|
||||
function plugin_PLUGINNAME_remove_data() {
|
||||
return false;
|
||||
}
|
||||
```
|
||||
### Registering Realms
|
||||
|
||||
#### Registering Hooks
|
||||
Pass the plugin name, page filename, and permission label to
|
||||
`api_plugin_register_realm()`. A comma-separated filename list can share one
|
||||
realm. The fourth argument controls whether the administrator receives the
|
||||
realm at registration. Grant access to other users or groups explicitly.
|
||||
|
||||
The way that your plugin is able to interact within Cacti is via the many hooks
|
||||
that are placed into the interface. As Cacti processes the various visual
|
||||
pages and backend functions, it will call specific hook functions which pass
|
||||
control over to any plugins that might want to interact with that aspect of
|
||||
Cacti. In order to utilize these hooks, your plugin must register for each
|
||||
hook that you require inside our installation function. This is done via a
|
||||
simple API function.
|
||||
|
||||
```php
|
||||
api_plugin_register_hook('PLUGINNAME', 'HOOKNAME', 'CALLBACKFUNCTION', 'FILENAME');
|
||||
```
|
||||
|
||||
Name | Description
|
||||
--- | ---
|
||||
PLUGINNAME | The name of your plugin
|
||||
HOOKNAME | The name of the hook you want to register
|
||||
CALLBACKFUNCTION | The name of your function to call when the hook is triggered.
|
||||
FILENAME | The name of the file which contains the above function (path relative to your plugin directory)
|
||||
|
||||
Taking our above example, if you wanted to display a new tab at the top of
|
||||
Cacti's Console, your setup.php file may look like this.
|
||||
|
||||
```php
|
||||
function plugin_PLUGINNAME_install () {
|
||||
api_plugin_register_hook('PLUGINNAME', 'top_graph_header_tabs', 'PLUGINNAME_show_tab', 'setup.php');
|
||||
}
|
||||
|
||||
function PLUGINNAME_show_tab () {
|
||||
global $config;
|
||||
print '<a href="' . $config['url_path'] . 'plugins/PLUGINNAME/PLUGINNAME.php"><img src="' . $config['url_path'] . 'plugins/PLUGINNAME/images/tab.gif" align="absmiddle" border="0"></a>';
|
||||
}
|
||||
```
|
||||
|
||||
Here you can find a full listing of the available hooks
|
||||
|
||||
[Hook Api Reference](Plugin-Hook-API-Ref.md)
|
||||
|
||||
#### Registering Realms
|
||||
|
||||
Cacti allows you to restrict access to various portions of Cacti by utilizing
|
||||
Realm Permissions. Creating a new realm will add a checkbox to the User
|
||||
Permissions form for the page you desire to restrict access to. You can create
|
||||
1 realm that permits access to multiple pages, or use multiple realms for
|
||||
different functional duties (ex: separating out the viewing and the
|
||||
configuration sections of your plugin).
|
||||
|
||||
We need to call this hook in the same function as we registered for hooks.
|
||||
Either of the api calls can come first (there is no order necessary).
|
||||
|
||||
```php
|
||||
api_plugin_register_realm('PLUGINNAME', 'FILENAMETORESTRICT', 'DISPLAYTEXT', 1);
|
||||
```
|
||||
|
||||
Name | Description
|
||||
--- | ---
|
||||
PLUGINNAME | Your plugin's name
|
||||
FILENAMETORESTRICT | the filename (relative to your plugin directory) to restrict access to, you can separate multiple with a comma
|
||||
DISPLAYTEXT | This is the text that will display on the User Permissions form for this Realm
|
||||
1 or 0 (true or false) | This tells it whether to automatically grant permission to the 'admin' user account (true)
|
||||
|
||||
So to follow our example, your install function would look like this
|
||||
|
||||
```php
|
||||
function plugin_PLUGINNAME_install () {
|
||||
api_plugin_register_hook('PLUGINNAME', 'top_graph_header_tabs', 'PLUGINNAME_show_tab', 'setup.php');
|
||||
api_plugin_register_realm('PLUGINNAME', 'PLUGINNAME.php,', 'View PLUGINNAME', 1);
|
||||
}
|
||||
```
|
||||
Load Cacti's authentication bootstrap on the plugin page. When drawing its
|
||||
tab, check `api_plugin_user_realm_auth('example.php')`. Test the page with
|
||||
an account that has the realm and one that lacks it.
|
||||
|
||||
---
|
||||
|
||||
Copyright (c) 2004-2026 The Cacti Group
|
||||
+99
-144
@@ -2,154 +2,119 @@
|
||||
|
||||
## Overview
|
||||
|
||||
Cacti Plugins allow users of Cacti to extend its functionality into areas
|
||||
that the core Cacti developers have not. They were written based off of
|
||||
the work of Jimmy Conner from the Squirrel Mail project years ago. They
|
||||
allow developers to augment the Cacti Website, and its polling processes
|
||||
to extend Cacti's reach.
|
||||
Cacti plugins extend the web interface and the polling process. The plugin
|
||||
architecture grew out of Jimmy Conner's work on the SquirrelMail project.
|
||||
|
||||
There are a number of popular plugins including:
|
||||
- [Thold](Plugin-Thold.md) checks data source values against thresholds.
|
||||
- [Syslog](Plugin-Syslog.md) collects log messages and matches them against
|
||||
rules that can trigger alerts.
|
||||
- [Monitor](Plugin-Monitor.md) shows device status on a dashboard.
|
||||
- [Intropage](Plugin-Intropage.md) displays Cacti metrics on a single page.
|
||||
- [Weathermap](Plugin-Weathermap.md) displays live data on network diagrams.
|
||||
|
||||
- **Thold** - A graph based service checking framework that leverages the
|
||||
data on Cacti graphs for performing service checks
|
||||
- **Syslog** - A plugin that allows you to view log data from hundreds or
|
||||
thousands of hosts and generate faults based upon pattern matching of
|
||||
that log data.
|
||||
- **Monitor** - A plugin that provides a Device Dashboard highlighting
|
||||
Cacti Devices that are experiencing faults.
|
||||
- **Intropage** - A plugin that provides a replacement to the Cacti console
|
||||
showing key performance metrics across all of Cacti from a single page.
|
||||
- **Weathermap** - A plugin that allows you to create architectural
|
||||
diagrams of your network and to animate them with status data.
|
||||
|
||||
In theory, these plugins can be integrated into Cacti very simply, and removed
|
||||
without breaking Cacti. However, it must be noted to always review the
|
||||
plugin's documentation before you start to use it.
|
||||
Read the plugin's installation and removal instructions before enabling it.
|
||||
To start a new plugin, see [Creating Plugins](Plugin-Creating-Plugins.md).
|
||||
|
||||
## Legacy Plugins Notice
|
||||
|
||||
Plugins written for Cacti 0.8.x require modifications in order to be compatible
|
||||
with Cacti 1.x. There are several changes that all plugin developers need to
|
||||
be aware of. Any of the Cacti Group maintained plugins can be
|
||||
used as reference plugins for driving your plugin migration to the 1.x
|
||||
framework and are available on [GitHub](https://github.com/Cacti/).
|
||||
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
|
||||
|
||||
In order to migrate your legacy Cacti plugins, there are several steps that
|
||||
need to be taken. This guide will provide a brief synopsis of changes that are
|
||||
required to make your plugins compatible with Cacti 1.0.
|
||||
For an example of how a maintained plugin registers its hooks, see
|
||||
[Graph Export](https://github.com/Cacti/plugin_gexport). For a core page with
|
||||
list filters, pagination, and bulk actions, see
|
||||
[vdef.php](https://github.com/Cacti/cacti/blob/1.2.x/vdef.php) on the
|
||||
1.2.x branch.
|
||||
|
||||
## Migration Steps
|
||||
|
||||
Each of the following steps should be followed to migrate your plugins. Some
|
||||
of these changes are optional, and some are mandatory. We will start with the
|
||||
list of steps that are required. Then, in future sections, we will provide
|
||||
details on performing each step.
|
||||
|
||||
### Required Steps
|
||||
|
||||
- Creation of Information (INFO) file (mandatory)
|
||||
|
||||
- Applying correct classes to Anchor tags to trigger callbacks (mandatory)
|
||||
|
||||
- Remove instances of including top_header.php, top_graph_header.php,
|
||||
top_general_header.php and replacing with function calls top_header(),
|
||||
bottom_footer(), top_graph_header(), and general_header(). (mandatory)
|
||||
|
||||
- Adding '&header=false' to most header() function calls to drive Ajax
|
||||
rendering. (mandatory)
|
||||
|
||||
- Movement of form elements to be W3C compliant as HTML5 requires it (mandatory)
|
||||
|
||||
- Moving the $nav variable within the page to ensure tables are formatted
|
||||
correctly. This includes the $nav before the table and the $nav afterwards.
|
||||
(mandatory)
|
||||
|
||||
- Remove all instances of $_GET, $_REQUEST, and $_POST and replacing the
|
||||
wrappers get_request_var(), get_filter_request_var(), set_request_var(),
|
||||
isset_request_var(), isempty_request_var() (mandatory)
|
||||
|
||||
- Utilize the 'validate_store_request_vars()' function to greatly simplify
|
||||
request validation on your pages. (mandatory)
|
||||
|
||||
- Migration of the Plugin to the PIA 2.x+ install and setup process. Cacti PIA
|
||||
1.x plugins are not supported in Cacti 1.0 and beyond. (mandatory)
|
||||
|
||||
- Removal of hooks that inject jQuery, jQueryUI into Cacti's header (mandatory)
|
||||
- Create an `INFO` file in the plugin directory and update the installation and
|
||||
setup functions in `setup.php`. See
|
||||
[Creating Plugins](Plugin-Creating-Plugins.md).
|
||||
- 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
|
||||
|
||||
- Remove inline styles, and use Cacti's classes instead (highly recommended)
|
||||
- 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.
|
||||
|
||||
- Migration of filters to Ajax callbacks (highly recommended)
|
||||
### INFO File Structure
|
||||
|
||||
- Removing references to the $colors array (optional)
|
||||
The `INFO` file uses INI syntax. Put the following keys in its `[info]`
|
||||
section.
|
||||
|
||||
- Using new functions for alternate colored rows, sorted, checkbox and other
|
||||
headers (optional)
|
||||
|
||||
- Using new options for headers to support tool tips, alignment etc (optional)
|
||||
|
||||
- Migration to new pagination functions, which simplify page navigation
|
||||
|
||||
### INFO File structure
|
||||
|
||||
The INFO file follows the INI file specification. An example INFO file
|
||||
includes the following sections:
|
||||
|
||||
- **name** - The name of the plugin directory
|
||||
|
||||
- **version** - The version number of the plugin
|
||||
|
||||
- **longname** - A description for the plugin
|
||||
|
||||
- **author** - The plugin's author
|
||||
|
||||
- **email** - An email contact in order to reach the author
|
||||
|
||||
- **homepage** - A link to the plugin author's homepage
|
||||
|
||||
- **compat** - Prior to Cacti 1.3, the minimum version of Cacti to support the
|
||||
plugin. After Cacti 1.3, it will represent the range of Cacti versions
|
||||
supported.
|
||||
|
||||
- **requires** - The list of plugins and versions that the current plugin needs
|
||||
in order to operate. This is a space delimited list of Plugins with version
|
||||
attributes similar to the **compat** section.
|
||||
|
||||
- **capabilities** - a comma delimited string of capabilities defining how the
|
||||
plugin works with remote data collectors
|
||||
|
||||
- **nosync** - a comma delimited string of directories or file extensions to
|
||||
skip during the remote data collector synchronization. File extensions must be
|
||||
formatted as `*.extension` and only are relevant in the base directory of the
|
||||
plugin. The following extensions are automatically excluded regardless of
|
||||
directory: 'tar', 'gz', 'zip', 'tgz', 'ttf', 'z', 'exe', 'pack', 'swp', 'swo'.
|
||||
- `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
|
||||
|
||||
From the Monitor plugin, we can see the following format:
|
||||
Monitor 3.0 declares Thold as a dependency. Cacti checks the installed
|
||||
version of Thold before it installs Monitor.
|
||||
|
||||
```
|
||||
```ini
|
||||
[info]
|
||||
name = monitor
|
||||
version = 2.8
|
||||
version = 3.0
|
||||
longname = Device Monitoring
|
||||
author = The Cacti Group
|
||||
email =
|
||||
homepage = http://www.cacti.net
|
||||
compat = 1.2.15
|
||||
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
|
||||
```
|
||||
|
||||
From the Syslog plugin, we can see a slightly different format.
|
||||
Syslog 5.0 excludes its local configuration file from synchronization and
|
||||
declares which hooks it uses on a remote collector.
|
||||
|
||||
```
|
||||
```ini
|
||||
[info]
|
||||
name = syslog
|
||||
version = 4.2
|
||||
version = 5.0
|
||||
longname = Syslog Monitoring
|
||||
author = The Cacti Group
|
||||
email =
|
||||
@@ -159,48 +124,38 @@ nosync = config.php
|
||||
capabilities = online_view:1, online_mgmt:1, offline_view:1, offline_mgmt:1, remote_collect:0, remote_poller:1
|
||||
```
|
||||
|
||||
Here we can see that the config.php file in the plugin directory will not be copied over to remote
|
||||
pollers, and we can see that Syslog allows for remote data collection using the
|
||||
**remote_poller:1** capabilities attribute.
|
||||
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](Plugin-Hook-API-Ref.md) for hook
|
||||
descriptions.
|
||||
|
||||
### Changes in Cacti 1.3+
|
||||
|
||||
Starting with Cacti 1.3 and beyond, the **compat** and **requires** lines can
|
||||
include ranges of support. For example, the following will be supported:
|
||||
On 1.2.x, write a single minimum Cacti version in `compat`, such as
|
||||
`compat = 1.2.32`. For plugin dependencies, use space-separated entries such
|
||||
as `requires = thold:1.2.1 monitor:2.0`. Consult the
|
||||
[development manual][development-guide] when porting a plugin to 1.3.
|
||||
|
||||
```
|
||||
compat = >=1.2.15 <1.3.0
|
||||
requires = thold:>1.2.1 <=2.0, monitor:>2.0
|
||||
```
|
||||
|
||||
Before Cacti 1.3, the **compat** and **requires** attributes assumed always >=,
|
||||
and there were never provisions for < or <= for any plugin. Due to changes in the
|
||||
Plugin Architecture, this will change starting with Cacti 1.3.
|
||||
|
||||
As mentioned, there are some very good examples of how to create or migrate
|
||||
plugins in the various Cacti plugins included on The Cacti Group's GitHub site.
|
||||
Also, for a very simple Cacti page, you can look at vdef.php as an example.
|
||||
You can use this as a template to manage a table using the Cacti framework.
|
||||
For a simple plugin example, please review the gexport plugin.
|
||||
[development-guide]:
|
||||
<https://github.com/Cacti/documentation/blob/develop/Plugin-Development.md>
|
||||
|
||||
## Charting Functionality
|
||||
|
||||
Several JavaScript based HTML5 Charting packages have been included in Cacti in
|
||||
an effort to assist plugin developers who wish to use graphing APIs in their
|
||||
plugins other than RRDtool.
|
||||
|
||||
- [Billboard.js](https://naver.github.io/billboard.js/)
|
||||
- [D3](https://d3js.org/)
|
||||
- [Chart.js](http://www.chartjs.org/)
|
||||
- [DyGraphs](http://dygraphs.com/)
|
||||
- [jQuery Sparklines](http://omnipotent.net/jquery.sparkline/)
|
||||
For browser charts, Cacti includes
|
||||
[billboard.js](https://naver.github.io/billboard.js/),
|
||||
[D3](https://d3js.org/), and [Chart.js](https://www.chartjs.org/).
|
||||
This branch also ships dygraphs and jQuery Sparklines. Check the JavaScript
|
||||
files on each branch your plugin supports before choosing a library.
|
||||
|
||||
## Logging
|
||||
|
||||
For developers using the Cacti framework, it is important to note that
|
||||
additional controls on logging have been added. Debug logging can now be
|
||||
controlled at not only a global level, but now per plugin, per device and even
|
||||
per file.
|
||||
In the console, open **Configuration > Settings**. On the **General** 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](Settings-General.md#log-settings).
|
||||
|
||||
---
|
||||
Copyright (c) 2004-2026 The Cacti Group
|
||||
+24
-9
@@ -2,25 +2,40 @@
|
||||
|
||||
## Overview
|
||||
|
||||
This section will help the Cacti plugin developer structure their plugins.
|
||||
However, the best way to create a plugin is to borrow someone else's. There
|
||||
are Cacti plugin examples on [Cacti's GitHub page](https://github.com/Cacti) and
|
||||
you can find them all over GitHub just by searching.
|
||||
Build against the Cacti branch you support. Use its core pages for request
|
||||
handling, navigation, and forms. Compare a maintained plugin that uses the
|
||||
same hooks, such as [Monitor](https://github.com/Cacti/plugin_monitor).
|
||||
|
||||
## Plugin Creation
|
||||
|
||||
Use the following guidelines for creating your first plugin.
|
||||
Start with the [minimal reference plugin](Plugin-Reference.md). To try a
|
||||
plugin with a visible page, download the example below and extract its
|
||||
`example/` directory under `plugins/` in a disposable installation. Open
|
||||
**Console > Configuration > Plugins**, install **Example Plugin**, and enable
|
||||
it. A user with the **View Example** realm can open the **Example** tab.
|
||||
|
||||

|
||||
|
||||
The page displays **The example page is enabled.** If the tab is missing,
|
||||
check the plugin's status, hook registration, and the user's realm. See
|
||||
[Creating a plugin](Plugin-Creating-Plugins.md#registering-realms).
|
||||
|
||||
## Plugin Namespaces
|
||||
|
||||
All plugins must use namespace isolation either through Classes or using
|
||||
the plugin name in their functions. This prevents name space collisions.
|
||||
Prefix global functions, settings, and plugin-owned tables with the directory
|
||||
name. Use a plugin-specific namespace for classes. Keep the lifecycle function
|
||||
names Cacti looks up, such as `plugin_example_version()`, in the global
|
||||
namespace.
|
||||
|
||||
An example plugin is provided here [Example Plugin](resources/example.tgz).
|
||||
[Download the example plugin](resources/example.tgz).
|
||||
|
||||
## Publishing Your Plugin
|
||||
|
||||
GitHub is the best place to publish your plugins. Learn to use it.
|
||||
Publish an archive that unpacks to the expected directory. Document the tested
|
||||
Cacti and PHP versions, dependencies, permissions, data collection behavior,
|
||||
and what happens to stored data during upgrade or removal. Test the archive
|
||||
itself on a fresh installation and test upgrading from the previous release.
|
||||
|
||||
---
|
||||
|
||||
Copyright (c) 2004-2026 The Cacti Group
|
||||
+1180
-230
File diff suppressed because it is too large.
Load diff
+36
-112
@@ -1,144 +1,68 @@
|
||||
# Reference Plugins
|
||||
|
||||
FIXME The reference plugin is under development. Nothing to see here yet.
|
||||
|
||||
The Reference Plugin(s) are generic plugins that implement key pieces of the
|
||||
Plugin Architecture.
|
||||
|
||||
They are broken down into several separate plugins, each covering different
|
||||
portions of the [Hook API Reference](Plugin-Hook-API-Ref.md).
|
||||
Use this example to check that Cacti can discover, install, and enable a
|
||||
plugin before you add a page, hook, or database table.
|
||||
|
||||
## Standard Files
|
||||
|
||||
The following files should be included in every plugin
|
||||
|
||||
* CHANGELOG
|
||||
* INFO
|
||||
* LICENSE
|
||||
* index.php
|
||||
* README.md
|
||||
* setup.php
|
||||
|
||||
In general, the index.php file example below should be included in every plugin
|
||||
directory as it prevents remote file browsing of your Cacti site.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
/*
|
||||
+-------------------------------------------------------------------------+
|
||||
| Copyright (C) 2004-2026 The Cacti Group |
|
||||
| |
|
||||
| This program is free software; you can redistribute it and/or |
|
||||
| modify it under the terms of the GNU General Public License |
|
||||
| as published by the Free Software Foundation; either version 2 |
|
||||
| of the License, or (at your option) any later version. |
|
||||
| |
|
||||
| This program is distributed in the hope that it will be useful, |
|
||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
| GNU General Public License for more details. |
|
||||
+-------------------------------------------------------------------------+
|
||||
| Cacti: The Complete RRDtool-based Graphing Solution |
|
||||
+-------------------------------------------------------------------------+
|
||||
| This code is designed, written, and maintained by the Cacti Group. See |
|
||||
| about.php and/or the AUTHORS file for specific developer information. |
|
||||
+-------------------------------------------------------------------------+
|
||||
| https://www.cacti.net/ |
|
||||
+-------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
header("Location:../index.php");
|
||||
|
||||
?>
|
||||
```
|
||||
Cacti uses `INFO` for metadata and `setup.php` for lifecycle callbacks. Ship a
|
||||
README with installation and upgrade instructions, a license, and a record of
|
||||
release changes. Add an `index.php` in browsable directories if your web
|
||||
server serves directory indexes. Protect each application page with Cacti's
|
||||
authentication bootstrap.
|
||||
|
||||
## File Structure
|
||||
|
||||
All plugin files should reside under their own respective plugin directory. The
|
||||
example below is for a plugin called 'myplugin'.
|
||||
Create this directory in a test installation. The two files below are
|
||||
sufficient for the example.
|
||||
|
||||
```console
|
||||
myplugin/
|
||||
images/
|
||||
myimage.png
|
||||
index.php
|
||||
lib/
|
||||
index.php
|
||||
functions.php
|
||||
include/
|
||||
index.php
|
||||
settings.php
|
||||
CHANGELOG
|
||||
INFO
|
||||
LICENSE
|
||||
README.md
|
||||
index.php
|
||||
setup.php
|
||||
```text
|
||||
plugins/
|
||||
myplugin/
|
||||
INFO
|
||||
setup.php
|
||||
```
|
||||
|
||||
As the plugin grows, put shared functions in `lib/`, settings in `include/`,
|
||||
and static images in `images/`. Keep the code in `setup.php` small because
|
||||
Cacti loads it during plugin discovery.
|
||||
|
||||
## Contents of Files
|
||||
|
||||
The four core sub-directories included in your plugin should be docs, images,
|
||||
lib, and include. As previously mentioned, each of these directories should
|
||||
include an index.php that points to its parent directory index.php. This way
|
||||
we prevent people from randomly browsing the contents of our web site.
|
||||
Save the following as `plugins/myplugin/INFO`. Set the compatibility floor of
|
||||
your own plugin to the oldest Cacti release you support and test.
|
||||
|
||||
The two main files required for every plugin are the INFO and the setup.php
|
||||
file. Without these two files, the plugin directory will not be recognized as a
|
||||
valid plugin and will be skipped.
|
||||
|
||||
The INFO file is formatted as a Microsoft standard INI file. It contains
|
||||
information about the plugin including its version, author, dependencies,
|
||||
functions, and minimum version of Cacti and other plugins required. Below, you
|
||||
can see a reference INFO file for the myplugin plugin.
|
||||
|
||||
```console
|
||||
```ini
|
||||
[info]
|
||||
name = myplugin
|
||||
version = 1.0
|
||||
longname = My First Plugin
|
||||
author = Depeche Mode
|
||||
email = somewhere@outthere.com
|
||||
homepage = http://www.outthere.com
|
||||
compat = 1.2
|
||||
requires = thold monitor
|
||||
capabilities = online_view:1, online_mgmt:1, offline_view:0, offline_mgmt:0, remote_collect:0
|
||||
author = Example Maintainer
|
||||
homepage = https://www.cacti.net
|
||||
compat = 1.2.32
|
||||
```
|
||||
|
||||
The setup file includes key plugin functions that allow the plugin to be
|
||||
installed, uninstalled, upgraded, etc. Those core functions include:
|
||||
Save the following as `plugins/myplugin/setup.php`.
|
||||
|
||||
```php
|
||||
<?php
|
||||
function plugin_myplugin_install() {
|
||||
}
|
||||
|
||||
function plugin_myplugin_uninstall() {
|
||||
}
|
||||
|
||||
function plugin_myplugin_check_config() {
|
||||
}
|
||||
|
||||
function plugin_myplugin_upgrade() {
|
||||
}
|
||||
|
||||
function plugin_myplugin_version() {
|
||||
$info = parse_ini_file(__DIR__ . '/INFO', true, INI_SCANNER_RAW);
|
||||
|
||||
return $info['info'];
|
||||
}
|
||||
|
||||
?>
|
||||
function plugin_myplugin_install() {
|
||||
// This example has no hooks, realms, or tables to register.
|
||||
}
|
||||
```
|
||||
|
||||
Without these core functions, in your setup.php, your plugin will not fully
|
||||
operate. We will document those functions and what they should include as we
|
||||
continue to document the plugin design principles.
|
||||
|
||||
Any core plugin functions should always be placed in the lib/functions.php file,
|
||||
and settings should go into the include/settings.php file. The plugin
|
||||
architecture allows hooks to be defined that reach into the include/settings.php
|
||||
file. Having those hooks point to the include version of the file will keep
|
||||
Cacti page loads fast. Including too much in the setup.php slows Cacti and
|
||||
should be avoided.
|
||||
Open **Console > Configuration > Plugins**. Install **My First Plugin** and
|
||||
enable it. Verify that the management page shows version **1.0** and the
|
||||
enabled state. This example has no user interface. To add a page or tab, see
|
||||
[Creating a plugin](Plugin-Creating-Plugins.md).
|
||||
|
||||
---
|
||||
|
||||
Copyright (c) 2004-2026 The Cacti Group
|
||||
@@ -365,6 +365,8 @@ the maintained Enterprise Linux instructions.
|
||||
|
||||
5. [Hook API Reference](Plugin-Hook-API-Ref.md)
|
||||
|
||||
6. [Development and Testing](Development-and-Testing.md)
|
||||
|
||||
### Plugins
|
||||
|
||||
1. [Supported Plugins](supported-plugins.md)
|
||||
|
||||
@@ -72,6 +72,10 @@ then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Keep the downloadable plugin alongside its guide in the offline manual.
|
||||
mkdir -p "${BASE_PATH}/${ODIR}/resources" || exit 1
|
||||
cp "${BASE_PATH}/resources/example.tgz" "${BASE_PATH}/${ODIR}/resources/" || exit 1
|
||||
|
||||
# copy css resourse
|
||||
echo "Copying css..."
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
Reference in new issue
Block a user