Plugin Development

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Developers, Moderators

Post Reply
kdas
Posts: 8
Joined: Fri Dec 09, 2011 1:21 am

Plugin Development

Post by kdas »

Hi All,

I am developing a new cacti plug-in. The plug-in will fetch the information from a transporter table and process the data and insert into our custom table at regular intervals.
My method will fetch the information from the source table and sleep for 5 minutes and go back fetch ,insert and its in a loop.

Question :
1. I invoked the method in check _config part and the code is below..
function plugin_das_check_config () {
if(read_config_option('kpip_enable') == 'on') {
calculateTimeStampp(read_config_option('polling_interval'));
}
return true;
}

This makes the enable button to active and not showing the disabling icon. since i have used sleep($polling_interval) method.

2. Instead, can we use any hook ? i have used poller_bottom,Output and called the method. The method is not invoked.

Kindly provide your suggestion on this .
It would be really helpful.

Thanks.

Das.
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Plugin Development

Post by TheWitness »

There are dozens of plugin examples at http://docs.cacti.net. Generally, if you want to do something immediately after the poller finishes, you use poller_bottom. Three good examples of intercepting the data as it's coming in are:

DSStats - Data Source Statistics (Much like Transporter)
THold - Threshold and Alarming
WeatherMap - Cacti Uber Tool

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
kdas
Posts: 8
Joined: Fri Dec 09, 2011 1:21 am

Re: Plugin Development

Post by kdas »

Thanks for the reply.
Can we use sleep method for implementing the polling intervals ?

Or only cron tab is the option ..?


Thanks.

Regards,
G. Karuppiah Das
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Plugin Development

Post by TheWitness »

I attempted to run PHP as a daemon years ago and the Cacti server would crash every fifth day. That was almost 8 years ago and a very old version of PHP. These days, many commercial entities use PHP in daemon mode w/o issues. However, we have found that using something that is not stateful is much safer as there are so many PHP versions floating around. Not using cron would have led to the collapse of the Cacti project years ago as this is a pure volunteer project and we all have day jobs. This is why we do things in cron.

For your part, you can do anything you want. In my day job, I do Cacti 'all the time' and there are daemons all over the place doing interesting things, but Cacti itself is still running in Cron.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
kdas
Posts: 8
Joined: Fri Dec 09, 2011 1:21 am

Re: Plugin Development

Post by kdas »

Thanks again for the response.

My problem with sleep, when i click the enable part of the plug-in the method fetch ,process, insert into custom table and goes to sleep so on....
With this,I am not getting the disable icon in the Action column of Plugin Management.

Even though my plug-in does the required thing, it does not allow the user to disable

Do you have any suggestion on this?

Regards
Das
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Plugin Development

Post by TheWitness »

There is a second option on the 'read_config_option' to reread the active status from the database instead of the stored value. Use that in your plugin and you can exit or not start if the user disables the plugin.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
kdas
Posts: 8
Joined: Fri Dec 09, 2011 1:21 am

Re: Plugin Development

Post by kdas »

I have planned to execute the sleep method in a background process. Below is my code.
Code:
$extra_args = "-q " . $config["base_path"] . "/plugins/testing1/poll.php >> 2>&1 ";
exec_background($command_string, $extra_args);

poll.php file:
#!/usr/bin/php -q
<?php

echo " Hello wordl";
cacti_log(" Hellow World ",TRUE,TESTING1);


?>

Just updating the log.
The code in poll.php is not getting executed.

Is there anything wrong?

Thanks.

Regards,
Das
cigamit
Developer
Posts: 3368
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Re: Plugin Development

Post by cigamit »

Can we backup a few steps and go back over exactly what you are trying to accomplish? From what I have read, it seems more like you should just use the poller_bottom hook that runs at the end of the poller (or poller_top if you want it before or on a more precise schedule). From there, you can run any function from your code that you like. Since the poller runs on an automated Cron, you can get a 5 minute interval pretty easily.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests