[INFO] How to add a form field to a device

Support for the Plugin Architecture

Moderators: Developers, Moderators

Post Reply
ariesgeek
Posts: 19
Joined: Mon Nov 27, 2006 1:24 pm

[INFO] How to add a form field to a device

Post by ariesgeek »

Not very intuitive, I had a bit of struggling, figured I'd post a HOWTO on this in the off chance someone searches for something similar 4 years from now. I have a series of scripts setup and want to create various levels of automatic graphing. For example, "No graphs", "No Interface Graphs," and "All Graphs."

We'll do this by example. In our example we'll have a plugin called "test_plugin" and we're adding a form field to accomplish the above.

Note, this assumes you're already familiar with the plugin architecture.

Step 1: Add your column to the host MySQL table:

Code: Select all

ALTER TABLE host ADD COLUMN ( test_plugin_auto_graph_level tinyint(1) unsigned NOT NULL default 1 );
The remaining steps occur in your setup.php file.

Step 2: Add your form element to the visible page:

Code: Select all

function test_plugin_config_form() {
        global $fields_host_edit, $test_plugin_auto_graph_levels;

        $fields_host_edit["test_plugin_auto_graph_level"] = array(
                "method"        => "drop_array",
                "friendly_name" => "Auto-Graph Level",
                "description"   => "Select the Auto-Graph level for this host.",
                "value"         => "|arg1:test_plugin_auto_graph_level|",
                "default"       => "1",
                "array"         => $test_plugin_auto_graph_levels,
                );
}
Step 3: You'll notice the array above. We need to create this and fill it with our possible values for the dropdown box:

Code: Select all

function test_plugin_config_arrays() {
        global $test_plugin_auto_graph_levels;

        $test_plugin_auto_graph_levels = array(
                "0"     => "No Graphs",
                "1"     => "No Interface Graphs",
                "2"     => "All Graphs");
}
Step 4: We can now display our form elements, make sure changes can be saved:

Code: Select all

function test_plugin_api_device_save($save) {
        $save["test_plugin_auto_graph_level"] = $_POST["test_plugin_auto_graph_level"];
        return $save;
}
Modify as you see fit for your own needs. I just hope this helps someone who does some searching at some point.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests