Welcome to OCS Inventory NG community support, where you can ask questions and receive answers from other members of the community.

Please ask questions only in English or French.

Release 2.12.3 available

The official documentation can be found on https://wiki.ocsinventory-ng.org. Read it before asking your question.

How to delete outdated plugin data?

We have a couple of custom plugins, and they are running as they should returning data like:

<PLUGIN>
<COLUMN>
My value
</COLUMN>
</PLUGIN>

These plugins return data depending on various conditions (f.x. is SQL Server installed), and this works fine until conditions change (someone uninstalls SQL Server).
I've tried returning different kinds of empty records like

<PLUGIN></PLUGIN> and <PLUGIN />
But any existing data persist.

How do I, properly, remove outdated data for an agent?

I have created sort of a workaround with an auto-updated TimeStamp column and have the query in cd_plugin.php filter on this TimeStamp being same as, or higher than, LASTDATE but this doesn't really seem like a proper solution.
Especially since this query is not used by the API so I need to do further filtering there as well.

So how do I return a "Delete any existing data" result for plugin?
in OCS Inventory NG plugins by (120 points)

1 Answer

0 votes

are you using official plugins or sefmade plugins?

the AI says you should use something like

<PLUGIN>
<DELETE>1</DELETE>
</PLUGIN>

in the xml file quote "Return an empty plugin structure when conditions are not met:"

This structure includes a <DELETE> tag with a value of 1, indicating that the existing data should be removed

In your plugin's Map.pm file, add logic to handle the deletion:

if ($xml->{PLUGIN}->{DELETE} && $xml->{PLUGIN}->{DELETE} == 1) {
    # Delete existing data for this plugin
    $dbh->do("DELETE FROM plugins WHERE hardware_id = ? AND name = ?", undef, $deviceId, $pluginName);
} else {
    # Process normal plugin data
    # ...
}

Update your cd_plugin.php file to check for the deletion flag:

if (isset($plugin_data['DELETE']) && $plugin_data['DELETE'] == 1) { // Remove the plugin data from the display continue; }

i'm sure you can hardly do anything with the ai stuff, but maybe it will give you some ideas

ago by (25.2k points)
edited ago by
 
Powered by Question2Answer
...