Actual requirements for PA 2.x? (also, a bug?)

Support for the Plugin Architecture

Moderators: Developers, Moderators

Post Reply
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Actual requirements for PA 2.x? (also, a bug?)

Post by Howie »

I was just figuring out what the minimal PA 2.x plugin looks like, and managed to kill the plugin management page. Having done a bit of tracing, I found this bit in /plugins.php (v2.4):

Code: Select all

 } else if (function_exists('plugin_' . $file . '_install') && function_exists('plugin_' . $file . '_version')) {
                                        $function = $file . '_version';
                                        $cinfo[$file] = $function();
So it checks for the existence of one function, but then calls a completely different one. The net result being you need both pluginname_version and plugin_pluginname_version for it to work, even though only one of those is required for it to be recognised as a new style plugin, and the possibility of breaking the management page. Isn't that wrong?

(oddly, I get no error on screen or in the httpd error log, either, which seems a bit funny for calling a non-existent function)
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

Ah nevermind - fixed in 2.5 already.
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
NegativeEpsilon
Posts: 9
Joined: Mon Sep 07, 2009 8:07 am

That's odd...

Post by NegativeEpsilon »

Hmm, I've just downloaded cacti-plugin-0.8.7e-PA-2.5 again, to ensure I wasn't using an old version.
The offending line 218 is still there?
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

Having just checked my production Cacti, you're right, it is still there.

Not sure what I was thinking before :roll:
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
NegativeEpsilon
Posts: 9
Joined: Mon Sep 07, 2009 8:07 am

On a side note

Post by NegativeEpsilon »

Heh, I knew I wasn't going mental :)

Did you manage to create that minimal plugin then?
I've just started to upgrade some plugins to the new PA, and seeing as the current reference plugin is a bit lacking, I'm reverse-documenting Thold.

Having cleared this plugin_$name_version issue up, I'm still not clear on how the plugin_$name_check_config function should be used.
Currently, it's called during installation of the plugin, in api_plugin_install. If at that point, the check fails (you return false), the plugin goes into Awaiting Configuration state. This leads me to believe that this function should to be used for checking missing dependencies / manual configuration, before enabling the plugin.
But suppose you then resolve the issue, after clicking the Check link in plugin management, the state is not altered (api_plugin_check_config does not change it).
EDIT: whoops, just noticed that api_plugin_check_config($id) was missing in plugins.php:65, making clicking on Check do nothing :P However, this still doesn't change the above.

Is my reasoning on the usage correct?

Also, I presume that plugin_$name_upgrade is planned for future development, as it currently isn't called from anywhere.
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

Here's my (slightly less) minimal plugin:

Code: Select all

<?php

function plugin_minimal_version()
{
        return array(   'name'          => 'minimal',
                        'version'       => '0.1',
                        'longname'      => 'My Minimal Plugin',
                        'author'        => 'Joe Hacker',
                        'homepage'      => 'http://example.org/myplugin/',
                        'email' => 'joe@example.org',
                        'url'           => 'http://example.org/version.php'
                        );

}

function plugin_minimal_install()
{
}

function minimal_version()
{
        return(plugin_minimal_version());
}
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

I see what you mean about Check. I think your interpretation of what it *should* do is correct, but looking through lib/plugins.php, there is nothing that resets it in there. I suspect that it's not completely finished - this part of the PA has evolved quite a bit over the last few versions, as different plugin requirements appear (e.g. thold moving to PA 2.x, and requiring settings).

I also started writing some dev docs a while ago. I'll dig out what I have and post it. It's nowhere near complete, and I've decided to stop (at least for now), since the PA will be changing shortly as it is integrated into 0.8.8.
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

Here it is. Parts are written up, but obviously big chunks are missing...
Attachments
Writing Cacti Plugins.pdf
(263.85 KiB) Downloaded 586 times
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
NegativeEpsilon
Posts: 9
Joined: Mon Sep 07, 2009 8:07 am

A more thorough example

Post by NegativeEpsilon »

It looks like a good start. If there really are significant architecture changes coming in 0.8.8, perhaps it may be better to hold off writing a detailed guide.
You're probably more familiar with the roadmap progress. Can we expect a new Cacti version shortly?

Here's what I came up with as a template for PA-2.5:

Code: Select all

<?php

/*
    Mandatory management functions
*/
function plugin_skeleton_version() {
    return array('name' => 'skeleton',
        'longname'  => 'Skeleton plugin',   // this will be used as a heading in the plugins table when the plugin is installed
        'version'   => '0.1',
        'author'    => 'NegativeEpsilon',
        'email' => 'delta@example.org',
        'webpage'   => 'http://example.org/',   // PA bug, this will be used in the initial display of an not yet installed plugin
        'homepage'  => 'http://example.org/');  // this address will be inserted into the plugin_config.webpage when installing, and displayed afterwards
}

/*
    PA bug
    plugins.lib:218 first checks:
        function_exists('plugin_' . $file . '_version')
    then calls:
        $f = $file . '_version'; $f();
*/
function skeleton_version() {
    return plugin_skeleton_version();
}

function plugin_skeleton_install() {
/*
    This is called when you press Install in the WebUI.
    It is not strictly mandatory, but if you want to register any hooks & setup tables, do it here
*/

/*
    api_plugin_db_table_create($plugin_name, $table_name, $table_def)
        $plugin_name    - name of the plugin (directory)
        $table_name - name of the table, probably best to use the form $plugin_name . '_whatever',
            as there is a possible 'security' hole with creating a new table that shares the name of an existing table.
            When the plugin would be uninstalled, the table would be dropped (would work even with Cacti core tables :))
        $table_def  - associative array of arrays, containing column definitions
*/
    $table_def = array();
    $table_def['columns'][] = array('name' => 'id', 'type' => 'int', 'NULL' => false, 'auto_increment' => true);
    $table_def['columns'][] = array('name' => 'data', 'type' => 'text');
    $table_def['primary'] = 'id';   // optional
    $table_def['keys'] = array();   // mandatory
    // we could define additional keys with $table_def['keys'][] = array('name' => 'key_name', 'columns' => 'columns')  // mandatory - bug?
    $table_def['type'] = 'MyISAM';  // mandatory
    api_plugin_db_table_create('skeleton', 'skeleton_data', $table_def);
    // if you have a lot of tables to create, it may be better to move this to a separate function, e.g. plugin_$name_setup_database

/*
    api_plugin_register_hook($plugin_name, $hook_name, $function_name, $file)
        $plugin_name    - name of the plugin (directory)
        $hook_name  - name of the hook, as listed in http://docs.cacti.net/plugins:development.hook_api_ref#hook_api_reference
        $function_name  - name of the function, that will be called
        $file   - file, containing the function (path is relative to $this plugin directory)
*/
    api_plugin_register_hook('skeleton', 'page_title', 'skeleton_page_title', 'setup.php');
}


/*
    Optional management functions
*/

function plugin_skeleton_check_config() {
/*
    This is called after plugin_$file_install. You can check for additional dependencies / (mis)configuration here.
    Return TRUE, if everything is OK, the plugin will go into state 'Disabled'.
    Return FALSE otherwise, the plugin will go into state 'Awaiting configuration'

    Caveat emptor:
        PA has a few bugs, that will first cause the 'Check' link on the plugin management page do nothing.
        When you fix that, you have to either manually change the plugin state in plugin_config table,
        or patch the api_plugin_check_config function, becuse the plugin will be stuck in 'Awaiting...'  state.

*/
    return TRUE;
}

function plugin_skeleton_uninstall() {
/*
    Tables and columns created with api_plugin_* calls will be automatically deleted.
    Here you can perform additional cleanup (files on disk, ...)
*/
}


/*
    Hook functions
    These can also be moved to separate files
*/

function skeleton_page_title() {
    // change every page title to contain the server name - useful if you have a ton of windows
    return $_SERVER['SERVER_NAME'] . ' - Cacti';
}

?>
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

Seems about right to me.

That particular functionality is already available over here though :-)

As for changes, I know as much as you. I'm not a dev. That 'guru' thing is put there by the forum, not me. I'm just an old noob :-)

The roadmap on the site says PA integrated in 0.8.8, and TheWitness says the devteam are aiming for 0.8.8 before the end of the year. If you look at the agenda from the 4.CCC.eu, then you can see that there are plans for changes to the plugin system in 0.8.8 too. At the very least, the UI has changed, so anything that is using Cacti's html_* functions would need updating, at a guess.
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests