Plugin Development

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Moderators, Developers

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

Plugin Development

#1 Post by kdas » Fri Dec 09, 2011 1:39 am

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: 14817
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Plugin Development

#2 Post by TheWitness » Fri Dec 09, 2011 8:25 am

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 MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

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

Re: Plugin Development

#3 Post by kdas » Fri Dec 09, 2011 8:35 am

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: 14817
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Plugin Development

#4 Post by TheWitness » Fri Dec 09, 2011 8:41 am

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 MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

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

Re: Plugin Development

#5 Post by kdas » Fri Dec 09, 2011 8:51 am

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: 14817
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Plugin Development

#6 Post by TheWitness » Fri Dec 09, 2011 8:56 am

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 MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

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

Re: Plugin Development

#7 Post by kdas » Wed Dec 14, 2011 7:09 am

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: 2782
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Re: Plugin Development

#8 Post by cigamit » Thu Dec 15, 2011 12:48 am

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